Changeset 8900 in josm for trunk


Ignore:
Timestamp:
2015-10-18T23:16:54+02:00 (9 years ago)
Author:
Don-vip
Message:

fix #11986, fix #11987, fix #11988: Patches by michael2402:

  • MapStatus: Use a BlockingQueue for cleaner waiting
  • Comment in AutoScaleAction#zoomTo is wrong
  • Documentation for AutoScaleAction
Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r8846 r8900  
    4343public class AutoScaleAction extends JosmAction {
    4444
     45    /**
     46     * A list of things we can zoom to. The zoom target is given depending on the mode.
     47     */
    4548    public static final Collection<String> MODES = Collections.unmodifiableList(Arrays.asList(
    4649        marktr(/* ICON(dialogs/autoscale/) */ "data"),
     
    5356        marktr(/* ICON(dialogs/autoscale/) */ "next")));
    5457
     58    /**
     59     * One of {@link #MODES}. Defines what we are zooming to.
     60     */
    5561    private final String mode;
    5662
     
    8389    }
    8490
     91    /**
     92     * Zooms the view to display the given set of primitives.
     93     * @param sel The primitives to zoom to, e.g. the current selection.
     94     */
    8595    public static void zoomTo(Collection<OsmPrimitive> sel) {
    8696        BoundingXYVisitor bboxCalculator = new BoundingXYVisitor();
    8797        bboxCalculator.computeBoundingBox(sel);
    88         // increase bbox by 0.001 degrees on each side. this is required
     98        // increase bbox. This is required
    8999        // especially if the bbox contains one single node, but helpful
    90100        // in most other cases as well.
     
    95105    }
    96106
     107    /**
     108     * Performs the auto scale operation of the given mode without the need to create a new action.
     109     * @param mode One of {@link #MODES}.
     110     */
    97111    public static void autoScale(String mode) {
    98112        new AutoScaleAction(mode, false).autoScale();
     
    172186    }
    173187
     188    /**
     189     * Performs this auto scale operation for the mode this action is in.
     190     */
    174191    public void autoScale() {
    175192        if (Main.isDisplayingMapView()) {
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r8855 r8900  
    3333import java.util.List;
    3434import java.util.TreeSet;
     35import java.util.concurrent.BlockingQueue;
     36import java.util.concurrent.LinkedBlockingQueue;
    3537
    3638import javax.swing.AbstractAction;
     
    348350        private MapFrame parent;
    349351
     352        private BlockingQueue<MouseState> incommingMouseState = new LinkedBlockingQueue<>();
     353
     354        private Point lastMousePos;
     355
    350356        Collector(MapFrame parent) {
    351357            this.parent = parent;
     
    360366            try {
    361367                for (;;) {
    362 
    363                     final MouseState ms = new MouseState();
    364                     synchronized (this) {
    365                         // TODO Would be better if the timeout wasn't necessary
    366                         try {
    367                             wait(1000);
    368                         } catch (InterruptedException e) {
    369                             // Occurs frequently during JOSM shutdown, log set to trace only
    370                             Main.trace("InterruptedException in "+MapStatus.class.getSimpleName());
     368                    try {
     369                        final MouseState ms = incommingMouseState.take();
     370                        if (parent != Main.map)
     371                            return; // exit, if new parent.
     372
     373                        // Do nothing, if required data is missing
     374                        if (ms.mousePos == null || mv.center == null) {
     375                            continue;
    371376                        }
    372                         ms.modifiers = mouseState.modifiers;
    373                         ms.mousePos = mouseState.mousePos;
    374                     }
    375                     if (parent != Main.map)
    376                         return; // exit, if new parent.
    377 
    378                     // Do nothing, if required data is missing
    379                     if (ms.mousePos == null || mv.center == null) {
    380                         continue;
    381                     }
    382 
    383                     try {
     377
    384378                        EventQueue.invokeAndWait(new CollectorWorker(ms));
    385379                    } catch (InterruptedException e) {
     
    650644            return l;
    651645        }
     646
     647        /**
     648         * Called whenever the mouse position or modifiers changed.
     649         * @param mousePos The new mouse position. <code>null</code> if it did not change.
     650         * @param modifiers The new modifiers.
     651         */
     652        public synchronized void updateMousePosition(Point mousePos, int modifiers) {
     653            MouseState ms = new MouseState();
     654            if (mousePos == null) {
     655                ms.mousePos = lastMousePos;
     656            } else {
     657                lastMousePos = mousePos;
     658            }
     659            // remove mouse states that are in the queue. Our mouse state is newer.
     660            incommingMouseState.clear();
     661            incommingMouseState.offer(ms);
     662        }
    652663    }
    653664
     
    660671        private int modifiers;
    661672    }
    662     /**
    663      * The last sent mouse movement event.
    664      */
    665     private transient MouseState mouseState = new MouseState();
    666673
    667674    private transient AWTEventListener awtListener = new AWTEventListener() {
     
    671678                    ((InputEvent) event).getComponent() == mv) {
    672679                synchronized (collector) {
    673                     mouseState.modifiers = ((InputEvent) event).getModifiersEx();
     680                    int modifiers = ((InputEvent) event).getModifiersEx();
     681                    Point mousePos = null;
    674682                    if (event instanceof MouseEvent) {
    675                         mouseState.mousePos = ((MouseEvent) event).getPoint();
     683                        mousePos = ((MouseEvent) event).getPoint();
    676684                    }
    677                     collector.notifyAll();
     685                    collector.updateMousePosition(mousePos, modifiers);
    678686                }
    679687            }
     
    685693        public void mouseMoved(MouseEvent e) {
    686694            synchronized (collector) {
    687                 mouseState.modifiers = e.getModifiersEx();
    688                 mouseState.mousePos = e.getPoint();
    689                 collector.notifyAll();
     695                collector.updateMousePosition(e.getPoint(), e.getModifiersEx());
    690696            }
    691697        }
     
    700706        @Override public void keyPressed(KeyEvent e) {
    701707            synchronized (collector) {
    702                 mouseState.modifiers = e.getModifiersEx();
    703                 collector.notifyAll();
     708                collector.updateMousePosition(null, e.getModifiersEx());
    704709            }
    705710        }
Note: See TracChangeset for help on using the changeset viewer.