Skip to main content

JXScrollMap Questions

7 replies [Last post]
aephyr
Offline
Joined: 2009-11-20

> I also posted about moving an
> [url=http://www.java.net/blog/kschaefe/archive/2010/09
> /22/swingx-jxscrollmap-incubator]incubator component[/url] into SwingX.

Is the implementation abstract enough to work with only a JViewport or does it require a JScollPane and the corner button? The press button and drag on popup behavior has me worried that it is the latter? BTW, not too thrill with that behavior, took me a few tries cos, no, I didn't read the how-to at the bottom of the demo. I was expecting a simple click on the button and moving the mouse about would do the trick, but you have to hold down the mouse button - bit of a drag (bad pun, sorry).

There are more reasons to change the behavior other than the fact that I hate it. For example: implementing a right click on the component to show the JXScrollMap at the point of the click or registering a key binding (e.g VK_CONTEXT_MENU) to show the JXScrollMap centered on the JViewport. That brings me to another point, the JXScrollMap should be controllable through the keyboard via the arrow keys. perhaps a unit scroll for an arrow press and a block scroll for an CTRL + arrow press.

One last question/possible RFE: Is there a way to control the size of the "hotspot" rectangle? If the component in the JViewport is sufficiently large (perhaps a map?) then the "you are here" rectangle might become too small. The way out would be to put the JXScrollMap in a JViewport itself that shows a larger portion of original component, but not necessarily all of it and dragging at the edges or using the arrow keys would scroll the JXScrollMap.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kleopatra
Offline
Joined: 2003-06-11

1+ for separating

We already have a negative example (not exactly the same, but similar: combined button and popup) in the column control of the table. In hindsight, I would regard that as a design accident - which I tried to patch sometime, but the outcome isn't really satisfying.

Cheers
Jeanette

kschaefe
Offline
Joined: 2006-06-08

Yeah, I think I'm there too. It's good to get the examples ahead to time to build good use cases. I like to try to figure out a decent way to handle the button aspect in a way that's reusable (such that JXColorSelectionButton goes away(?) and uses the same mechanism).

Want to capture some other ideas that were mentioned elsewhere:
Remove the mouse pointer and use the "window" as the mouse when moving the viewport view.
If we tackle keyboard navigation, we need to respect Scrollables.

Good conversation folks!

Karl

tl5
Offline
Joined: 2008-11-20

This component is working great!
I use it with a JXTable. It's getting slow with big tables, because it's rendering the whole content before displaying it in the ScrollMap. Does anyone knows a way to speed up the Renderer?

A NullPointerException gets thrown in the updateViewportViewPosition() method in the Handler class of BasicScrollMapPopup.java while clicking ferocious and very fast on the icon.
A null check like this fixes it:
[code]
Rectangle r = (Rectangle) shapePainter.getShape();
if ( r == null )
return;
Point p = r.getLocation();
[/code]

kschaefe
Offline
Joined: 2006-06-08

Good questions. So good in fact, I thought I would branch them into their own topic to kickstart more discussion.

I am taking a few days for some post-JavaOne fun, but early next week I will place the JavaDoc up to begin a more formal review of the component. Until that happen, here are the quick answers:

JXScrollMap does not need to be placed in a JScrollPane. In fact, I fully expect that most users of it would rather forego JScrollPane altogether when they use it. JXScrollMap will always stay synchronized with the view in the viewport. Furthermore, if it is embedded inside a JScrollPane, it will also synchronize with the viewport, so if the viewport changes the component is up-to-date.

We can consider another activation opens. Personally, I like the "draggy" nature, but I am used to that behavior. As you say, there may other use cases to force to work another way. Just random thinking, perhaps we could get away with adding the MenuElement interface and see how it works.... I doubt we could really make the component truly functional in a keyboard only scenario, but I hadn't really given much thought to that. Your ideas seem really good.

The size of the view rectangle is proportional to the size of the viewport. The viewport is displayed in the popup, scaled-down. The maximum size of the popup is configurable, so it would be possible to alter it for really large items. So, the hook is there for client code to do that already.

All of the code is currently in my incubator for folks to play with:
https://jdnc-incubator.dev.java.net/source/browse/jdnc-incubator/trunk/s...

Karl

aephyr
Offline
Joined: 2009-11-20

I think there are two components here masquerading as one. Which isn't necessarily a problem, but with the current setup it is impossible to use the slave independently. The so-called slave is the JXPanel imagePanel in BasicScrollMapPopup and is also the component that I think of as the "real" JXScrollMap. That JXPanel should be the JXScrollMap and another component (JXScrollMapButton?) could be made to provide the button->JXScrollMap popup functionality. A JXScrollMapButton without an independent JXScrollMap is like if swing contained a JComboBox, but no JList. It should be possible to add the component that shows in the popup to a Container just as one can add the component that shows up in JComboBox's popup (a JList) to a Container.

You can keep the drag behavior, but just transfer the drag handling from the button component to the imagePanel component. I never did like the requirement of keeping the mouse pressed to keep a popup open. Do any look and feels do that? I suppose you could keep that functionality for those look and feels by forwarding dragged events on the button to drag events on the imagePanel programmatically.

Perhaps there could be some kind of convenience method similar to JOptionPane's createDialog(..) or JFileChooser's showDialog(..) method except for popups so that developers can do as they please with the popup (e.g. the right click to show popup as I described earlier).

kschaefe
Offline
Joined: 2006-06-08

Hmm, I had similar concerns when working with it initially. I am not completely sold one way or the other. However, there is a clear use-case for a list and a drop-down. The fact that the drop-down reuses the list is simply an implementation detail; there is no easy way to get at that list.

Before splitting out the "popup" from the "button," we should asked, is one going to be used without the other? I banged this idea around quite a bit and had a difficult time coming up with something.

So, what use-cases do you see using this in an environment where it does not popup? Forget mousing concerns, you may have. I just want to know where this would be useful on its own embedded into the display.

Karl

aephyr
Offline
Joined: 2009-11-20

All analogies are false, the point was simply that you can display a list of objects without a JComboBox and you should be able to display a JXScrollMap (the "real" one) without the button.

As for whether it will actually be used without a popup is to be seen in the wild, though note that it still may be desirable to display the popup without the button. The component reminds me of the mini-map display in many games. Perhaps a developer would want to use a similar thing for a real-world map, below or to the side of the main map with other controls that toggle certain details and the such. The JXScrollMap would serve as a "you are here" indicator with the added benefit of being able to jump anywhere else on the map instantly.

Also, perhaps a developer doesn't want to use the popup that you use. For instance, they may wish to use PopupFactory to create their own popup that doesn't disappear so easily as JPopupMenu does. Or perhaps they wish to add other controls to the popup.

JOptionPane and JFileChooser aren't expected to be used without a JDialog, yet they are still simple components with which you can do anything. I actually have used both of those without a JDialog. It was for a Look and Feel customizer that created a preview for every swing component grouped variously among tabs.