Ignore:
Timestamp:
2009-07-28T20:01:00+02:00 (17 years ago)
Author:
Gubaer
Message:

fixed #3116: NullPointerException when creating a relation without the data layer selected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r1856 r1866  
    101101        //
    102102        JPanel buttonPanel = new JPanel(new GridLayout(1,3));
    103         buttonPanel.add(new SideButton(marktr("New"), "addrelation", "Selection", tr("Create a new relation"), new ActionListener() {
    104             public void actionPerformed(ActionEvent e) {
    105                 // call relation editor with null argument to create new relation
    106                 RelationEditor.getEditor(Main.map.mapView.getEditLayer(),null, null).setVisible(true);
    107             }
    108         }), GBC.std());
     103
     104        // the new action
     105        //
     106        NewAction newAction = new NewAction();
     107        Layer.listeners.add(newAction);
     108        buttonPanel.add(new SideButton(newAction), GBC.std());
    109109
    110110        // the edit action
     
    313313        }
    314314    }
     315
     316    /**
     317     * The edit action
     318     *
     319     */
     320    class NewAction extends AbstractAction implements LayerChangeListener{
     321        public NewAction() {
     322            putValue(SHORT_DESCRIPTION,tr("Create a new relation"));
     323            putValue(NAME, tr("New"));
     324            putValue(SMALL_ICON, ImageProvider.get("dialogs", "addrelation"));
     325            setEnabled(false);
     326        }
     327
     328        public void run() {
     329            RelationEditor.getEditor(Main.map.mapView.getEditLayer(),null, null).setVisible(true);
     330        }
     331
     332        public void actionPerformed(ActionEvent e) {
     333            run();
     334        }
     335
     336        protected void updateEnabledState() {
     337            setEnabled(Main.main != null && Main.main.getEditLayer() != null);
     338        }
     339
     340        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     341            updateEnabledState();
     342        }
     343
     344        public void layerAdded(Layer newLayer) {
     345            updateEnabledState();
     346        }
     347
     348        public void layerRemoved(Layer oldLayer) {
     349            updateEnabledState();
     350        }
     351    }
    315352}
Note: See TracChangeset for help on using the changeset viewer.