September 2012


Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Wed, 5 Sep 2012 00:44:59 -0400
text/plain (76 lines)
Actually, it's a little more complicated than this.  

1. The minimum and maximum values of the scroll bars are buggy and incorrect.
2. It's flashy because changing their values like this causes a repaint in which the background is filled first. :-(

You could do it instead using scrollRectToVisible but it's complicated to compute the value you want, and it doesn't fix #2.

So to fix #1 you have to test the minimum and maximum.  Something like this:

        JScrollBar horizontal = display.display.getHorizontalScrollBar();
        horizontalCurrent = horizontal.getValue();
        horizontalMaximum = horizontal.getValue();
        horizontalMinimum = horizontal.getValue();

        JScrollBar vertical = display.display.getVerticalScrollBar();
        verticalCurrent = vertical.getValue();
        verticalMaximum = vertical.getValue();
        verticalMinimum = vertical.getValue();

Now you have proper min, max, and current values for the horizontal and vertical.  But you're about to get hit with a flashy repaint.  You can fix this by setting the scroll mode to JViewport.BACKINGSTORE_SCROLL_MODE and then changing it back later.  I do it by first calling 


... then doing the code above, then after I've got my info, or have set the scrollbars as I like, I then finally say:

        SwingUtilities.invokeLater(new Runnable() 
		{ public void run() { port.setScrollMode(JViewport.BLIT_SCROLL_MODE); } });

What a hack.  Anyway, this appears to work right.  Since it's such a mess to do programmatically, I'm adding in a new API where you can scroll to a certain percentage value (between 0.0 and 1.0) both horizontally and vertically, and also test the current percentage value.  Note that this is DIFFERENT from changing the origin offset, which is also available.  The origin offset just changes where field portrayals think (0,0) is.  It doesn't change the Display2D's belief about what it's displaying scroll-wise.


On Sep 4, 2012, at 7:35 PM, Sean Luke wrote:

> Changing the viewport is not a built-in feature to MASON, and it's a little complicated: the scroll value will depend on the current scale.  And it's further complicated by multiple overlaid field portrayals.
> So at the moment here's what you can do.  At any point the horizontal (and vertical) scrollbar has a minimum and a maximum, which you can get like this:
> JScrollBar h = display.display.getHorizontalScrollBar();
> Now you can change the bar value:
> int min = h.getMinimum();
> int max = h.getMaximum();
> int currentValue = h.getValue();
> h.setValue(  /* some value between min and max inclusive */ );
> If there's no bar being displayed (maybe you're scaled way out), you'll still get min and max values but the value will always be 0 and won't change even if you set it.  No warnings though, stupid Java.
> After you set the value you have to clue the JScrollPane in that its scrollbars changed.  It's too dumb to realize this :-(  The easiest way to do this is to set the JScrollPane's viewport to the inside display again.  Maybe repaint for good measure though it's probably not needed:
> display.display.getViewport().setView(display.insideDisplay);
> display.repaint();
> At this point the field should have been scrolled to your desired location.
> So the question is: what API would you like in Display2D to do this automatically for you?  We can't scroll to a value because the min and max values change depending on the degree of scaling at the moment.  Maybe scroll to a percentage/proportion value?
> Sean
> On Sep 4, 2012, at 1:37 PM, Joey Harrison wrote:
>> We're working on a model with a very large map and investigating a tiny area within it. Every time we run the model, it takes a long time to pan, zoom, pan, zoom, ... until the right area is in view. Has anyone found a way to save a given viewport and have it come up that way on start up?
>> Thanks,
>> Joey