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