Changeset 2901 in josm


Ignore:
Timestamp:
Jan 28, 2010 5:52:55 PM (3 years ago)
Author:
mjulius
Message:

new button in LayerListDialog: Duplicate Layer
This creates a duplicate of the selected layer without a file association
see #4440

Location:
trunk
Files:
2 added
1 deleted
1 edited

Legend:

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

    r2897 r2901  
    3838 
    3939import org.openstreetmap.josm.Main; 
     40import org.openstreetmap.josm.actions.DuplicateLayerAction; 
    4041import org.openstreetmap.josm.actions.MergeLayerAction; 
    4142import org.openstreetmap.josm.gui.MapFrame; 
     
    130131        buttonPanel.add(new SideButton(mergeLayerAction)); 
    131132 
     133        // -- duplicate layer action 
     134        DuplicateAction duplicateLayerAction = new DuplicateAction(); 
     135        adaptTo(duplicateLayerAction, model); 
     136        adaptTo(duplicateLayerAction, selectionModel); 
     137        buttonPanel.add(new SideButton(duplicateLayerAction)); 
     138 
    132139        //-- delete layer action 
    133140        DeleteLayerAction deleteLayerAction = new DeleteLayerAction(); 
     
    480487 
    481488    /** 
     489     * The action to merge the currently selected layer into another layer. 
     490     */ 
     491    public final class DuplicateAction extends AbstractAction implements IEnabledStateUpdating { 
     492        private  Layer layer; 
     493 
     494        public DuplicateAction(Layer layer) throws IllegalArgumentException { 
     495            this(); 
     496            CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 
     497            this.layer = layer; 
     498            putValue(NAME, tr("Duplicate")); 
     499            updateEnabledState(); 
     500        } 
     501 
     502        public DuplicateAction() { 
     503            putValue(SMALL_ICON, ImageProvider.get("dialogs", "duplicatelayer")); 
     504            putValue(SHORT_DESCRIPTION, tr("Duplicate this layer")); 
     505            putValue("help", HelpUtil.ht("/Dialog/LayerDialog#DuplicateLayer")); 
     506            updateEnabledState(); 
     507        } 
     508 
     509        public void actionPerformed(ActionEvent e) { 
     510            if (layer != null) { 
     511                new DuplicateLayerAction().duplicate(layer); 
     512            } else { 
     513                Layer selectedLayer = getModel().getSelectedLayers().get(0); 
     514                new DuplicateLayerAction().duplicate(selectedLayer); 
     515            } 
     516        } 
     517 
     518        protected boolean isActiveLayer(Layer layer) { 
     519            if (Main.map == null) return false; 
     520            if (Main.map.mapView == null) return false; 
     521            return Main.map.mapView.getActiveLayer() == layer; 
     522        } 
     523 
     524        public void updateEnabledState() { 
     525            if (layer == null) { 
     526                if (getModel().getSelectedLayers().size() == 1) { 
     527                    setEnabled(DuplicateLayerAction.canDuplicate(getModel().getSelectedLayers().get(0))); 
     528                } else { 
     529                    setEnabled(false); 
     530                } 
     531            } else { 
     532                setEnabled(DuplicateLayerAction.canDuplicate(layer)); 
     533            } 
     534        } 
     535    } 
     536 
     537    /** 
    482538     * the list cell renderer used to render layer list entries 
    483539     * 
Note: See TracChangeset for help on using the changeset viewer.