Changeset 20586 in osm for applications/editors/josm/plugins
- Timestamp:
- 2010-03-21T18:42:23+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions
- Files:
-
- 30 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/AdvancedEditorPanel.java
r20527 r20586 38 38 JPanel pnl = new JPanel(new BorderLayout()); 39 39 HtmlPanel msg = new HtmlPanel(); 40 msg.setText(tr( 41 "<html><body>In the following table you can edit the <strong>raw tags</strong>" 42 + " of the OSM relation representing this turn restriction." 43 )); 40 msg.setText("<html><body>" + 41 tr("In the following table you can edit the <strong>raw tags</strong>" 42 + " of the OSM relation representing this turn restriction.") 43 + "</body></html>" 44 ); 44 45 pnl.add(msg, BorderLayout.NORTH); 45 46 pnlTagEditor = new TagEditorPanel(model.getTagEditorModel()); … … 57 58 JPanel pnl = new JPanel(new BorderLayout()); 58 59 HtmlPanel msg = new HtmlPanel(); 59 msg.setText( tr(60 "<html><body>In the following table you can edit the <strong>raw members</strong>"61 + " of the OSM relation representing this turn restriction." 62 ) );60 msg.setText("<html><body>" 61 + tr("In the following table you can edit the <strong>raw members</strong>" 62 + " of the OSM relation representing this turn restriction.") + "</body></html>" 63 ); 63 64 pnl.add(msg, BorderLayout.NORTH); 64 65 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/BasicEditorPanel.java
r20489 r20586 11 11 import javax.swing.JScrollPane; 12 12 13 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 14 import org.openstreetmap.josm.plugins.turnrestrictions.editor.NavigationControler.BasicEditorFokusTargets; 13 15 import org.openstreetmap.josm.tools.CheckParameterUtil; 14 16 … … 17 19 * i.e. its restriction type, the from, the to, and the via objects. 18 20 * 19 *20 21 */ 21 public class BasicEditorPanel extends JPanel {22 public class BasicEditorPanel extends VerticallyScrollablePanel { 22 23 23 24 /** the turn restriction model */ 24 25 private TurnRestrictionEditorModel model; 26 27 /** the UI widgets */ 28 private TurnRestrictionLegEditor fromEditor; 29 private TurnRestrictionLegEditor toEditor; 30 private ViaList lstVias; 31 private TurnRestrictionComboBox cbTurnRestrictions; 32 private VehicleExceptionEditor vehicleExceptionsEditor; 25 33 26 34 /** … … 40 48 gc.gridx = 1; 41 49 gc.weightx = 1.0; 42 add(new TurnRestrictionComboBox(new TurnRestrictionComboBoxModel(model)), gc); 50 add(cbTurnRestrictions = new TurnRestrictionComboBox(new TurnRestrictionComboBoxModel(model)), gc); 43 51 44 52 // the editor for selecting the 'from' leg … … 50 58 gc.gridx = 1; 51 59 gc.weightx = 1.0; 52 add(new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM),gc); 60 add(fromEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM),gc); 53 61 54 62 // the editor for selecting the 'to' leg … … 61 69 gc.gridx = 1; 62 70 gc.weightx = 1.0; 63 add(new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.TO),gc); 71 add(toEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.TO),gc); 64 72 65 73 // the editor for selecting the 'vias' … … 73 81 gc.weightx = 1.0; 74 82 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 75 add(new JScrollPane(new ViaList(new ViaListModel(model, selectionModel), selectionModel)),gc); 83 add(new JScrollPane(lstVias = new ViaList(new ViaListModel(model, selectionModel), selectionModel)),gc); 84 85 // the editor for vehicle exceptions 86 vehicleExceptionsEditor = new VehicleExceptionEditor(model); 87 gc.gridx = 0; 88 gc.gridy = 4; 89 gc.weightx = 1.0; 90 gc.gridwidth = 2; 91 gc.insets = new Insets(0,0,5,5); 92 add(vehicleExceptionsEditor, gc); 76 93 77 94 // just a filler - grabs remaining space 78 95 gc.gridx = 0; 79 gc.gridy = 4;96 gc.gridy = 5; 80 97 gc.gridwidth = 2; 81 98 gc.weighty = 1.0; … … 99 116 } 100 117 101 118 /** 119 * Requests the focus on one of the input widgets for turn 120 * restriction data. 121 * 122 * @param focusTarget the target component to request focus for. 123 * Ignored if null. 124 */ 125 public void requestFocusFor(BasicEditorFokusTargets focusTarget){ 126 if (focusTarget == null) return; 127 switch(focusTarget){ 128 case RESTRICION_TYPE: 129 cbTurnRestrictions.requestFocusInWindow(); 130 break; 131 case FROM: 132 fromEditor.requestFocusInWindow(); 133 break; 134 case TO: 135 toEditor.requestFocusInWindow(); 136 break; 137 case VIA: 138 lstVias.requestFocusInWindow(); 139 break; 140 } 141 } 102 142 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java
r20527 r20586 16 16 import org.openstreetmap.josm.Main; 17 17 import org.openstreetmap.josm.data.SelectionChangedListener; 18 import org.openstreetmap.josm.data.osm.DataSet;19 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 19 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 45 44 private final List<OsmPrimitive> selection = new ArrayList<OsmPrimitive>(); 46 45 private DefaultListSelectionModel selectionModel; 47 private DataSet dataSet;46 private OsmDataLayer layer; 48 47 49 48 /** … … 51 50 * 52 51 * @param selectionModel the selection model used in the list. Must not be null. 53 * @param dataSet the datasetthis model is displaying the selection from. Must not be null.52 * @param layer the layer this model is displaying the selection from. Must not be null. 54 53 * @throws IllegalArgumentException thrown if {@code selectionModel} is null 55 */ 56 public JosmSelectionListModel(DataSet dataSet, DefaultListSelectionModel selectionModel) { 54 * @throws IllegalArgumentException thrown if {@code layer} is null 55 */ 56 public JosmSelectionListModel(OsmDataLayer layer, DefaultListSelectionModel selectionModel) { 57 57 CheckParameterUtil.ensureParameterNotNull(selectionModel, "selectionModel"); 58 CheckParameterUtil.ensureParameterNotNull( dataSet, "dataSet");59 this. dataSet = dataSet;58 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 59 this.layer = layer; 60 60 this.selectionModel = selectionModel; 61 setJOSMSelection( dataSet.getSelected());61 setJOSMSelection(layer.data.getSelected()); 62 62 } 63 63 … … 160 160 // don't show a JOSM selection if we don't have a data layer 161 161 setJOSMSelection(null); 162 } else if (newLayer .data != dataSet){162 } else if (newLayer != layer){ 163 163 // don't show a JOSM selection if this turn restriction editor doesn't 164 164 // manipulate data in the current data layer … … 177 177 OsmDataLayer layer = Main.main.getEditLayer(); 178 178 if(layer == null) return; 179 if (layer .data != dataSet) return;179 if (layer != this.layer) return; 180 180 setJOSMSelection(newSelection); 181 181 } … … 185 185 /* ------------------------------------------------------------------------ */ 186 186 public void dataChanged(DataChangedEvent event) { 187 if (event.getDataset() != dataSet) return;187 if (event.getDataset() != layer.data) return; 188 188 fireContentsChanged(this, 0, getSize()); 189 189 } 190 190 191 191 public void nodeMoved(NodeMovedEvent event) { 192 if (event.getDataset() != dataSet) return;192 if (event.getDataset() != layer.data) return; 193 193 // may influence the display name of primitives, update the data 194 194 update(event.getPrimitives()); … … 196 196 197 197 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 198 if (event.getDataset() != dataSet) return;198 if (event.getDataset() != layer.data) return; 199 199 // may influence the display name of primitives, update the data 200 200 update(event.getPrimitives()); … … 202 202 203 203 public void relationMembersChanged(RelationMembersChangedEvent event) { 204 if (event.getDataset() != dataSet) return;204 if (event.getDataset() != layer.data) return; 205 205 // may influence the display name of primitives, update the data 206 206 update(event.getPrimitives()); … … 208 208 209 209 public void tagsChanged(TagsChangedEvent event) { 210 if (event.getDataset() != dataSet) return;210 if (event.getDataset() != layer.data) return; 211 211 // may influence the display name of primitives, update the data 212 212 update(event.getPrimitives()); … … 214 214 215 215 public void wayNodesChanged(WayNodesChangedEvent event) { 216 if (event.getDataset() != dataSet) return;216 if (event.getDataset() != layer.data) return; 217 217 // may influence the display name of primitives, update the data 218 218 update(event.getPrimitives()); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java
r20489 r20586 53 53 * builds the UI for the panel 54 54 */ 55 protected void build( DataSet ds) {55 protected void build(OsmDataLayer layer) { 56 56 setLayout(new BorderLayout()); 57 57 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 58 model = new JosmSelectionListModel( ds,selectionModel);58 model = new JosmSelectionListModel(layer,selectionModel); 59 59 lstSelection = new JList(model); 60 60 lstSelection.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); … … 73 73 74 74 /** 75 * Creates the JOSM selection panel for the selection in a data set.75 * Creates the JOSM selection panel for the selection in an OSM data layer 76 76 * 77 * @param dsthe dataset. Must not be null.78 * @exception IllegalArgumentException thrown if dsis null77 * @param layer the data layer. Must not be null. 78 * @exception IllegalArgumentException thrown if {@code layer} is null 79 79 */ 80 public JosmSelectionPanel( DataSet ds) throws IllegalArgumentException{81 CheckParameterUtil.ensureParameterNotNull( ds, "ds");82 build( ds);80 public JosmSelectionPanel(OsmDataLayer layer) throws IllegalArgumentException{ 81 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 82 build(layer); 83 83 } 84 84 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberEditorModel.java
r20527 r20586 136 136 return isChanged; 137 137 } 138 138 139 139 /** 140 140 * Replies the set of {@see OsmPrimitive}s with the role 'from'. If no -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r20556 r20586 19 19 import java.util.Iterator; 20 20 import java.util.List; 21 import java.util.Observable; 22 import java.util.Observer; 21 23 import java.util.logging.Logger; 22 24 … … 26 28 import javax.swing.JOptionPane; 27 29 import javax.swing.JPanel; 30 import javax.swing.JScrollPane; 28 31 import javax.swing.JSplitPane; 29 32 import javax.swing.JTabbedPane; … … 46 49 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 47 50 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 51 import org.openstreetmap.josm.plugins.turnrestrictions.qa.IssuesView; 48 52 import org.openstreetmap.josm.tools.CheckParameterUtil; 49 53 import org.openstreetmap.josm.tools.ImageProvider; 50 54 51 52 public class TurnRestrictionEditor extends JDialog { 55 public class TurnRestrictionEditor extends JDialog implements NavigationControler{ 53 56 final private static Logger logger = Logger.getLogger(TurnRestrictionEditor.class.getName()); 54 57 … … 81 84 private BasicEditorPanel pnlBasicEditor; 82 85 private AdvancedEditorPanel pnlAdvancedEditor; 86 private IssuesView pnlIssuesView; 83 87 private TurnRestrictionEditorModel editorModel; 88 private JTabbedPane tpEditors; 84 89 85 90 /** … … 105 110 */ 106 111 protected JPanel buildJOSMSelectionPanel() { 107 pnlJosmSelection = new JosmSelectionPanel(layer .data);112 pnlJosmSelection = new JosmSelectionPanel(layer); 108 113 return pnlJosmSelection; 109 114 } … … 117 122 protected JPanel buildEditorPanel() { 118 123 JPanel pnl = new JPanel(new BorderLayout()); 119 JTabbedPane tpEditors = new JTabbedPane(); 120 tpEditors.add(pnlBasicEditor =new BasicEditorPanel(editorModel)); 124 tpEditors = new JTabbedPane(); 125 JScrollPane pane = new JScrollPane(pnlBasicEditor =new BasicEditorPanel(editorModel)); 126 pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 127 pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 128 tpEditors.add(pane); 121 129 tpEditors.setTitleAt(0, tr("Basic")); 122 130 tpEditors.setToolTipTextAt(0, tr("Edit basic attributes of a turn restriction")); … … 125 133 tpEditors.setTitleAt(1, tr("Advanced")); 126 134 tpEditors.setToolTipTextAt(1, tr("Edit the raw tags and members of this turn restriction")); 135 136 tpEditors.add(pnlIssuesView = new IssuesView(editorModel.getIssuesModel())); 137 tpEditors.setTitleAt(2, tr("Errors/Warnings")); 138 tpEditors.setToolTipTextAt(2, tr("Show errors and warnings related to this turn restriction")); 127 139 128 140 pnl.add(tpEditors, BorderLayout.CENTER); … … 182 194 */ 183 195 protected void build() { 184 editorModel = new TurnRestrictionEditorModel(getLayer()); 196 editorModel = new TurnRestrictionEditorModel(getLayer(), this); 185 197 Container c = getContentPane(); 186 198 c.setLayout(new BorderLayout()); … … 188 200 c.add(buildContentPanel(), BorderLayout.CENTER); 189 201 c.add(buildOkCancelButtonPanel(), BorderLayout.SOUTH); 202 203 editorModel.getIssuesModel().addObserver(new IssuesModelObserver()); 190 204 setSize(600,600); 191 205 } … … 346 360 } 347 361 348 /** 362 /* ----------------------------------------------------------------------- */ 363 /* interface NavigationControler */ 364 /* ----------------------------------------------------------------------- */ 365 public void gotoBasicEditor() { 366 tpEditors.setSelectedIndex(0); 367 } 368 369 public void gotoAdvancedEditor() { 370 tpEditors.setSelectedIndex(1); 371 } 372 373 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 374 tpEditors.setSelectedIndex(0); 375 pnlBasicEditor.requestFocusFor(focusTarget); 376 } 377 378 /** 349 379 * The abstract base action for applying the updates of a turn restriction 350 380 * to the dataset. … … 745 775 } 746 776 } 777 778 class IssuesModelObserver implements Observer { 779 public void update(Observable o, Object arg) { 780 int numWarnings = editorModel.getIssuesModel().getNumWarnings(); 781 int numErrors = editorModel.getIssuesModel().getNumErrors(); 782 String warningText = null; 783 if (numWarnings > 0){ 784 warningText = trn("{0} warning", "{0} warnings", numWarnings, numWarnings); 785 } 786 String errorText = null; 787 if (numErrors > 0){ 788 errorText = trn("{0} error", "{0} errors", numErrors, numErrors); 789 } 790 String title = ""; 791 if (errorText != null) { 792 title += errorText; 793 } 794 if (warningText != null){ 795 if (title.length() > 0){ 796 title += "/"; 797 } 798 title += warningText; 799 } 800 if (title.length() == 0){ 801 title = tr("no issues"); 802 } 803 tpEditors.setTitleAt(2, title); 804 tpEditors.setEnabledAt(2, numWarnings + numErrors > 0); 805 } 806 } 747 807 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java
r20527 r20586 31 31 import org.openstreetmap.josm.gui.tagging.TagEditorModel; 32 32 import org.openstreetmap.josm.gui.tagging.TagModel; 33 import org.openstreetmap.josm.plugins.turnrestrictions.qa.IssuesModel; 33 34 import org.openstreetmap.josm.tools.CheckParameterUtil; 34 35 … … 66 67 private final TagEditorModel tagEditorModel = new TagEditorModel(); 67 68 private RelationMemberEditorModel memberModel; 69 private IssuesModel issuesModel; 68 70 69 71 /** … … 73 75 * @throws IllegalArgumentException thrown if {@code layer} is null 74 76 */ 75 public TurnRestrictionEditorModel(OsmDataLayer layer) throws IllegalArgumentException{ 77 public TurnRestrictionEditorModel(OsmDataLayer layer, NavigationControler navigationControler) throws IllegalArgumentException{ 76 78 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 77 79 this.layer = layer; 78 80 memberModel = new RelationMemberEditorModel(layer); 79 81 memberModel.addTableModelListener(new RelationMemberModelListener()); 82 issuesModel = new IssuesModel(this,navigationControler); 83 addObserver(issuesModel); 84 tagEditorModel.addTableModelListener(new TagEditorModelObserver()); 80 85 } 81 86 … … 305 310 return memberModel; 306 311 } 312 313 /** 314 * Replies the model for the open issues in this turn restriction 315 * editor. 316 * 317 * @return the model for the open issues in this turn restriction 318 * editor 319 */ 320 public IssuesModel getIssuesModel() { 321 return issuesModel; 322 } 323 324 /** 325 * Replies the current value of the tag "except", or the empty string 326 * if the tag doesn't exist. 327 * 328 * @return 329 */ 330 public ExceptValueModel getExcept() { 331 TagModel tag = tagEditorModel.get("except"); 332 if (tag == null) return new ExceptValueModel(""); 333 return new ExceptValueModel(tag.getValue()); 334 } 335 336 /** 337 * Sets the current value of the tag "except". Removes the 338 * tag is {@code value} is null or consists of white 339 * space only. 340 * 341 * @param value the new value for 'except' 342 */ 343 public void setExcept(ExceptValueModel value){ 344 if (value == null || value.getValue().equals("")) { 345 if (tagEditorModel.get("except") != null){ 346 tagEditorModel.delete("except"); 347 setChanged(); 348 notifyObservers(); 349 } 350 return; 351 } 352 TagModel tag = tagEditorModel.get("except"); 353 if (tag == null) { 354 tagEditorModel.prepend(new TagModel("except", value.getValue())); 355 setChanged(); 356 notifyObservers(); 357 } else { 358 if (!tag.getValue().equals(value.getValue())) { 359 tag.setValue(value.getValue().trim()); 360 setChanged(); 361 notifyObservers(); 362 } 363 } 364 } 307 365 308 366 /* ----------------------------------------------------------------------------------------- */ … … 363 421 notifyObservers(); 364 422 } 365 } 423 } 424 425 class TagEditorModelObserver implements TableModelListener { 426 public void tableChanged(TableModelEvent e) { 427 setChanged(); 428 notifyObservers(); 429 } 430 } 366 431 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java
r20527 r20586 195 195 return role; 196 196 } 197 197 198 198 /* ----------------------------------------------------------------------------- */ 199 199 /* interface Observer */ -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionType.java
r20489 r20586 56 56 return null; 57 57 } 58 59 /** 60 * Replies true if {@code tagValue} is a standard restriction type. 61 * 62 * @param tagValue the tag value 63 * @return true if {@code tagValue} is a standard restriction type 64 */ 65 static public boolean isStandardTagValue(String tagValue){ 66 return fromTagValue(tagValue) != null; 67 } 58 68 }
Note:
See TracChangeset
for help on using the changeset viewer.