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 @ 63
History | View | Annotate | Download (3.79 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 List<FLyrVect> vectLayers; |
56 |
private FLayer selectedLayer;
|
57 |
|
58 |
/**
|
59 |
*
|
60 |
*/
|
61 |
public FLayersComboBoxModel(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 |
vectLayers.add(lyrVect); |
77 |
if(lyrVect.isActive()){
|
78 |
selectedLayer = lyrVect; |
79 |
} |
80 |
} |
81 |
} |
82 |
} |
83 |
}); |
84 |
} catch (BaseException e1) {
|
85 |
logger.warn("Can't get linear vector layers", e1);
|
86 |
} |
87 |
} |
88 |
|
89 |
/*
|
90 |
* (non-Javadoc)
|
91 |
*
|
92 |
* @see javax.swing.ListModel#getSize()
|
93 |
*/
|
94 |
public int getSize() { |
95 |
return vectLayers.size(); //.getLayersCount(); |
96 |
} |
97 |
|
98 |
/*
|
99 |
* (non-Javadoc)
|
100 |
*
|
101 |
* @see javax.swing.ListModel#getElementAt(int)
|
102 |
*/
|
103 |
public FLayer getElementAt(int index) { |
104 |
return vectLayers.get(index); //.getLayer(index); |
105 |
} |
106 |
|
107 |
/*
|
108 |
* (non-Javadoc)
|
109 |
*
|
110 |
* @see javax.swing.ComboBoxModel#setSelectedItem(java.lang.Object)
|
111 |
*/
|
112 |
public void setSelectedItem(final Object anItem) { |
113 |
selectedLayer = (FLayer) anItem; |
114 |
fireContentsChanged(this, -1, -1); |
115 |
} |
116 |
|
117 |
/*
|
118 |
* (non-Javadoc)
|
119 |
*
|
120 |
* @see javax.swing.ComboBoxModel#getSelectedItem()
|
121 |
*/
|
122 |
public Object getSelectedItem() { |
123 |
return selectedLayer;
|
124 |
} |
125 |
|
126 |
} |