Revision 42252 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

View differences:

SelectionByTheme.java
23 23
 */
24 24
package org.gvsig.app.gui.selectionByTheme;
25 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 26
import org.gvsig.andami.PluginServices;
35 27
import org.gvsig.andami.ui.mdiManager.IWindow;
36 28
import org.gvsig.andami.ui.mdiManager.WindowInfo;
37 29
import org.gvsig.gui.beans.swing.JButton;
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.i18n.I18nManager;
38 32
import org.gvsig.utils.swing.JComboBox;
39 33

  
34
import javax.swing.*;
40 35

  
36
import java.awt.*;
37
import java.util.ArrayList;
41 38

  
42 39
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 40

  
62
	private SelectionByThemeModel dataSource = null;
41
    /**
42
     * 
43
     */
44
    private static final long serialVersionUID = -5094042907941800674L;
63 45

  
64
	private ArrayList listeners = new ArrayList();
46
    public static final int EQUALS = 0;
65 47

  
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);
48
    public static final int DISJOINT = 1;
112 49

  
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
	}
50
    public static final int INTERSECTS = 2;
255 51

  
256
	/**
257
	 * @return
258
	 */
259
	public SelectionByThemeModel getModel() {
260
		return dataSource;
261
	}
52
    public static final int TOUCHES = 3;
262 53

  
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
	}
54
    public static final int CROSSES = 4;
286 55

  
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
		}
56
    public static final int WITHIN = 5;
293 57

  
294
	}
58
    public static final int CONTAINS = 6;
295 59

  
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
		}
60
    public static final int OVERLAPS = 7;
302 61

  
303
	}
62
    private I18nManager i18nManager = ToolsLocator.getI18nManager();
304 63

  
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
		}
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
    };
311 74

  
312
	}
75
    private SelectionByThemeModel dataSource = null;
313 76

  
314
	/**
315
	 * DOCUMENT ME!
316
	 *
317
	 * @param arg0
318
	 *
319
	 * @return
320
	 */
321
	public boolean addSelectionListener(SelectionByThemeListener arg0) {
322
		return listeners.add(arg0);
323
	}
77
    private ArrayList listeners = new ArrayList();
324 78

  
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
	}
79
    private JPanel jPanel = null;
340 80

  
341
	public Object getWindowProfile() {
342
		return WindowInfo.DIALOG_PROFILE;
343
	}
81
    private JPanel jPanel1 = null;
344 82

  
345
}  //  @jve:visual-info  decl-index=0 visual-constraint="10,10"
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"

Also available in: Unified diff