Ignore:
Timestamp:
2009-08-02T23:15:26+02:00 (15 years ago)
Author:
Gubaer
Message:

update: rewrite of layer dialog
new: allows multiple selection of layers in the dialog
new: move up, move down, toggle visibility, and delete on multiple layers
new: merge from an arbitrary layer into another layer, not only from the first into the second
new: new action for merging of the currently selected primitives on an arbitrary layer
new: make "active" layer explicit (special icon); activating a layer automatically moves it in the first position
refactoring: public fields 'name' and 'visible' on Layer are @deprecated. Use the setter/getters instead, Layer now emits PropertyChangeEvents if name or visibility are changed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r1808 r1890  
    88import java.awt.Graphics;
    99import java.awt.event.ActionEvent;
     10import java.beans.PropertyChangeListener;
     11import java.beans.PropertyChangeSupport;
    1012import java.io.File;
    1113import java.util.Collection;
     
    3941 */
    4042abstract public class Layer implements Destroyable, MapViewPaintable {
     43    static public final String VISIBLE_PROP = Layer.class.getName() + ".visible";
     44    static public final String NAME_PROP = Layer.class.getName() + ".name";
     45
     46    /** keeps track of property change listeners */
     47    private PropertyChangeSupport propertyChangeSupport;
    4148
    4249    /**
     
    5865    /**
    5966     * The visibility state of the layer.
    60      */
     67     *
     68     * @deprecated use {@see #setVisible(boolean)} and {@see #isVisible()} instead. This field
     69     * is going to be private (or protected) in a future release.
     70     */
     71    @Deprecated
    6172    public boolean visible = true;
    6273
     
    6879    /**
    6980     * The name of this layer.
    70      */
     81     *
     82     * @deprecated use {@see #getName()} and {@see #setName(String)} instead. This field
     83     * is going to be private  (or protected) in the future.
     84     */
     85    @Deprecated
    7186    public String name;
    7287    /**
     
    7994     */
    8095    public Layer(String name) {
    81         this.name = name;
     96        this.propertyChangeSupport = new PropertyChangeSupport(this);
     97        setName(name);
    8298    }
    8399
     
    140156    public String getName() {
    141157        return name;
     158    }
     159
     160    /**
     161     * Sets the name of the layer
     162     *
     163     *@param name the name. If null, the name is set to the empty string.
     164     *
     165     */
     166    public void setName(String name) {
     167        if (name == null) {
     168            name = "";
     169        }
     170        String oldValue = this.name;
     171        this.name = name;
     172        if (!oldValue.equals(this.name)) {
     173            propertyChangeSupport.firePropertyChange(NAME_PROP, oldValue, this.name);
     174        }
    142175    }
    143176
     
    189222    }
    190223
     224    /**
     225     * Sets the visibility of this layer. Emits property change event for
     226     * property {@see #VISIBLE_PROP}.
     227     *
     228     * @param visible true, if the layer is visible; false, otherwise.
     229     */
     230    public void setVisible(boolean visible) {
     231        boolean oldValue = this.visible;
     232        this.visible  = visible;
     233        if (oldValue != this.visible) {
     234            fireVisibleChanged(oldValue, this.visible);
     235        }
     236    }
     237
     238    /**
     239     * Replies true if this layer is visible. False, otherwise.
     240     * @return  true if this layer is visible. False, otherwise.
     241     */
     242    public boolean isVisible() {
     243        return visible;
     244    }
     245
     246    /**
     247     * Toggles the visibility state of this layer.
     248     */
     249    public void toggleVisible() {
     250        setVisible(!isVisible());
     251    }
     252
     253    /**
     254     * Adds a {@see PropertyChangeListener}
     255     *
     256     * @param listener the listener
     257     */
     258    public void addPropertyChangeListener(PropertyChangeListener listener) {
     259        propertyChangeSupport.addPropertyChangeListener(listener);
     260    }
     261
     262    /**
     263     * Removes a {@see PropertyChangeListener}
     264     *
     265     * @param listener the listener
     266     */
     267    public void removePropertyChangeListener(PropertyChangeListener listener) {
     268        propertyChangeSupport.removePropertyChangeListener(listener);
     269    }
     270
     271    /**
     272     * fires a property change for the property {@see #VISIBLE_PROP}
     273     *
     274     * @param oldValue the old value
     275     * @param newValue the new value
     276     */
     277    protected void fireVisibleChanged(boolean oldValue, boolean newValue) {
     278        propertyChangeSupport.firePropertyChange(VISIBLE_PROP, oldValue, newValue);
     279    }
    191280}
Note: See TracChangeset for help on using the changeset viewer.