Changeset 1890 in josm for trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
- Timestamp:
- 2009-08-02T23:15:26+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r1808 r1890 8 8 import java.awt.Graphics; 9 9 import java.awt.event.ActionEvent; 10 import java.beans.PropertyChangeListener; 11 import java.beans.PropertyChangeSupport; 10 12 import java.io.File; 11 13 import java.util.Collection; … … 39 41 */ 40 42 abstract 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; 41 48 42 49 /** … … 58 65 /** 59 66 * 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 61 72 public boolean visible = true; 62 73 … … 68 79 /** 69 80 * 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 71 86 public String name; 72 87 /** … … 79 94 */ 80 95 public Layer(String name) { 81 this.name = name; 96 this.propertyChangeSupport = new PropertyChangeSupport(this); 97 setName(name); 82 98 } 83 99 … … 140 156 public String getName() { 141 157 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 } 142 175 } 143 176 … … 189 222 } 190 223 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 } 191 280 }
Note:
See TracChangeset
for help on using the changeset viewer.