Statistics
| Revision:

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

History | View | Annotate | Download (8.66 KB)

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

    
3
import java.util.ArrayList;
4

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

    
8
import com.iver.mdiApp.App;
9
import com.iver.mdiApp.ui.MDIManager.View;
10
import com.iver.mdiApp.ui.MDIManager.ViewInfo;
11

    
12

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

    
33
        private SelectionByThemeDataSource dataSource = null;
34

    
35
        private int[] indexes;
36

    
37
        private ArrayList listeners = new ArrayList();
38

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

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

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