Changeset 2697 in josm
- Timestamp:
- 2009-12-28T20:45:40+01:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r2677 r2697 5 5 import java.awt.BorderLayout; 6 6 import java.awt.Component; 7 import java.awt. GridLayout;7 import java.awt.FlowLayout; 8 8 import java.awt.Point; 9 9 import java.awt.Rectangle; … … 29 29 import javax.swing.JPanel; 30 30 import javax.swing.JScrollPane; 31 import javax.swing.JToolBar; 31 32 import javax.swing.KeyStroke; 32 33 import javax.swing.ListModel; … … 42 43 import org.openstreetmap.josm.gui.MapFrame; 43 44 import org.openstreetmap.josm.gui.MapView; 44 import org.openstreetmap.josm.gui. SideButton;45 import org.openstreetmap.josm.gui.help.HelpUtil; 45 46 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 46 47 import org.openstreetmap.josm.gui.layer.Layer; 47 48 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 49 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 48 50 import org.openstreetmap.josm.tools.ImageProvider; 49 51 import org.openstreetmap.josm.tools.Shortcut; … … 96 98 97 99 protected JPanel createButtonPanel() { 98 JPanel buttonPanel = new JPanel(new GridLayout(1, 5)); 100 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0)); 101 102 JToolBar tb = new JToolBar(JToolBar.HORIZONTAL); 103 tb.setFloatable(false); 99 104 100 105 // -- move up action … … 102 107 adaptTo(moveUpAction, model); 103 108 adaptTo(moveUpAction,selectionModel); 104 buttonPanel.add(new SideButton(moveUpAction));109 tb.add(moveUpAction); 105 110 106 111 // -- move down action … … 108 113 adaptTo(moveDownAction, model); 109 114 adaptTo(moveDownAction,selectionModel); 110 buttonPanel.add(new SideButton(moveDownAction));115 tb.add(moveDownAction); 111 116 112 117 // -- activate action … … 114 119 adaptTo(activateLayerAction, selectionModel); 115 120 MapView.addLayerChangeListener(activateLayerAction); 116 buttonPanel.add(new SideButton(activateLayerAction, "activate"));121 tb.add(activateLayerAction); 117 122 118 123 // -- show hide action 119 124 ShowHideLayerAction showHideLayerAction = new ShowHideLayerAction(); 120 125 adaptTo(showHideLayerAction, selectionModel); 121 buttonPanel.add(new SideButton(showHideLayerAction, "showhide"));126 tb.add(showHideLayerAction); 122 127 123 128 // -- merge layer action … … 125 130 adaptTo(mergeLayerAction, model); 126 131 adaptTo(mergeLayerAction,selectionModel); 127 buttonPanel.add(new SideButton(mergeLayerAction)); 132 tb.add(mergeLayerAction); 133 128 134 129 135 //-- delete layer action … … 134 140 layerList.getActionMap().put("deleteLayer", deleteLayerAction); 135 141 adaptTo(deleteLayerAction, selectionModel); 136 buttonPanel.add(new SideButton(deleteLayerAction, "delete")); 137 142 tb.add(deleteLayerAction); 143 144 buttonPanel.add(tb); 138 145 return buttonPanel; 139 146 } … … 157 164 layerList = new LayerList(model); 158 165 layerList.setSelectionModel(selectionModel); 159 layerList.addMouseListener(new LayerListMouseAdapter()); 166 layerList.addMouseListener(new DblClickAdapter()); 167 layerList.addMouseListener(new PopupMenuHandler()); 160 168 layerList.setBackground(UIManager.getColor("Button.background")); 161 169 layerList.setCellRenderer(new LayerListCellRenderer()); … … 172 180 layerList.ensureIndexIsVisible(index); 173 181 } 174 175 182 public void refresh() { 176 183 layerList.repaint(); … … 244 251 */ 245 252 public final class DeleteLayerAction extends AbstractAction implements IEnabledStateUpdating { 246 private Layer layer;247 248 /**249 * Creates a {@see DeleteLayerAction} for a specific layer.250 *251 * @param layer the layer. Must not be null.252 * @exception IllegalArgumentException thrown, if layer is null253 */254 public DeleteLayerAction(Layer layer) {255 this();256 if (layer == null)257 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "layer"));258 this.layer = layer;259 putValue(NAME, tr("Delete"));260 updateEnabledState();261 }262 263 253 /** 264 254 * Creates a {@see DeleteLayerAction} which will delete the currently … … 268 258 public DeleteLayerAction() { 269 259 putValue(SMALL_ICON,ImageProvider.get("dialogs", "delete")); 270 putValue(SHORT_DESCRIPTION, tr("Delete the selected layer.")); 271 putValue("help", "Action/LayerDelete"); 260 putValue(SHORT_DESCRIPTION, tr("Delete the selected layers.")); 261 putValue(NAME, tr("Delete")); 262 putValue("help", HelpUtil.ht("/Dialog/LayerDialog#DeleteLayer")); 272 263 updateEnabledState(); 273 264 } … … 299 290 300 291 public void actionPerformed(ActionEvent e) { 301 List<Layer> selectedLayers; 302 if (this.layer == null) { 303 selectedLayers = getModel().getSelectedLayers(); 304 } else { 305 selectedLayers = Collections.singletonList(this.layer); 306 } 292 List<Layer> selectedLayers = getModel().getSelectedLayers(); 307 293 if (selectedLayers.isEmpty()) 308 294 return; … … 315 301 316 302 public void updateEnabledState() { 317 if (layer == null) { 318 setEnabled(! getModel().getSelectedLayers().isEmpty()); 319 } else { 320 setEnabled(true); 321 } 303 setEnabled(! getModel().getSelectedLayers().isEmpty()); 322 304 } 323 305 } … … 350 332 putValue(SMALL_ICON, ImageProvider.get("dialogs", "showhide")); 351 333 putValue(SHORT_DESCRIPTION, tr("Toggle visible state of the selected layer.")); 352 putValue("help", "Action/LayerShowHide");334 putValue("help", HelpUtil.ht("/Dialog/LayerDialog#ShowHideLayer")); 353 335 updateEnabledState(); 354 336 } … … 392 374 putValue(SMALL_ICON, ImageProvider.get("dialogs", "activate")); 393 375 putValue(SHORT_DESCRIPTION, tr("Activate the selected layer")); 394 putValue("help", "Action/ActivateLayer");376 putValue("help", HelpUtil.ht("/Dialog/LayerDialog#ActivateLayer")); 395 377 updateEnabledState(); 396 378 } … … 457 439 putValue(SMALL_ICON, ImageProvider.get("dialogs", "mergedown")); 458 440 putValue(SHORT_DESCRIPTION, tr("Merge this layer into another layer")); 459 putValue("help", "Action/MergeLayer");441 putValue("help", HelpUtil.ht("/Dialog/LayerDialog#MergeLayer")); 460 442 updateEnabledState(); 461 443 } … … 521 503 } 522 504 523 class LayerListMouseAdapter extends MouseAdapter {524 525 p rivate void openPopup(MouseEvent e) {526 Point p = e .getPoint();505 class PopupMenuHandler extends PopupMenuLauncher { 506 @Override 507 public void launch(MouseEvent evt) { 508 Point p = evt.getPoint(); 527 509 int index = layerList.locationToIndex(p); 528 510 if (index < 0) return; 529 if (!layerList.getCellBounds(index, index).contains(e .getPoint()))511 if (!layerList.getCellBounds(index, index).contains(evt.getPoint())) 530 512 return; 531 513 if (!layerList.isSelectedIndex(index)) { … … 536 518 menu.show(LayerListDialog.this, p.x, p.y-3); 537 519 } 538 @Override public void mousePressed(MouseEvent e) { 539 if (e.isPopupTrigger()) { 540 openPopup(e); 541 } 542 } 543 @Override public void mouseReleased(MouseEvent e) { 544 if (e.isPopupTrigger()) { 545 openPopup(e); 546 } 547 } 520 } 521 522 class DblClickAdapter extends MouseAdapter { 548 523 @Override public void mouseClicked(MouseEvent e) { 549 524 if (e.getClickCount() == 2) { … … 1042 1017 */ 1043 1018 public DeleteLayerAction createDeleteLayerAction(Layer layer) { 1044 return new DeleteLayerAction(layer); 1019 // the delete layer action doesn't depend on the current layer 1020 return new DeleteLayerAction(); 1045 1021 } 1046 1022
Note:
See TracChangeset
for help on using the changeset viewer.