Changeset 4792 in josm


Ignore:
Timestamp:
2012-01-14T16:54:57+01:00 (8 years ago)
Author:
simon04
Message:

fix #7168 - add a "zoom to gap" functionality to the relation editor

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r4238 r4792  
    1010import java.awt.event.MouseAdapter;
    1111import java.awt.event.MouseEvent;
     12import java.util.Arrays;
     13import java.util.Collection;
    1214
    1315import javax.swing.AbstractAction;
     
    2527import org.openstreetmap.josm.actions.AutoScaleAction;
    2628import org.openstreetmap.josm.data.osm.OsmPrimitive;
     29import org.openstreetmap.josm.data.osm.Way;
    2730import org.openstreetmap.josm.gui.MapView;
    2831import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
     32import org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction;
    2933import org.openstreetmap.josm.gui.layer.Layer;
    3034import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    4044    protected JPopupMenu popupMenu;
    4145    private ZoomToAction zoomToAction;
     46    private ZoomToGapAction zoomToGap;
    4247
    4348    /**
     
    132137     *
    133138     */
    134     class SelectPreviousColumnCellAction extends AbstractAction {
     139    private class SelectPreviousColumnCellAction extends AbstractAction {
    135140
    136141        public void actionPerformed(ActionEvent e) {
     
    163168            getSelectionModel().addListSelectionListener(zoomToAction);
    164169            popupMenu.add(zoomToAction);
     170            zoomToGap = new ZoomToGapAction();
     171            MapView.addLayerChangeListener(zoomToGap);
     172            getSelectionModel().addListSelectionListener(zoomToGap);
     173            popupMenu.add(zoomToGap);
    165174        }
    166175        return popupMenu;
     
    169178    public void unlinkAsListener() {
    170179        MapView.removeLayerChangeListener(zoomToAction);
     180        MapView.removeLayerChangeListener(zoomToGap);
    171181    }
    172182
     
    189199    }
    190200
    191     class ZoomToAction extends AbstractAction implements LayerChangeListener, ListSelectionListener {
     201    private class ZoomToAction extends AbstractAction implements LayerChangeListener, ListSelectionListener {
    192202        public ZoomToAction() {
    193203            putValue(NAME, tr("Zoom to"));
     
    240250    }
    241251
     252    private class ZoomToGapAction extends AbstractAction implements LayerChangeListener, ListSelectionListener {
     253
     254        public ZoomToGapAction() {
     255            putValue(NAME, tr("Zoom to Gap"));
     256            putValue(SHORT_DESCRIPTION, tr("Zoom to the gap in the way sequence"));
     257            updateEnabledState();
     258        }
     259
     260        private WayConnectionType getConnectionType() {
     261            return getMemberTableModel().getWayConnection(getSelectedRows()[0]);
     262        }
     263
     264        private final Collection<Direction> connectionTypesOfInterest = Arrays.asList(WayConnectionType.Direction.FORWARD, WayConnectionType.Direction.BACKWARD);
     265
     266        private boolean hasGap() {
     267            WayConnectionType connectionType = getConnectionType();
     268            return connectionTypesOfInterest.contains(connectionType.direction)
     269                    && !(connectionType.linkNext && connectionType.linkPrev);
     270        }
     271
     272        @Override
     273        public void actionPerformed(ActionEvent e) {
     274            WayConnectionType connectionType = getConnectionType();
     275            Way way = (Way) getMemberTableModel().getReferredPrimitive(getSelectedRows()[0]);
     276            if (!connectionType.linkPrev) {
     277                layer.data.setSelected(WayConnectionType.Direction.FORWARD.equals(connectionType.direction)
     278                        ? way.firstNode() : way.lastNode());
     279                AutoScaleAction.autoScale("selection");
     280            } else if (!connectionType.linkNext) {
     281                layer.data.setSelected(WayConnectionType.Direction.FORWARD.equals(connectionType.direction)
     282                        ? way.lastNode() : way.firstNode());
     283                AutoScaleAction.autoScale("selection");
     284            }
     285        }
     286
     287        private void updateEnabledState() {
     288            setEnabled(Main.main != null
     289                    && Main.main.getEditLayer() == layer
     290                    && getSelectedRowCount() == 1
     291                    && hasGap());
     292        }
     293
     294        @Override
     295        public void valueChanged(ListSelectionEvent e) {
     296            updateEnabledState();
     297        }
     298
     299        @Override
     300        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     301            updateEnabledState();
     302        }
     303
     304        @Override
     305        public void layerAdded(Layer newLayer) {
     306            updateEnabledState();
     307        }
     308
     309        @Override
     310        public void layerRemoved(Layer oldLayer) {
     311            updateEnabledState();
     312        }
     313    }
     314
    242315    protected MemberTableModel getMemberTableModel() {
    243316        return (MemberTableModel) getModel();
    244317    }
    245318
    246     class DblClickHandler extends MouseAdapter {
     319    private class DblClickHandler extends MouseAdapter {
     320
    247321        protected void setSelection(MouseEvent e) {
    248322            int row = rowAtPoint(e.getPoint());
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r4337 r4792  
    179179            return members.get(rowIndex).getMember();
    180180        case 2:
    181             return wayConnection(rowIndex);
     181            return getWayConnection(rowIndex);
    182182        }
    183183        // should not happen
     
    868868    }
    869869
    870     private WayConnectionType wayConnection(int i) {
     870    WayConnectionType getWayConnection(int i) {
    871871        if (connectionType == null) {
    872872            updateLinks();
Note: See TracChangeset for help on using the changeset viewer.