- Timestamp:
- 2009-07-12T19:38:18+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r1772 r1778 1 1 package org.openstreetmap.josm.gui.dialogs; 2 2 3 import static org.openstreetmap.josm.tools.I18n.marktr; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.marktr;5 5 6 6 import java.awt.BorderLayout; … … 13 13 import java.util.Collections; 14 14 15 import javax.swing.AbstractAction; 15 16 import javax.swing.DefaultListModel; 17 import javax.swing.JButton; 16 18 import javax.swing.JList; 17 19 import javax.swing.JPanel; … … 20 22 import javax.swing.event.ListSelectionEvent; 21 23 import javax.swing.event.ListSelectionListener; 24 22 25 import org.openstreetmap.josm.Main; 23 26 import org.openstreetmap.josm.command.DeleteCommand; … … 33 36 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 34 37 import org.openstreetmap.josm.tools.GBC; 38 import org.openstreetmap.josm.tools.ImageProvider; 35 39 import org.openstreetmap.josm.tools.Shortcut; 36 40 … … 54 58 private JList displaylist = new JList(list); 55 59 56 private SideButton sbEdit = new SideButton(marktr("Edit"), "edit", "Selection", tr( "Open an editor for the selected relation"), new ActionListener() { 57 public void actionPerformed(ActionEvent e) { 58 Relation toEdit = getSelected(); 59 if (toEdit == null) 60 return; 61 RelationEditor.getEditor(Main.map.mapView.getEditLayer(),toEdit, null).setVisible(true); 62 } 63 }); 64 65 private SideButton sbDel = new SideButton(marktr("Delete"), "delete", "Selection", tr("Delete the selected relation"), new ActionListener() { 66 public void actionPerformed(ActionEvent e) { 67 Relation toDelete = getSelected(); 68 if (toDelete == null) 69 return; 70 71 Main.main.undoRedo.add( 72 new DeleteCommand(Collections.singleton(toDelete))); 73 } 74 }); 75 60 /** the edit action */ 61 private EditAction editAction; 62 /** the delete action */ 63 private DeleteAction deleteAction; 64 65 66 /** 67 * constructor 68 */ 76 69 public RelationListDialog() { 77 70 super(tr("Relations"), "relationlist", tr("Open a list of all relations."), 78 71 Shortcut.registerShortcut("subwindow:relations", tr("Toggle: {0}", tr("Relations")), KeyEvent.VK_R, Shortcut.GROUP_LAYER), 150); 72 73 // create the list of relations 74 // 79 75 displaylist.setCellRenderer(new OsmPrimitivRenderer()); 80 76 displaylist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); … … 86 82 } 87 83 }); 88 89 84 add(new JScrollPane(displaylist), BorderLayout.CENTER); 90 85 86 // create the panel with buttons 87 // 91 88 JPanel buttonPanel = new JPanel(new GridLayout(1,4)); 92 93 89 buttonPanel.add(new SideButton(marktr("New"), "addrelation", "Selection", tr("Create a new relation"), new ActionListener() { 94 90 public void actionPerformed(ActionEvent e) { … … 98 94 }), GBC.std()); 99 95 100 buttonPanel.add(sbEdit, GBC.std()); 101 102 buttonPanel.add(sbDel, GBC.eol()); 96 // the edit action 97 // 98 editAction = new EditAction(); 99 displaylist.addListSelectionListener(editAction); 100 displaylist.addMouseListener(new MouseAdapter(){ 101 @Override public void mouseClicked(MouseEvent e) { 102 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { 103 editAction.run(); 104 } 105 } 106 }); 107 buttonPanel.add(new JButton(editAction), GBC.std()); 108 109 // the delete action 110 // 111 deleteAction = new DeleteAction(); 112 displaylist.addListSelectionListener(deleteAction); 113 buttonPanel.add(new JButton(deleteAction), GBC.eol()); 114 add(buttonPanel, BorderLayout.SOUTH); 115 116 // register as layer listener 117 // 103 118 Layer.listeners.add(this); 104 add(buttonPanel, BorderLayout.SOUTH);105 106 displaylist.addListSelectionListener(new ListSelectionListener() {107 public void valueChanged(ListSelectionEvent e) {108 sbEdit.setEnabled(getSelected() != null);109 sbDel.setEnabled(getSelected() != null);110 }111 });112 119 } 113 120 … … 134 141 setTitle(tr("Relations"), false); 135 142 } 136 137 sbEdit.setEnabled(list.size() > 0);138 sbDel.setEnabled(list.size() > 0);139 143 } 140 144 … … 155 159 } 156 160 } 161 157 162 public void layerAdded(Layer a) { 158 163 if (a instanceof OsmDataLayer) { … … 160 165 } 161 166 } 167 162 168 public void dataChanged(OsmDataLayer l) { 163 169 updateList(); … … 220 226 } 221 227 } 228 229 /** 230 * The edit action 231 * 232 */ 233 class EditAction extends AbstractAction implements ListSelectionListener, Runnable{ 234 public EditAction() { 235 putValue(SHORT_DESCRIPTION,tr( "Open an editor for the selected relation")); 236 putValue(NAME, tr("Edit")); 237 putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit")); 238 setEnabled(false); 239 } 240 241 public void run() { 242 if (!isEnabled()) return; 243 Relation toEdit = getSelected(); 244 if (toEdit == null) 245 return; 246 RelationEditor.getEditor(Main.map.mapView.getEditLayer(),toEdit, null).setVisible(true); 247 } 248 249 public void actionPerformed(ActionEvent e) { 250 run(); 251 } 252 253 public void valueChanged(ListSelectionEvent e) { 254 setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0); 255 } 256 } 257 258 /** 259 * The delete action 260 * 261 */ 262 class DeleteAction extends AbstractAction implements ListSelectionListener, Runnable { 263 public DeleteAction() { 264 putValue(SHORT_DESCRIPTION,tr("Delete the selected relation")); 265 putValue(NAME, tr("Delete")); 266 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 267 setEnabled(false); 268 } 269 270 public void run() { 271 if (!isEnabled()) return; 272 Relation toDelete = getSelected(); 273 if (toDelete == null) 274 return; 275 Main.main.undoRedo.add( 276 new DeleteCommand(Collections.singleton(toDelete))); 277 } 278 279 public void actionPerformed(ActionEvent e) { 280 run(); 281 } 282 283 public void valueChanged(ListSelectionEvent e) { 284 setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0); 285 } 286 } 222 287 }
Note:
See TracChangeset
for help on using the changeset viewer.