svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / gui / selectionByTheme / SelectionByTheme.java @ 42252
History | View | Annotate | Download (11.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.gui.selectionByTheme; |
25 |
|
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
28 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
29 |
import org.gvsig.gui.beans.swing.JButton; |
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.i18n.I18nManager; |
32 |
import org.gvsig.utils.swing.JComboBox; |
33 |
|
34 |
import javax.swing.*; |
35 |
|
36 |
import java.awt.*; |
37 |
import java.util.ArrayList; |
38 |
|
39 |
public class SelectionByTheme extends JPanel implements IWindow { |
40 |
|
41 |
/**
|
42 |
*
|
43 |
*/
|
44 |
private static final long serialVersionUID = -5094042907941800674L; |
45 |
|
46 |
public static final int EQUALS = 0; |
47 |
|
48 |
public static final int DISJOINT = 1; |
49 |
|
50 |
public static final int INTERSECTS = 2; |
51 |
|
52 |
public static final int TOUCHES = 3; |
53 |
|
54 |
public static final int CROSSES = 4; |
55 |
|
56 |
public static final int WITHIN = 5; |
57 |
|
58 |
public static final int CONTAINS = 6; |
59 |
|
60 |
public static final int OVERLAPS = 7; |
61 |
|
62 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
63 |
|
64 |
public final String[] textosAcciones = new String[] { |
65 |
i18nManager.getTranslation("Sean_iguales_a"), // "sean iguales a", |
66 |
i18nManager.getTranslation("Sean_disjuntos_a"), // "sean disjuntos a", |
67 |
i18nManager.getTranslation("Intersecten_con"), // "intersecten con", |
68 |
i18nManager.getTranslation("Toquen"), // "toquen", |
69 |
i18nManager.getTranslation("Crucen_con"), // "crucen con", |
70 |
i18nManager.getTranslation("Contengan"), // "contengan", |
71 |
i18nManager.getTranslation("Esten_contenidos_en"), // "est?n contenidos en", |
72 |
i18nManager.getTranslation("Se_superponen_a"), // "se superponen a" |
73 |
}; |
74 |
|
75 |
private SelectionByThemeModel dataSource = null; |
76 |
|
77 |
private ArrayList listeners = new ArrayList(); |
78 |
|
79 |
private JPanel jPanel = null; |
80 |
|
81 |
private JPanel jPanel1 = null; |
82 |
|
83 |
private JLabel jLabel = null; |
84 |
|
85 |
private JComboBox cmbAction = null; |
86 |
|
87 |
private JLabel jLabel1 = null; |
88 |
|
89 |
private JComboBox cmbCapas = null; |
90 |
|
91 |
private JButton btnNew = null; |
92 |
|
93 |
private JButton btnAdd = null; |
94 |
|
95 |
private JButton btnFrom = null; |
96 |
|
97 |
private JButton btnCancel = null; |
98 |
|
99 |
/**
|
100 |
* This is the default constructor
|
101 |
*/
|
102 |
public SelectionByTheme() {
|
103 |
super();
|
104 |
initialize(); |
105 |
} |
106 |
|
107 |
/**
|
108 |
* This method initializes this
|
109 |
*
|
110 |
* @return void
|
111 |
*/
|
112 |
private void initialize() { |
113 |
this.setLayout(new GridBagLayout()); |
114 |
GridBagConstraints c = new GridBagConstraints(); |
115 |
|
116 |
c.fill = GridBagConstraints.BOTH;
|
117 |
c.anchor = GridBagConstraints.LINE_START;
|
118 |
c.insets = new Insets(3, 10, 3, 10); |
119 |
|
120 |
// Labels and Comboboxes
|
121 |
c.weightx = 1;
|
122 |
|
123 |
c.gridx = 0;
|
124 |
c.gridy = 0;
|
125 |
this.add(getJLabel(), c);
|
126 |
|
127 |
c.gridy = 1;
|
128 |
this.add(getCmbAction(), c);
|
129 |
|
130 |
c.gridy = 2;
|
131 |
this.add(getJLabel1(), c);
|
132 |
|
133 |
c.gridy = 3;
|
134 |
this.add(getCmbCapas(), c);
|
135 |
|
136 |
|
137 |
// Buttons
|
138 |
c.weightx = 0;
|
139 |
c.gridx = 1;
|
140 |
|
141 |
c.gridy = 0;
|
142 |
this.add(getBtnNew(), c);
|
143 |
|
144 |
c.gridy = 1;
|
145 |
this.add(getBtnAdd(), c);
|
146 |
|
147 |
c.gridy = 2;
|
148 |
this.add(getBtnFrom(), c);
|
149 |
|
150 |
c.gridy = 3;
|
151 |
this.add(getBtnCancel(), c);
|
152 |
|
153 |
|
154 |
this.setSize(540, 95); |
155 |
} |
156 |
|
157 |
/**
|
158 |
* This method initializes jLabel
|
159 |
*
|
160 |
* @return JLabel
|
161 |
*/
|
162 |
private JLabel getJLabel() { |
163 |
if (jLabel == null) { |
164 |
jLabel = new JLabel(); |
165 |
jLabel.setText(i18nManager |
166 |
.getTranslation("select_features_that_XcolonX"));
|
167 |
jLabel.setVerticalAlignment(SwingConstants.BOTTOM);
|
168 |
jLabel.setToolTipText(i18nManager.getTranslation("select_from_the_active_layers"));
|
169 |
} |
170 |
return jLabel;
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* This method initializes cmbAction
|
175 |
*
|
176 |
* @return JComboBox
|
177 |
*/
|
178 |
private JComboBox getCmbAction() { |
179 |
if (cmbAction == null) { |
180 |
cmbAction = new JComboBox(); |
181 |
cmbAction.setPreferredSize(new java.awt.Dimension(200, 20)); |
182 |
DefaultComboBoxModel model = new DefaultComboBoxModel( |
183 |
textosAcciones); |
184 |
cmbAction.setModel(model); |
185 |
} |
186 |
return cmbAction;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* This method initializes jLabel1
|
191 |
*
|
192 |
* @return JLabel
|
193 |
*/
|
194 |
private JLabel getJLabel1() { |
195 |
if (jLabel1 == null) { |
196 |
jLabel1 = new JLabel(); |
197 |
jLabel1.setText(i18nManager.getTranslation("capa_XcolonX"));
|
198 |
jLabel1.setVerticalAlignment(SwingConstants.BOTTOM);
|
199 |
jLabel1.setToolTipText(i18nManager.getTranslation("layer_to_which_belong_the_elements_that_are_going_to_be_selected"));
|
200 |
} |
201 |
return jLabel1;
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* This method initializes cmbCapas
|
206 |
*
|
207 |
* @return JComboBox
|
208 |
*/
|
209 |
private JComboBox getCmbCapas() { |
210 |
if (cmbCapas == null) { |
211 |
cmbCapas = new JComboBox(); |
212 |
cmbCapas.setPreferredSize(new java.awt.Dimension(200, 20)); |
213 |
} |
214 |
return cmbCapas;
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* This method initializes btnNew
|
219 |
*
|
220 |
* @return JButton
|
221 |
*/
|
222 |
private JButton getBtnNew() { |
223 |
if (btnNew == null) { |
224 |
btnNew = new JButton(); |
225 |
btnNew.setText(i18nManager.getTranslation("Nuevo_conjunto"));
|
226 |
btnNew.setMargin(new java.awt.Insets(3, 3, 3, 3)); |
227 |
btnNew.addActionListener(new java.awt.event.ActionListener() {
|
228 |
|
229 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
230 |
callNewListeners(cmbCapas.getSelectedIndex(), |
231 |
cmbAction.getSelectedIndex()); |
232 |
} |
233 |
}); |
234 |
} |
235 |
return btnNew;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* This method initializes btnAdd
|
240 |
*
|
241 |
* @return JButton
|
242 |
*/
|
243 |
private JButton getBtnAdd() { |
244 |
if (btnAdd == null) { |
245 |
btnAdd = new JButton(); |
246 |
btnAdd.setText(i18nManager.getTranslation("Anadir_al_conjunto"));
|
247 |
btnAdd.setMargin(new java.awt.Insets(3, 3, 3, 3)); |
248 |
btnAdd.addActionListener(new java.awt.event.ActionListener() {
|
249 |
|
250 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
251 |
callAddToListeners(cmbCapas.getSelectedIndex(), |
252 |
cmbAction.getSelectedIndex()); |
253 |
} |
254 |
}); |
255 |
} |
256 |
return btnAdd;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* This method initializes btnFrom
|
261 |
*
|
262 |
* @return JButton
|
263 |
*/
|
264 |
private JButton getBtnFrom() { |
265 |
if (btnFrom == null) { |
266 |
btnFrom = new JButton(); |
267 |
btnFrom.setText(i18nManager |
268 |
.getTranslation("Seleccionar_del_conjunto"));
|
269 |
btnFrom.setMargin(new java.awt.Insets(3, 3, 3, 3)); |
270 |
btnFrom.addActionListener(new java.awt.event.ActionListener() {
|
271 |
|
272 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
273 |
callFromListeners(cmbCapas.getSelectedIndex(), |
274 |
cmbAction.getSelectedIndex()); |
275 |
} |
276 |
}); |
277 |
} |
278 |
return btnFrom;
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* This method initializes btnCancel
|
283 |
*
|
284 |
* @return JButton
|
285 |
*/
|
286 |
private JButton getBtnCancel() { |
287 |
if (btnCancel == null) { |
288 |
btnCancel = new JButton(); |
289 |
btnCancel.setText(i18nManager.getTranslation("Cancel"));
|
290 |
btnCancel.setMargin(new java.awt.Insets(3, 3, 3, 3)); |
291 |
btnCancel.addActionListener(new java.awt.event.ActionListener() {
|
292 |
|
293 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
294 |
PluginServices.getMDIManager().closeWindow( |
295 |
SelectionByTheme.this); |
296 |
} |
297 |
}); |
298 |
} |
299 |
return btnCancel;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* @return
|
304 |
*/
|
305 |
public SelectionByThemeModel getModel() {
|
306 |
return dataSource;
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* @param source
|
311 |
*/
|
312 |
public void setModel(SelectionByThemeModel source) { |
313 |
dataSource = source; |
314 |
String[] nameLayers = new String[dataSource.getLayers() |
315 |
.getLayersCount()]; |
316 |
for (int i = 0; i < nameLayers.length; i++) { |
317 |
nameLayers[i] = dataSource.getLayers().getLayer(i).getName(); |
318 |
} |
319 |
DefaultComboBoxModel model = new DefaultComboBoxModel(nameLayers); |
320 |
cmbCapas.setModel(model); |
321 |
} |
322 |
|
323 |
/**
|
324 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
325 |
*/
|
326 |
public WindowInfo getWindowInfo() {
|
327 |
WindowInfo vi = new WindowInfo(WindowInfo.MODALDIALOG);
|
328 |
vi.setWidth(this.getWidth());
|
329 |
vi.setHeight(this.getHeight());
|
330 |
vi.setTitle(i18nManager.getTranslation("Seleccion_por_capa"));
|
331 |
return vi;
|
332 |
} |
333 |
|
334 |
private void callNewListeners(int selection, int actionCode) { |
335 |
for (int i = 0; i < listeners.size(); i++) { |
336 |
SelectionByThemeListener l = (SelectionByThemeListener) listeners |
337 |
.get(i); |
338 |
l.newSet(dataSource.getLayers().getActives(), dataSource |
339 |
.getLayers().getLayer(selection), actionCode); |
340 |
} |
341 |
|
342 |
} |
343 |
|
344 |
private void callAddToListeners(int selection, int actionCode) { |
345 |
for (int i = 0; i < listeners.size(); i++) { |
346 |
SelectionByThemeListener l = (SelectionByThemeListener) listeners |
347 |
.get(i); |
348 |
l.addToSet(dataSource.getLayers().getActives(), dataSource |
349 |
.getLayers().getLayer(selection), actionCode); |
350 |
} |
351 |
|
352 |
} |
353 |
|
354 |
private void callFromListeners(int selection, int actionCode) { |
355 |
for (int i = 0; i < listeners.size(); i++) { |
356 |
SelectionByThemeListener l = (SelectionByThemeListener) listeners |
357 |
.get(i); |
358 |
l.fromSet(dataSource.getLayers().getActives(), dataSource |
359 |
.getLayers().getLayer(selection), actionCode); |
360 |
} |
361 |
|
362 |
} |
363 |
|
364 |
/**
|
365 |
* DOCUMENT ME!
|
366 |
*
|
367 |
* @param arg0
|
368 |
* @return
|
369 |
*/
|
370 |
public boolean addSelectionListener(SelectionByThemeListener arg0) { |
371 |
return listeners.add(arg0);
|
372 |
} |
373 |
|
374 |
/**
|
375 |
* DOCUMENT ME!
|
376 |
*
|
377 |
* @param arg0
|
378 |
* @return
|
379 |
*/
|
380 |
public boolean removeSelectionListener(SelectionByThemeListener arg0) { |
381 |
return listeners.remove(arg0);
|
382 |
} |
383 |
|
384 |
/**
|
385 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
386 |
*/
|
387 |
public void viewActivated() {} |
388 |
|
389 |
public Object getWindowProfile() { |
390 |
return WindowInfo.DIALOG_PROFILE;
|
391 |
} |
392 |
|
393 |
} // @jve:visual-info decl-index=0 visual-constraint="10,10"
|