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 / FLayersMComboBoxModel.java @ 47

History | View | Annotate | Download (4 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 FLayersMComboBoxModel extends AbstractListModel<FLayer> implements ComboBoxModel<FLayer> {
47

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

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

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

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

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

    
69
                }
70

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

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

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

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

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

    
129
}