svn-gvsig-desktop / tags / v1_0_2_Build_906 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / selectionByTheme / SelectionByTheme.java @ 10972
History | View | Annotate | Download (9.75 KB)
1 | 1103 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 934 | fernando | package com.iver.cit.gvsig.gui.selectionByTheme; |
42 | |||
43 | 6122 | jaume | import java.awt.BorderLayout; |
44 | import java.awt.GridLayout; |
||
45 | 934 | fernando | import java.util.ArrayList; |
46 | |||
47 | import javax.swing.DefaultComboBoxModel; |
||
48 | 6122 | jaume | import javax.swing.JLabel; |
49 | 934 | fernando | import javax.swing.JPanel; |
50 | |||
51 | 6122 | jaume | import org.gvsig.gui.beans.swing.JButton; |
52 | |||
53 | 934 | fernando | import com.iver.andami.PluginServices; |
54 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
55 | 6880 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
56 | 6122 | jaume | import com.iver.utiles.swing.JComboBox; |
57 | 934 | fernando | |
58 | |||
59 | 6877 | cesar | public class SelectionByTheme extends JPanel implements IWindow { |
60 | 934 | fernando | public static final int EQUALS = 0; |
61 | public static final int DISJOINT = 1; |
||
62 | public static final int INTERSECTS = 2; |
||
63 | public static final int TOUCHES = 3; |
||
64 | public static final int CROSSES = 4; |
||
65 | public static final int WITHIN = 5; |
||
66 | public static final int CONTAINS = 6; |
||
67 | public static final int OVERLAPS = 7; |
||
68 | 3437 | jmorell | public final String[] textosAcciones = new String[] { |
69 | PluginServices.getText(this, "Sean_iguales_a"), //"sean iguales a", |
||
70 | PluginServices.getText(this, "Sean_disjuntos_a"), //"sean disjuntos a", |
||
71 | PluginServices.getText(this, "Intersecten_con"), //"intersecten con", |
||
72 | PluginServices.getText(this, "Toquen"), //"toquen", |
||
73 | PluginServices.getText(this, "Crucen_con"), //"crucen con", |
||
74 | PluginServices.getText(this, "Contengan"), //"contengan", |
||
75 | PluginServices.getText(this, "Esten_contenidos_en"), //"est?n contenidos en", |
||
76 | PluginServices.getText(this, "Se_superponen_a"), //"se superponen a" |
||
77 | 934 | fernando | }; |
78 | |||
79 | 950 | fernando | private SelectionByThemeModel dataSource = null; |
80 | 934 | fernando | |
81 | private ArrayList listeners = new ArrayList(); |
||
82 | |||
83 | 6122 | jaume | private JPanel jPanel = null; |
84 | private JPanel jPanel1 = null; |
||
85 | private JLabel jLabel = null; |
||
86 | private JComboBox cmbAction = null; |
||
87 | private JLabel jLabel1 = null; |
||
88 | private JComboBox cmbCapas = null; |
||
89 | private JButton btnNew = null; |
||
90 | private JButton btnAdd = null; |
||
91 | private JButton btnFrom = null; |
||
92 | private JButton btnCancel = null; |
||
93 | 934 | fernando | /**
|
94 | * This is the default constructor
|
||
95 | */
|
||
96 | public SelectionByTheme() {
|
||
97 | super();
|
||
98 | initialize(); |
||
99 | } |
||
100 | /**
|
||
101 | * This method initializes this
|
||
102 | 6122 | jaume | *
|
103 | 934 | fernando | * @return void
|
104 | */
|
||
105 | private void initialize() { |
||
106 | 6122 | jaume | this.setLayout(new BorderLayout(10, 10)); |
107 | this.add(new JLabel(), BorderLayout.NORTH); |
||
108 | this.add(new JLabel(), BorderLayout.WEST); |
||
109 | this.add(getJPanel(), BorderLayout.CENTER); |
||
110 | this.add(getJPanel1(), BorderLayout.EAST); |
||
111 | this.add(new JLabel(), BorderLayout.SOUTH); |
||
112 | 7365 | jmvivo | this.setSize(540, 95); |
113 | 934 | fernando | } |
114 | /**
|
||
115 | * This method initializes jPanel
|
||
116 | 6122 | jaume | *
|
117 | * @return JPanel
|
||
118 | 934 | fernando | */
|
119 | 6122 | jaume | private JPanel getJPanel() { |
120 | 934 | fernando | if(jPanel == null) { |
121 | 6122 | jaume | jPanel = new JPanel(); |
122 | 934 | fernando | java.awt.FlowLayout layFlowLayout1 = new java.awt.FlowLayout();
|
123 | layFlowLayout1.setVgap(30);
|
||
124 | 6122 | jaume | jPanel.setLayout(new GridLayout(4, 2, 5, 5)); |
125 | 934 | fernando | jPanel.add(getJLabel(), null);
|
126 | jPanel.add(getCmbAction(), null);
|
||
127 | jPanel.add(getJLabel1(), null);
|
||
128 | jPanel.add(getCmbCapas(), null);
|
||
129 | 6122 | jaume | |
130 | 934 | fernando | } |
131 | return jPanel;
|
||
132 | } |
||
133 | /**
|
||
134 | * This method initializes jPanel1
|
||
135 | 6122 | jaume | *
|
136 | * @return JPanel
|
||
137 | 934 | fernando | */
|
138 | 6122 | jaume | private JPanel getJPanel1() { |
139 | 934 | fernando | if(jPanel1 == null) { |
140 | 6122 | jaume | jPanel1 = new JPanel(); |
141 | jPanel1.setLayout(new GridLayout(4, 1, 5, 5)); |
||
142 | 934 | fernando | jPanel1.add(getBtnNew(), null);
|
143 | jPanel1.add(getBtnAdd(), null);
|
||
144 | jPanel1.add(getBtnFrom(), null);
|
||
145 | jPanel1.add(getBtnCancel(), null);
|
||
146 | 7365 | jmvivo | jPanel1.setPreferredSize(new java.awt.Dimension(200,220)); |
147 | 934 | fernando | } |
148 | return jPanel1;
|
||
149 | } |
||
150 | /**
|
||
151 | * This method initializes jLabel
|
||
152 | 6122 | jaume | *
|
153 | * @return JLabel
|
||
154 | 934 | fernando | */
|
155 | 6122 | jaume | private JLabel getJLabel() { |
156 | 934 | fernando | if(jLabel == null) { |
157 | 6122 | jaume | jLabel = new JLabel(); |
158 | 3437 | jmorell | jLabel.setText(PluginServices.getText(this, "Seleccionar_de_las_capas_activas_los_elementos_que") + "... "); |
159 | 934 | fernando | } |
160 | return jLabel;
|
||
161 | } |
||
162 | /**
|
||
163 | * This method initializes cmbAction
|
||
164 | 6122 | jaume | *
|
165 | * @return JComboBox
|
||
166 | 934 | fernando | */
|
167 | 6122 | jaume | private JComboBox getCmbAction() { |
168 | 934 | fernando | if(cmbAction == null) { |
169 | 6122 | jaume | cmbAction = new JComboBox(); |
170 | 934 | fernando | cmbAction.setPreferredSize(new java.awt.Dimension(200,20)); |
171 | DefaultComboBoxModel model = new DefaultComboBoxModel(textosAcciones); |
||
172 | cmbAction.setModel(model); |
||
173 | } |
||
174 | return cmbAction;
|
||
175 | } |
||
176 | /**
|
||
177 | * This method initializes jLabel1
|
||
178 | 6122 | jaume | *
|
179 | * @return JLabel
|
||
180 | 934 | fernando | */
|
181 | 6122 | jaume | private JLabel getJLabel1() { |
182 | 934 | fernando | if(jLabel1 == null) { |
183 | 6122 | jaume | jLabel1 = new JLabel(); |
184 | 3437 | jmorell | jLabel1.setText(PluginServices.getText(this, "Elementos_seleccionados_de_la_capa")); |
185 | 934 | fernando | } |
186 | return jLabel1;
|
||
187 | } |
||
188 | /**
|
||
189 | * This method initializes cmbCapas
|
||
190 | 6122 | jaume | *
|
191 | * @return JComboBox
|
||
192 | 934 | fernando | */
|
193 | 6122 | jaume | private JComboBox getCmbCapas() { |
194 | 934 | fernando | if(cmbCapas == null) { |
195 | 6122 | jaume | cmbCapas = new JComboBox(); |
196 | 934 | fernando | cmbCapas.setPreferredSize(new java.awt.Dimension(200,20)); |
197 | } |
||
198 | return cmbCapas;
|
||
199 | } |
||
200 | /**
|
||
201 | * This method initializes btnNew
|
||
202 | 6122 | jaume | *
|
203 | * @return JButton
|
||
204 | 934 | fernando | */
|
205 | 6122 | jaume | private JButton getBtnNew() { |
206 | 934 | fernando | if(btnNew == null) { |
207 | 6122 | jaume | btnNew = new JButton(); |
208 | 3437 | jmorell | btnNew.setText(PluginServices.getText(this, "Nuevo_conjunto")); |
209 | 934 | fernando | btnNew.setMargin(new java.awt.Insets(2,2,2,2)); |
210 | 6122 | jaume | btnNew.addActionListener(new java.awt.event.ActionListener() {
|
211 | 934 | fernando | public void actionPerformed(java.awt.event.ActionEvent e) { |
212 | callNewListeners(cmbCapas.getSelectedIndex(), cmbAction.getSelectedIndex()); |
||
213 | } |
||
214 | }); |
||
215 | } |
||
216 | return btnNew;
|
||
217 | } |
||
218 | /**
|
||
219 | * This method initializes btnAdd
|
||
220 | 6122 | jaume | *
|
221 | * @return JButton
|
||
222 | 934 | fernando | */
|
223 | 6122 | jaume | private JButton getBtnAdd() { |
224 | 934 | fernando | if(btnAdd == null) { |
225 | 6122 | jaume | btnAdd = new JButton(); |
226 | 3437 | jmorell | btnAdd.setText(PluginServices.getText(this, "Anadir_al_conjunto")); |
227 | 934 | fernando | btnAdd.setMargin(new java.awt.Insets(2,2,2,2)); |
228 | 6122 | jaume | btnAdd.addActionListener(new java.awt.event.ActionListener() {
|
229 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
230 | 934 | fernando | callAddToListeners(cmbCapas.getSelectedIndex(), cmbAction.getSelectedIndex()); |
231 | } |
||
232 | }); |
||
233 | } |
||
234 | return btnAdd;
|
||
235 | } |
||
236 | /**
|
||
237 | * This method initializes btnFrom
|
||
238 | 6122 | jaume | *
|
239 | * @return JButton
|
||
240 | 934 | fernando | */
|
241 | 6122 | jaume | private JButton getBtnFrom() { |
242 | 934 | fernando | if(btnFrom == null) { |
243 | 6122 | jaume | btnFrom = new JButton(); |
244 | 3437 | jmorell | btnFrom.setText(PluginServices.getText(this, "Seleccionar_del_conjunto")); |
245 | 934 | fernando | btnFrom.setMargin(new java.awt.Insets(2,2,2,2)); |
246 | 6122 | jaume | btnFrom.addActionListener(new java.awt.event.ActionListener() {
|
247 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
248 | 934 | fernando | callFromListeners(cmbCapas.getSelectedIndex(), cmbAction.getSelectedIndex()); |
249 | } |
||
250 | }); |
||
251 | } |
||
252 | return btnFrom;
|
||
253 | } |
||
254 | /**
|
||
255 | * This method initializes btnCancel
|
||
256 | 6122 | jaume | *
|
257 | * @return JButton
|
||
258 | 934 | fernando | */
|
259 | 6122 | jaume | private JButton getBtnCancel() { |
260 | 934 | fernando | if(btnCancel == null) { |
261 | 6122 | jaume | btnCancel = new JButton(); |
262 | 3437 | jmorell | btnCancel.setText(PluginServices.getText(this, "Cancel")); |
263 | 934 | fernando | btnCancel.setMargin(new java.awt.Insets(2,2,2,2)); |
264 | 6122 | jaume | btnCancel.addActionListener(new java.awt.event.ActionListener() {
|
265 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
266 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(SelectionByTheme.this); |
267 | 934 | fernando | } |
268 | }); |
||
269 | } |
||
270 | return btnCancel;
|
||
271 | } |
||
272 | 6122 | jaume | |
273 | 934 | fernando | /**
|
274 | * @return
|
||
275 | */
|
||
276 | 950 | fernando | public SelectionByThemeModel getModel() {
|
277 | 934 | fernando | return dataSource;
|
278 | } |
||
279 | |||
280 | /**
|
||
281 | * @param source
|
||
282 | */
|
||
283 | 950 | fernando | public void setModel(SelectionByThemeModel source) { |
284 | 934 | fernando | dataSource = source; |
285 | String[] nameLayers = new String[dataSource.getLayers().getLayersCount()]; |
||
286 | for (int i=0; i < nameLayers.length; i++) |
||
287 | nameLayers[i] = dataSource.getLayers().getLayer(i).getName(); |
||
288 | 6122 | jaume | DefaultComboBoxModel model =
|
289 | 934 | fernando | new DefaultComboBoxModel(nameLayers); |
290 | cmbCapas.setModel(model); |
||
291 | } |
||
292 | /**
|
||
293 | 6880 | cesar | * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
294 | 934 | fernando | */
|
295 | 6880 | cesar | public WindowInfo getWindowInfo() {
|
296 | WindowInfo vi = new WindowInfo(WindowInfo.MODALDIALOG);
|
||
297 | 6122 | jaume | vi.setWidth(this.getWidth()+8); |
298 | vi.setHeight(this.getHeight());
|
||
299 | vi.setTitle(PluginServices.getText(this, "Seleccion_por_capa")); |
||
300 | 943 | fernando | return vi;
|
301 | 934 | fernando | } |
302 | 6122 | jaume | |
303 | 934 | fernando | private void callNewListeners(int selection, int actionCode){ |
304 | for (int i = 0; i < listeners.size(); |
||
305 | i++) { |
||
306 | SelectionByThemeListener l = (SelectionByThemeListener) listeners.get(i); |
||
307 | 943 | fernando | l.newSet(dataSource.getLayers().getActives(), dataSource.getLayers().getLayer(selection), actionCode); |
308 | 934 | fernando | } |
309 | 6122 | jaume | |
310 | 934 | fernando | } |
311 | 6122 | jaume | |
312 | 934 | fernando | private void callAddToListeners(int selection, int actionCode){ |
313 | for (int i = 0; i < listeners.size(); |
||
314 | i++) { |
||
315 | SelectionByThemeListener l = (SelectionByThemeListener) listeners.get(i); |
||
316 | 943 | fernando | l.addToSet(dataSource.getLayers().getActives(), dataSource.getLayers().getLayer(selection), actionCode); |
317 | 934 | fernando | } |
318 | 6122 | jaume | |
319 | 934 | fernando | } |
320 | 6122 | jaume | |
321 | 934 | fernando | private void callFromListeners(int selection, int actionCode){ |
322 | for (int i = 0; i < listeners.size(); |
||
323 | i++) { |
||
324 | SelectionByThemeListener l = (SelectionByThemeListener) listeners.get(i); |
||
325 | 943 | fernando | l.fromSet(dataSource.getLayers().getActives(), dataSource.getLayers().getLayer(selection), actionCode); |
326 | 934 | fernando | } |
327 | 6122 | jaume | |
328 | 934 | fernando | } |
329 | 6122 | jaume | |
330 | 934 | fernando | /**
|
331 | * DOCUMENT ME!
|
||
332 | *
|
||
333 | * @param arg0
|
||
334 | *
|
||
335 | * @return
|
||
336 | */
|
||
337 | public boolean addSelectionListener(SelectionByThemeListener arg0) { |
||
338 | return listeners.add(arg0);
|
||
339 | } |
||
340 | |||
341 | /**
|
||
342 | * DOCUMENT ME!
|
||
343 | *
|
||
344 | * @param arg0
|
||
345 | *
|
||
346 | * @return
|
||
347 | */
|
||
348 | public boolean removeSelectionListener(SelectionByThemeListener arg0) { |
||
349 | return listeners.remove(arg0);
|
||
350 | } |
||
351 | /**
|
||
352 | 6880 | cesar | * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
353 | 934 | fernando | */
|
354 | public void viewActivated() { |
||
355 | } |
||
356 | 6122 | jaume | |
357 | 934 | fernando | } // @jve:visual-info decl-index=0 visual-constraint="10,10" |