Changeset 32375 in osm for applications
- Timestamp:
- 2016-06-23T01:27:28+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/.settings/org.eclipse.jdt.core.prefs
r30736 r32375 81 81 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled 82 82 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled 83 org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore 83 84 org.eclipse.jdt.core.compiler.problem.unusedImport=warning 84 85 org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -
applications/editors/josm/plugins/turnrestrictions/build.xml
r32329 r32375 4 4 <property name="commit.message" value="Adapt to JOSM core change (DefaultNameFormatter)"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="10 279"/>6 <property name="plugin.main.version" value="10369"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/CreateOrEditTurnRestrictionAction.java
r29854 r32375 50 50 } 51 51 52 @Override 52 53 public void actionPerformed(ActionEvent e) { 53 OsmDataLayer layer = Main. main.getEditLayer();54 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 54 55 if (layer == null) return; 55 56 Collection<Relation> trs = TurnRestrictionSelectionPopupPanel.getTurnRestrictionsParticipatingIn(layer.data.getSelected()); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java
r30737 r32375 24 24 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 25 25 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 26 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 26 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 27 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 27 28 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 29 import org.openstreetmap.josm.plugins.turnrestrictions.dnd.PrimitiveIdListProvider; … … 30 31 31 32 /** 32 * JosmSelectionListModel is the model for a list which displays the currently selected 33 * JosmSelectionListModel is the model for a list which displays the currently selected 33 34 * objects in the current edit layer. 34 * 35 * 35 36 */ 36 public class JosmSelectionListModel extends AbstractListModel<OsmPrimitive> implements EditLayerChangeListener, SelectionChangedListener, DataSetListener, PrimitiveIdListProvider{37 public class JosmSelectionListModel extends AbstractListModel<OsmPrimitive> implements ActiveLayerChangeListener, SelectionChangedListener, DataSetListener, PrimitiveIdListProvider{ 37 38 //static private final Logger logger = Logger.getLogger(JosmSelectionListModel.class.getName()); 38 39 39 40 private final List<OsmPrimitive> selection = new ArrayList<>(); 40 41 private final DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); … … 43 44 /** 44 45 * Constructor 45 * 46 * 46 47 * @param selectionModel the selection model used in the list. Must not be null. 47 48 * @param layer the layer this model is displaying the selection from. Must not be null. 48 49 * @throws IllegalArgumentException thrown if {@code layer} is null 49 50 */ 50 public JosmSelectionListModel(OsmDataLayer layer) throws IllegalArgumentException{51 public JosmSelectionListModel(OsmDataLayer layer) { 51 52 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 52 53 this.layer = layer; … … 54 55 } 55 56 57 @Override 56 58 public OsmPrimitive getElementAt(int index) { 57 59 return selection.get(index); 58 60 } 59 61 62 @Override 60 63 public int getSize() { 61 64 return selection.size(); … … 65 68 * Replies the collection of OSM primitives currently selected in the view 66 69 * of this model 67 * 70 * 68 71 * @return the selected primitives 69 72 */ … … 80 83 /** 81 84 * Sets the OSM primitives to be selected in the view of this model 82 * 85 * 83 86 * @param sel the collection of primitives to select 84 87 */ … … 103 106 /** 104 107 * Sets the collection of currently selected OSM objects 105 * 108 * 106 109 * @param selection the collection of currently selected OSM objects 107 110 */ … … 114 117 } 115 118 this.selection.addAll(selection); 116 fireContentsChanged(this, 0, getSize()); 117 setSelected(sel); 119 fireContentsChanged(this, 0, getSize()); 120 setSelected(sel); 118 121 // if the user selects exactly one primitive (i.e. a way), we automatically 119 // select it in the list of selected JOSM objects too. 122 // select it in the list of selected JOSM objects too. 120 123 if (getSelected().isEmpty() && this.selection.size() == 1) { 121 124 setSelected(this.selection); … … 126 129 * Triggers a refresh of the view for all primitives in {@code toUpdate} 127 130 * which are currently displayed in the view 128 * 131 * 129 132 * @param toUpdate the collection of primitives to update 130 133 */ … … 141 144 setSelected(sel); 142 145 } 143 146 144 147 public ListSelectionModel getListSelectionModel() { 145 148 return selectionModel; … … 147 150 148 151 /* ------------------------------------------------------------------------ */ 149 /* interface EditLayerChangeListener */ 150 /* ------------------------------------------------------------------------ */ 151 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 152 /* interface ActiveLayerChangeListener */ 153 /* ------------------------------------------------------------------------ */ 154 @Override 155 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 156 OsmDataLayer newLayer = Main.getLayerManager().getEditLayer(); 152 157 if (newLayer == null) { 153 // don't show a JOSM selection if we don't have a data layer 158 // don't show a JOSM selection if we don't have a data layer 154 159 setJOSMSelection(null); 155 160 } else if (newLayer != layer){ … … 165 170 /* interface SelectionChangeListener */ 166 171 /* ------------------------------------------------------------------------ */ 172 @Override 167 173 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 168 174 // only update the JOSM selection if it is changed in the same data layer 169 175 // this turn restriction editor is working on 170 OsmDataLayer layer = Main. main.getEditLayer();176 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 171 177 if(layer == null) return; 172 178 if (layer != this.layer) return; … … 177 183 /* interface DataSetListener */ 178 184 /* ------------------------------------------------------------------------ */ 185 @Override 179 186 public void dataChanged(DataChangedEvent event) { 180 187 if (event.getDataset() != layer.data) return; … … 182 189 } 183 190 191 @Override 184 192 public void nodeMoved(NodeMovedEvent event) { 185 193 if (event.getDataset() != layer.data) return; … … 188 196 } 189 197 198 @Override 190 199 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 191 200 if (event.getDataset() != layer.data) return; … … 194 203 } 195 204 205 @Override 196 206 public void relationMembersChanged(RelationMembersChangedEvent event) { 197 207 if (event.getDataset() != layer.data) return; … … 200 210 } 201 211 212 @Override 202 213 public void tagsChanged(TagsChangedEvent event) { 203 214 if (event.getDataset() != layer.data) return; … … 206 217 } 207 218 219 @Override 208 220 public void wayNodesChanged(WayNodesChangedEvent event) { 209 221 if (event.getDataset() != layer.data) return; … … 212 224 } 213 225 226 @Override 214 227 public void primitivesAdded(PrimitivesAddedEvent event) {/* ignored - handled by SelectionChangeListener */} 228 @Override 215 229 public void primitivesRemoved(PrimitivesRemovedEvent event) {/* ignored - handled by SelectionChangeListener*/} 216 230 217 231 /* ------------------------------------------------------------------------ */ 218 232 /* interface PrimitiveIdListProvider */ 219 233 /* ------------------------------------------------------------------------ */ 234 @Override 220 235 public List<PrimitiveId> getSelectedPrimitiveIds() { 221 236 List<PrimitiveId> ret = new ArrayList<>(getSelected().size()); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java
r30454 r32375 21 21 import javax.swing.TransferHandler; 22 22 23 import org.openstreetmap.josm.Main; 23 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 25 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 25 26 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 26 27 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 27 import org.openstreetmap.josm.gui.MapView;28 28 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 29 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 45 45 /** the model managing the selection */ 46 46 private JosmSelectionListModel model; 47 47 48 48 private CopyAction actCopy; 49 49 private TransferHandler transferHandler; 50 50 51 51 /** 52 * builds the UI for the panel 52 * builds the UI for the panel 53 53 */ 54 54 protected void build(OsmDataLayer layer) { … … 60 60 lstSelection.setTransferHandler(transferHandler = new JosmSelectionTransferHandler(model)); 61 61 lstSelection.setDragEnabled(true); 62 62 63 63 add(new JScrollPane(lstSelection), BorderLayout.CENTER); 64 64 add(new JLabel(tr("Selection")), BorderLayout.NORTH); 65 66 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 65 66 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 67 67 actCopy = new CopyAction(); 68 68 lstSelection.addMouseListener(new PopupLauncher()); 69 69 } 70 70 71 71 /** 72 72 * Creates the JOSM selection panel for the selection in an OSM data layer 73 * 73 * 74 74 * @param layer the data layer. Must not be null. 75 75 * @exception IllegalArgumentException thrown if {@code layer} is null … … 78 78 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 79 79 this.model = model; 80 build(layer); 80 build(layer); 81 81 } 82 82 83 83 /** 84 * wires the UI as listener to global event sources 84 * wires the UI as listener to global event sources 85 85 */ 86 86 public void wireListeners() { 87 Ma pView.addEditLayerChangeListener(model);87 Main.getLayerManager().addActiveLayerChangeListener(model); 88 88 DatasetEventManager.getInstance().addDatasetListener(model, FireMode.IN_EDT); 89 89 SelectionEventManager.getInstance().addSelectionListener(model, FireMode.IN_EDT_CONSOLIDATED); 90 90 } 91 91 92 92 /** 93 * removes the UI as listener to global event sources 93 * removes the UI as listener to global event sources 94 94 */ 95 95 public void unwireListeners() { 96 Ma pView.removeEditLayerChangeListener(model);96 Main.getLayerManager().removeActiveLayerChangeListener(model); 97 97 DatasetEventManager.getInstance().removeDatasetListener(model); 98 SelectionEventManager.getInstance().removeSelectionListener(model); 98 SelectionEventManager.getInstance().removeSelectionListener(model); 99 99 } 100 100 101 101 class PopupLauncher extends PopupMenuLauncher { 102 102 @Override 103 103 public void launch(MouseEvent evt) { 104 104 new PopupMenu().show(lstSelection, evt.getX(), evt.getY()); 105 } 105 } 106 106 } 107 107 108 108 class PopupMenu extends JPopupMenu { 109 109 public PopupMenu() { … … 116 116 class CopyAction extends AbstractAction { 117 117 private Action delegate; 118 118 119 119 public CopyAction(){ 120 120 putValue(NAME, tr("Copy")); … … 125 125 } 126 126 127 @Override 127 128 public void actionPerformed(ActionEvent e) { 128 129 delegate.actionPerformed(e); 129 130 } 130 131 } 131 132 132 133 static private class JosmSelectionTransferHandler extends PrimitiveIdListTransferHandler { 133 134 public JosmSelectionTransferHandler(PrimitiveIdListProvider provider) { -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r32329 r32375 58 58 public class TurnRestrictionEditor extends JDialog implements NavigationControler{ 59 59 //final private static Logger logger = Logger.getLogger(TurnRestrictionEditor.class.getName()); 60 60 61 61 /** the property name for the current turn restriction 62 62 * @link #setRelation(Relation) … … 69 69 */ 70 70 static public final String TURN_RESTRICION_SNAPSHOT_PROP = RelationEditor.class.getName() + ".turnRestrictionSnapshot"; 71 71 72 72 /** 73 73 * The turn restriction this editor is working on … … 77 77 /** 78 78 * The version of the turn restriction when editing is started. This is 79 * null if a new turn restriction is created. 79 * null if a new turn restriction is created. 80 80 */ 81 81 protected Relation turnRestrictionSnapshot; … … 83 83 /** the data layer the turn restriction belongs to */ 84 84 private OsmDataLayer layer; 85 85 86 86 private JosmSelectionPanel pnlJosmSelection; 87 87 private BasicEditorPanel pnlBasicEditor; … … 89 89 private JTabbedPane tpEditors; 90 90 private PreferenceChangeHandler preferenceChangeHandler; 91 91 92 92 /** 93 93 * builds the panel with the OK and the Cancel button … … 108 108 return pnl; 109 109 } 110 111 /** 112 * builds the panel which displays the JOSM selection 110 111 /** 112 * builds the panel which displays the JOSM selection 113 113 * @return 114 114 */ … … 117 117 return pnlJosmSelection; 118 118 } 119 120 /** 121 * Builds the panel with the editor forms (the left panel in the split pane of 119 120 /** 121 * Builds the panel with the editor forms (the left panel in the split pane of 122 122 * this dialog) 123 * 123 * 124 124 * @return 125 125 */ … … 133 133 tpEditors.setTitleAt(0, tr("Basic")); 134 134 tpEditors.setToolTipTextAt(0, tr("Edit basic attributes of a turn restriction")); 135 135 136 136 tpEditors.add(new AdvancedEditorPanel(editorModel)); 137 137 tpEditors.setTitleAt(1, tr("Advanced")); 138 138 tpEditors.setToolTipTextAt(1, tr("Edit the raw tags and members of this turn restriction")); 139 139 140 140 tpEditors.add(new IssuesView(editorModel.getIssuesModel())); 141 141 tpEditors.setTitleAt(2, tr("Errors/Warnings")); 142 142 tpEditors.setToolTipTextAt(2, tr("Show errors and warnings related to this turn restriction")); 143 143 144 144 pnl.add(tpEditors, BorderLayout.CENTER); 145 145 return pnl; 146 146 } 147 147 148 148 /** 149 149 * Builds the content panel, i.e. the core area of the dialog with the editor 150 * masks and the JOSM selection view 151 * 150 * masks and the JOSM selection view 151 * 152 152 * @return 153 153 */ … … 169 169 return pnl; 170 170 } 171 171 172 172 /** 173 173 * Creates the toolbar … … 193 193 return tb; 194 194 } 195 195 196 196 /** 197 197 * builds the UI 198 198 */ 199 protected void build() { 199 protected void build() { 200 200 editorModel = new TurnRestrictionEditorModel(getLayer(), this); 201 201 Container c = getContentPane(); 202 202 c.setLayout(new BorderLayout()); 203 203 c.add(buildToolBar(), BorderLayout.NORTH); 204 c.add(buildContentPanel(), BorderLayout.CENTER); 204 c.add(buildContentPanel(), BorderLayout.CENTER); 205 205 c.add(buildOkCancelButtonPanel(), BorderLayout.SOUTH); 206 206 207 207 editorModel.getIssuesModel().addObserver(new IssuesModelObserver()); 208 setSize(600,600); 209 } 210 208 setSize(600,600); 209 } 210 211 211 /** 212 212 * Creates a new turn restriction editor 213 213 * 214 * @param owner the component relative to which the dialog is displayed 214 * @param owner the component relative to which the dialog is displayed 215 215 * @param layer the {@link OsmDataLayer} in whose context a relation is edited. Must not be null. 216 216 * @throws IllegalArgumentException thrown if layer is null … … 219 219 this(owner, layer, null); 220 220 } 221 221 222 222 /** 223 223 * Creates a new turn restriction editor 224 224 * 225 * @param owner the component relative to which the dialog is displayed 225 * @param owner the component relative to which the dialog is displayed 226 226 * @param layer the {@link OsmDataLayer} in whose context a relation is edited. Must not be null. 227 227 * @param turnRestriction the relation. Can be null if a new relation is to be edited. … … 235 235 setTurnRestriction(turnRestriction); 236 236 } 237 237 238 238 /** 239 239 * Replies the currently edited turn restriction … … 253 253 * is already assigned to a dataset, the dataset of {@link #getLayer()} is required, otherwise 254 254 * a {@link IllegalArgumentException} is thrown.</p> 255 * 255 * 256 256 * @param turnRestriction the turn restriction 257 257 * @throws IllegalArgumentException thrown if {@code turnRestriction} belongs to a different dataset than 258 258 * that owned by the layer {@link #getLayer()} 259 259 */ 260 protected void setTurnRestriction(Relation turnRestriction) { 260 protected void setTurnRestriction(Relation turnRestriction) { 261 261 if (turnRestriction == null) { 262 262 editorModel.populate(new Relation()); … … 271 271 updateTitle(); 272 272 } 273 273 274 274 /** 275 275 * updates the title of the turn restriction editor … … 284 284 } 285 285 } 286 286 287 287 /** 288 288 * Replies the {@link OsmDataLayer} in whose context this relation editor is … … 307 307 /** 308 308 * Sets the turn restriction snapshot 309 * 309 * 310 310 * @param snapshot the snapshot 311 311 */ 312 protected void setTurnRestrictionSnapshot(Relation snapshot) { 312 protected void setTurnRestrictionSnapshot(Relation snapshot) { 313 313 turnRestrictionSnapshot = snapshot; 314 314 support.firePropertyChange(TURN_RESTRICION_SNAPSHOT_PROP, null, turnRestrictionSnapshot); 315 315 } 316 316 317 317 /** 318 318 * <p>Replies true if the currently edited turn restriction has been changed elsewhere.</p> … … 326 326 return ! turnRestriction.hasEqualSemanticAttributes(turnRestrictionSnapshot); 327 327 } 328 329 /** 330 * Replies the editor model for this editor 328 329 /** 330 * Replies the editor model for this editor 331 331 */ 332 332 public TurnRestrictionEditorModel getModel() { 333 333 return editorModel; 334 334 } 335 335 336 @Override 336 337 public void setVisible(boolean visible) { 337 338 if (visible && ! isVisible()) { … … 350 351 } 351 352 } 352 353 353 354 /* ----------------------------------------------------------------------- */ 354 355 /* property change support */ … … 365 366 this.support.removePropertyChangeListener(listener); 366 367 } 367 368 368 369 /* ----------------------------------------------------------------------- */ 369 370 /* interface NavigationControler */ 370 371 /* ----------------------------------------------------------------------- */ 372 @Override 371 373 public void gotoBasicEditor() { 372 374 tpEditors.setSelectedIndex(0); 373 375 } 374 376 377 @Override 375 378 public void gotoAdvancedEditor() { 376 379 tpEditors.setSelectedIndex(1); 377 380 } 378 381 382 @Override 379 383 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 380 384 tpEditors.setSelectedIndex(0); … … 386 390 * to the dataset. 387 391 */ 388 abstract class SavingAction extends AbstractAction { 392 abstract class SavingAction extends AbstractAction { 389 393 protected boolean confirmSaveDespiteOfErrorsAndWarnings(){ 390 394 int numErrors = editorModel.getIssuesModel().getNumErrors(); 391 395 int numWarnings = editorModel.getIssuesModel().getNumWarnings(); 392 396 if (numErrors + numWarnings == 0) return true; 393 397 394 398 StringBuffer sb = new StringBuffer(); 395 399 sb.append("<html>"); … … 418 422 ) 419 423 }; 420 424 421 425 int ret = HelpAwareOptionPane.showOptionDialog( 422 426 JOptionPane.getFrameForComponent(TurnRestrictionEditor.this), … … 429 433 HelpUtil.ht("/Plugin/TurnRestrictions#PendingErrorsAndWarnings") 430 434 ); 431 return ret == 0 /* OK */; 432 } 433 435 return ret == 0 /* OK */; 436 } 437 434 438 /** 435 439 * Replies the list of relation members in {@code r} which refer to 436 440 * a deleted or invisible primitives. 437 * 438 * @param r the relation 441 * 442 * @param r the relation 439 443 * @return the list of relation members in {@code r} which refer to 440 444 * a deleted or invisible member … … 449 453 return ret; 450 454 } 451 455 452 456 /** 453 457 * Removes all members referring to deleted or invisible primitives 454 458 * from the turn restriction {@code tr}. 455 * 459 * 456 460 * @param tr the turn restriction 457 461 */ … … 466 470 tr.setMembers(members); 467 471 } 468 472 469 473 /** 470 474 * <p>Asks the user how to proceed if a turn restriction refers to deleted or invisible 471 475 * primitives.</p> 472 * 476 * 473 477 * <p>If this method returns true the respective members should be removed and the turn 474 478 * restriction should be saved anyway. If it replies false, the turn restriction must not 475 479 * be saved. </p> 476 * 477 * @param deletedMembers the list of members referring to deleted or invisible primitives 478 * @return the confirmation 480 * 481 * @param deletedMembers the list of members referring to deleted or invisible primitives 482 * @return the confirmation 479 483 */ 480 protected boolean confirmSaveTurnRestrictionWithDeletePrimitives(List<RelationMember> deletedMembers) { 484 protected boolean confirmSaveTurnRestrictionWithDeletePrimitives(List<RelationMember> deletedMembers) { 481 485 StringBuffer sb = new StringBuffer(); 482 486 sb.append("<html>"); … … 496 500 sb.append(tr("Updates to this turn restriction can''t be saved unless deleted members are removed.<br>" 497 501 + "How to you want to proceed?")); 498 502 499 503 ButtonSpec[] options = new ButtonSpec[] { 500 504 new ButtonSpec( … … 511 515 ) 512 516 }; 513 517 514 518 int ret = HelpAwareOptionPane.showOptionDialog( 515 519 TurnRestrictionEditor.this, … … 521 525 options[1], // cancel is default 522 526 null // FIXME: provide help topic 523 ); 524 return ret == 0 /* OK button */; 525 } 526 527 ); 528 return ret == 0 /* OK button */; 529 } 530 527 531 /** 528 532 * apply updates to a new turn restriction 529 533 */ 530 protected boolean applyNewTurnRestriction() { 534 protected boolean applyNewTurnRestriction() { 531 535 Relation newTurnRestriction = new Relation(); 532 536 editorModel.apply(newTurnRestriction); … … 536 540 if (newTurnRestriction.getMembersCount() == 0 && !newTurnRestriction.hasKeys()) 537 541 return true; 538 539 // check whether the turn restriction refers to new 542 543 // check whether the turn restriction refers to new 540 544 List<RelationMember> deletedMembers = getDeletedRelationMembers(newTurnRestriction); 541 545 if (!deletedMembers.isEmpty()) { … … 545 549 removeDeletedMembers(newTurnRestriction); 546 550 } 547 551 548 552 Main.main.undoRedo.add(new AddCommand(getLayer(),newTurnRestriction)); 549 553 … … 575 579 * outside of the turn restriction editor. 576 580 */ 577 protected void applyExistingNonConflictingTurnRestriction() { 581 protected void applyExistingNonConflictingTurnRestriction() { 578 582 if (getTurnRestriction().getDataSet() == null) { 579 583 editorModel.apply(getTurnRestriction()); … … 581 585 } else { 582 586 Relation toUpdate = new Relation(getTurnRestriction()); 583 editorModel.apply(toUpdate); 587 editorModel.apply(toUpdate); 584 588 Main.main.undoRedo.add(new ChangeCommand(getTurnRestriction(), toUpdate)); 585 589 } … … 652 656 applyNewTurnRestriction(); 653 657 return; 654 } 655 658 } 659 656 660 Relation toUpdate = new Relation(getTurnRestriction()); 657 661 editorModel.apply(toUpdate); 658 662 if (TurnRestrictionEditorModel.hasSameMembersAndTags(toUpdate, getTurnRestriction())) 659 // nothing to update 663 // nothing to update 660 664 return; 661 665 662 666 if (isDirtyTurnRestriction()) { 663 667 if (confirmClosingBecauseOfDirtyState()) { … … 671 675 } else { 672 676 applyExistingNonConflictingTurnRestriction(); 673 } 674 } 675 677 } 678 } 679 680 @Override 676 681 public void actionPerformed(ActionEvent e) { 677 682 run(); 678 683 } 679 684 } 680 685 681 686 class OKAction extends SavingAction { 682 687 public OKAction() { … … 698 703 } 699 704 return; 700 } 701 705 } 706 702 707 Relation toUpdate = new Relation(getTurnRestriction()); 703 708 editorModel.apply(toUpdate); 704 709 if (TurnRestrictionEditorModel.hasSameMembersAndTags(toUpdate, getTurnRestriction())){ 705 // nothing to update 710 // nothing to update 706 711 setVisible(false); 707 712 return; 708 713 } 709 714 710 715 if (isDirtyTurnRestriction()) { 711 716 // the turn restriction this editor is working on has changed outside 712 // of the editor. 717 // of the editor. 713 718 if (confirmClosingBecauseOfDirtyState()) { 714 719 if (getLayer().getConflicts().hasConflictForMy(getTurnRestriction())) { … … 721 726 } else { 722 727 applyExistingNonConflictingTurnRestriction(); 723 } 728 } 724 729 setVisible(false); 725 730 } 726 731 732 @Override 727 733 public void actionPerformed(ActionEvent e) { 728 734 run(); … … 731 737 732 738 /** 733 * Action for canceling the current dialog 739 * Action for canceling the current dialog 734 740 */ 735 741 class CancelAction extends AbstractAction { … … 743 749 } 744 750 751 @Override 745 752 public void actionPerformed(ActionEvent e) { 746 753 setVisible(false); 747 754 } 748 755 } 749 756 750 757 class DeleteAction extends AbstractAction implements PropertyChangeListener{ 751 758 public DeleteAction() { … … 755 762 updateEnabledState(); 756 763 } 757 758 protected void updateEnabledState() { 764 765 protected void updateEnabledState() { 759 766 Relation tr = getTurnRestriction(); 760 767 setEnabled(tr != null && tr.getDataSet() != null); 761 768 } 762 769 770 @Override 763 771 public void actionPerformed(ActionEvent e) { 764 772 Relation tr = getTurnRestriction(); … … 771 779 } 772 780 781 @Override 773 782 public void propertyChange(PropertyChangeEvent evt) { 774 783 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ … … 777 786 } 778 787 } 779 788 780 789 class SelectAction extends AbstractAction implements PropertyChangeListener{ 781 790 public SelectAction() { … … 785 794 updateEnabledState(); 786 795 } 787 796 788 797 protected void updateEnabledState() { 789 798 Relation tr = getTurnRestriction(); … … 791 800 } 792 801 802 @Override 793 803 public void actionPerformed(ActionEvent e) { 794 804 Relation tr = getTurnRestriction(); … … 797 807 } 798 808 809 @Override 799 810 public void propertyChange(PropertyChangeEvent evt) { 800 811 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ … … 803 814 } 804 815 } 805 816 806 817 class ZoomToAction extends AbstractAction implements PropertyChangeListener{ 807 818 public ZoomToAction() { … … 811 822 updateEnabledState(); 812 823 } 813 824 814 825 protected void updateEnabledState() { 815 826 Relation tr = getTurnRestriction(); … … 817 828 } 818 829 830 @Override 819 831 public void actionPerformed(ActionEvent e) { 820 if (Main. main.getActiveLayer() != getLayer()){832 if (Main.getLayerManager().getActiveLayer() != getLayer()){ 821 833 Main.getLayerManager().setActiveLayer(getLayer()); 822 834 } 823 835 Relation tr = getTurnRestriction(); 824 836 if (tr == null || tr.getDataSet() == null) return; 825 getLayer().data.setSelected(tr); 837 getLayer().data.setSelected(tr); 826 838 AutoScaleAction.zoomToSelection(); 827 839 } 828 840 841 @Override 829 842 public void propertyChange(PropertyChangeEvent evt) { 830 843 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ … … 833 846 } 834 847 } 835 848 836 849 class IssuesModelObserver implements Observer { 850 @Override 837 851 public void update(Observable o, Object arg) { 838 852 int numWarnings = editorModel.getIssuesModel().getNumWarnings(); … … 861 875 tpEditors.setTitleAt(2, title); 862 876 tpEditors.setEnabledAt(2, numWarnings + numErrors > 0); 863 } 864 } 865 877 } 878 } 879 866 880 /** 867 881 * <p>Listens to changes of the preference {@link PreferenceKeys#ROAD_SIGNS} 868 882 * and refreshes the set of road icons.</p> 869 * 883 * 870 884 * <p>Listens to changes of the preference {@link PreferenceKeys#SHOW_VIAS_IN_BASIC_EDITOR} 871 885 * and toggles the visibility of the list of via-objects in the Basic … … 873 887 * 874 888 */ 875 class PreferenceChangeHandler implements PreferenceChangedListener { 889 class PreferenceChangeHandler implements PreferenceChangedListener { 876 890 public void refreshIconSet() { 877 891 pnlBasicEditor.initIconSetFromPreferences(Main.pref); 878 892 } 879 880 public void preferenceChanged(PreferenceChangeEvent evt) { 893 894 @Override 895 public void preferenceChanged(PreferenceChangeEvent evt) { 881 896 if (evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)){ 882 897 refreshIconSet(); 883 898 } else if (evt.getKey().equals(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR)) { 884 899 pnlBasicEditor.initViasVisibilityFromPreferences(Main.pref); 885 } 900 } 886 901 } 887 902 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorManager.java
r30737 r32375 11 11 import java.util.Map.Entry; 12 12 13 import org.openstreetmap.josm.Main; 13 14 import org.openstreetmap.josm.data.osm.PrimitiveId; 14 15 import org.openstreetmap.josm.data.osm.Relation; 15 import org.openstreetmap.josm.gui.MapView;16 16 import org.openstreetmap.josm.gui.layer.Layer; 17 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 18 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 19 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 20 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 17 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 22 … … 21 25 * 22 26 */ 23 public class TurnRestrictionEditorManager extends WindowAdapter implements MapView.LayerChangeListener{27 public class TurnRestrictionEditorManager extends WindowAdapter implements LayerChangeListener { 24 28 //static private final Logger logger = Logger.getLogger(TurnRestrictionEditorManager.class.getName()); 25 29 … … 35 39 if (TurnRestrictionEditorManager.instance == null) { 36 40 TurnRestrictionEditorManager.instance = new TurnRestrictionEditorManager(); 37 Ma pView.addLayerChangeListener(TurnRestrictionEditorManager.instance);41 Main.getLayerManager().addLayerChangeListener(TurnRestrictionEditorManager.instance); 38 42 } 39 43 return TurnRestrictionEditorManager.instance; … … 103 107 */ 104 108 public TurnRestrictionEditorManager(){} 105 109 106 110 /** 107 111 * Register the editor for a turn restriction managed by a … … 268 272 } 269 273 } 270 274 271 275 /* ----------------------------------------------------------------------------------- */ 272 /* interface MapView.LayerChangeListener */276 /* interface LayerChangeListener */ 273 277 /* ----------------------------------------------------------------------------------- */ 274 /** 275 * called when a layer is removed 276 * 277 */ 278 public void layerRemoved(Layer oldLayer) { 278 279 @Override 280 public void layerRemoving(LayerRemoveEvent e) { 281 Layer oldLayer = e.getRemovedLayer(); 279 282 if (oldLayer == null || ! (oldLayer instanceof OsmDataLayer)) 280 283 return; … … 293 296 } 294 297 295 public void activeLayerChange(Layer oldLayer, Layer newLayer) {/* irrelevant in this context */} 296 public void layerAdded(Layer newLayer) {/* irrelevant in this context */} 298 @Override 299 public void layerAdded(LayerAddEvent e) { 300 // irrelevant in this context 301 } 302 303 @Override 304 public void layerOrderChanged(LayerOrderChangeEvent e) { 305 // irrelevant in this context 306 } 297 307 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetListModel.java
r30737 r32375 19 19 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 20 20 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 21 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 21 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 22 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 22 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 24 24 25 /** 25 26 * <p>This is the list model for the list of turn restrictions in the current data set.</p> 26 * 27 * <p>The model is a {@link EditLayerChangeListener}. It initializes itself from the data set of27 * 28 * <p>The model is a {@link ActiveLayerChangeListener}. It initializes itself from the data set of 28 29 * the current edit layer.</p> 29 * 30 * 30 31 * <p>The model is a {@link DataSetListener}. It updates itself to reflect the list of turn 31 * restrictions in the current data set.</p> 32 * restrictions in the current data set.</p> 32 33 * 33 34 */ 34 public class TurnRestrictionsInDatasetListModel extends TurnRestrictionsListModel implements EditLayerChangeListener, DataSetListener {35 public class TurnRestrictionsInDatasetListModel extends TurnRestrictionsListModel implements ActiveLayerChangeListener, DataSetListener { 35 36 //private static final Logger logger = Logger.getLogger(TurnRestrictionsInDatasetListModel.class.getName()); 36 37 37 38 public TurnRestrictionsInDatasetListModel( 38 39 DefaultListSelectionModel selectionModel) { 39 40 super(selectionModel); 40 41 } 41 42 42 43 /** 43 44 * Filters the list of turn restrictions from a collection of OSM primitives. 44 * 45 * @param primitives the primitives 46 * @return the list of turn restrictions 45 * 46 * @param primitives the primitives 47 * @return the list of turn restrictions 47 48 */ 48 49 protected List<Relation> filterTurnRestrictions(Collection<? extends OsmPrimitive> primitives) { … … 55 56 return ret; 56 57 } 57 58 58 59 /* --------------------------------------------------------------------------- */ 59 /* interface EditLayerChangeListener */60 /* interface ActiveLayerChangeListener */ 60 61 /* --------------------------------------------------------------------------- */ 61 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 62 @Override 63 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 64 OsmDataLayer newLayer = Main.getLayerManager().getEditLayer(); 62 65 if (newLayer == null) { 63 66 setTurnRestrictions(null); … … 72 75 setTurnRestrictions(turnRestrictions); 73 76 } 74 77 75 78 /* --------------------------------------------------------------------------- */ 76 79 /* interface DataSetListener */ 77 /* --------------------------------------------------------------------------- */ 78 public void dataChanged(DataChangedEvent event) { 79 OsmDataLayer layer = Main.main.getEditLayer(); 80 /* --------------------------------------------------------------------------- */ 81 @Override 82 public void dataChanged(DataChangedEvent event) { 83 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 80 84 if (layer == null) { 81 85 setTurnRestrictions(null); … … 86 90 } 87 91 92 @Override 88 93 public void primitivesAdded(PrimitivesAddedEvent event) { 89 94 List<Relation> turnRestrictions = filterTurnRestrictions(event.getPrimitives()); … … 93 98 } 94 99 100 @Override 95 101 public void primitivesRemoved(PrimitivesRemovedEvent event) { 96 102 List<Relation> turnRestrictions = filterTurnRestrictions(event.getPrimitives()); … … 100 106 } 101 107 108 @Override 102 109 public void relationMembersChanged(RelationMembersChangedEvent event) { 103 110 List<Relation> turnRestrictions = filterTurnRestrictions(event.getPrimitives()); 104 111 if (!turnRestrictions.isEmpty()) { 105 112 List<Relation> sel = getSelectedTurnRestrictions(); 106 for(Relation tr: turnRestrictions) { 113 for(Relation tr: turnRestrictions) { 107 114 // enforce a repaint of the respective turn restriction 108 115 int idx = getTurnRestrictionIndex(tr); … … 113 120 } 114 121 122 @Override 115 123 public void tagsChanged(TagsChangedEvent event) { 116 124 List<Relation> turnRestrictions = filterTurnRestrictions(event.getPrimitives()); 117 125 if (!turnRestrictions.isEmpty()) { 118 126 List<Relation> sel = getSelectedTurnRestrictions(); 119 for(Relation tr: turnRestrictions) { 127 for(Relation tr: turnRestrictions) { 120 128 // enforce a repaint of the respective turn restriction 121 129 int idx = getTurnRestrictionIndex(tr); … … 123 131 } 124 132 setSelectedTurnRestrictions(sel); 125 } 133 } 126 134 } 127 135 136 @Override 128 137 public void wayNodesChanged(WayNodesChangedEvent event) {/* ignore */} 138 @Override 129 139 public void nodeMoved(NodeMovedEvent event) {/* ignore */} 140 @Override 130 141 public void otherDatasetChange(AbstractDatasetChangedEvent event) {/* ignore */} 131 142 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetView.java
r30454 r32375 12 12 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 13 13 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 14 import org.openstreetmap.josm.gui.MapView; 15 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 14 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 16 15 17 16 /** 18 17 * This is the view for the list of turn restrictions in the current data set. 19 18 */ 20 public class TurnRestrictionsInDatasetView extends AbstractTurnRestrictionsListView { 19 public class TurnRestrictionsInDatasetView extends AbstractTurnRestrictionsListView { 21 20 protected void build() { 22 21 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); … … 26 25 lstTurnRestrictions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 27 26 lstTurnRestrictions.setCellRenderer(new TurnRestrictionCellRenderer()); 28 27 29 28 setLayout(new BorderLayout()); 30 29 add(new JScrollPane(lstTurnRestrictions), BorderLayout.CENTER); … … 32 31 33 32 protected void registerAsListener() { 34 Ma pView.addEditLayerChangeListener((EditLayerChangeListener)model);33 Main.getLayerManager().addActiveLayerChangeListener((ActiveLayerChangeListener)model); 35 34 DatasetEventManager.getInstance().addDatasetListener((DataSetListener)model, FireMode.IN_EDT); 36 if (Main. main.getEditLayer() != null) {37 model.setTurnRestrictions(Main. main.getEditLayer().data.getRelations());35 if (Main.getLayerManager().getEditLayer() != null) { 36 model.setTurnRestrictions(Main.getLayerManager().getEditLayer().data.getRelations()); 38 37 } 39 38 } 40 39 41 40 protected void unregisterAsListener() { 42 Ma pView.removeEditLayerChangeListener((EditLayerChangeListener)model);41 Main.getLayerManager().removeActiveLayerChangeListener((ActiveLayerChangeListener)model); 43 42 DatasetEventManager.getInstance().removeDatasetListener((DataSetListener)model); 44 43 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionListModel.java
r30737 r32375 7 7 import javax.swing.DefaultListSelectionModel; 8 8 9 import org.openstreetmap.josm.Main; 9 10 import org.openstreetmap.josm.data.SelectionChangedListener; 10 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 12 import org.openstreetmap.josm.data.osm.Relation; 12 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 13 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 14 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 13 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 16 … … 17 19 * objects in the current selection. 18 20 */ 19 public class TurnRestrictionsInSelectionListModel extends TurnRestrictionsListModel implements EditLayerChangeListener, SelectionChangedListener {21 public class TurnRestrictionsInSelectionListModel extends TurnRestrictionsListModel implements ActiveLayerChangeListener, SelectionChangedListener { 20 22 //private static final Logger logger = Logger.getLogger(TurnRestrictionsInSelectionListModel.class.getName()); 21 23 22 24 public TurnRestrictionsInSelectionListModel( 23 25 DefaultListSelectionModel selectionModel) { 24 26 super(selectionModel); 25 27 } 26 28 27 29 /** 28 * Initializes the model with the turn restrictions the primitives in 30 * Initializes the model with the turn restrictions the primitives in 29 31 * {@code selection} participate. 30 * 32 * 31 33 * @param selection the collection of selected primitives 32 34 */ … … 44 46 45 47 /* --------------------------------------------------------------------------- */ 46 /* interface EditLayerChangeListener*/48 /* interface ActiveLayerChangeListener */ 47 49 /* --------------------------------------------------------------------------- */ 48 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 50 @Override 51 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 52 OsmDataLayer newLayer = Main.getLayerManager().getEditLayer(); 49 53 if (newLayer == null) { 50 54 setTurnRestrictions(null); … … 53 57 initFromSelection(newLayer.data.getSelected()); 54 58 } 55 59 56 60 /* --------------------------------------------------------------------------- */ 57 61 /* interface SelectionChangedListener */ 58 /* --------------------------------------------------------------------------- */ 62 /* --------------------------------------------------------------------------- */ 63 @Override 59 64 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 60 65 initFromSelection(newSelection); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionView.java
r30454 r32375 14 14 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 15 15 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 16 import org.openstreetmap.josm.gui.MapView; 17 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 16 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 18 17 19 18 /** 20 * This is the view for the list of turn restrictions related to objects in the 19 * This is the view for the list of turn restrictions related to objects in the 21 20 * current selection. 22 * 21 * 23 22 */ 24 23 public class TurnRestrictionsInSelectionView extends AbstractTurnRestrictionsListView { … … 31 30 lstTurnRestrictions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 32 31 lstTurnRestrictions.setCellRenderer(new TurnRestrictionCellRenderer()); 33 32 34 33 setLayout(new BorderLayout()); 35 34 add(new JScrollPane(lstTurnRestrictions), BorderLayout.CENTER); … … 37 36 38 37 protected void registerAsListener() { 39 Ma pView.addEditLayerChangeListener((EditLayerChangeListener)model);38 Main.getLayerManager().addActiveLayerChangeListener((ActiveLayerChangeListener)model); 40 39 SelectionEventManager.getInstance().addSelectionListener((SelectionChangedListener)model, FireMode.IN_EDT_CONSOLIDATED); 41 40 TurnRestrictionsInSelectionListModel m = (TurnRestrictionsInSelectionListModel)model; 42 if (Main. main.getEditLayer() != null){43 m.initFromSelection(Main. main.getEditLayer().data.getSelected());41 if (Main.getLayerManager().getEditLayer() != null){ 42 m.initFromSelection(Main.getLayerManager().getEditLayer().data.getSelected()); 44 43 } else { 45 44 m.initFromSelection(Collections.<OsmPrimitive>emptyList()); … … 48 47 49 48 protected void unregisterAsListener() { 50 Ma pView.removeEditLayerChangeListener((EditLayerChangeListener)model);51 SelectionEventManager.getInstance().removeSelectionListener((SelectionChangedListener)model); 49 Main.getLayerManager().removeActiveLayerChangeListener((ActiveLayerChangeListener)model); 50 SelectionEventManager.getInstance().removeSelectionListener((SelectionChangedListener)model); 52 51 } 53 52 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListDialog.java
r30737 r32375 29 29 import org.openstreetmap.josm.data.osm.Relation; 30 30 import org.openstreetmap.josm.data.osm.RelationMember; 31 import org.openstreetmap.josm.gui.MapView;32 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;33 31 import org.openstreetmap.josm.gui.SideButton; 34 32 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 35 33 import org.openstreetmap.josm.gui.help.HelpUtil; 34 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 35 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 36 36 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 37 37 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 49 49 * <li>the list of turn restrictions related to OSM objects in the current selection</li> 50 50 * </ol> 51 * 51 * 52 52 */ 53 53 public class TurnRestrictionsListDialog extends ToggleDialog{ … … 60 60 /** the view for the turn restrictions related to the current selection */ 61 61 private TurnRestrictionsInSelectionView pnlTurnRestrictionsInSelection; 62 62 63 63 /** three actions */ 64 64 private NewAction actNew; 65 65 private EditAction actEdit; 66 private DeleteAction actDelete; 66 private DeleteAction actDelete; 67 67 private SelectSelectedTurnRestrictions actSelectSelectedTurnRestrictions; 68 68 private ZoomToAction actZoomTo; 69 69 private SwitchListViewHandler switchListViewHandler; 70 70 71 71 private AbstractTurnRestrictionsListView currentListView = null; 72 72 73 73 /** the main content panel in this toggle dialog */ 74 74 private JPanel pnlContent; 75 75 private PreferenceChangeHandler preferenceChangeHandler; 76 76 77 77 @Override 78 78 public void showNotify() { 79 pnlTurnRestrictionsInDataSet.registerAsListener(); 79 pnlTurnRestrictionsInDataSet.registerAsListener(); 80 80 pnlTurnRestrictionsInSelection.registerAsListener(); 81 Ma pView.addEditLayerChangeListener(actNew);81 Main.getLayerManager().addActiveLayerChangeListener(actNew); 82 82 actNew.updateEnabledState(); 83 83 Main.pref.addPreferenceChangeListener(preferenceChangeHandler); … … 89 89 pnlTurnRestrictionsInDataSet.unregisterAsListener(); 90 90 pnlTurnRestrictionsInSelection.unregisterAsListener(); 91 Ma pView.removeEditLayerChangeListener(actNew);91 Main.getLayerManager().removeActiveLayerChangeListener(actNew); 92 92 Main.pref.removePreferenceChangeListener(preferenceChangeHandler); 93 93 } … … 119 119 new SideButton(actDelete, false /* don't show the name */) 120 120 })); 121 122 // create the two list views 121 122 // create the two list views 123 123 pnlTurnRestrictionsInDataSet = new TurnRestrictionsInDatasetView(); 124 124 pnlTurnRestrictionsInSelection = new TurnRestrictionsInSelectionView(); 125 126 // wire the handler for switching between list views 125 126 // wire the handler for switching between list views 127 127 switchListViewHandler = new SwitchListViewHandler(); 128 128 switchListViewHandler.activateListView(pnlTurnRestrictionsInDataSet); 129 129 cbInSelectionOnly.addItemListener(switchListViewHandler); 130 131 // wire the popup menu launcher to the two turn restriction lists 130 131 // wire the popup menu launcher to the two turn restriction lists 132 132 TurnRestrictionsPopupLauncher launcher = new TurnRestrictionsPopupLauncher(); 133 133 pnlTurnRestrictionsInDataSet.getList().addMouseListener(launcher); 134 134 pnlTurnRestrictionsInSelection.getList().addMouseListener(launcher); 135 135 136 136 preferenceChangeHandler = new PreferenceChangeHandler(); 137 138 } 139 137 138 } 139 140 140 /** 141 141 * Constructor … … 143 143 public TurnRestrictionsListDialog() { 144 144 super( 145 tr("Turn Restrictions"), 145 tr("Turn Restrictions"), 146 146 "turnrestrictions", 147 147 tr("Display and manage turn restrictions in the current data set"), … … 151 151 build(); 152 152 HelpUtil.setHelpContext(this, HelpUtil.ht("/Plugin/TurnRestrictions#TurnRestrictionToggleDialog")); 153 } 154 153 } 154 155 155 /** 156 156 * Switches between the two list view. … … 166 166 } 167 167 pnlContent.add(view,BorderLayout.CENTER); 168 currentListView = view; 168 currentListView = view; 169 169 view.addListSelectionListener(actEdit); 170 170 view.addListSelectionListener(actDelete); … … 176 176 actZoomTo.updateEnabledState(); 177 177 currentListView.revalidate(); 178 currentListView.repaint(); 179 } 180 178 currentListView.repaint(); 179 } 180 181 @Override 181 182 public void itemStateChanged(ItemEvent e) { 182 183 switch(e.getStateChange()) { … … 184 185 activateListView(pnlTurnRestrictionsInSelection); 185 186 break; 186 187 case ItemEvent.DESELECTED: 187 188 case ItemEvent.DESELECTED: 188 189 activateListView(pnlTurnRestrictionsInDataSet); 189 190 break; … … 191 192 } 192 193 } 193 194 194 195 /** 195 196 * The edit action … … 199 200 public EditAction() { 200 201 putValue(SHORT_DESCRIPTION,tr("Open an editor for the selected turn restriction")); 201 putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit"));202 new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this); 202 203 putValue(NAME, tr("Edit")); 203 204 setEnabled(false); … … 205 206 protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) { 206 207 Collection<RelationMember> members = new HashSet<>(); 207 Collection<OsmPrimitive> selection = Main. main.getEditLayer().data.getSelected();208 Collection<OsmPrimitive> selection = Main.getLayerManager().getEditLayer().data.getSelected(); 208 209 for (RelationMember member: r.getMembers()) { 209 210 if (selection.contains(member.getMember())) { … … 217 218 if (toEdit == null) 218 219 return; 219 OsmDataLayer layer = Main. main.getEditLayer();220 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 220 221 TurnRestrictionEditorManager manager = TurnRestrictionEditorManager.getInstance(); 221 222 TurnRestrictionEditor editor = manager.getEditorForRelation(layer, toEdit); … … 232 233 } 233 234 235 @Override 234 236 public void actionPerformed(ActionEvent e) { 235 237 if (!isEnabled()) … … 243 245 setEnabled(currentListView!= null && currentListView.getModel().getSelectedTurnRestrictions().size() == 1); 244 246 } 245 247 248 @Override 246 249 public void valueChanged(ListSelectionEvent e) { 247 250 updateEnabledState(); … … 258 261 public DeleteAction() { 259 262 putValue(SHORT_DESCRIPTION,tr("Delete the selected turn restriction")); 260 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));263 new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this); 261 264 putValue(NAME, tr("Delete")); 262 265 setEnabled(false); … … 267 270 return; 268 271 org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation( 269 Main. main.getEditLayer(),272 Main.getLayerManager().getEditLayer(), 270 273 toDelete 271 274 ); 272 275 } 273 276 277 @Override 274 278 public void actionPerformed(ActionEvent e) { 275 279 if (!isEnabled()) return; … … 279 283 } 280 284 } 281 285 282 286 public void updateEnabledState() { 283 287 setEnabled(currentListView != null && !currentListView.getModel().getSelectedTurnRestrictions().isEmpty()); 284 288 } 285 289 290 @Override 286 291 public void valueChanged(ListSelectionEvent e) { 287 292 updateEnabledState(); … … 293 298 * 294 299 */ 295 class NewAction extends AbstractAction implements EditLayerChangeListener{300 class NewAction extends AbstractAction implements ActiveLayerChangeListener { 296 301 public NewAction() { 297 302 putValue(SHORT_DESCRIPTION,tr("Create a new turn restriction")); 298 putValue(SMALL_ICON, ImageProvider.get("new"));303 new ImageProvider("new").getResource().attachImageIcon(this); 299 304 putValue(NAME, tr("New")); 300 305 updateEnabledState(); … … 302 307 303 308 public void run() { 304 OsmDataLayer layer = Main.main.getEditLayer();309 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 305 310 if (layer == null) return; 306 311 Relation tr = new TurnRestrictionBuilder().buildFromSelection(layer); 307 312 TurnRestrictionEditor editor = new TurnRestrictionEditor(TurnRestrictionsListDialog.this, layer, tr); 308 TurnRestrictionEditorManager.getInstance().positionOnScreen(editor); 313 TurnRestrictionEditorManager.getInstance().positionOnScreen(editor); 309 314 TurnRestrictionEditorManager.getInstance().register(layer, tr, editor); 310 315 editor.setVisible(true); 311 316 } 312 317 318 @Override 313 319 public void actionPerformed(ActionEvent e) { 314 320 run(); … … 316 322 317 323 public void updateEnabledState() { 318 setEnabled(Main. main != null && Main.main.hasEditLayer());319 } 320 321 public void editLayerChanged(OsmDataLayer oldLayer,322 OsmDataLayer newLayer) {323 updateEnabledState(); 324 } 325 } 326 327 /** 328 * Sets the selection of the current data set to the currently selected 324 setEnabled(Main.getLayerManager().getEditLayer() != null); 325 } 326 327 @Override 328 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 329 updateEnabledState(); 330 } 331 } 332 333 /** 334 * Sets the selection of the current data set to the currently selected 329 335 * turn restrictions. 330 336 * … … 340 346 } 341 347 348 @Override 342 349 public void actionPerformed(ActionEvent e) { 343 350 if (!isEnabled()) return; 344 351 List<Relation> toSelect = currentListView.getModel().getSelectedTurnRestrictions(); 345 352 if (toSelect.isEmpty()) return; 346 OsmDataLayer layer= Main. main.getEditLayer();353 OsmDataLayer layer= Main.getLayerManager().getEditLayer(); 347 354 if (layer == null) return; 348 355 layer.data.setSelected(toSelect); 349 356 } 350 357 351 358 public void updateEnabledState() { 352 359 setEnabled(currentListView != null && !currentListView.getModel().getSelectedTurnRestrictions().isEmpty()); 353 360 } 354 361 362 @Override 355 363 public void valueChanged(ListSelectionEvent e) { 356 364 updateEnabledState(); 357 365 } 358 366 } 359 360 /** 361 * Sets the selection of the current data set to the currently selected 367 368 /** 369 * Sets the selection of the current data set to the currently selected 362 370 * turn restrictions. 363 371 * … … 373 381 } 374 382 383 @Override 375 384 public void actionPerformed(ActionEvent e) { 376 385 if (!isEnabled()) return; 377 386 List<Relation> toSelect = currentListView.getModel().getSelectedTurnRestrictions(); 378 387 if (toSelect.isEmpty()) return; 379 OsmDataLayer layer= Main. main.getEditLayer();388 OsmDataLayer layer= Main.getLayerManager().getEditLayer(); 380 389 if (layer == null) return; 381 390 layer.data.setSelected(toSelect); 382 391 new AutoScaleAction("selection").autoScale(); 383 392 } 384 393 385 394 public void updateEnabledState() { 386 395 setEnabled(currentListView != null && !currentListView.getModel().getSelectedTurnRestrictions().isEmpty()); 387 396 } 388 397 398 @Override 389 399 public void valueChanged(ListSelectionEvent e) { 390 400 updateEnabledState(); 391 401 } 392 402 } 393 403 394 404 /** 395 405 * The launcher for the popup menu. 396 * 406 * 397 407 */ 398 408 class TurnRestrictionsPopupLauncher extends PopupMenuLauncher { … … 412 422 413 423 /** 414 * The popup menu 424 * The popup menu 415 425 * 416 426 */ … … 425 435 } 426 436 } 427 437 428 438 /** 429 439 * Listens the changes of the preference {@link PreferenceKeys#ROAD_SIGNS} 430 * and refreshes the set of road icons 431 * 432 */ 433 class PreferenceChangeHandler implements PreferenceChangedListener { 440 * and refreshes the set of road icons 441 * 442 */ 443 class PreferenceChangeHandler implements PreferenceChangedListener { 434 444 public void refreshIconSet() { 435 445 pnlTurnRestrictionsInDataSet.initIconSetFromPreferences(Main.pref); … … 437 447 repaint(); 438 448 } 439 440 public void preferenceChanged(PreferenceChangeEvent evt) { 449 450 @Override 451 public void preferenceChanged(PreferenceChangeEvent evt) { 441 452 if (!evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)) return; 442 453 refreshIconSet();
Note:
See TracChangeset
for help on using the changeset viewer.