svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / gui / LayerSelectionPanel.java @ 30840
History | View | Annotate | Download (7.63 KB)
1 | 8410 | azabala | /*
|
---|---|---|---|
2 | * Created on 27-oct-2006
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | /* CVS MESSAGES:
|
||
45 | *
|
||
46 | * $Id$
|
||
47 | * $Log$
|
||
48 | 13583 | fjp | * Revision 1.4 2007-09-07 11:29:47 fjp
|
49 | * Casi compila. Falta arreglar lo de FArrowSymbol y retocar el graphiclist de FMap.
|
||
50 | *
|
||
51 | * Revision 1.3 2006/11/08 19:32:44 azabala
|
||
52 | 8410 | azabala | * *** empty log message ***
|
53 | *
|
||
54 | 8624 | azabala | * Revision 1.2 2006/11/03 19:39:29 azabala
|
55 | * *** empty log message ***
|
||
56 | *
|
||
57 | 8513 | azabala | * Revision 1.1 2006/10/27 18:26:07 azabala
|
58 | * *** empty log message ***
|
||
59 | 8410 | azabala | *
|
60 | 8513 | azabala | *
|
61 | 8410 | azabala | */
|
62 | 22182 | fpenarrubia | package org.gvsig.graph.gui; |
63 | 8410 | azabala | |
64 | 8513 | azabala | import java.awt.BorderLayout; |
65 | 8410 | azabala | import java.awt.Container; |
66 | import java.awt.GridBagConstraints; |
||
67 | import java.awt.Window; |
||
68 | import java.awt.event.ActionEvent; |
||
69 | import java.awt.event.ActionListener; |
||
70 | import java.util.ArrayList; |
||
71 | import java.util.Arrays; |
||
72 | |||
73 | import javax.swing.DefaultComboBoxModel; |
||
74 | import javax.swing.JComboBox; |
||
75 | import javax.swing.JLabel; |
||
76 | import javax.swing.JPanel; |
||
77 | 13583 | fjp | |
78 | 8410 | azabala | import org.gvsig.gui.beans.AcceptCancelPanel; |
79 | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
||
80 | |||
81 | 13583 | fjp | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
82 | 8410 | azabala | import com.iver.andami.PluginServices; |
83 | import com.iver.andami.ui.mdiManager.IWindow; |
||
84 | import com.iver.andami.ui.mdiManager.WindowInfo; |
||
85 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
86 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
87 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
88 | |||
89 | /**
|
||
90 | * Component that shows in a combobox all the TOC's layers, and allows
|
||
91 | * user to select one of them.
|
||
92 | *
|
||
93 | * It optionally allows to filter layers for a given geometry type.
|
||
94 | *
|
||
95 | *
|
||
96 | * */
|
||
97 | 8513 | azabala | public class LayerSelectionPanel extends JPanel implements IWindow{ |
98 | 8410 | azabala | |
99 | 8513 | azabala | private GridBagLayoutPanel contentPanel;
|
100 | |||
101 | 8410 | azabala | FLayers layers = null;
|
102 | JComboBox layersComboBox = null; |
||
103 | AcceptCancelPanel buttonPanel = null;
|
||
104 | |||
105 | |||
106 | private ActionListener okActionListener = new ActionListener(){ |
||
107 | public void actionPerformed(ActionEvent arg0) { |
||
108 | wasFinishPressed = true;
|
||
109 | closeParent(LayerSelectionPanel.this); |
||
110 | } |
||
111 | }; |
||
112 | |||
113 | private ActionListener cancelActionListener = new ActionListener(){ |
||
114 | public void actionPerformed(ActionEvent arg0) { |
||
115 | wasFinishPressed = false;
|
||
116 | closeParent(LayerSelectionPanel.this); |
||
117 | } |
||
118 | }; |
||
119 | String title = null; |
||
120 | String introductoryText = null; |
||
121 | |||
122 | 8513 | azabala | boolean wasFinishPressed = false; |
123 | 8410 | azabala | |
124 | /**
|
||
125 | * Optinal filter to show in the combo box layers of a given
|
||
126 | * geometry typ0e
|
||
127 | * */
|
||
128 | 23212 | fpenarrubia | ArrayList<Integer> geometryType = new ArrayList<Integer>(); |
129 | 8410 | azabala | |
130 | /**
|
||
131 | * If it is not null, we'll filter layers to only show
|
||
132 | * types of this class
|
||
133 | * */
|
||
134 | Class layerType;
|
||
135 | private WindowInfo wi;
|
||
136 | |||
137 | |||
138 | |||
139 | public LayerSelectionPanel(FLayers tocLayers,
|
||
140 | String title,
|
||
141 | String introductoryText){
|
||
142 | 8513 | azabala | this(tocLayers, title, introductoryText, (Class) null, -1); |
143 | |||
144 | } |
||
145 | |||
146 | public LayerSelectionPanel(FLayers layers, String title, |
||
147 | String introductoryText, Class class1, int geometryType) { |
||
148 | 8410 | azabala | super();
|
149 | 8513 | azabala | this.layers = layers;
|
150 | 8410 | azabala | this.introductoryText = introductoryText;
|
151 | 8513 | azabala | this.layerType = class1;
|
152 | 23212 | fpenarrubia | this.geometryType.add(geometryType);
|
153 | 8410 | azabala | initialize(); |
154 | } |
||
155 | 8513 | azabala | |
156 | 23212 | fpenarrubia | public void addGeometryTypeConstraint(int geometryType){ |
157 | 8410 | azabala | if(layerType == null || !(layerType.isAssignableFrom(FLyrVect.class))) |
158 | return;
|
||
159 | 23212 | fpenarrubia | this.geometryType.add(geometryType);
|
160 | updateLayerCombo(); |
||
161 | 8410 | azabala | } |
162 | |||
163 | public void setLayerTypeConstraint(Class layerClass){ |
||
164 | this.layerType = layerClass;
|
||
165 | } |
||
166 | |||
167 | |||
168 | public FLayer getLayer() {
|
||
169 | FLayer solution = null;
|
||
170 | String selectedLayer = (String)layersComboBox.getSelectedItem(); |
||
171 | 8624 | azabala | if(selectedLayer != null){ |
172 | if(!(selectedLayer.trim().equals(""))) |
||
173 | solution = layers.getLayer(selectedLayer); |
||
174 | } |
||
175 | |||
176 | 8410 | azabala | return solution;
|
177 | } |
||
178 | |||
179 | public void setFLayers(FLayers layers){ |
||
180 | this.layers = layers;
|
||
181 | updateLayerCombo(); |
||
182 | } |
||
183 | |||
184 | public void initialize(){ |
||
185 | 8513 | azabala | setLayout(new BorderLayout()); |
186 | contentPanel = new GridBagLayoutPanel();
|
||
187 | 8624 | azabala | contentPanel.addComponent(new JLabel(introductoryText), GridBagConstraints.BOTH); |
188 | JComboBox comboBox = getLayersComboBox();
|
||
189 | contentPanel.addComponent(PluginServices.getText(null, "Capas:"), comboBox); |
||
190 | 8513 | azabala | add(contentPanel, BorderLayout.NORTH);
|
191 | add(getButtonPanel(), BorderLayout.SOUTH);
|
||
192 | |||
193 | 8410 | azabala | } |
194 | |||
195 | AcceptCancelPanel getButtonPanel() { |
||
196 | if (buttonPanel == null) { |
||
197 | buttonPanel = new AcceptCancelPanel();
|
||
198 | buttonPanel.setOkButtonActionListener(okActionListener); |
||
199 | buttonPanel.setCancelButtonActionListener(cancelActionListener); |
||
200 | } |
||
201 | return buttonPanel;
|
||
202 | } |
||
203 | |||
204 | |||
205 | void updateLayerCombo(){
|
||
206 | DefaultComboBoxModel defaultModel =
|
||
207 | new DefaultComboBoxModel(getLayerNames()); |
||
208 | layersComboBox.setModel(defaultModel); |
||
209 | } |
||
210 | |||
211 | public boolean wasFinishPressed(){ |
||
212 | return wasFinishPressed;
|
||
213 | } |
||
214 | |||
215 | protected FLayer[] getLayerForType(FLayers layers){ |
||
216 | FLayer[] solution = null; |
||
217 | int numLayers = layers.getLayersCount();
|
||
218 | if(layers != null && numLayers > 0){ |
||
219 | ArrayList list = new ArrayList(); |
||
220 | for(int i = 0; i < numLayers; i++){ |
||
221 | FLayer layer = layers.getLayer(i); |
||
222 | if(layerType != null){ |
||
223 | if(!layer.getClass().isAssignableFrom(layerType))
|
||
224 | continue;
|
||
225 | if(layer instanceof FLyrVect){ |
||
226 | 23212 | fpenarrubia | FLyrVect lyrVect = (FLyrVect) layer; |
227 | 8410 | azabala | try {
|
228 | 23212 | fpenarrubia | for (int j=0; j < geometryType.size(); j++) { |
229 | if(lyrVect.getShapeType() == geometryType.get(j))
|
||
230 | list.add(layer); |
||
231 | } |
||
232 | 13583 | fjp | } catch (ReadDriverException e) {
|
233 | 8410 | azabala | continue;
|
234 | } |
||
235 | }//if
|
||
236 | }//if
|
||
237 | if(layer instanceof FLayers){ |
||
238 | list.addAll(Arrays.asList(getLayerForType((FLayers)layer)));
|
||
239 | } |
||
240 | }//for
|
||
241 | solution = new FLyrVect[list.size()];
|
||
242 | list.toArray(solution); |
||
243 | }//if
|
||
244 | return solution;
|
||
245 | } |
||
246 | |||
247 | protected String[] getLayerNames() { |
||
248 | String[] solution = null; |
||
249 | ArrayList nameList = new ArrayList(); |
||
250 | FLayer[] layers = getLayerForType(this.layers); |
||
251 | for(int i = 0; i < layers.length; i++){ |
||
252 | nameList.add(layers[i].getName()); |
||
253 | } |
||
254 | solution = new String[nameList.size()]; |
||
255 | nameList.toArray(solution); |
||
256 | return solution;
|
||
257 | } |
||
258 | |||
259 | private JComboBox getLayersComboBox() { |
||
260 | if (layersComboBox == null) { |
||
261 | layersComboBox = new JComboBox(); |
||
262 | } |
||
263 | updateLayerCombo(); |
||
264 | return layersComboBox;
|
||
265 | } |
||
266 | |||
267 | public static void closeParent(JPanel component){ |
||
268 | Container container = component.getParent();
|
||
269 | Container parentOfContainer = null; |
||
270 | while(! (container instanceof Window)){ |
||
271 | parentOfContainer = container.getParent(); |
||
272 | container = parentOfContainer; |
||
273 | } |
||
274 | ((Window)container).dispose();
|
||
275 | } |
||
276 | |||
277 | |||
278 | |||
279 | public WindowInfo getWindowInfo() {
|
||
280 | if (wi==null) { |
||
281 | wi = new WindowInfo(WindowInfo.MODALDIALOG);
|
||
282 | 30840 | fpenarrubia | wi.setWidth(350);
|
283 | 8624 | azabala | wi.setHeight(120);
|
284 | 8410 | azabala | wi.setTitle(title); |
285 | } |
||
286 | return wi;
|
||
287 | } |
||
288 | 24989 | jcampos | public Object getWindowProfile(){ |
289 | return WindowInfo.DIALOG_PROFILE;
|
||
290 | } |
||
291 | 8410 | azabala | |
292 | } // @jve:decl-index=0:visual-constraint="10,10"
|