Changeset 32386 in osm for applications/editors/josm/plugins/turnrestrictions
- Timestamp:
- 2016-06-23T18:26:53+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java
r32375 r32386 120 120 putValue(NAME, tr("Copy")); 121 121 putValue(SHORT_DESCRIPTION, tr("Copy to the clipboard")); 122 putValue(SMALL_ICON, ImageProvider.get("copy"));122 new ImageProvider("copy").getResource().attachImageIcon(this); 123 123 putValue(ACCELERATOR_KEY, Shortcut.getCopyKeyStroke()); 124 124 delegate = lstSelection.getActionMap().get("copy"); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberTable.java
r29854 r32386 97 97 putValue(NAME, tr("Delete")); 98 98 putValue(SHORT_DESCRIPTION, tr("Clear the selected roles or delete the selected members")); 99 putValue(SMALL_ICON, ImageProvider.get("deletesmall"));99 new ImageProvider("deletesmall").getResource().attachImageIcon(this); 100 100 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0)); 101 101 updateEnabledState(); … … 123 123 putValue(NAME, tr("Paste")); 124 124 putValue(SHORT_DESCRIPTION, tr("Insert new relation members from object in the clipboard")); 125 putValue(SMALL_ICON, ImageProvider.get("paste"));125 new ImageProvider("paste").getResource().attachImageIcon(this); 126 126 putValue(ACCELERATOR_KEY, Shortcut.getPasteKeyStroke()); 127 127 updateEnabledState(); … … 164 164 putValue(SHORT_DESCRIPTION, tr("Move the selected relation members down by one position")); 165 165 putValue(ACCELERATOR_KEY,keyStroke); 166 putValue(SMALL_ICON, ImageProvider.get("dialogs", "movedown"));166 new ImageProvider("dialogs", "movedown").getResource().attachImageIcon(this); 167 167 updateEnabledState(); 168 168 } … … 191 191 putValue(SHORT_DESCRIPTION, tr("Move the selected relation members up by one position")); 192 192 putValue(ACCELERATOR_KEY,keyStroke); 193 putValue(SMALL_ICON, ImageProvider.get("dialogs", "moveup"));193 new ImageProvider("dialogs", "moveup").getResource().attachImageIcon(this); 194 194 updateEnabledState(); 195 195 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r32375 r32386 23 23 24 24 import javax.swing.AbstractAction; 25 import javax.swing.JButton; 25 26 import javax.swing.JComponent; 26 27 import javax.swing.JDialog; … … 46 47 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 47 48 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 48 import org.openstreetmap.josm.gui.SideButton;49 49 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 50 50 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; … … 99 99 pnl.setLayout(new FlowLayout(FlowLayout.CENTER)); 100 100 101 SideButton b;102 pnl.add(b = new SideButton(new OKAction()));101 JButton b; 102 pnl.add(b = new JButton(new OKAction())); 103 103 b.setName("btnOK"); 104 pnl.add(b = new SideButton(new CancelAction()));104 pnl.add(b = new JButton(new CancelAction())); 105 105 b.setName("btnCancel"); 106 pnl.add(b = new SideButton(new ContextSensitiveHelpAction(ht("/Plugin/TurnRestrictions#TurnRestrictionEditor"))));106 pnl.add(b = new JButton(new ContextSensitiveHelpAction(ht("/Plugin/TurnRestrictions#TurnRestrictionEditor")))); 107 107 b.setName("btnHelp"); 108 108 return pnl; … … 643 643 public ApplyAction() { 644 644 putValue(SHORT_DESCRIPTION, tr("Apply the current updates")); 645 putValue(SMALL_ICON, ImageProvider.get("save"));645 new ImageProvider("save").getResource().attachImageIcon(this); 646 646 putValue(NAME, tr("Apply")); 647 647 setEnabled(true); … … 687 687 public OKAction() { 688 688 putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog")); 689 putValue(SMALL_ICON, ImageProvider.get("ok"));689 new ImageProvider("ok").getResource().attachImageIcon(this); 690 690 putValue(NAME, tr("OK")); 691 691 setEnabled(true); … … 742 742 public CancelAction() { 743 743 putValue(SHORT_DESCRIPTION, tr("Cancel the updates and close the dialog")); 744 putValue(SMALL_ICON, ImageProvider.get("cancel"));744 new ImageProvider("cancel").getResource().attachImageIcon(this); 745 745 putValue(NAME, tr("Cancel")); 746 746 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("ESCAPE")); … … 759 759 putValue(NAME, tr("Delete")); 760 760 putValue(SHORT_DESCRIPTION, tr("Delete this turn restriction")); 761 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));761 new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this); 762 762 updateEnabledState(); 763 763 } … … 791 791 putValue(NAME, tr("Select")); 792 792 putValue(SHORT_DESCRIPTION, tr("Select this turn restriction")); 793 putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));793 new ImageProvider("dialogs", "select").getResource().attachImageIcon(this); 794 794 updateEnabledState(); 795 795 } … … 819 819 putValue(NAME, tr("Zoom to")); 820 820 putValue(SHORT_DESCRIPTION, tr("Activate the layer this turn restriction belongs to and zoom to it")); 821 putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale", "data"));821 new ImageProvider("dialogs/autoscale", "data").getResource().attachImageIcon(this); 822 822 updateEnabledState(); 823 823 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java
r30737 r32386 60 60 public class TurnRestrictionLegEditor extends JPanel implements Observer, PrimitiveIdListProvider { 61 61 //static private final Logger logger = Logger.getLogger(TurnRestrictionLegEditor.class.getName()); 62 62 63 63 private JLabel lblOsmObject; 64 64 private final Set<OsmPrimitive> legs = new HashSet<>(); 65 65 private TurnRestrictionEditorModel model; 66 private TurnRestrictionLegRole role; 66 private TurnRestrictionLegRole role; 67 67 private DeleteAction actDelete; 68 68 private CopyAction actCopy; … … 70 70 private AcceptAction actAccept; 71 71 private TransferHandler transferHandler; 72 73 /** 74 * builds the UI 72 73 /** 74 * builds the UI 75 75 */ 76 76 protected void build() { 77 77 setLayout(new BorderLayout()); 78 add(lblOsmObject = new JLabel(), BorderLayout.CENTER); 78 add(lblOsmObject = new JLabel(), BorderLayout.CENTER); 79 79 lblOsmObject.setOpaque(true); 80 80 lblOsmObject.setBorder(null); … … 85 85 ) 86 86 ); 87 87 88 88 JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0)); 89 89 pnlButtons.setBorder(null); … … 94 94 btn.setText(null); 95 95 btn.setBorder(BorderFactory.createRaisedBevelBorder()); 96 96 97 97 actAccept = new AcceptAction(); 98 98 pnlButtons.add(btn = new JButton(actAccept)); … … 101 101 btn.setBorder(BorderFactory.createRaisedBevelBorder()); 102 102 add(pnlButtons, BorderLayout.EAST); 103 103 104 104 // focus handling 105 105 FocusHandler fh = new FocusHandler(); 106 lblOsmObject.setFocusable(true); 107 lblOsmObject.addFocusListener(fh); 106 lblOsmObject.setFocusable(true); 107 lblOsmObject.addFocusListener(fh); 108 108 this.addFocusListener(fh); 109 109 … … 113 113 addMouseListener(meh); 114 114 lblOsmObject.addMouseListener(new PopupLauncher()); 115 115 116 116 // enable DEL to remove the object from the turn restriction 117 117 registerKeyboardAction(actDelete,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0) , JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); … … 127 127 JComponent c = (JComponent)e.getSource(); 128 128 TransferHandler th = c.getTransferHandler(); 129 th.exportAsDrag(c, e, TransferHandler.COPY); 130 } 129 th.exportAsDrag(c, e, TransferHandler.COPY); 130 } 131 131 }); 132 132 actCopy = new CopyAction(); 133 133 actPaste = new PasteAction(); 134 134 } 135 136 /** 137 * Constructor 138 * 135 136 /** 137 * Constructor 138 * 139 139 * @param model the model. Must not be null. 140 140 * @param role the leg role of the leg this editor is editing. Must not be null. … … 145 145 CheckParameterUtil.ensureParameterNotNull(model, "model"); 146 146 CheckParameterUtil.ensureParameterNotNull(role, "role"); 147 147 148 148 this.model = model; 149 149 this.role = role; 150 150 build(); 151 151 model.addObserver(this); 152 refresh(); 152 refresh(); 153 153 } 154 154 … … 171 171 lblOsmObject.setIcon(null); 172 172 lblOsmObject.setText(tr("multiple objects with role ''{0}''",this.role.getOsmRole())); 173 lblOsmObject.setToolTipText(null); 173 lblOsmObject.setToolTipText(null); 174 174 } 175 175 renderColors(); 176 176 actDelete.updateEnabledState(); 177 177 } 178 178 179 179 /** 180 180 * Render the foreground and background color … … 191 191 } 192 192 } 193 193 194 194 /** 195 195 * Replies the model for this editor 196 * 197 * @return the model 196 * 197 * @return the model 198 198 */ 199 199 public TurnRestrictionEditorModel getModel() { 200 200 return model; 201 201 } 202 203 /** 204 * Replies the role of this editor 205 * 206 * @return the role 202 203 /** 204 * Replies the role of this editor 205 * 206 * @return the role 207 207 */ 208 208 public TurnRestrictionLegRole getRole() { 209 209 return role; 210 } 211 210 } 211 212 212 /* ----------------------------------------------------------------------------- */ 213 213 /* interface Observer */ 214 214 /* ----------------------------------------------------------------------------- */ 215 215 public void update(Observable o, Object arg) { 216 refresh(); 217 } 218 216 refresh(); 217 } 218 219 219 /* ----------------------------------------------------------------------------- */ 220 220 /* interface PrimitiveIdListProvider */ … … 226 226 return Collections.emptyList(); 227 227 } 228 228 229 229 /* ----------------------------------------------------------------------------- */ 230 230 /* inner classes */ 231 /* ----------------------------------------------------------------------------- */ 232 /** 233 * Responds to focus change events 231 /* ----------------------------------------------------------------------------- */ 232 /** 233 * Responds to focus change events 234 234 */ 235 235 class FocusHandler extends FocusAdapter { … … 242 242 public void focusLost(FocusEvent e) { 243 243 renderColors(); 244 } 245 } 246 244 } 245 } 246 247 247 class MouseEventHandler extends MouseAdapter { 248 248 @Override 249 249 public void mouseClicked(MouseEvent e) { 250 250 lblOsmObject.requestFocusInWindow(); 251 } 252 } 253 254 /** 255 * Deletes the way from the turn restriction 251 } 252 } 253 254 /** 255 * Deletes the way from the turn restriction 256 256 */ 257 257 class DeleteAction extends AbstractAction { … … 259 259 putValue(SHORT_DESCRIPTION, tr("Delete from turn restriction")); 260 260 putValue(NAME, tr("Delete")); 261 putValue(SMALL_ICON, ImageProvider.get("deletesmall"));261 new ImageProvider("deletesmall").getResource().attachImageIcon(this); 262 262 putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0)); 263 263 updateEnabledState(); 264 264 } 265 265 266 266 public void actionPerformed(ActionEvent e) { 267 model.setTurnRestrictionLeg(role, null); 268 } 269 267 model.setTurnRestrictionLeg(role, null); 268 } 269 270 270 public void updateEnabledState() { 271 271 setEnabled(legs.size()>0); 272 272 } 273 273 } 274 274 275 275 /** 276 276 * Accepts the currently selected way as turn restriction leg. Only enabled, 277 * if there is exactly one way selected 277 * if there is exactly one way selected 278 278 */ 279 279 class AcceptAction extends AbstractAction implements ListSelectionListener { 280 280 281 281 public AcceptAction() { 282 282 putValue(SHORT_DESCRIPTION, tr("Accept the currently selected way")); 283 283 putValue(NAME, tr("Accept")); 284 putValue(SMALL_ICON, ImageProvider.get("accept"));284 new ImageProvider("accept").getResource().attachImageIcon(this); 285 285 model.getJosmSelectionListModel().getListSelectionModel().addListSelectionListener(this); 286 286 updateEnabledState(); 287 287 } 288 288 289 289 public void actionPerformed(ActionEvent e) { 290 290 List<Way> selWays = OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class); 291 291 if (selWays.size() != 1) return; 292 292 Way w = selWays.get(0); 293 model.setTurnRestrictionLeg(role, w); 294 } 295 293 model.setTurnRestrictionLeg(role, w); 294 } 295 296 296 public void updateEnabledState() { 297 297 setEnabled(OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class).size() == 1); … … 303 303 } 304 304 } 305 306 /** 307 * The transfer handler for Drag-and-Drop. 305 306 /** 307 * The transfer handler for Drag-and-Drop. 308 308 */ 309 309 class LegEditorTransferHandler extends PrimitiveIdListTransferHandler { 310 310 Logger logger = Logger.getLogger(LegEditorTransferHandler.class.getName()); 311 311 312 312 public LegEditorTransferHandler(PrimitiveIdListProvider provider){ 313 313 super(provider); … … 341 341 } 342 342 } 343 343 344 344 class PopupLauncher extends PopupMenuLauncher { 345 345 @Override 346 346 public void launch(MouseEvent evt) { 347 347 new PopupMenu().show(lblOsmObject, evt.getX(), evt.getY()); 348 } 349 } 350 348 } 349 } 350 351 351 class PopupMenu extends JPopupMenu { 352 352 public PopupMenu() { … … 355 355 item.setTransferHandler(transferHandler); 356 356 actPaste.updateEnabledState(); 357 item = add(actPaste); 357 item = add(actPaste); 358 358 item.setTransferHandler(transferHandler); 359 359 addSeparator(); … … 361 361 } 362 362 } 363 363 364 364 class CopyAction extends AbstractAction { 365 365 private Action delegate; 366 366 367 367 public CopyAction(){ 368 368 putValue(NAME, tr("Copy")); 369 369 putValue(SHORT_DESCRIPTION, tr("Copy to the clipboard")); 370 putValue(SMALL_ICON, ImageProvider.get("copy"));370 new ImageProvider("copy").getResource().attachImageIcon(this); 371 371 putValue(ACCELERATOR_KEY, Shortcut.getCopyKeyStroke()); 372 372 delegate = TurnRestrictionLegEditor.this.getActionMap().get("copy"); … … 377 377 delegate.actionPerformed(e); 378 378 } 379 379 380 380 public void updateEnabledState() { 381 381 setEnabled(legs.size() == 1); 382 382 } 383 383 } 384 384 385 385 class PasteAction extends AbstractAction { 386 386 private Action delegate; 387 387 388 388 public boolean canPaste() { 389 389 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 390 390 for (DataFlavor df: clipboard.getAvailableDataFlavors()) { 391 391 if (df.equals(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR)) return true; 392 } 393 // FIXME: check whether there are selected objects in the JOSM copy/paste buffer 392 } 393 // FIXME: check whether there are selected objects in the JOSM copy/paste buffer 394 394 return false; 395 395 } 396 396 397 397 public PasteAction(){ 398 398 putValue(NAME, tr("Paste")); 399 399 putValue(SHORT_DESCRIPTION, tr("Paste from the clipboard")); 400 putValue(SMALL_ICON, ImageProvider.get("paste"));400 new ImageProvider("paste").getResource().attachImageIcon(this); 401 401 putValue(ACCELERATOR_KEY, Shortcut.getPasteKeyStroke()); 402 402 delegate = TurnRestrictionLegEditor.this.getActionMap().get("paste"); 403 403 } 404 404 405 405 public void updateEnabledState() { 406 406 setEnabled(canPaste()); … … 408 408 409 409 public void actionPerformed(ActionEvent e) { 410 delegate.actionPerformed(e); 411 } 412 } 413 414 410 delegate.actionPerformed(e); 411 } 412 } 413 414 415 415 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionSelectionPopupPanel.java
r30737 r32386 56 56 private JButton btnNew; 57 57 /** the table with the turn restrictions which can be edited */ 58 private JTable tblTurnRestrictions; 58 private JTable tblTurnRestrictions; 59 59 private OsmDataLayer layer; 60 60 61 61 /** 62 62 * Replies the collection of turn restrictions the primitives in {@code primitives} 63 63 * currently participate in. 64 * 64 * 65 65 * @param primitives the collection of primitives. May be null. 66 * @return the collection of "parent" turn restrictions. 66 * @return the collection of "parent" turn restrictions. 67 67 */ 68 68 static public Collection<Relation> getTurnRestrictionsParticipatingIn(Collection<OsmPrimitive> primitives){ … … 82 82 return ret; 83 83 } 84 84 85 85 /** 86 86 * Registers 1..9 shortcuts for the first 9 turn restrictions to 87 87 * edit 88 * 89 * @param editCandiates the edit candidates 88 * 89 * @param editCandiates the edit candidates 90 90 */ 91 91 protected void registerEditShortcuts(Collection<Relation> editCandiates){ … … 107 107 } 108 108 /** 109 * Builds the panel with the turn restrictions table 110 * 111 * @param editCandiates the list of edit candiates 112 * @return the panel 109 * Builds the panel with the turn restrictions table 110 * 111 * @param editCandiates the list of edit candiates 112 * @return the panel 113 113 */ 114 114 protected JPanel buildTurnRestrictionTablePanel(Collection<Relation> editCandiates) { … … 118 118 TurnRestrictionCellRenderer renderer = new TurnRestrictionCellRenderer(); 119 119 tblTurnRestrictions.setRowHeight((int)renderer.getPreferredSize().getHeight()); 120 121 // create a scroll pane, remove the table header 120 121 // create a scroll pane, remove the table header 122 122 JScrollPane pane = new JScrollPane(tblTurnRestrictions); 123 123 pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); … … 125 125 tblTurnRestrictions.setTableHeader(null); 126 126 pane.setColumnHeaderView(null); 127 128 // respond to double click and ENTER 127 128 // respond to double click and ENTER 129 129 EditSelectedTurnRestrictionAction action = new EditSelectedTurnRestrictionAction(); 130 130 tblTurnRestrictions.addMouseListener(action); 131 131 tblTurnRestrictions.registerKeyboardAction(action, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), WHEN_FOCUSED); 132 132 133 133 tblTurnRestrictions.addFocusListener(new FocusHandler()); 134 134 135 135 JPanel pnl = new JPanel(new BorderLayout()); 136 136 pnl.add(pane, BorderLayout.CENTER); 137 137 138 138 pnl.setBackground(UIManager.getColor("Table.background")); 139 139 pane.setBackground(UIManager.getColor("Table.background")); 140 return pnl; 141 } 142 143 /** 144 * Builds the panel 145 * 140 return pnl; 141 } 142 143 /** 144 * Builds the panel 145 * 146 146 * @param editCandiates the edit candidates 147 147 */ … … 153 153 registerKeyboardAction(new CloseAction(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 154 154 registerKeyboardAction(btnNew.getAction(), KeyStroke.getKeyStroke(KeyEvent.VK_N,0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 155 155 156 156 btnNew.addFocusListener(new FocusHandler()); 157 157 158 158 if (editCandiates != null && ! editCandiates.isEmpty()) { 159 add(buildTurnRestrictionTablePanel(editCandiates), BorderLayout.CENTER); 159 add(buildTurnRestrictionTablePanel(editCandiates), BorderLayout.CENTER); 160 160 registerEditShortcuts(editCandiates); 161 161 } 162 163 setBackground(UIManager.getColor("Table.background")); 164 } 165 166 162 163 setBackground(UIManager.getColor("Table.background")); 164 } 165 166 167 167 /** 168 168 * Creates the panel 169 * 169 * 170 170 * @param layer the reference OSM data layer. Must not be null. 171 171 * @throws IllegalArgumentException thrown if {@code layer} is null … … 176 176 build(getTurnRestrictionsParticipatingIn(layer.data.getSelected())); 177 177 } 178 178 179 179 /** 180 180 * Creates the panel 181 * 181 * 182 182 * @param layer the reference OSM data layer. Must not be null. 183 * @param editCandidates a collection of turn restrictions as edit candidates. May be null. 183 * @param editCandidates a collection of turn restrictions as edit candidates. May be null. 184 184 * @throws IllegalArgumentException thrown if {@code layer} is null 185 185 */ … … 189 189 build(editCandiates); 190 190 } 191 192 /** 193 * Launches a popup with this panel as content 191 192 /** 193 * Launches a popup with this panel as content 194 194 */ 195 195 public void launch(){ … … 208 208 return new Dimension(300, bestheight); 209 209 } 210 210 211 211 /* --------------------------------------------------------------------------------------- */ 212 212 /* inner classes */ 213 213 /* --------------------------------------------------------------------------------------- */ 214 214 215 215 private class NewAction extends AbstractAction { 216 216 public NewAction() { 217 217 putValue(NAME, tr("Create new turn restriction")); 218 218 putValue(SHORT_DESCRIPTION, tr("Launch the turn restriction editor to create a new turn restriction")); 219 putValue(SMALL_ICON, ImageProvider.get("new"));219 new ImageProvider("new").getResource().attachImageIcon(this); 220 220 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, 0)); 221 221 } … … 232 232 } 233 233 } 234 234 235 235 abstract private class AbstractEditTurnRestrictionAction extends AbstractAction { 236 236 protected void launchEditor(Relation tr){ … … 251 251 } 252 252 } 253 253 254 254 private class EditTurnRestrictionAction extends AbstractEditTurnRestrictionAction { 255 255 private int idx; 256 256 257 257 public EditTurnRestrictionAction(int idx){ 258 258 this.idx = idx; 259 259 } 260 260 261 261 public void actionPerformed(ActionEvent e) { 262 262 Relation tr = (Relation)tblTurnRestrictions.getModel().getValueAt(idx, 1); 263 263 launchEditor(tr); 264 } 265 } 266 264 } 265 } 266 267 267 private class EditSelectedTurnRestrictionAction extends AbstractEditTurnRestrictionAction implements MouseListener{ 268 268 public void editTurnRestrictionAtRow(int row){ … … 279 279 int row = tblTurnRestrictions.rowAtPoint(e.getPoint()); 280 280 if (row < 0) return; 281 editTurnRestrictionAtRow(row); 281 editTurnRestrictionAtRow(row); 282 282 } 283 283 public void mouseEntered(MouseEvent e) {} … … 286 286 public void mouseReleased(MouseEvent e) {} 287 287 } 288 288 289 289 private class CloseAction extends AbstractAction { 290 290 public void actionPerformed(ActionEvent e) { … … 292 292 parentPopup.hide(); 293 293 } 294 } 295 } 296 294 } 295 } 296 297 297 private static class TurnRestrictionTableModel extends AbstractTableModel { 298 298 private final ArrayList<Relation> turnrestrictions = new ArrayList<>(); … … 305 305 fireTableDataChanged(); 306 306 } 307 307 308 308 public int getRowCount() { 309 309 return turnrestrictions.size(); … … 329 329 } 330 330 } 331 332 private static class TurnRestrictionTableColumnModel extends DefaultTableColumnModel { 333 public TurnRestrictionTableColumnModel() { 331 332 private static class TurnRestrictionTableColumnModel extends DefaultTableColumnModel { 333 public TurnRestrictionTableColumnModel() { 334 334 // the idx column 335 TableColumn col = new TableColumn(0); 335 TableColumn col = new TableColumn(0); 336 336 col.setResizable(false); 337 337 col.setWidth(50); 338 338 addColumn(col); 339 340 // the column displaying turn restrictions 341 col = new TableColumn(1); 339 340 // the column displaying turn restrictions 341 col = new TableColumn(1); 342 342 col.setResizable(false); 343 343 col.setPreferredWidth(400); 344 344 col.setCellRenderer(new TurnRestrictionCellRenderer()); 345 addColumn(col); 346 } 347 } 348 349 private class FocusHandler extends FocusAdapter { 345 addColumn(col); 346 } 347 } 348 349 private class FocusHandler extends FocusAdapter { 350 350 @Override 351 351 public void focusLost(FocusEvent e) { 352 352 // if we loose the focus to a component outside of the popup panel 353 // we hide the popup 353 // we hide the popup 354 354 if (e.getOppositeComponent() == null ||!SwingUtilities.isDescendingFrom(e.getOppositeComponent(), TurnRestrictionSelectionPopupPanel.this)) { 355 355 if (parentPopup != null){ -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ViaList.java
r30454 r32386 41 41 /** 42 42 * <p>ViaList is a JList which displays the 'via' members of a turn restriction.</p> 43 * 43 * 44 44 * <p>A ViaList is connected to a {@link TurnRestrictionEditorModel} through its 45 * {@link ViaListModel}.</p> 46 * 45 * {@link ViaListModel}.</p> 46 * 47 47 */ 48 48 public class ViaList extends JList<OsmPrimitive> { 49 49 50 50 //static private final Logger logger = Logger.getLogger(ViaList.class.getName()); 51 51 … … 57 57 private PasteAction actPaste; 58 58 private TransferHandler transferHandler; 59 59 60 60 /** 61 * Constructor 62 * 61 * Constructor 62 * 63 63 * @param model the via list model. Must not be null. 64 64 * @param selectionModel the selection model. Must not be null. 65 * 65 * 66 66 */ 67 67 public ViaList(ViaListModel model, DefaultListSelectionModel selectionModel) { … … 71 71 setSelectionModel(selectionModel); 72 72 setCellRenderer(new OsmPrimitivRenderer()); 73 setDragEnabled(true); 73 setDragEnabled(true); 74 74 setTransferHandler(transferHandler =new ViaListTransferHandler(model)); 75 75 setVisibleRowCount(4); 76 76 77 77 actDelete = new DeleteAction(); 78 78 selectionModel.addListSelectionListener(actDelete); 79 79 registerKeyboardAction(actDelete, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 80 80 81 81 actMoveDown = new MoveDownAction(); 82 82 selectionModel.addListSelectionListener(actMoveDown); … … 86 86 selectionModel.addListSelectionListener(actMoveUp); 87 87 registerKeyboardAction(actMoveUp, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 88 88 89 89 actCopy = new CopyAction(); 90 90 actPaste = new PasteAction(); 91 91 getSelectionModel().addListSelectionListener(actCopy); 92 93 addMouseListener(new ViaListPopupMenuLaucher()); 94 } 95 92 93 addMouseListener(new ViaListPopupMenuLaucher()); 94 } 95 96 96 /** 97 * The transfer handler for Drag-and-Drop. 97 * The transfer handler for Drag-and-Drop. 98 98 */ 99 99 class ViaListTransferHandler extends PrimitiveIdListTransferHandler { 100 100 Logger logger = Logger.getLogger(ViaListTransferHandler.class.getName()); 101 101 102 102 private boolean isViaListInDragOperation = false; 103 103 private List<Integer> selectedRowsMemento = null; 104 104 105 105 public ViaListTransferHandler(PrimitiveIdListProvider provider) { 106 106 super(provider); … … 111 111 // a drag operation on itself is always allowed 112 112 if (isViaListInDragOperation) return true; 113 return isSupportedFlavor(transferFlavors); 113 return isSupportedFlavor(transferFlavors); 114 114 } 115 115 116 116 @SuppressWarnings("unchecked") 117 117 @Override 118 public boolean importData(JComponent comp, Transferable t) { 118 public boolean importData(JComponent comp, Transferable t) { 119 119 if (!isSupportedFlavor(t.getTransferDataFlavors())) return false; 120 120 if (isViaListInDragOperation) { … … 122 122 int targetRow = getSelectedIndex(); 123 123 if (targetRow <0) return true; 124 model.moveVias(selectedRowsMemento, targetRow); 124 model.moveVias(selectedRowsMemento, targetRow); 125 125 } else { 126 126 // this is a drag operation from another component … … 148 148 selectedRowsMemento = model.getSelectedRows(); 149 149 super.exportAsDrag(comp, e, action); 150 } 151 } 152 150 } 151 } 152 153 153 class DeleteAction extends AbstractAction implements ListSelectionListener { 154 154 public DeleteAction() { 155 155 putValue(NAME, tr("Remove")); 156 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));157 putValue(SHORT_DESCRIPTION,tr("Remove the currently selected vias")); 158 putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0)); 159 updateEnabledState(); 160 } 161 156 new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this); 157 putValue(SHORT_DESCRIPTION,tr("Remove the currently selected vias")); 158 putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0)); 159 updateEnabledState(); 160 } 161 162 162 public void valueChanged(ListSelectionEvent e) { 163 updateEnabledState(); 164 } 165 163 updateEnabledState(); 164 } 165 166 166 public void updateEnabledState() { 167 167 setEnabled(getSelectedIndex() >= 0); … … 169 169 170 170 public void actionPerformed(ActionEvent e) { 171 model.removeSelectedVias(); 172 } 173 } 174 175 class MoveDownAction extends AbstractAction implements ListSelectionListener{ 171 model.removeSelectedVias(); 172 } 173 } 174 175 class MoveDownAction extends AbstractAction implements ListSelectionListener{ 176 176 public MoveDownAction(){ 177 177 putValue(NAME, tr("Move down")); 178 178 putValue(SHORT_DESCRIPTION, tr("Move the selected vias down by one position")); 179 179 putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK)); 180 putValue(SMALL_ICON, ImageProvider.get("dialogs", "movedown"));181 updateEnabledState(); 182 } 183 180 new ImageProvider("dialogs", "movedown").getResource().attachImageIcon(this); 181 updateEnabledState(); 182 } 183 184 184 public void actionPerformed(ActionEvent e) { 185 185 model.moveDown(); … … 193 193 setEnabled(getSelectionModel().getMaxSelectionIndex() < getModel().getSize() -1); 194 194 } 195 195 196 196 public void valueChanged(ListSelectionEvent e) { 197 updateEnabledState(); 198 } 199 } 200 201 class MoveUpAction extends AbstractAction implements ListSelectionListener{ 197 updateEnabledState(); 198 } 199 } 200 201 class MoveUpAction extends AbstractAction implements ListSelectionListener{ 202 202 public MoveUpAction() { 203 203 putValue(NAME, tr("Move up")); 204 204 putValue(SHORT_DESCRIPTION, tr("Move the selected vias up by one position")); 205 205 putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK)); 206 putValue(SMALL_ICON, ImageProvider.get("dialogs", "moveup"));207 updateEnabledState(); 208 } 209 206 new ImageProvider("dialogs", "moveup").getResource().attachImageIcon(this); 207 updateEnabledState(); 208 } 209 210 210 public void actionPerformed(ActionEvent e) { 211 211 model.moveUp(); … … 219 219 setEnabled(getSelectionModel().getMinSelectionIndex() > 0); 220 220 } 221 221 222 222 public void valueChanged(ListSelectionEvent e) { 223 updateEnabledState(); 223 updateEnabledState(); 224 224 } 225 225 } … … 227 227 class CopyAction extends AbstractAction implements ListSelectionListener { 228 228 private Action delegate; 229 229 230 230 public CopyAction(){ 231 231 putValue(NAME, tr("Copy")); 232 232 putValue(SHORT_DESCRIPTION, tr("Copy the selected vias to the clipboard")); 233 putValue(SMALL_ICON, ImageProvider.get("copy"));233 new ImageProvider("copy").getResource().attachImageIcon(this); 234 234 putValue(ACCELERATOR_KEY, Shortcut.getCopyKeyStroke()); 235 235 delegate = ViaList.this.getActionMap().get("copy"); 236 236 } 237 237 238 public void actionPerformed(ActionEvent e) { 238 public void actionPerformed(ActionEvent e) { 239 239 delegate.actionPerformed(e); 240 240 } … … 243 243 setEnabled(!model.getSelectedVias().isEmpty()); 244 244 } 245 245 246 246 public void valueChanged(ListSelectionEvent e) { 247 247 updateEnabledState(); 248 248 } 249 249 } 250 250 251 251 class PasteAction extends AbstractAction { 252 252 private Action delegate; 253 253 254 254 public boolean canPaste() { 255 255 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 256 256 for (DataFlavor df: clipboard.getAvailableDataFlavors()) { 257 257 if (df.equals(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR)) return true; 258 } 259 // FIXME: check whether there are selected objects in the JOSM copy/paste buffer 258 } 259 // FIXME: check whether there are selected objects in the JOSM copy/paste buffer 260 260 return false; 261 261 } 262 262 263 263 public PasteAction(){ 264 264 putValue(NAME, tr("Paste")); 265 265 putValue(SHORT_DESCRIPTION, tr("Insert ''via'' objects from the clipboard")); 266 putValue(SMALL_ICON, ImageProvider.get("paste"));266 new ImageProvider("paste").getResource().attachImageIcon(this); 267 267 putValue(ACCELERATOR_KEY, Shortcut.getPasteKeyStroke()); 268 268 delegate = ViaList.this.getActionMap().get("paste"); … … 273 273 setEnabled(canPaste()); 274 274 } 275 276 public void actionPerformed(ActionEvent e) { 277 delegate.actionPerformed(e); 278 } 279 } 280 275 276 public void actionPerformed(ActionEvent e) { 277 delegate.actionPerformed(e); 278 } 279 } 280 281 281 class ViaListPopupMenu extends JPopupMenu { 282 282 public ViaListPopupMenu() { 283 283 JMenuItem item = add(actCopy); 284 item.setTransferHandler(transferHandler); 284 item.setTransferHandler(transferHandler); 285 285 item = add(actPaste); 286 286 actPaste.updateEnabledState(); … … 293 293 } 294 294 } 295 295 296 296 class ViaListPopupMenuLaucher extends PopupMenuLauncher { 297 297 @Override … … 304 304 } 305 305 new ViaListPopupMenu().show(ViaList.this, evt.getX(), evt.getY()); 306 } 307 } 306 } 307 } 308 308 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListDialog.java
r32375 r32386 200 200 public EditAction() { 201 201 putValue(SHORT_DESCRIPTION,tr("Open an editor for the selected turn restriction")); 202 new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this );202 new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this, true); 203 203 putValue(NAME, tr("Edit")); 204 204 setEnabled(false); … … 261 261 public DeleteAction() { 262 262 putValue(SHORT_DESCRIPTION,tr("Delete the selected turn restriction")); 263 new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this );263 new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true); 264 264 putValue(NAME, tr("Delete")); 265 265 setEnabled(false); … … 301 301 public NewAction() { 302 302 putValue(SHORT_DESCRIPTION,tr("Create a new turn restriction")); 303 new ImageProvider("new").getResource().attachImageIcon(this );303 new ImageProvider("new").getResource().attachImageIcon(this, true); 304 304 putValue(NAME, tr("New")); 305 305 updateEnabledState(); … … 341 341 public SelectSelectedTurnRestrictions() { 342 342 putValue(SHORT_DESCRIPTION,tr("Set the current JOSM selection to the selected turn restrictions")); 343 putValue(SMALL_ICON, ImageProvider.get("selectall"));343 new ImageProvider("selectall").getResource().attachImageIcon(this); 344 344 putValue(NAME, tr("Select in current data layer")); 345 345 setEnabled(false); … … 376 376 public ZoomToAction() { 377 377 putValue(SHORT_DESCRIPTION,tr("Zoom to the currently selected turn restrictions")); 378 putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale/selection"));378 new ImageProvider("dialogs/autoscale/selection").getResource().attachImageIcon(this); 379 379 putValue(NAME, tr("Zoom to")); 380 380 setEnabled(false);
Note:
See TracChangeset
for help on using the changeset viewer.