Changeset 4792 in josm for trunk/src/org
- Timestamp:
- 2012-01-14T16:54:57+01:00 (13 years ago)
- 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 10 10 import java.awt.event.MouseAdapter; 11 11 import java.awt.event.MouseEvent; 12 import java.util.Arrays; 13 import java.util.Collection; 12 14 13 15 import javax.swing.AbstractAction; … … 25 27 import org.openstreetmap.josm.actions.AutoScaleAction; 26 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 import org.openstreetmap.josm.data.osm.Way; 27 30 import org.openstreetmap.josm.gui.MapView; 28 31 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 32 import org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction; 29 33 import org.openstreetmap.josm.gui.layer.Layer; 30 34 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 40 44 protected JPopupMenu popupMenu; 41 45 private ZoomToAction zoomToAction; 46 private ZoomToGapAction zoomToGap; 42 47 43 48 /** … … 132 137 * 133 138 */ 134 class SelectPreviousColumnCellAction extends AbstractAction {139 private class SelectPreviousColumnCellAction extends AbstractAction { 135 140 136 141 public void actionPerformed(ActionEvent e) { … … 163 168 getSelectionModel().addListSelectionListener(zoomToAction); 164 169 popupMenu.add(zoomToAction); 170 zoomToGap = new ZoomToGapAction(); 171 MapView.addLayerChangeListener(zoomToGap); 172 getSelectionModel().addListSelectionListener(zoomToGap); 173 popupMenu.add(zoomToGap); 165 174 } 166 175 return popupMenu; … … 169 178 public void unlinkAsListener() { 170 179 MapView.removeLayerChangeListener(zoomToAction); 180 MapView.removeLayerChangeListener(zoomToGap); 171 181 } 172 182 … … 189 199 } 190 200 191 class ZoomToAction extends AbstractAction implements LayerChangeListener, ListSelectionListener {201 private class ZoomToAction extends AbstractAction implements LayerChangeListener, ListSelectionListener { 192 202 public ZoomToAction() { 193 203 putValue(NAME, tr("Zoom to")); … … 240 250 } 241 251 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 242 315 protected MemberTableModel getMemberTableModel() { 243 316 return (MemberTableModel) getModel(); 244 317 } 245 318 246 class DblClickHandler extends MouseAdapter { 319 private class DblClickHandler extends MouseAdapter { 320 247 321 protected void setSelection(MouseEvent e) { 248 322 int row = rowAtPoint(e.getPoint()); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r4337 r4792 179 179 return members.get(rowIndex).getMember(); 180 180 case 2: 181 return wayConnection(rowIndex);181 return getWayConnection(rowIndex); 182 182 } 183 183 // should not happen … … 868 868 } 869 869 870 private WayConnectionType wayConnection(int i) {870 WayConnectionType getWayConnection(int i) { 871 871 if (connectionType == null) { 872 872 updateLinks();
Note:
See TracChangeset
for help on using the changeset viewer.