Changeset 20556 in osm for applications/editors
- Timestamp:
- 2010-03-19T15:35:57+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
- Files:
-
- 3 added
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionsPlugin.java
r20489 r20556 14 14 public class TurnRestrictionsPlugin extends Plugin{ 15 15 16 private CreateOrEditTurnRestrictionAction actCreateOrEditTurnRestriction; 17 16 18 public TurnRestrictionsPlugin(PluginInformation info) { 17 19 super(info); 20 actCreateOrEditTurnRestriction = new CreateOrEditTurnRestrictionAction(); 18 21 } 19 22 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r20527 r20556 12 12 import java.awt.event.WindowAdapter; 13 13 import java.awt.event.WindowEvent; 14 import java.beans.PropertyChangeEvent; 14 15 import java.beans.PropertyChangeListener; 15 16 import java.beans.PropertyChangeSupport; … … 31 32 32 33 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.actions.AutoScaleAction; 33 35 import org.openstreetmap.josm.command.AddCommand; 34 36 import org.openstreetmap.josm.command.ChangeCommand; … … 47 49 import org.openstreetmap.josm.tools.ImageProvider; 48 50 51 49 52 public class TurnRestrictionEditor extends JDialog { 50 53 final private static Logger logger = Logger.getLogger(TurnRestrictionEditor.class.getName()); … … 160 163 tb.setFloatable(false); 161 164 tb.add(new ApplyAction()); 165 tb.addSeparator(); 166 DeleteAction actDelete = new DeleteAction(); 167 tb.add(actDelete); 168 addPropertyChangeListener(actDelete); 169 tb.addSeparator(); 170 SelectAction actSelect = new SelectAction(); 171 tb.add(actSelect); 172 addPropertyChangeListener(actSelect); 173 174 ZoomToAction actZoomTo = new ZoomToAction(); 175 tb.add(actZoomTo); 176 addPropertyChangeListener(actZoomTo); 162 177 return tb; 163 178 } … … 225 240 * that owned by the layer {@see #getLayer()} 226 241 */ 227 protected void setTurnRestriction(Relation turnRestriction) { 228 242 protected void setTurnRestriction(Relation turnRestriction) { 229 243 if (turnRestriction == null) { 230 244 editorModel.populate(new Relation()); … … 237 251 Relation oldValue = this.turnRestriction; 238 252 this.turnRestriction = turnRestriction; 239 if (this.turnRestriction != oldValue) { 240 support.firePropertyChange(TURN_RESTRICION_PROP, oldValue, this.turnRestriction); 241 } 253 support.firePropertyChange(TURN_RESTRICION_PROP, null, this.turnRestriction); 242 254 updateTitle(); 243 255 } … … 247 259 */ 248 260 protected void updateTitle() { 249 if (getTurnRestriction() == null ) {250 setTitle(tr("Create new turn restriction in layer ''{0}''", layer.getName()));261 if (getTurnRestriction() == null || getTurnRestriction().getDataSet() == null) { 262 setTitle(tr("Create a new turn restriction in layer ''{0}''", layer.getName())); 251 263 } else if (getTurnRestriction().isNew()) { 252 setTitle(tr("Edit new turn restriction in layer ''{0}''", layer.getName()));264 setTitle(tr("Edit a new turn restriction in layer ''{0}''", layer.getName())); 253 265 } else { 254 setTitle(tr("Edit turn restriction #{0}in layer ''{1}''", Long.toString(turnRestriction.getId()), layer.getName()));266 setTitle(tr("Edit turn restriction ''{0}'' in layer ''{1}''", Long.toString(turnRestriction.getId()), layer.getName())); 255 267 } 256 268 } … … 281 293 * @param snapshot the snapshot 282 294 */ 283 protected void setTurnRestrictionSnapshot(Relation snapshot) { 284 Relation oldValue = turnRestrictionSnapshot; 295 protected void setTurnRestrictionSnapshot(Relation snapshot) { 285 296 turnRestrictionSnapshot = snapshot; 286 if (turnRestrictionSnapshot != oldValue) { 287 support.firePropertyChange(TURN_RESTRICION_SNAPSHOT_PROP, oldValue, turnRestrictionSnapshot); 288 } 297 support.firePropertyChange(TURN_RESTRICION_SNAPSHOT_PROP, null, turnRestrictionSnapshot); 289 298 } 290 299 … … 486 495 * outside of the turn restriction editor. 487 496 */ 488 protected void applyExistingNonConflictingTurnRestriction() { 489 Relation toUpdate = new Relation(getTurnRestriction()); 490 editorModel.apply(toUpdate); 491 Main.main.undoRedo.add(new ChangeCommand(getTurnRestriction(), toUpdate)); 497 protected void applyExistingNonConflictingTurnRestriction() { 498 if (getTurnRestriction().getDataSet() == null) { 499 editorModel.apply(getTurnRestriction()); 500 Main.main.undoRedo.add(new AddCommand(getTurnRestriction())); 501 } else { 502 Relation toUpdate = new Relation(getTurnRestriction()); 503 editorModel.apply(toUpdate); 504 Main.main.undoRedo.add(new ChangeCommand(getTurnRestriction(), toUpdate)); 505 } 492 506 // this will refresh the snapshot and update the dialog title 493 507 // … … 645 659 } 646 660 } 661 662 class DeleteAction extends AbstractAction implements PropertyChangeListener{ 663 public DeleteAction() { 664 putValue(NAME, tr("Delete")); 665 putValue(SHORT_DESCRIPTION, tr(("Delete this turn restriction"))); 666 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 667 updateEnabledState(); 668 } 669 670 protected void updateEnabledState() { 671 Relation tr = getTurnRestriction(); 672 setEnabled(tr != null && tr.getDataSet() != null); 673 } 674 675 public void actionPerformed(ActionEvent e) { 676 Relation tr = getTurnRestriction(); 677 if (tr == null || tr.getDataSet() == null) return; 678 org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation( 679 getLayer(), 680 tr 681 ); 682 setVisible(false); 683 } 684 685 public void propertyChange(PropertyChangeEvent evt) { 686 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ 687 updateEnabledState(); 688 } 689 } 690 } 691 692 class SelectAction extends AbstractAction implements PropertyChangeListener{ 693 public SelectAction() { 694 putValue(NAME, tr("Select")); 695 putValue(SHORT_DESCRIPTION, tr(("Select this turn restriction"))); 696 putValue(SMALL_ICON, ImageProvider.get("dialogs", "select")); 697 updateEnabledState(); 698 } 699 700 protected void updateEnabledState() { 701 Relation tr = getTurnRestriction(); 702 setEnabled(tr != null && tr.getDataSet() != null); 703 } 704 705 public void actionPerformed(ActionEvent e) { 706 Relation tr = getTurnRestriction(); 707 if (tr == null || tr.getDataSet() == null) return; 708 getLayer().data.setSelected(tr); 709 } 710 711 public void propertyChange(PropertyChangeEvent evt) { 712 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ 713 updateEnabledState(); 714 } 715 } 716 } 717 718 class ZoomToAction extends AbstractAction implements PropertyChangeListener{ 719 public ZoomToAction() { 720 putValue(NAME, tr("Zoom to")); 721 putValue(SHORT_DESCRIPTION, tr(("Activate the layer this turn restriction belongs to and zoom to it"))); 722 putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale", "data")); 723 updateEnabledState(); 724 } 725 726 protected void updateEnabledState() { 727 Relation tr = getTurnRestriction(); 728 setEnabled(tr != null && tr.getDataSet() != null); 729 } 730 731 public void actionPerformed(ActionEvent e) { 732 if (Main.main.getActiveLayer() != getLayer()){ 733 Main.map.mapView.setActiveLayer(getLayer()); 734 } 735 Relation tr = getTurnRestriction(); 736 if (tr == null || tr.getDataSet() == null) return; 737 getLayer().data.setSelected(tr); 738 AutoScaleAction.zoomToSelection(); 739 } 740 741 public void propertyChange(PropertyChangeEvent evt) { 742 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ 743 updateEnabledState(); 744 } 745 } 746 } 647 747 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionCellRenderer.java
r20526 r20556 11 11 import java.util.HashSet; 12 12 import java.util.Set; 13 import java.util.logging.Logger; 13 14 14 15 import javax.swing.ImageIcon; … … 16 17 import javax.swing.JList; 17 18 import javax.swing.JPanel; 19 import javax.swing.JTable; 18 20 import javax.swing.ListCellRenderer; 19 21 import javax.swing.UIManager; 20 21 import org.openstreetmap.josm.Main; 22 import javax.swing.table.TableCellRenderer; 23 22 24 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 23 25 import org.openstreetmap.josm.data.osm.Relation; … … 27 29 import org.openstreetmap.josm.gui.JMultilineLabel; 28 30 import org.openstreetmap.josm.tools.ImageProvider; 31 import static org.openstreetmap.josm.tools.I18n.trc; 29 32 30 33 /** 31 * This the cell renderer for turn restrictions in the turn restriction list 32 * dialog. 33 * 34 * This is a cell renderer for turn restrictions. 35 * 36 * It can be used a cell renderer in lists of turn restrictions and as cell renderer in 37 * {@see JTable}s displaying turn restrictions. 38 * 34 39 */ 35 public class TurnRestrictionListCellRenderer extends JPanel implements ListCellRenderer{ 36 40 public class TurnRestrictionCellRenderer extends JPanel implements ListCellRenderer, TableCellRenderer{ 41 static private final Logger logger = Logger.getLogger(TurnRestrictionCellRenderer.class.getName()); 42 37 43 /** the names of restriction types */ 38 44 static private Set<String> RESTRICTION_TYPES = new HashSet<String>( … … 53 59 private JLabel to; 54 60 55 public TurnRestriction ListCellRenderer() {61 public TurnRestrictionCellRenderer() { 56 62 build(); 57 63 } … … 103 109 gc.gridheight = 2; 104 110 gc.anchor = GridBagConstraints.CENTER; 105 gc.insets = new Insets(0, 2,0,2);111 gc.insets = new Insets(0,0,2,2); 106 112 add(icon = new JLabel(), gc); 107 113 … … 112 118 gc.gridheight = 1; 113 119 gc.weightx = 0.0; 114 gc.insets = new Insets(0,0,0,0); 115 add(new JMultilineLabel("<html><strong>From:</strong></html>"), gc); 120 add(new JMultilineLabel("<html><strong>" + trc("turnrestrictions","From:") + "</strong></html>"), gc); 116 121 117 122 gc.gridx = 2; … … 124 129 gc.gridy = 1; 125 130 gc.weightx = 0.0; 126 add(new JMultilineLabel("<html><strong> To:</strong></html>"), gc);131 add(new JMultilineLabel("<html><strong>" + trc("turnrestriction", "To:") + "</strong></html>"), gc); 127 132 128 133 gc.gridx = 2; … … 208 213 this.to.setForeground(fg); 209 214 } 210 215 216 /* ---------------------------------------------------------------------------------- */ 217 /* interface ListCellRenderer */ 218 /* ---------------------------------------------------------------------------------- */ 211 219 public Component getListCellRendererComponent(JList list, Object value, 212 220 int index, boolean isSelected, boolean cellHasFocus) { 213 221 214 222 renderColor(isSelected); 223 Relation tr = (Relation)value; 224 renderIcon(tr); 225 renderFrom(tr); 226 renderTo(tr); 227 return this; 228 } 229 230 /* ---------------------------------------------------------------------------------- */ 231 /* interface TableCellRenderer */ 232 /* ---------------------------------------------------------------------------------- */ 233 public Component getTableCellRendererComponent(JTable table, Object value, 234 boolean isSelected, boolean hasFocus, int row, int column) { 235 renderColor(isSelected); 215 236 Relation tr = (Relation)value; 216 237 renderIcon(tr); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetView.java
r20489 r20556 25 25 lstTurnRestrictions.setSelectionModel(selectionModel); 26 26 lstTurnRestrictions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 27 lstTurnRestrictions.setCellRenderer(new TurnRestriction ListCellRenderer());27 lstTurnRestrictions.setCellRenderer(new TurnRestrictionCellRenderer()); 28 28 29 29 setLayout(new BorderLayout()); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionView.java
r20489 r20556 28 28 lstTurnRestrictions.setSelectionModel(selectionModel); 29 29 lstTurnRestrictions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 30 lstTurnRestrictions.setCellRenderer(new TurnRestriction ListCellRenderer());30 lstTurnRestrictions.setCellRenderer(new TurnRestrictionCellRenderer()); 31 31 32 32 setLayout(new BorderLayout()); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListDialog.java
r20489 r20556 33 33 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 34 34 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 35 import org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionBuilder; 35 36 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditor; 36 37 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditorManager; … … 304 305 305 306 public void run() { 306 Relation tr = new Relation();307 307 OsmDataLayer layer = Main.main.getEditLayer(); 308 308 if (layer == null) return; 309 TurnRestrictionEditor editor = new TurnRestrictionEditor(TurnRestrictionsListDialog.this, layer); 309 Relation tr = new TurnRestrictionBuilder().buildFromSelection(layer); 310 TurnRestrictionEditor editor = new TurnRestrictionEditor(TurnRestrictionsListDialog.this, layer, tr); 310 311 TurnRestrictionEditorManager.getInstance().positionOnScreen(editor); 311 312 TurnRestrictionEditorManager.getInstance().register(layer, tr, editor);
Note:
See TracChangeset
for help on using the changeset viewer.