Ignore:
Timestamp:
2019-11-02T15:11:34+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #16796 - Rework of GPX track colors / layer preferences (patch by Bjoeni)

File:
1 edited

Legend:

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

    r15371 r15496  
    2626import org.openstreetmap.josm.data.ProjectionBounds;
    2727import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    28 import org.openstreetmap.josm.data.preferences.AbstractProperty;
    29 import org.openstreetmap.josm.data.preferences.AbstractProperty.ValueChangeListener;
    30 import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    3128import org.openstreetmap.josm.data.projection.Projection;
    3229import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
     
    165162    private File associatedFile;
    166163
    167     private final ValueChangeListener<Object> invalidateListener = change -> invalidate();
    168164    private boolean isDestroyed;
    169165
     
    199195
    200196    /**
    201      * Gets the color property to use for this layer.
    202      * @return The color property.
    203      * @since 10824
    204      */
    205     public AbstractProperty<Color> getColorProperty() {
    206         NamedColorProperty base = getBaseColorProperty();
    207         if (base != null) {
    208             return base.getChildColor(NamedColorProperty.COLOR_CATEGORY_LAYER, getName(), base.getName());
    209         } else {
    210             return null;
    211         }
    212     }
    213 
    214     /**
    215      * Gets the color property that stores the default color for this layer.
    216      * @return The property or <code>null</code> if this layer is not colored.
    217      * @since 10824
    218      */
    219     protected NamedColorProperty getBaseColorProperty() {
     197     * @return whether the layer has / can handle colors.
     198     * @since 15496
     199     */
     200    public boolean hasColor() {
     201        return false;
     202    }
     203
     204    /**
     205     * Return the current color of the layer
     206     * @return null when not present or not supported
     207     * @since 15496
     208     */
     209    public Color getColor() {
    220210        return null;
    221211    }
    222212
    223     private void addColorPropertyListener() {
    224         AbstractProperty<Color> colorProperty = getColorProperty();
    225         if (colorProperty != null) {
    226             colorProperty.addListener(invalidateListener);
    227         }
    228     }
    229 
    230     private void removeColorPropertyListener() {
    231         AbstractProperty<Color> colorProperty = getColorProperty();
    232         if (colorProperty != null) {
    233             colorProperty.removeListener(invalidateListener);
    234         }
     213    /**
     214     * Sets the color for this layer. Nothing happens if not supported by the layer
     215     * @param color the color to be set, <code>null</code> for default
     216     * @since 15496
     217     */
     218    public void setColor(Color color) {
    235219    }
    236220
     
    303287        isDestroyed = true;
    304288        // Override in subclasses if needed
    305         removeColorPropertyListener();
    306289    }
    307290
     
    340323     */
    341324    public void setName(String name) {
    342         if (this.name != null) {
    343             removeColorPropertyListener();
    344         }
    345325        String oldValue = this.name;
    346326        this.name = Optional.ofNullable(name).orElse("");
     
    348328            propertyChangeSupport.firePropertyChange(NAME_PROP, oldValue, this.name);
    349329        }
    350 
    351         // re-add listener
    352         addColorPropertyListener();
    353330        invalidate();
    354331    }
     
    540517        @Override
    541518        public void actionPerformed(ActionEvent e) {
    542             SaveAction.getInstance().doSave(layer);
     519            SaveAction.getInstance().doSave(layer, true);
    543520        }
    544521    }
Note: See TracChangeset for help on using the changeset viewer.