Statistics
| Revision:

gvsig-lrs / org.gvsig.lrs / trunk / org.gvsig.lrs / org.gvsig.lrs.swing / org.gvsig.lrs.swing.impl / src / main / java / org / gvsig / lrs / swing / impl / FLayersComboBoxModel.java @ 6

History | View | Annotate | Download (3.82 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.lrs.swing.impl;
24

    
25
import java.util.ArrayList;
26
import java.util.List;
27

    
28
import javax.swing.AbstractListModel;
29
import javax.swing.ComboBoxModel;
30

    
31
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
33

    
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.fmap.mapcontext.layers.FLayer;
36
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection;
37
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor;
38
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
39
import org.gvsig.tools.exception.BaseException;
40
import org.gvsig.tools.visitor.VisitCanceledException;
41

    
42
/**
43
 * @author fdiaz
44
 *
45
 */
46
public class FLayersComboBoxModel extends AbstractListModel<FLayer> implements ComboBoxModel<FLayer> {
47

    
48
    /**
49
     *
50
     */
51
    private static final long serialVersionUID = -1271707498886332136L;
52

    
53
    private static final Logger logger = LoggerFactory.getLogger(FLayersComboBoxModel.class);
54

    
55
    private LayerCollection layers;
56
    private List<FLyrVect> vectLayers;
57
    private FLayer selectedLayer;
58

    
59
    /**
60
     *
61
     */
62
    public FLayersComboBoxModel(LayerCollection layers) {
63
        this.layers = layers;
64
        vectLayers = new ArrayList<FLyrVect>();
65
        try {
66
            layers.accept(new LayersVisitor() {
67

    
68
                public void visit(Object obj) throws VisitCanceledException, BaseException {
69
                    // TODO Auto-generated method stub
70

    
71
                }
72

    
73
                public void visit(FLayer layer) throws BaseException {
74
                    if (layer instanceof FLyrVect) {
75
                        FLyrVect lyrVect = (FLyrVect) layer;
76
                        if (lyrVect.getGeometryType().isTypeOf(Geometry.TYPES.CURVE)
77
                            || lyrVect.getGeometryType().isTypeOf(Geometry.TYPES.MULTICURVE)) {
78
                            vectLayers.add(lyrVect);
79
                            if(lyrVect.isActive()){
80
                                selectedLayer = lyrVect;
81
                            }
82
                        }
83
                    }
84
                }
85
            });
86
        } catch (BaseException e1) {
87
            logger.warn("Can't get linear vector layers", e1);
88
        }
89
    }
90

    
91
    /*
92
     * (non-Javadoc)
93
     *
94
     * @see javax.swing.ListModel#getSize()
95
     */
96
    public int getSize() {
97
        return vectLayers.size(); //.getLayersCount();
98
    }
99

    
100
    /*
101
     * (non-Javadoc)
102
     *
103
     * @see javax.swing.ListModel#getElementAt(int)
104
     */
105
    public FLayer getElementAt(int index) {
106
        return vectLayers.get(index); //.getLayer(index);
107
    }
108

    
109
    /*
110
     * (non-Javadoc)
111
     *
112
     * @see javax.swing.ComboBoxModel#setSelectedItem(java.lang.Object)
113
     */
114
    public void setSelectedItem(final Object anItem) {
115
        selectedLayer = (FLayer) anItem;
116
    }
117

    
118
    /*
119
     * (non-Javadoc)
120
     *
121
     * @see javax.swing.ComboBoxModel#getSelectedItem()
122
     */
123
    public Object getSelectedItem() {
124
        return selectedLayer;
125
    }
126

    
127
}