Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / selectionByTheme / SelectionByTheme.java @ 943

History | View | Annotate | Download (8.87 KB)

1
package com.iver.cit.gvsig.gui.selectionByTheme;
2

    
3
import java.util.ArrayList;
4

    
5
import javax.swing.DefaultComboBoxModel;
6
import javax.swing.JPanel;
7

    
8
import com.iver.andami.PluginServices;
9
import com.iver.andami.ui.mdiManager.View;
10
import com.iver.andami.ui.mdiManager.ViewInfo;
11
import com.iver.cit.gvsig.fmap.layers.FLayer;
12

    
13

    
14
public class SelectionByTheme extends JPanel implements View {
15
        public static final int EQUALS = 0;
16
        public static final int DISJOINT = 1;
17
        public static final int INTERSECTS = 2;
18
        public static final int TOUCHES = 3;
19
        public static final int CROSSES = 4;
20
        public static final int WITHIN = 5;
21
        public static final int CONTAINS = 6;
22
        public static final int OVERLAPS = 7;
23
        public static final String[] textosAcciones = new String[] {
24
        "sean iguales a",
25
        "sean disjuntos a",
26
        "intersecten con",
27
        "toquen",
28
        "crucen con",
29
        "est?n contenidos en",
30
        "contengan",
31
        "se superponen a"
32
        };
33

    
34
        private SelectionByThemeDataSource dataSource = null;
35

    
36
        private ArrayList listeners = new ArrayList();
37

    
38
        private javax.swing.JPanel jPanel = null;
39
        private javax.swing.JPanel jPanel1 = null;
40
        private javax.swing.JLabel jLabel = null;
41
        private javax.swing.JComboBox cmbAction = null;
42
        private javax.swing.JLabel jLabel1 = null;
43
        private javax.swing.JComboBox cmbCapas = null;
44
        private javax.swing.JButton btnNew = null;
45
        private javax.swing.JButton btnAdd = null;
46
        private javax.swing.JButton btnFrom = null;
47
        private javax.swing.JButton btnCancel = null;
48
        /**
49
         * This is the default constructor
50
         */
51
        public SelectionByTheme() {
52
                super();
53
                initialize();
54
        }
55
        /**
56
         * This method initializes this
57
         * 
58
         * @return void
59
         */
60
        private void initialize() {
61
                java.awt.FlowLayout layFlowLayout2 = new java.awt.FlowLayout();
62
                layFlowLayout2.setHgap(0);
63
                layFlowLayout2.setVgap(0);
64
                this.setLayout(layFlowLayout2);
65
                this.add(getJPanel(), null);
66
                this.add(getJPanel1(), null);
67
                this.setSize(440, 220);
68
        }
69
        /**
70
         * This method initializes jPanel
71
         * 
72
         * @return javax.swing.JPanel
73
         */
74
        private javax.swing.JPanel getJPanel() {
75
                if(jPanel == null) {
76
                        jPanel = new javax.swing.JPanel();
77
                        java.awt.FlowLayout layFlowLayout1 = new java.awt.FlowLayout();
78
                        layFlowLayout1.setVgap(30);
79
                        jPanel.setLayout(layFlowLayout1);
80
                        jPanel.add(getJLabel(), null);
81
                        jPanel.add(getCmbAction(), null);
82
                        jPanel.add(getJLabel1(), null);
83
                        jPanel.add(getCmbCapas(), null);
84
                        jPanel.setPreferredSize(new java.awt.Dimension(290,220));
85
                }
86
                return jPanel;
87
        }
88
        /**
89
         * This method initializes jPanel1
90
         * 
91
         * @return javax.swing.JPanel
92
         */
93
        private javax.swing.JPanel getJPanel1() {
94
                if(jPanel1 == null) {
95
                        jPanel1 = new javax.swing.JPanel();
96
                        java.awt.FlowLayout layFlowLayout3 = new java.awt.FlowLayout();
97
                        layFlowLayout3.setVgap(25);
98
                        jPanel1.setLayout(layFlowLayout3);
99
                        jPanel1.add(getBtnNew(), null);
100
                        jPanel1.add(getBtnAdd(), null);
101
                        jPanel1.add(getBtnFrom(), null);
102
                        jPanel1.add(getBtnCancel(), null);
103
                        jPanel1.setPreferredSize(new java.awt.Dimension(140,220));
104
                }
105
                return jPanel1;
106
        }
107
        /**
108
         * This method initializes jLabel
109
         * 
110
         * @return javax.swing.JLabel
111
         */
112
        private javax.swing.JLabel getJLabel() {
113
                if(jLabel == null) {
114
                        jLabel = new javax.swing.JLabel();
115
                        jLabel.setText("Seleccionar de las capas activas los elementos que... ");
116
                        jLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
117
                }
118
                return jLabel;
119
        }
120
        /**
121
         * This method initializes cmbAction
122
         * 
123
         * @return javax.swing.JComboBox
124
         */
125
        private javax.swing.JComboBox getCmbAction() {
126
                if(cmbAction == null) {
127
                        cmbAction = new javax.swing.JComboBox();
128
                        cmbAction.setPreferredSize(new java.awt.Dimension(200,20));
129
                        DefaultComboBoxModel model = new DefaultComboBoxModel(textosAcciones);
130
                        cmbAction.setModel(model);
131
                        cmbAction.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
132
                }
133
                return cmbAction;
134
        }
135
        /**
136
         * This method initializes jLabel1
137
         * 
138
         * @return javax.swing.JLabel
139
         */
140
        private javax.swing.JLabel getJLabel1() {
141
                if(jLabel1 == null) {
142
                        jLabel1 = new javax.swing.JLabel();
143
                        jLabel1.setText("elementos seleccionados de la capa");
144
                        jLabel1.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
145
                }
146
                return jLabel1;
147
        }
148
        /**
149
         * This method initializes cmbCapas
150
         * 
151
         * @return javax.swing.JComboBox
152
         */
153
        private javax.swing.JComboBox getCmbCapas() {
154
                if(cmbCapas == null) {
155
                        cmbCapas = new javax.swing.JComboBox();
156
                        cmbCapas.setPreferredSize(new java.awt.Dimension(200,20));
157
                        cmbCapas.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
158
                }
159
                return cmbCapas;
160
        }
161
        /**
162
         * This method initializes btnNew
163
         * 
164
         * @return javax.swing.JButton
165
         */
166
        private javax.swing.JButton getBtnNew() {
167
                if(btnNew == null) {
168
                        btnNew = new javax.swing.JButton();
169
                        btnNew.setText("Nuevo Conjunto");
170
                        btnNew.setMargin(new java.awt.Insets(2,2,2,2));
171
                        btnNew.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
172
                        btnNew.addActionListener(new java.awt.event.ActionListener() { 
173
                                public void actionPerformed(java.awt.event.ActionEvent e) {
174
                                        callNewListeners(cmbCapas.getSelectedIndex(), cmbAction.getSelectedIndex());
175
                                }
176
                        });
177
                }
178
                return btnNew;
179
        }
180
        /**
181
         * This method initializes btnAdd
182
         * 
183
         * @return javax.swing.JButton
184
         */
185
        private javax.swing.JButton getBtnAdd() {
186
                if(btnAdd == null) {
187
                        btnAdd = new javax.swing.JButton();
188
                        btnAdd.setText("A?adir al conjunto");
189
                        btnAdd.setMargin(new java.awt.Insets(2,2,2,2));
190
                        btnAdd.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
191
                        btnAdd.addActionListener(new java.awt.event.ActionListener() { 
192
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
193
                                        callAddToListeners(cmbCapas.getSelectedIndex(), cmbAction.getSelectedIndex());
194
                                }
195
                        });
196
                }
197
                return btnAdd;
198
        }
199
        /**
200
         * This method initializes btnFrom
201
         * 
202
         * @return javax.swing.JButton
203
         */
204
        private javax.swing.JButton getBtnFrom() {
205
                if(btnFrom == null) {
206
                        btnFrom = new javax.swing.JButton();
207
                        btnFrom.setText("Seleccionar del conjunto");
208
                        btnFrom.setMargin(new java.awt.Insets(2,2,2,2));
209
                        btnFrom.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
210
                        btnFrom.addActionListener(new java.awt.event.ActionListener() { 
211
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
212
                                        callFromListeners(cmbCapas.getSelectedIndex(), cmbAction.getSelectedIndex());
213
                                }
214
                        });
215
                }
216
                return btnFrom;
217
        }
218
        /**
219
         * This method initializes btnCancel
220
         * 
221
         * @return javax.swing.JButton
222
         */
223
        private javax.swing.JButton getBtnCancel() {
224
                if(btnCancel == null) {
225
                        btnCancel = new javax.swing.JButton();
226
                        btnCancel.setText("Cancel");
227
                        btnCancel.setMargin(new java.awt.Insets(2,2,2,2));
228
                        btnCancel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10));
229
                        btnCancel.addActionListener(new java.awt.event.ActionListener() { 
230
                                public void actionPerformed(java.awt.event.ActionEvent e) {    
231
                                        PluginServices.getMDIManager().closeView(SelectionByTheme.this);
232
                                }
233
                        });
234
                }
235
                return btnCancel;
236
        }
237
        
238
        /**
239
         * @return
240
         */
241
        public SelectionByThemeDataSource getDataSource() {
242
                return dataSource;
243
        }
244

    
245
        /**
246
         * @param source
247
         */
248
        public void setDataSource(SelectionByThemeDataSource source) {
249
                dataSource = source;
250
                String[] nameLayers = new String[dataSource.getLayers().getLayersCount()];
251
                for (int i=0; i < nameLayers.length; i++)
252
                        nameLayers[i] = dataSource.getLayers().getLayer(i).getName();
253
                DefaultComboBoxModel model = 
254
                        new DefaultComboBoxModel(nameLayers);
255
                cmbCapas.setModel(model);
256
        }
257
        /**
258
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
259
         */
260
        public ViewInfo getViewInfo() {
261
                ViewInfo vi = new ViewInfo();
262
                return vi;
263
        }
264
        
265
        private void callNewListeners(int selection, int actionCode){
266
                for (int i = 0; i < listeners.size();
267
                                i++) {
268
                        SelectionByThemeListener l = (SelectionByThemeListener) listeners.get(i);
269
                        l.newSet(dataSource.getLayers().getActives(), dataSource.getLayers().getLayer(selection), actionCode);
270
                }
271
                
272
        }
273
        
274
        private void callAddToListeners(int selection, int actionCode){
275
                for (int i = 0; i < listeners.size();
276
                                i++) {
277
                        SelectionByThemeListener l = (SelectionByThemeListener) listeners.get(i);
278
                        l.addToSet(dataSource.getLayers().getActives(), dataSource.getLayers().getLayer(selection), actionCode);
279
                }
280
                
281
        }
282
        
283
        private void callFromListeners(int selection, int actionCode){
284
                for (int i = 0; i < listeners.size();
285
                                i++) {
286
                        SelectionByThemeListener l = (SelectionByThemeListener) listeners.get(i);
287
                        l.fromSet(dataSource.getLayers().getActives(), dataSource.getLayers().getLayer(selection), actionCode);
288
                }
289
                
290
        }
291
        
292
        /**
293
         * DOCUMENT ME!
294
         *
295
         * @param arg0
296
         *
297
         * @return
298
         */
299
        public boolean addSelectionListener(SelectionByThemeListener arg0) {
300
                return listeners.add(arg0);
301
        }
302

    
303
        /**
304
         * DOCUMENT ME!
305
         *
306
         * @param arg0
307
         *
308
         * @return
309
         */
310
        public boolean removeSelectionListener(SelectionByThemeListener arg0) {
311
                return listeners.remove(arg0);
312
        }
313
        /**
314
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
315
         */
316
        public void viewActivated() {
317
        }
318
        
319
}  //  @jve:visual-info  decl-index=0 visual-constraint="10,10"