001// License: GPL. For details, see Readme.txt file.
002package org.openstreetmap.gui.jmapviewer;
003
004import java.util.List;
005
006public class LayerGroup extends AbstractLayer {
007    private List<AbstractLayer> layers;
008
009    public LayerGroup(String name) {
010        super(name);
011    }
012
013    public LayerGroup(String name, String description) {
014        super(name, description);
015    }
016
017    public LayerGroup(String name, Style style) {
018        super(name, style);
019    }
020
021    public LayerGroup(String name, String description, Style style) {
022        super(name, description, style);
023    }
024
025    public LayerGroup(LayerGroup parent, String name) {
026        super(parent, name);
027    }
028
029    public LayerGroup(LayerGroup parent, String name, String description, Style style) {
030        super(name, description, style);
031    }
032
033    public List<AbstractLayer> getLayers() {
034        return layers;
035    }
036
037    public void setElements(List<AbstractLayer> layers) {
038        this.layers = layers;
039    }
040
041    public Layer addLayer(String name) {
042        Layer layer = new Layer(this, name);
043        layers = add(layers, layer);
044        return layer;
045    }
046
047    public LayerGroup add(AbstractLayer layer) {
048        layer.setParent(this);
049        layers = add(layers, layer);
050        return this;
051    }
052
053    public void calculateVisibleTexts() {
054        Boolean calculate = null;
055        if (layers != null && !layers.isEmpty()) {
056            calculate = layers.get(0).isVisibleTexts();
057            for (int i = 1; i < layers.size(); i++) {
058                calculate = resultOf(calculate, layers.get(i).isVisibleTexts());
059            }
060        }
061        setVisibleTexts(calculate);
062        if (getParent() != null) getParent().calculateVisibleTexts();
063    }
064
065    public Boolean resultOf(Boolean b1, Boolean b2) {
066        if (b1 != null && b1.equals(b2)) {
067            return b1;
068        }
069        return Boolean.FALSE;
070    }
071}