001// License: GPL. For details, see Readme.txt file.
002package org.openstreetmap.gui.jmapviewer;
003
004import java.util.ArrayList;
005import java.util.List;
006
007public class AbstractLayer {
008    private LayerGroup parent;
009    private String name;
010    private String description;
011    private Style style;
012    private Boolean visible;
013    private Boolean visibleTexts = Boolean.TRUE;
014
015    public AbstractLayer(String name) {
016        this(name, (String) null);
017    }
018
019    public AbstractLayer(String name, String description) {
020        this(name, description, MapMarkerCircle.getDefaultStyle());
021    }
022
023    public AbstractLayer(String name, Style style) {
024        this(name, null, style);
025    }
026
027    public AbstractLayer(String name, String description, Style style) {
028        this(null, name, description, style);
029    }
030
031    public AbstractLayer(LayerGroup parent, String name) {
032        this(parent, name, MapMarkerCircle.getDefaultStyle());
033    }
034
035    public AbstractLayer(LayerGroup parent, String name, Style style) {
036        this(parent, name, null, style);
037    }
038
039    public AbstractLayer(LayerGroup parent, String name, String description, Style style) {
040        setParent(parent);
041        setName(name);
042        setDescription(description);
043        setStyle(style);
044        setVisible(Boolean.TRUE);
045
046        if (parent != null) parent.add(this);
047    }
048
049    public LayerGroup getParent() {
050        return parent;
051    }
052
053    public void setParent(LayerGroup parent) {
054        this.parent = parent;
055    }
056
057    public String getName() {
058        return name;
059    }
060
061    public void setName(String name) {
062        this.name = name;
063    }
064
065    public String getDescription() {
066        return description;
067    }
068
069    public void setDescription(String description) {
070        this.description = description;
071    }
072
073    public Style getStyle() {
074        return style;
075    }
076
077    public void setStyle(Style style) {
078        this.style = style;
079    }
080
081    public Boolean isVisible() {
082        return visible;
083    }
084
085    public void setVisible(Boolean visible) {
086        this.visible = visible;
087    }
088
089    public static <E> List<E> add(List<E> list, E element) {
090        if (element != null) {
091            if (list == null) list = new ArrayList<>();
092            if (!list.contains(element)) list.add(element);
093        }
094        return list;
095    }
096
097    public Boolean isVisibleTexts() {
098        return visibleTexts;
099    }
100
101    public void setVisibleTexts(Boolean visibleTexts) {
102        this.visibleTexts = visibleTexts;
103    }
104
105    @Override
106    public String toString() {
107        return name;
108    }
109}