Changeset 1814 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
- Timestamp:
- 2009-07-19T19:04:49+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r1722 r1814 43 43 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 44 44 import org.openstreetmap.josm.gui.SideButton; 45 import org.openstreetmap.josm.gui.layer.Layer; 46 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 47 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 45 48 import org.openstreetmap.josm.tools.Shortcut; 46 49 … … 52 55 * @author imi 53 56 */ 54 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener {57 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener { 55 58 56 59 private static final int SELECTION_HISTORY_SIZE = 10; … … 80 83 public SelectionListDialog() { 81 84 super(tr("Current Selection"), "selectionlist", tr("Open a selection list window."), 82 Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);85 Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 83 86 84 87 selectionHistory = new LinkedList<Collection<? extends OsmPrimitive>>(); … … 89 92 @Override 90 93 public void mouseClicked(MouseEvent e) { 91 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) 94 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { 92 95 updateMap(); 96 } 93 97 } 94 98 … … 112 116 tr("Set the selected elements on the map to the selected items in the list above."), 113 117 new ActionListener() { 114 115 116 117 118 public void actionPerformed(ActionEvent e) { 119 updateMap(); 120 } 121 }); 118 122 buttonPanel.add(selectButton); 119 123 BasicArrowButton selectionHistoryMenuButton = createArrowButton(selectButton); … … 134 138 buttonPanel.add(new SideButton(marktr("Reload"), "refresh", "SelectionList", tr("Refresh the selection list."), 135 139 new ActionListener() { 136 137 selectionChanged(Main.ds.getSelected());138 139 140 public void actionPerformed(ActionEvent e) { 141 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 142 } 143 })); 140 144 141 145 searchButton = new SideButton(marktr("Search"), "search", "SelectionList", tr("Search for objects."), … … 159 163 popupMenu.add(zoomToSelection); 160 164 161 selectionChanged(Main.ds.getSelected()); 165 if (Main.main.getCurrentDataSet() != null) { 166 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 167 } 162 168 163 169 DataSet.selListeners.add(this); 170 Layer.listeners.add(this); 164 171 } 165 172 … … 179 186 public void setVisible(boolean b) { 180 187 super.setVisible(b); 181 if (b) 182 selectionChanged(Main.ds.getSelected()); 188 if (b && Main.main.getCurrentDataSet() != null) { 189 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 190 } 183 191 } 184 192 … … 204 212 for (int i = 0; i < selected.length; i++) { 205 213 Object o = list.get(selected[i]); 206 if (o instanceof OsmPrimitive) 214 if (o instanceof OsmPrimitive) { 207 215 ((OsmPrimitive) o).visit(box); 216 } 208 217 } 209 218 if (box.getBounds() == null) … … 247 256 list.setSize(selArr.length); 248 257 int i = 0; 249 for (OsmPrimitive osm : selArr) 258 for (OsmPrimitive osm : selArr) { 250 259 list.setElementAt(osm, i++); 260 } 251 261 if (selectionHistory != null && newSelection.size() > 0 && !newSelection.equals(historyIgnoreSelection)) { 252 262 historyIgnoreSelection = null; … … 259 269 } 260 270 selectionHistory.addFirst(newSelection); 261 while (selectionHistory.size() > SELECTION_HISTORY_SIZE) 271 while (selectionHistory.size() > SELECTION_HISTORY_SIZE) { 262 272 selectionHistory.removeLast(); 273 } 263 274 } 264 275 … … 267 278 int relations = 0; 268 279 for (OsmPrimitive o : newSelection) { 269 if (o instanceof Way) 280 if (o instanceof Way) { 270 281 ways++; 271 else if (o instanceof Node)282 } else if (o instanceof Node) { 272 283 nodes++; 273 else if (o instanceof Relation)284 } else if (o instanceof Relation) { 274 285 relations++; 286 } 275 287 } 276 288 … … 288 300 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); 289 301 for (int i = 0; i < list.getSize(); ++i) 290 if (displaylist.isSelectedIndex(i)) 302 if (displaylist.isSelectedIndex(i)) { 291 303 sel.add((OsmPrimitive) list.get(i)); 292 Main.ds.setSelected(sel); 304 } 305 Main.main.getCurrentDataSet().setSelected(sel); 293 306 } 294 307 … … 308 321 int relations = 0; 309 322 for (OsmPrimitive o : sel) { 310 if (o instanceof Way) 323 if (o instanceof Way) { 311 324 ways++; 312 else if (o instanceof Node)325 } else if (o instanceof Node) { 313 326 nodes++; 314 else if (o instanceof Relation)327 } else if (o instanceof Relation) { 315 328 relations++; 329 } 316 330 } 317 331 String text = ""; 318 if(ways != 0) 332 if(ways != 0) { 319 333 text += (text.length() > 0 ? ", " : "") 320 334 + trn("{0} way", "{0} ways", ways, ways); 321 if(nodes != 0) 335 } 336 if(nodes != 0) { 322 337 text += (text.length() > 0 ? ", " : "") 323 338 + trn("{0} node", "{0} nodes", nodes, nodes); 324 if(relations != 0) 339 } 340 if(relations != 0) { 325 341 text += (text.length() > 0 ? ", " : "") 326 342 + trn("{0} relation", "{0} relations", relations, relations); 343 } 327 344 setText(tr("Selection: {0}", text)); 328 345 addActionListener(this); … … 331 348 public void actionPerformed(ActionEvent e) { 332 349 historyIgnoreSelection = sel; 333 Main. ds.setSelected(sel);350 Main.main.getCurrentDataSet().setSelected(sel); 334 351 } 335 352 … … 355 372 356 373 } 374 375 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 376 if (newLayer instanceof OsmDataLayer) { 377 OsmDataLayer dataLayer = (OsmDataLayer)newLayer; 378 selectionChanged(dataLayer.data.getSelected()); 379 380 } 381 382 } 383 384 public void layerAdded(Layer newLayer) { 385 // do nothing 386 387 } 388 389 public void layerRemoved(Layer oldLayer) { 390 // do nothing 391 392 } 357 393 }
Note:
See TracChangeset
for help on using the changeset viewer.