Changeset 1817 in josm
- Timestamp:
- 2009-07-20T20:19:22+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r1814 r1817 39 39 import org.openstreetmap.josm.data.osm.Way; 40 40 import org.openstreetmap.josm.gui.ExtendedDialog; 41 import org.openstreetmap.josm.gui.layer.Layer; 42 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 41 43 import org.openstreetmap.josm.tools.GBC; 42 44 import org.openstreetmap.josm.tools.Pair; … … 48 50 * @author Imi 49 51 */ 50 public class CombineWayAction extends JosmAction implements SelectionChangedListener {52 public class CombineWayAction extends JosmAction implements SelectionChangedListener,LayerChangeListener { 51 53 52 54 public CombineWayAction() { … … 54 56 Shortcut.registerShortcut("tools:combineway", tr("Tool: {0}", tr("Combine Way")), KeyEvent.VK_C, Shortcut.GROUP_EDIT), true); 55 57 DataSet.selListeners.add(this); 58 Layer.listeners.add(this); 59 refreshEnabled(); 56 60 } 57 61 58 62 public void actionPerformed(ActionEvent event) { 63 if (getCurrentDataSet() == null) 64 return; 59 65 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 60 66 LinkedList<Way> selectedWays = new LinkedList<Way>(); … … 298 304 */ 299 305 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 300 boolean first = false; 301 for (OsmPrimitive osm : newSelection) { 306 refreshEnabled(); 307 } 308 309 protected void refreshEnabled() { 310 if (getCurrentDataSet() == null) { 311 setEnabled(false); 312 return; 313 } 314 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 315 int numWays = 0; 316 317 for (OsmPrimitive osm : selection) 302 318 if (osm instanceof Way) { 303 if (first) { 304 setEnabled(true); 305 return; 306 } 307 first = true; 308 } 309 } 310 setEnabled(false); 311 } 319 numWays++; 320 } 321 setEnabled(numWays >= 2); 322 } 323 324 325 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 326 refreshEnabled(); 327 } 328 329 public void layerAdded(Layer newLayer) { 330 refreshEnabled(); 331 332 } 333 334 public void layerRemoved(Layer oldLayer) { 335 refreshEnabled(); 336 } 337 312 338 }
Note:
See TracChangeset
for help on using the changeset viewer.