Ignore:
Timestamp:
2016-06-23T01:27:28+02:00 (9 years ago)
Author:
donvip
Message:

update to JOSM 10369

Location:
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/CreateOrEditTurnRestrictionAction.java

    r29854 r32375  
    5050    }
    5151
     52    @Override
    5253    public void actionPerformed(ActionEvent e) {
    53         OsmDataLayer layer = Main.main.getEditLayer();
     54        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    5455        if (layer == null) return;
    5556        Collection<Relation> trs = TurnRestrictionSelectionPopupPanel.getTurnRestrictionsParticipatingIn(layer.data.getSelected());
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java

    r30737 r32375  
    2424import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    2525import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    26 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
     26import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     27import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    2728import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2829import org.openstreetmap.josm.plugins.turnrestrictions.dnd.PrimitiveIdListProvider;
     
    3031
    3132/**
    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
    3334 * objects in the current edit layer.
    34  * 
     35 *
    3536 */
    36 public class JosmSelectionListModel extends AbstractListModel<OsmPrimitive> implements EditLayerChangeListener, SelectionChangedListener, DataSetListener, PrimitiveIdListProvider{
     37public class JosmSelectionListModel extends AbstractListModel<OsmPrimitive> implements ActiveLayerChangeListener, SelectionChangedListener, DataSetListener, PrimitiveIdListProvider{
    3738    //static private final Logger logger = Logger.getLogger(JosmSelectionListModel.class.getName());
    38    
     39
    3940    private final List<OsmPrimitive> selection = new ArrayList<>();
    4041    private final DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
     
    4344    /**
    4445     * Constructor
    45      * 
     46     *
    4647     * @param selectionModel the selection model used in the list. Must not be null.
    4748     * @param layer the layer this model is displaying the selection from. Must not be null.
    4849     * @throws IllegalArgumentException thrown if {@code layer} is null
    4950     */
    50     public JosmSelectionListModel(OsmDataLayer layer) throws IllegalArgumentException{
     51    public JosmSelectionListModel(OsmDataLayer layer) {
    5152        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    5253        this.layer = layer;
     
    5455    }
    5556
     57    @Override
    5658    public OsmPrimitive getElementAt(int index) {
    5759        return selection.get(index);
    5860    }
    5961
     62    @Override
    6063    public int getSize() {
    6164        return selection.size();
     
    6568     * Replies the collection of OSM primitives currently selected in the view
    6669     * of this model
    67      * 
     70     *
    6871     * @return the selected primitives
    6972     */
     
    8083    /**
    8184     * Sets the OSM primitives to be selected in the view of this model
    82      * 
     85     *
    8386     * @param sel the collection of primitives to select
    8487     */
     
    103106    /**
    104107     * Sets the collection of currently selected OSM objects
    105      * 
     108     *
    106109     * @param selection the collection of currently selected OSM objects
    107110     */
     
    114117        }
    115118        this.selection.addAll(selection);
    116         fireContentsChanged(this, 0, getSize());       
    117         setSelected(sel);       
     119        fireContentsChanged(this, 0, getSize());
     120        setSelected(sel);
    118121        // 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.
    120123        if (getSelected().isEmpty() && this.selection.size() == 1) {
    121124            setSelected(this.selection);
     
    126129     * Triggers a refresh of the view for all primitives in {@code toUpdate}
    127130     * which are currently displayed in the view
    128      * 
     131     *
    129132     * @param toUpdate the collection of primitives to update
    130133     */
     
    141144        setSelected(sel);
    142145    }
    143        
     146
    144147    public ListSelectionModel getListSelectionModel() {
    145148        return selectionModel;
     
    147150
    148151    /* ------------------------------------------------------------------------ */
    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();
    152157        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
    154159            setJOSMSelection(null);
    155160        } else if (newLayer != layer){
     
    165170    /* interface SelectionChangeListener                                        */
    166171    /* ------------------------------------------------------------------------ */
     172    @Override
    167173    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    168174        // only update the JOSM selection if it is changed in the same data layer
    169175        // this turn restriction editor is working on
    170         OsmDataLayer layer = Main.main.getEditLayer();
     176        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    171177        if(layer == null) return;
    172178        if (layer != this.layer) return;
     
    177183    /* interface DataSetListener                                                */
    178184    /* ------------------------------------------------------------------------ */
     185    @Override
    179186    public void dataChanged(DataChangedEvent event) {
    180187        if (event.getDataset() != layer.data) return;
     
    182189    }
    183190
     191    @Override
    184192    public void nodeMoved(NodeMovedEvent event) {
    185193        if (event.getDataset() != layer.data) return;
     
    188196    }
    189197
     198    @Override
    190199    public void otherDatasetChange(AbstractDatasetChangedEvent event) {
    191200        if (event.getDataset() != layer.data) return;
     
    194203    }
    195204
     205    @Override
    196206    public void relationMembersChanged(RelationMembersChangedEvent event) {
    197207        if (event.getDataset() != layer.data) return;
     
    200210    }
    201211
     212    @Override
    202213    public void tagsChanged(TagsChangedEvent event) {
    203214        if (event.getDataset() != layer.data) return;
     
    206217    }
    207218
     219    @Override
    208220    public void wayNodesChanged(WayNodesChangedEvent event) {
    209221        if (event.getDataset() != layer.data) return;
     
    212224    }
    213225
     226    @Override
    214227    public void primitivesAdded(PrimitivesAddedEvent event) {/* ignored - handled by SelectionChangeListener */}
     228    @Override
    215229    public void primitivesRemoved(PrimitivesRemovedEvent event) {/* ignored - handled by SelectionChangeListener*/}
    216  
     230
    217231    /* ------------------------------------------------------------------------ */
    218232    /* interface PrimitiveIdListProvider                                        */
    219233    /* ------------------------------------------------------------------------ */
     234    @Override
    220235    public List<PrimitiveId> getSelectedPrimitiveIds() {
    221236        List<PrimitiveId> ret = new ArrayList<>(getSelected().size());
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java

    r30454 r32375  
    2121import javax.swing.TransferHandler;
    2222
     23import org.openstreetmap.josm.Main;
    2324import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2425import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    2526import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
    2627import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    27 import org.openstreetmap.josm.gui.MapView;
    2828import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    2929import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    4545    /** the model managing the selection */
    4646    private JosmSelectionListModel model;
    47    
     47
    4848    private CopyAction actCopy;
    4949    private TransferHandler transferHandler;
    50    
     50
    5151    /**
    52      * builds the UI for the panel 
     52     * builds the UI for the panel
    5353     */
    5454    protected void build(OsmDataLayer layer) {
     
    6060        lstSelection.setTransferHandler(transferHandler = new JosmSelectionTransferHandler(model));
    6161        lstSelection.setDragEnabled(true);
    62        
     62
    6363        add(new JScrollPane(lstSelection), BorderLayout.CENTER);
    6464        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));
    6767        actCopy = new CopyAction();
    6868        lstSelection.addMouseListener(new PopupLauncher());
    6969    }
    70    
     70
    7171    /**
    7272     * Creates the JOSM selection panel for the selection in an OSM data layer
    73      * 
     73     *
    7474     * @param layer the data layer. Must not be null.
    7575     * @exception IllegalArgumentException thrown if {@code layer} is null
     
    7878        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    7979        this.model = model;
    80         build(layer); 
     80        build(layer);
    8181    }
    82    
     82
    8383    /**
    84      * wires the UI as listener to global event sources 
     84     * wires the UI as listener to global event sources
    8585     */
    8686    public void wireListeners() {
    87         MapView.addEditLayerChangeListener(model);
     87        Main.getLayerManager().addActiveLayerChangeListener(model);
    8888        DatasetEventManager.getInstance().addDatasetListener(model, FireMode.IN_EDT);
    8989        SelectionEventManager.getInstance().addSelectionListener(model, FireMode.IN_EDT_CONSOLIDATED);
    9090    }
    91    
     91
    9292    /**
    93      * removes the UI as listener to global event sources 
     93     * removes the UI as listener to global event sources
    9494     */
    9595    public void unwireListeners() {
    96         MapView.removeEditLayerChangeListener(model);
     96        Main.getLayerManager().removeActiveLayerChangeListener(model);
    9797        DatasetEventManager.getInstance().removeDatasetListener(model);
    98         SelectionEventManager.getInstance().removeSelectionListener(model);     
     98        SelectionEventManager.getInstance().removeSelectionListener(model);
    9999    }
    100    
     100
    101101    class PopupLauncher extends PopupMenuLauncher {
    102102        @Override
    103103        public void launch(MouseEvent evt) {
    104104            new PopupMenu().show(lstSelection, evt.getX(), evt.getY());
    105         }       
     105        }
    106106    }
    107    
     107
    108108    class PopupMenu extends JPopupMenu {
    109109        public PopupMenu() {
     
    116116    class CopyAction extends AbstractAction {
    117117        private Action delegate;
    118        
     118
    119119        public CopyAction(){
    120120            putValue(NAME, tr("Copy"));
     
    125125        }
    126126
     127        @Override
    127128        public void actionPerformed(ActionEvent e) {
    128129            delegate.actionPerformed(e);
    129130        }
    130131    }
    131    
     132
    132133    static private class JosmSelectionTransferHandler extends PrimitiveIdListTransferHandler {
    133134        public JosmSelectionTransferHandler(PrimitiveIdListProvider provider) {
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java

    r32329 r32375  
    5858public class TurnRestrictionEditor extends JDialog implements NavigationControler{
    5959    //final private static Logger logger = Logger.getLogger(TurnRestrictionEditor.class.getName());
    60    
     60
    6161    /** the property name for the current turn restriction
    6262     * @link #setRelation(Relation)
     
    6969     */
    7070    static public final String TURN_RESTRICION_SNAPSHOT_PROP = RelationEditor.class.getName() + ".turnRestrictionSnapshot";
    71    
     71
    7272    /**
    7373     * The turn restriction this editor is working on
     
    7777    /**
    7878     * 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.
    8080     */
    8181    protected Relation turnRestrictionSnapshot;
     
    8383    /** the data layer the turn restriction belongs to */
    8484    private OsmDataLayer layer;
    85    
     85
    8686    private JosmSelectionPanel pnlJosmSelection;
    8787    private BasicEditorPanel pnlBasicEditor;
     
    8989    private JTabbedPane tpEditors;
    9090    private PreferenceChangeHandler preferenceChangeHandler;
    91    
     91
    9292    /**
    9393     * builds the panel with the OK and the Cancel button
     
    108108        return pnl;
    109109    }
    110    
    111     /**
    112      * builds the panel which displays the JOSM selection 
     110
     111    /**
     112     * builds the panel which displays the JOSM selection
    113113     * @return
    114114     */
     
    117117        return pnlJosmSelection;
    118118    }
    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
    122122     * this dialog)
    123      * 
     123     *
    124124     * @return
    125125     */
     
    133133        tpEditors.setTitleAt(0, tr("Basic"));
    134134        tpEditors.setToolTipTextAt(0, tr("Edit basic attributes of a turn restriction"));
    135        
     135
    136136        tpEditors.add(new AdvancedEditorPanel(editorModel));
    137137        tpEditors.setTitleAt(1, tr("Advanced"));
    138138        tpEditors.setToolTipTextAt(1, tr("Edit the raw tags and members of this turn restriction"));
    139        
     139
    140140        tpEditors.add(new IssuesView(editorModel.getIssuesModel()));
    141141        tpEditors.setTitleAt(2, tr("Errors/Warnings"));
    142142        tpEditors.setToolTipTextAt(2, tr("Show errors and warnings related to this turn restriction"));
    143        
     143
    144144        pnl.add(tpEditors, BorderLayout.CENTER);
    145145        return pnl;
    146146    }
    147    
     147
    148148    /**
    149149     * 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     *
    152152     * @return
    153153     */
     
    169169        return pnl;
    170170    }
    171    
     171
    172172    /**
    173173     * Creates the toolbar
     
    193193        return tb;
    194194    }
    195    
     195
    196196    /**
    197197     * builds the UI
    198198     */
    199     protected void build() {       
     199    protected void build() {
    200200        editorModel = new TurnRestrictionEditorModel(getLayer(), this);
    201201        Container c = getContentPane();
    202202        c.setLayout(new BorderLayout());
    203203        c.add(buildToolBar(), BorderLayout.NORTH);
    204         c.add(buildContentPanel(), BorderLayout.CENTER);       
     204        c.add(buildContentPanel(), BorderLayout.CENTER);
    205205        c.add(buildOkCancelButtonPanel(), BorderLayout.SOUTH);
    206        
     206
    207207        editorModel.getIssuesModel().addObserver(new IssuesModelObserver());
    208         setSize(600,600);       
    209     }   
    210    
     208        setSize(600,600);
     209    }
     210
    211211    /**
    212212    * Creates a new turn restriction editor
    213213    *
    214     * @param owner the component relative to which the dialog is displayed 
     214    * @param owner the component relative to which the dialog is displayed
    215215    * @param layer  the {@link OsmDataLayer} in whose context a relation is edited. Must not be null.
    216216    * @throws IllegalArgumentException thrown if layer is null
     
    219219        this(owner, layer, null);
    220220    }
    221    
     221
    222222     /**
    223223     * Creates a new turn restriction editor
    224224     *
    225      * @param owner the component relative to which the dialog is displayed 
     225     * @param owner the component relative to which the dialog is displayed
    226226     * @param layer  the {@link OsmDataLayer} in whose context a relation is edited. Must not be null.
    227227     * @param turnRestriction the relation. Can be null if a new relation is to be edited.
     
    235235        setTurnRestriction(turnRestriction);
    236236    }
    237    
     237
    238238    /**
    239239     * Replies the currently edited turn restriction
     
    253253     * is already assigned to a dataset, the dataset of {@link #getLayer()} is required, otherwise
    254254     * a {@link IllegalArgumentException} is thrown.</p>
    255      * 
     255     *
    256256     * @param turnRestriction the turn restriction
    257257     * @throws IllegalArgumentException thrown if {@code turnRestriction} belongs to a different dataset than
    258258     * that owned by the layer {@link #getLayer()}
    259259     */
    260     protected void setTurnRestriction(Relation turnRestriction) {     
     260    protected void setTurnRestriction(Relation turnRestriction) {
    261261        if (turnRestriction == null) {
    262262            editorModel.populate(new Relation());
     
    271271        updateTitle();
    272272    }
    273    
     273
    274274    /**
    275275     * updates the title of the turn restriction editor
     
    284284        }
    285285    }
    286    
     286
    287287    /**
    288288     * Replies the {@link OsmDataLayer} in whose context this relation editor is
     
    307307    /**
    308308     * Sets the turn restriction snapshot
    309      * 
     309     *
    310310     * @param snapshot the snapshot
    311311     */
    312     protected void setTurnRestrictionSnapshot(Relation snapshot) {       
     312    protected void setTurnRestrictionSnapshot(Relation snapshot) {
    313313        turnRestrictionSnapshot = snapshot;
    314314        support.firePropertyChange(TURN_RESTRICION_SNAPSHOT_PROP, null, turnRestrictionSnapshot);
    315315    }
    316    
     316
    317317    /**
    318318     * <p>Replies true if the currently edited turn restriction has been changed elsewhere.</p>
     
    326326        return ! turnRestriction.hasEqualSemanticAttributes(turnRestrictionSnapshot);
    327327    }
    328    
    329     /**
    330      * Replies the editor model for this editor 
     328
     329    /**
     330     * Replies the editor model for this editor
    331331     */
    332332    public TurnRestrictionEditorModel getModel() {
    333333        return editorModel;
    334334    }
    335    
     335
     336    @Override
    336337    public void setVisible(boolean visible) {
    337338        if (visible && ! isVisible()) {
     
    350351        }
    351352    }
    352    
     353
    353354    /* ----------------------------------------------------------------------- */
    354355    /* property change support                                                 */
     
    365366        this.support.removePropertyChangeListener(listener);
    366367    }
    367    
     368
    368369    /* ----------------------------------------------------------------------- */
    369370    /* interface NavigationControler                                           */
    370371    /* ----------------------------------------------------------------------- */
     372    @Override
    371373    public void gotoBasicEditor() {
    372374        tpEditors.setSelectedIndex(0);
    373375    }
    374376
     377    @Override
    375378    public void gotoAdvancedEditor() {
    376379        tpEditors.setSelectedIndex(1);
    377380    }
    378381
     382    @Override
    379383    public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
    380384        tpEditors.setSelectedIndex(0);
     
    386390     * to the dataset.
    387391     */
    388     abstract class SavingAction extends AbstractAction {       
     392    abstract class SavingAction extends AbstractAction {
    389393        protected boolean confirmSaveDespiteOfErrorsAndWarnings(){
    390394            int numErrors = editorModel.getIssuesModel().getNumErrors();
    391395            int numWarnings = editorModel.getIssuesModel().getNumWarnings();
    392396            if (numErrors + numWarnings == 0) return true;
    393            
     397
    394398            StringBuffer sb = new StringBuffer();
    395399            sb.append("<html>");
     
    418422                    )
    419423            };
    420            
     424
    421425            int ret = HelpAwareOptionPane.showOptionDialog(
    422426                    JOptionPane.getFrameForComponent(TurnRestrictionEditor.this),
     
    429433                    HelpUtil.ht("/Plugin/TurnRestrictions#PendingErrorsAndWarnings")
    430434            );
    431             return ret == 0 /* OK */;           
    432         }
    433        
     435            return ret == 0 /* OK */;
     436        }
     437
    434438        /**
    435439         * Replies the list of relation members in {@code r} which refer to
    436440         * a deleted or invisible primitives.
    437          * 
    438          * @param r the relation 
     441         *
     442         * @param r the relation
    439443         * @return the list of relation members in {@code r} which refer to
    440444         * a deleted or invisible member
     
    449453            return ret;
    450454        }
    451        
     455
    452456        /**
    453457         * Removes all members referring to deleted or invisible primitives
    454458         * from the turn restriction {@code tr}.
    455          * 
     459         *
    456460         * @param tr  the turn restriction
    457461         */
     
    466470            tr.setMembers(members);
    467471        }
    468        
     472
    469473        /**
    470474         * <p>Asks the user how to proceed if a turn restriction refers to deleted or invisible
    471475         * primitives.</p>
    472          * 
     476         *
    473477         * <p>If this method returns true the respective members should be removed and the turn
    474478         * restriction should be saved anyway. If it replies false, the turn restriction must not
    475479         * 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
    479483         */
    480         protected boolean confirmSaveTurnRestrictionWithDeletePrimitives(List<RelationMember> deletedMembers) {                     
     484        protected boolean confirmSaveTurnRestrictionWithDeletePrimitives(List<RelationMember> deletedMembers) {
    481485            StringBuffer sb = new StringBuffer();
    482486            sb.append("<html>");
     
    496500            sb.append(tr("Updates to this turn restriction can''t be saved unless deleted members are removed.<br>"
    497501                    + "How to you want to proceed?"));
    498            
     502
    499503            ButtonSpec[] options = new ButtonSpec[] {
    500504                    new ButtonSpec(
     
    511515                       )
    512516            };
    513            
     517
    514518            int ret = HelpAwareOptionPane.showOptionDialog(
    515519                    TurnRestrictionEditor.this,
     
    521525                    options[1], // cancel is default
    522526                    null // FIXME: provide help topic
    523             );         
    524             return ret == 0 /* OK button */; 
    525         }
    526        
     527            );
     528            return ret == 0 /* OK button */;
     529        }
     530
    527531        /**
    528532         * apply updates to a new turn restriction
    529533         */
    530         protected boolean applyNewTurnRestriction() {           
     534        protected boolean applyNewTurnRestriction() {
    531535            Relation newTurnRestriction = new Relation();
    532536            editorModel.apply(newTurnRestriction);
     
    536540            if (newTurnRestriction.getMembersCount() == 0 && !newTurnRestriction.hasKeys())
    537541                return true;
    538            
    539             // check whether the turn restriction refers to new 
     542
     543            // check whether the turn restriction refers to new
    540544            List<RelationMember> deletedMembers = getDeletedRelationMembers(newTurnRestriction);
    541545            if (!deletedMembers.isEmpty()) {
     
    545549                removeDeletedMembers(newTurnRestriction);
    546550            }
    547            
     551
    548552            Main.main.undoRedo.add(new AddCommand(getLayer(),newTurnRestriction));
    549553
     
    575579         * outside of the turn restriction editor.
    576580         */
    577         protected void applyExistingNonConflictingTurnRestriction() {           
     581        protected void applyExistingNonConflictingTurnRestriction() {
    578582            if (getTurnRestriction().getDataSet() == null) {
    579583                editorModel.apply(getTurnRestriction());
     
    581585            } else {
    582586                Relation toUpdate = new Relation(getTurnRestriction());
    583                 editorModel.apply(toUpdate);           
     587                editorModel.apply(toUpdate);
    584588                Main.main.undoRedo.add(new ChangeCommand(getTurnRestriction(), toUpdate));
    585589            }
     
    652656                applyNewTurnRestriction();
    653657                return;
    654             } 
    655            
     658            }
     659
    656660            Relation toUpdate = new Relation(getTurnRestriction());
    657661            editorModel.apply(toUpdate);
    658662            if (TurnRestrictionEditorModel.hasSameMembersAndTags(toUpdate, getTurnRestriction()))
    659                 // nothing to update 
     663                // nothing to update
    660664                return;
    661            
     665
    662666            if (isDirtyTurnRestriction()) {
    663667                if (confirmClosingBecauseOfDirtyState()) {
     
    671675            } else {
    672676                applyExistingNonConflictingTurnRestriction();
    673             }           
    674         }
    675 
     677            }
     678        }
     679
     680        @Override
    676681        public void actionPerformed(ActionEvent e) {
    677682            run();
    678683        }
    679684    }
    680    
     685
    681686    class OKAction extends SavingAction {
    682687        public OKAction() {
     
    698703                }
    699704                return;
    700             } 
    701            
     705            }
     706
    702707            Relation toUpdate = new Relation(getTurnRestriction());
    703708            editorModel.apply(toUpdate);
    704709            if (TurnRestrictionEditorModel.hasSameMembersAndTags(toUpdate, getTurnRestriction())){
    705                 // nothing to update 
     710                // nothing to update
    706711                setVisible(false);
    707712                return;
    708713            }
    709            
     714
    710715            if (isDirtyTurnRestriction()) {
    711716                // the turn restriction this editor is working on has changed outside
    712                 // of the editor. 
     717                // of the editor.
    713718                if (confirmClosingBecauseOfDirtyState()) {
    714719                    if (getLayer().getConflicts().hasConflictForMy(getTurnRestriction())) {
     
    721726            } else {
    722727                applyExistingNonConflictingTurnRestriction();
    723             }       
     728            }
    724729            setVisible(false);
    725730        }
    726731
     732        @Override
    727733        public void actionPerformed(ActionEvent e) {
    728734            run();
     
    731737
    732738    /**
    733      * Action for canceling the current dialog 
     739     * Action for canceling the current dialog
    734740     */
    735741    class CancelAction extends AbstractAction {
     
    743749        }
    744750
     751        @Override
    745752        public void actionPerformed(ActionEvent e) {
    746753            setVisible(false);
    747754        }
    748755    }
    749    
     756
    750757    class DeleteAction extends AbstractAction implements PropertyChangeListener{
    751758        public DeleteAction() {
     
    755762            updateEnabledState();
    756763        }
    757        
    758         protected void updateEnabledState() {           
     764
     765        protected void updateEnabledState() {
    759766            Relation tr = getTurnRestriction();
    760767            setEnabled(tr != null && tr.getDataSet() != null);
    761768        }
    762769
     770        @Override
    763771        public void actionPerformed(ActionEvent e) {
    764772            Relation tr = getTurnRestriction();
     
    771779        }
    772780
     781        @Override
    773782        public void propertyChange(PropertyChangeEvent evt) {
    774783            if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     
    777786        }
    778787    }
    779    
     788
    780789    class SelectAction extends AbstractAction implements PropertyChangeListener{
    781790        public SelectAction() {
     
    785794            updateEnabledState();
    786795        }
    787        
     796
    788797        protected void updateEnabledState() {
    789798            Relation tr = getTurnRestriction();
     
    791800        }
    792801
     802        @Override
    793803        public void actionPerformed(ActionEvent e) {
    794804            Relation tr = getTurnRestriction();
     
    797807        }
    798808
     809        @Override
    799810        public void propertyChange(PropertyChangeEvent evt) {
    800811            if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     
    803814        }
    804815    }
    805    
     816
    806817    class ZoomToAction extends AbstractAction implements PropertyChangeListener{
    807818        public ZoomToAction() {
     
    811822            updateEnabledState();
    812823        }
    813        
     824
    814825        protected void updateEnabledState() {
    815826            Relation tr = getTurnRestriction();
     
    817828        }
    818829
     830        @Override
    819831        public void actionPerformed(ActionEvent e) {
    820             if (Main.main.getActiveLayer() != getLayer()){
     832            if (Main.getLayerManager().getActiveLayer() != getLayer()){
    821833                Main.getLayerManager().setActiveLayer(getLayer());
    822834            }
    823835            Relation tr = getTurnRestriction();
    824836            if (tr == null || tr.getDataSet() == null) return;
    825             getLayer().data.setSelected(tr);           
     837            getLayer().data.setSelected(tr);
    826838            AutoScaleAction.zoomToSelection();
    827839        }
    828840
     841        @Override
    829842        public void propertyChange(PropertyChangeEvent evt) {
    830843            if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     
    833846        }
    834847    }
    835    
     848
    836849    class IssuesModelObserver implements Observer {
     850        @Override
    837851        public void update(Observable o, Object arg) {
    838852            int numWarnings = editorModel.getIssuesModel().getNumWarnings();
     
    861875            tpEditors.setTitleAt(2, title);
    862876            tpEditors.setEnabledAt(2, numWarnings + numErrors > 0);
    863         }       
    864     }
    865    
     877        }
     878    }
     879
    866880    /**
    867881     * <p>Listens to changes of the preference {@link PreferenceKeys#ROAD_SIGNS}
    868882     * and refreshes the set of road icons.</p>
    869      * 
     883     *
    870884     * <p>Listens to changes of the preference {@link PreferenceKeys#SHOW_VIAS_IN_BASIC_EDITOR}
    871885     * and toggles the visibility of the list of via-objects in the Basic
     
    873887     *
    874888     */
    875     class PreferenceChangeHandler implements PreferenceChangedListener {       
     889    class PreferenceChangeHandler implements PreferenceChangedListener {
    876890        public void refreshIconSet() {
    877891            pnlBasicEditor.initIconSetFromPreferences(Main.pref);
    878892        }
    879        
    880         public void preferenceChanged(PreferenceChangeEvent evt) {         
     893
     894        @Override
     895        public void preferenceChanged(PreferenceChangeEvent evt) {
    881896            if (evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)){
    882897                refreshIconSet();
    883898            } else if (evt.getKey().equals(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR)) {
    884899                pnlBasicEditor.initViasVisibilityFromPreferences(Main.pref);
    885             }           
     900            }
    886901        }
    887902    }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorManager.java

    r30737 r32375  
    1111import java.util.Map.Entry;
    1212
     13import org.openstreetmap.josm.Main;
    1314import org.openstreetmap.josm.data.osm.PrimitiveId;
    1415import org.openstreetmap.josm.data.osm.Relation;
    15 import org.openstreetmap.josm.gui.MapView;
    1616import org.openstreetmap.josm.gui.layer.Layer;
     17import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     18import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     19import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     20import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    1721import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1822
     
    2125 *
    2226 */
    23 public class TurnRestrictionEditorManager extends WindowAdapter implements MapView.LayerChangeListener{
     27public class TurnRestrictionEditorManager extends WindowAdapter implements LayerChangeListener {
    2428    //static private final Logger logger = Logger.getLogger(TurnRestrictionEditorManager.class.getName());
    2529
     
    3539        if (TurnRestrictionEditorManager.instance == null) {
    3640            TurnRestrictionEditorManager.instance = new TurnRestrictionEditorManager();
    37             MapView.addLayerChangeListener(TurnRestrictionEditorManager.instance);
     41            Main.getLayerManager().addLayerChangeListener(TurnRestrictionEditorManager.instance);
    3842        }
    3943        return TurnRestrictionEditorManager.instance;
     
    103107     */
    104108    public TurnRestrictionEditorManager(){}
    105    
     109
    106110    /**
    107111     * Register the editor for a turn restriction managed by a
     
    268272        }
    269273    }
    270    
     274
    271275    /* ----------------------------------------------------------------------------------- */
    272     /* interface MapView.LayerChangeListener                                               */
     276    /* interface LayerChangeListener                                               */
    273277    /* ----------------------------------------------------------------------------------- */
    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();
    279282        if (oldLayer == null || ! (oldLayer instanceof OsmDataLayer))
    280283            return;
     
    293296    }
    294297
    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    }
    297307}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetListModel.java

    r30737 r32375  
    1919import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    2020import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    21 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
     21import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     22import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    2223import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2324
    2425/**
    2526 * <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 of
     27 *
     28 * <p>The model is a {@link ActiveLayerChangeListener}. It initializes itself from the data set of
    2829 * the current edit layer.</p>
    29  * 
     30 *
    3031 * <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>
    3233 *
    3334 */
    34 public class TurnRestrictionsInDatasetListModel extends TurnRestrictionsListModel implements EditLayerChangeListener, DataSetListener {
     35public class TurnRestrictionsInDatasetListModel extends TurnRestrictionsListModel implements ActiveLayerChangeListener, DataSetListener {
    3536    //private static final Logger logger = Logger.getLogger(TurnRestrictionsInDatasetListModel.class.getName());
    36    
     37
    3738    public TurnRestrictionsInDatasetListModel(
    3839            DefaultListSelectionModel selectionModel) {
    3940        super(selectionModel);
    4041    }
    41    
     42
    4243    /**
    4344     * 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
    4748     */
    4849    protected List<Relation> filterTurnRestrictions(Collection<? extends OsmPrimitive> primitives) {
     
    5556        return ret;
    5657    }
    57    
     58
    5859    /* --------------------------------------------------------------------------- */
    59     /* interface EditLayerChangeListener                                           */
     60    /* interface ActiveLayerChangeListener                                           */
    6061    /* --------------------------------------------------------------------------- */
    61     public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     62    @Override
     63    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     64        OsmDataLayer newLayer = Main.getLayerManager().getEditLayer();
    6265        if (newLayer == null) {
    6366            setTurnRestrictions(null);
     
    7275        setTurnRestrictions(turnRestrictions);
    7376    }
    74    
     77
    7578    /* --------------------------------------------------------------------------- */
    7679    /* 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();
    8084        if (layer == null) {
    8185            setTurnRestrictions(null);
     
    8690    }
    8791
     92    @Override
    8893    public void primitivesAdded(PrimitivesAddedEvent event) {
    8994        List<Relation> turnRestrictions = filterTurnRestrictions(event.getPrimitives());
     
    9398    }
    9499
     100    @Override
    95101    public void primitivesRemoved(PrimitivesRemovedEvent event) {
    96102        List<Relation> turnRestrictions = filterTurnRestrictions(event.getPrimitives());
     
    100106    }
    101107
     108    @Override
    102109    public void relationMembersChanged(RelationMembersChangedEvent event) {
    103110        List<Relation> turnRestrictions = filterTurnRestrictions(event.getPrimitives());
    104111        if (!turnRestrictions.isEmpty()) {
    105112            List<Relation> sel = getSelectedTurnRestrictions();
    106             for(Relation tr: turnRestrictions) {   
     113            for(Relation tr: turnRestrictions) {
    107114                // enforce a repaint of the respective turn restriction
    108115                int idx = getTurnRestrictionIndex(tr);
     
    113120    }
    114121
     122    @Override
    115123    public void tagsChanged(TagsChangedEvent event) {
    116124        List<Relation> turnRestrictions = filterTurnRestrictions(event.getPrimitives());
    117125        if (!turnRestrictions.isEmpty()) {
    118126            List<Relation> sel = getSelectedTurnRestrictions();
    119             for(Relation tr: turnRestrictions) {   
     127            for(Relation tr: turnRestrictions) {
    120128                // enforce a repaint of the respective turn restriction
    121129                int idx = getTurnRestrictionIndex(tr);
     
    123131            }
    124132            setSelectedTurnRestrictions(sel);
    125         }       
     133        }
    126134    }
    127135
     136    @Override
    128137    public void wayNodesChanged(WayNodesChangedEvent event) {/* ignore */}
     138    @Override
    129139    public void nodeMoved(NodeMovedEvent event) {/* ignore */}
     140    @Override
    130141    public void otherDatasetChange(AbstractDatasetChangedEvent event) {/* ignore */}
    131142}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetView.java

    r30454 r32375  
    1212import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    1313import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
    14 import org.openstreetmap.josm.gui.MapView;
    15 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
     14import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1615
    1716/**
    1817 * This is the view for the list of turn restrictions in the current data set.
    1918 */
    20 public class TurnRestrictionsInDatasetView extends AbstractTurnRestrictionsListView {   
     19public class TurnRestrictionsInDatasetView extends AbstractTurnRestrictionsListView {
    2120    protected void build() {
    2221        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
     
    2625        lstTurnRestrictions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    2726        lstTurnRestrictions.setCellRenderer(new TurnRestrictionCellRenderer());
    28        
     27
    2928        setLayout(new BorderLayout());
    3029        add(new JScrollPane(lstTurnRestrictions), BorderLayout.CENTER);
     
    3231
    3332    protected void registerAsListener() {
    34         MapView.addEditLayerChangeListener((EditLayerChangeListener)model);
     33        Main.getLayerManager().addActiveLayerChangeListener((ActiveLayerChangeListener)model);
    3534        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());
    3837        }
    3938    }
    4039
    4140    protected void unregisterAsListener() {
    42         MapView.removeEditLayerChangeListener((EditLayerChangeListener)model);
     41        Main.getLayerManager().removeActiveLayerChangeListener((ActiveLayerChangeListener)model);
    4342        DatasetEventManager.getInstance().removeDatasetListener((DataSetListener)model);
    4443    }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionListModel.java

    r30737 r32375  
    77import javax.swing.DefaultListSelectionModel;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.data.SelectionChangedListener;
    1011import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1112import org.openstreetmap.josm.data.osm.Relation;
    12 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
     13import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     14import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1315import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1416
     
    1719 * objects in the current selection.
    1820 */
    19 public class TurnRestrictionsInSelectionListModel extends TurnRestrictionsListModel implements EditLayerChangeListener, SelectionChangedListener {
     21public class TurnRestrictionsInSelectionListModel extends TurnRestrictionsListModel implements ActiveLayerChangeListener, SelectionChangedListener {
    2022    //private static final Logger logger = Logger.getLogger(TurnRestrictionsInSelectionListModel.class.getName());
    21    
     23
    2224    public TurnRestrictionsInSelectionListModel(
    2325            DefaultListSelectionModel selectionModel) {
    2426        super(selectionModel);
    2527    }
    26    
     28
    2729    /**
    28      * Initializes the model with the turn restrictions the primitives in 
     30     * Initializes the model with the turn restrictions the primitives in
    2931     * {@code selection} participate.
    30      * 
     32     *
    3133     * @param selection the collection of selected primitives
    3234     */
     
    4446
    4547    /* --------------------------------------------------------------------------- */
    46     /* interface EditLayerChangeListener                                           */
     48    /* interface ActiveLayerChangeListener                                         */
    4749    /* --------------------------------------------------------------------------- */
    48     public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     50    @Override
     51    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
     52        OsmDataLayer newLayer = Main.getLayerManager().getEditLayer();
    4953        if (newLayer == null) {
    5054            setTurnRestrictions(null);
     
    5357        initFromSelection(newLayer.data.getSelected());
    5458    }
    55    
     59
    5660    /* --------------------------------------------------------------------------- */
    5761    /* interface SelectionChangedListener                                          */
    58     /* --------------------------------------------------------------------------- */   
     62    /* --------------------------------------------------------------------------- */
     63    @Override
    5964    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    6065        initFromSelection(newSelection);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionView.java

    r30454 r32375  
    1414import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
    1515import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    16 import org.openstreetmap.josm.gui.MapView;
    17 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
     16import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    1817
    1918/**
    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
    2120 * current selection.
    22  * 
     21 *
    2322 */
    2423public class TurnRestrictionsInSelectionView extends AbstractTurnRestrictionsListView {
     
    3130        lstTurnRestrictions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    3231        lstTurnRestrictions.setCellRenderer(new TurnRestrictionCellRenderer());
    33        
     32
    3433        setLayout(new BorderLayout());
    3534        add(new JScrollPane(lstTurnRestrictions), BorderLayout.CENTER);
     
    3736
    3837    protected void registerAsListener() {
    39         MapView.addEditLayerChangeListener((EditLayerChangeListener)model);
     38        Main.getLayerManager().addActiveLayerChangeListener((ActiveLayerChangeListener)model);
    4039        SelectionEventManager.getInstance().addSelectionListener((SelectionChangedListener)model, FireMode.IN_EDT_CONSOLIDATED);
    4140        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());
    4443        } else {
    4544            m.initFromSelection(Collections.<OsmPrimitive>emptyList());
     
    4847
    4948    protected void unregisterAsListener() {
    50         MapView.removeEditLayerChangeListener((EditLayerChangeListener)model);
    51         SelectionEventManager.getInstance().removeSelectionListener((SelectionChangedListener)model);       
     49        Main.getLayerManager().removeActiveLayerChangeListener((ActiveLayerChangeListener)model);
     50        SelectionEventManager.getInstance().removeSelectionListener((SelectionChangedListener)model);
    5251    }
    5352
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListDialog.java

    r30737 r32375  
    2929import org.openstreetmap.josm.data.osm.Relation;
    3030import org.openstreetmap.josm.data.osm.RelationMember;
    31 import org.openstreetmap.josm.gui.MapView;
    32 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    3331import org.openstreetmap.josm.gui.SideButton;
    3432import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    3533import org.openstreetmap.josm.gui.help.HelpUtil;
     34import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
     35import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    3636import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3737import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    4949 *   <li>the list of turn restrictions related to OSM objects in the current selection</li>
    5050 * </ol>
    51  * 
     51 *
    5252 */
    5353public class TurnRestrictionsListDialog extends ToggleDialog{
     
    6060    /** the view for the turn restrictions related to the current selection */
    6161    private TurnRestrictionsInSelectionView pnlTurnRestrictionsInSelection;
    62    
     62
    6363    /** three actions */
    6464    private NewAction actNew;
    6565    private EditAction actEdit;
    66     private DeleteAction actDelete; 
     66    private DeleteAction actDelete;
    6767    private SelectSelectedTurnRestrictions actSelectSelectedTurnRestrictions;
    6868    private ZoomToAction actZoomTo;
    6969    private SwitchListViewHandler switchListViewHandler;
    70    
     70
    7171    private AbstractTurnRestrictionsListView currentListView = null;
    72    
     72
    7373    /** the main content panel in this toggle dialog */
    7474    private JPanel pnlContent;
    7575    private PreferenceChangeHandler preferenceChangeHandler;
    76    
     76
    7777    @Override
    7878    public void showNotify() {
    79         pnlTurnRestrictionsInDataSet.registerAsListener();     
     79        pnlTurnRestrictionsInDataSet.registerAsListener();
    8080        pnlTurnRestrictionsInSelection.registerAsListener();
    81         MapView.addEditLayerChangeListener(actNew);
     81        Main.getLayerManager().addActiveLayerChangeListener(actNew);
    8282        actNew.updateEnabledState();
    8383        Main.pref.addPreferenceChangeListener(preferenceChangeHandler);
     
    8989        pnlTurnRestrictionsInDataSet.unregisterAsListener();
    9090        pnlTurnRestrictionsInSelection.unregisterAsListener();
    91         MapView.removeEditLayerChangeListener(actNew);
     91        Main.getLayerManager().removeActiveLayerChangeListener(actNew);
    9292        Main.pref.removePreferenceChangeListener(preferenceChangeHandler);
    9393    }
     
    119119            new SideButton(actDelete, false /* don't show the name */)
    120120        }));
    121        
    122         // create the two list views 
     121
     122        // create the two list views
    123123        pnlTurnRestrictionsInDataSet = new TurnRestrictionsInDatasetView();
    124124        pnlTurnRestrictionsInSelection = new TurnRestrictionsInSelectionView();
    125        
    126         // wire the handler for switching between list views 
     125
     126        // wire the handler for switching between list views
    127127        switchListViewHandler = new SwitchListViewHandler();
    128128        switchListViewHandler.activateListView(pnlTurnRestrictionsInDataSet);
    129129        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
    132132        TurnRestrictionsPopupLauncher launcher = new TurnRestrictionsPopupLauncher();
    133133        pnlTurnRestrictionsInDataSet.getList().addMouseListener(launcher);
    134134        pnlTurnRestrictionsInSelection.getList().addMouseListener(launcher);
    135        
     135
    136136        preferenceChangeHandler = new PreferenceChangeHandler();
    137        
    138     }
    139    
     137
     138    }
     139
    140140    /**
    141141     * Constructor
     
    143143    public TurnRestrictionsListDialog() {
    144144        super(
    145                 tr("Turn Restrictions"), 
     145                tr("Turn Restrictions"),
    146146                "turnrestrictions",
    147147                tr("Display and manage turn restrictions in the current data set"),
     
    151151        build();
    152152        HelpUtil.setHelpContext(this, HelpUtil.ht("/Plugin/TurnRestrictions#TurnRestrictionToggleDialog"));
    153     }   
    154    
     153    }
     154
    155155    /**
    156156     * Switches between the two list view.
     
    166166            }
    167167            pnlContent.add(view,BorderLayout.CENTER);
    168             currentListView = view;                     
     168            currentListView = view;
    169169            view.addListSelectionListener(actEdit);
    170170            view.addListSelectionListener(actDelete);
     
    176176            actZoomTo.updateEnabledState();
    177177            currentListView.revalidate();
    178             currentListView.repaint();         
    179         }
    180 
     178            currentListView.repaint();
     179        }
     180
     181        @Override
    181182        public void itemStateChanged(ItemEvent e) {
    182183            switch(e.getStateChange()) {
     
    184185                activateListView(pnlTurnRestrictionsInSelection);
    185186                break;
    186                
    187             case ItemEvent.DESELECTED:     
     187
     188            case ItemEvent.DESELECTED:
    188189                activateListView(pnlTurnRestrictionsInDataSet);
    189190                break;
     
    191192        }
    192193    }
    193    
     194
    194195     /**
    195196     * The edit action
     
    199200        public EditAction() {
    200201            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);
    202203            putValue(NAME, tr("Edit"));
    203204            setEnabled(false);
     
    205206        protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) {
    206207            Collection<RelationMember> members = new HashSet<>();
    207             Collection<OsmPrimitive> selection = Main.main.getEditLayer().data.getSelected();
     208            Collection<OsmPrimitive> selection = Main.getLayerManager().getEditLayer().data.getSelected();
    208209            for (RelationMember member: r.getMembers()) {
    209210                if (selection.contains(member.getMember())) {
     
    217218            if (toEdit == null)
    218219                return;
    219             OsmDataLayer layer = Main.main.getEditLayer();
     220            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    220221            TurnRestrictionEditorManager manager = TurnRestrictionEditorManager.getInstance();
    221222            TurnRestrictionEditor editor = manager.getEditorForRelation(layer, toEdit);
     
    232233        }
    233234
     235        @Override
    234236        public void actionPerformed(ActionEvent e) {
    235237            if (!isEnabled())
     
    243245            setEnabled(currentListView!= null && currentListView.getModel().getSelectedTurnRestrictions().size() == 1);
    244246        }
    245        
     247
     248        @Override
    246249        public void valueChanged(ListSelectionEvent e) {
    247250            updateEnabledState();
     
    258261        public DeleteAction() {
    259262            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);
    261264            putValue(NAME, tr("Delete"));
    262265            setEnabled(false);
     
    267270                return;
    268271            org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation(
    269                     Main.main.getEditLayer(),
     272                    Main.getLayerManager().getEditLayer(),
    270273                    toDelete
    271274            );
    272275        }
    273276
     277        @Override
    274278        public void actionPerformed(ActionEvent e) {
    275279            if (!isEnabled()) return;
     
    279283            }
    280284        }
    281        
     285
    282286        public void updateEnabledState() {
    283287            setEnabled(currentListView != null && !currentListView.getModel().getSelectedTurnRestrictions().isEmpty());
    284288        }
    285289
     290        @Override
    286291        public void valueChanged(ListSelectionEvent e) {
    287292            updateEnabledState();
     
    293298     *
    294299     */
    295      class NewAction extends AbstractAction implements EditLayerChangeListener{
     300     class NewAction extends AbstractAction implements ActiveLayerChangeListener {
    296301        public NewAction() {
    297302            putValue(SHORT_DESCRIPTION,tr("Create a new turn restriction"));
    298             putValue(SMALL_ICON, ImageProvider.get("new"));
     303            new ImageProvider("new").getResource().attachImageIcon(this);
    299304            putValue(NAME, tr("New"));
    300305            updateEnabledState();
     
    302307
    303308        public void run() {
    304              OsmDataLayer layer =  Main.main.getEditLayer();
     309             OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    305310             if (layer == null) return;
    306311             Relation tr = new TurnRestrictionBuilder().buildFromSelection(layer);
    307312             TurnRestrictionEditor editor = new TurnRestrictionEditor(TurnRestrictionsListDialog.this, layer, tr);
    308              TurnRestrictionEditorManager.getInstance().positionOnScreen(editor);             
     313             TurnRestrictionEditorManager.getInstance().positionOnScreen(editor);
    309314             TurnRestrictionEditorManager.getInstance().register(layer, tr, editor);
    310315             editor.setVisible(true);
    311316        }
    312317
     318        @Override
    313319        public void actionPerformed(ActionEvent e) {
    314320            run();
     
    316322
    317323        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
    329335     * turn restrictions.
    330336     *
     
    340346        }
    341347
     348        @Override
    342349        public void actionPerformed(ActionEvent e) {
    343350            if (!isEnabled()) return;
    344351            List<Relation> toSelect = currentListView.getModel().getSelectedTurnRestrictions();
    345352            if (toSelect.isEmpty()) return;
    346             OsmDataLayer layer= Main.main.getEditLayer();
     353            OsmDataLayer layer= Main.getLayerManager().getEditLayer();
    347354            if (layer == null) return;
    348355            layer.data.setSelected(toSelect);
    349356        }
    350        
     357
    351358        public void updateEnabledState() {
    352359            setEnabled(currentListView != null && !currentListView.getModel().getSelectedTurnRestrictions().isEmpty());
    353360        }
    354361
     362        @Override
    355363        public void valueChanged(ListSelectionEvent e) {
    356364            updateEnabledState();
    357365        }
    358366    }
    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
    362370     * turn restrictions.
    363371     *
     
    373381        }
    374382
     383        @Override
    375384        public void actionPerformed(ActionEvent e) {
    376385            if (!isEnabled()) return;
    377386            List<Relation> toSelect = currentListView.getModel().getSelectedTurnRestrictions();
    378387            if (toSelect.isEmpty()) return;
    379             OsmDataLayer layer= Main.main.getEditLayer();
     388            OsmDataLayer layer= Main.getLayerManager().getEditLayer();
    380389            if (layer == null) return;
    381390            layer.data.setSelected(toSelect);
    382391            new AutoScaleAction("selection").autoScale();
    383392        }
    384        
     393
    385394        public void updateEnabledState() {
    386395            setEnabled(currentListView != null && !currentListView.getModel().getSelectedTurnRestrictions().isEmpty());
    387396        }
    388397
     398        @Override
    389399        public void valueChanged(ListSelectionEvent e) {
    390400            updateEnabledState();
    391401        }
    392402    }
    393    
     403
    394404    /**
    395405     * The launcher for the popup menu.
    396      * 
     406     *
    397407     */
    398408    class TurnRestrictionsPopupLauncher extends PopupMenuLauncher {
     
    412422
    413423    /**
    414      * The popup menu 
     424     * The popup menu
    415425     *
    416426     */
     
    425435        }
    426436    }
    427    
     437
    428438    /**
    429439     * 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 {
    434444        public void refreshIconSet() {
    435445            pnlTurnRestrictionsInDataSet.initIconSetFromPreferences(Main.pref);
     
    437447            repaint();
    438448        }
    439        
    440         public void preferenceChanged(PreferenceChangeEvent evt) {         
     449
     450        @Override
     451        public void preferenceChanged(PreferenceChangeEvent evt) {
    441452            if (!evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)) return;
    442453            refreshIconSet();
Note: See TracChangeset for help on using the changeset viewer.