Changeset 2759 in josm for trunk


Ignore:
Timestamp:
2010-01-07T19:29:53+01:00 (10 years ago)
Author:
mjulius
Message:

Make the new zoom previous and next actions listen to zoom changes and set enabled state.

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r2758 r2759  
    1818import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1919import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     20import org.openstreetmap.josm.gui.MapView;
    2021import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    2122import org.openstreetmap.josm.gui.layer.Layer;
     
    226227                setEnabled(true);
    227228            }
     229        } else if ("previous".equals(mode)) {
     230            setEnabled(Main.map != null && Main.map.mapView != null && Main.map.mapView.hasZoomUndoEntries());
     231        } else if ("next".equals(mode)) {
     232            setEnabled(Main.map != null && Main.map.mapView != null && Main.map.mapView.hasZoomRedoEntries());
    228233        } else {
    229234            setEnabled(
     
    240245        }
    241246    }
     247
     248    @Override
     249    protected void installAdapters() {
     250        super.installAdapters();
     251        // make this action listen to zoom change events
     252        //
     253        zoomChangeAdapter = new ZoomChangeAdapter();
     254        MapView.addZoomChangeListener(zoomChangeAdapter);
     255        initEnabledState();
     256    }
     257
     258    /**
     259     * Adapter for selection change events
     260     *
     261     */
     262    private class ZoomChangeAdapter implements MapView.ZoomChangeListener {
     263        public void zoomChanged() {
     264            updateEnabledState();
     265        }
     266    }
     267
     268    private ZoomChangeAdapter zoomChangeAdapter;
    242269}
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r2621 r2759  
    139139    }
    140140
    141     private void installAdapters() {
     141    protected void installAdapters() {
    142142        // make this action listen to layer change and selection change events
    143143        //
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r2758 r2759  
    1313import java.util.List;
    1414import java.util.TreeMap;
     15import java.util.concurrent.CopyOnWriteArrayList;
    1516
    1617import javax.swing.JComponent;
     
    3839 */
    3940public class NavigatableComponent extends JComponent implements Helpful {
     41
     42    /**
     43     * Interface to notify listeners of the change of the zoom area.
     44     */
     45    public interface ZoomChangeListener {
     46        void zoomChanged();
     47    }
     48
     49    /**
     50     * the zoom listeners
     51     */
     52    private static final CopyOnWriteArrayList<ZoomChangeListener> zoomChangeListeners = new CopyOnWriteArrayList<ZoomChangeListener>();
     53
     54    /**
     55     * Removes a zoom change listener
     56     *
     57     * @param listener the listener. Ignored if null or already absent
     58     */
     59    public static void removeZoomChangeListener(NavigatableComponent.ZoomChangeListener listener) {
     60        zoomChangeListeners.remove(listener);
     61    }
     62
     63    /**
     64     * Adds a zoom change listener
     65     *
     66     * @param listener the listener. Ignored if null or already registered.
     67     */
     68    public static void addZoomChangeListener(NavigatableComponent.ZoomChangeListener listener) {
     69        if (listener != null) {
     70            zoomChangeListeners.addIfAbsent(listener);
     71        }
     72    }
     73
     74    protected static void fireZoomChanged() {
     75        for (ZoomChangeListener l : zoomChangeListeners) {
     76            l.zoomChanged();
     77        }
     78    }
     79
    4080
    4181    public static final int snapDistance = Main.pref.getInteger("node.snap-distance", 10);
     
    267307
    268308        repaint();
     309        fireZoomChanged();
    269310    }
    270311
     
    367408            zoomNoUndoTo(zoom.getCenterEastNorth(), zoom.getScale());
    368409        }
     410    }
     411
     412    public boolean hasZoomUndoEntries() {
     413        return !zoomUndoBuffer.isEmpty();
     414    }
     415
     416    public boolean hasZoomRedoEntries() {
     417        return !zoomRedoBuffer.isEmpty();
    369418    }
    370419
Note: See TracChangeset for help on using the changeset viewer.