Statistics
| Revision:

svn-gvsig-desktop / trunk / prototypes / mobile / desktop / extensions / extExportMobile / src / es / prodevelop / gvsig / exportMobile / ui / panels / LayerAtributes.java @ 19124

History | View | Annotate | Download (8.04 KB)

1
package es.prodevelop.gvsig.exportMobile.ui.panels;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Dimension;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
8
import java.util.ArrayList;
9

    
10
import javax.swing.BorderFactory;
11
import javax.swing.JButton;
12
import javax.swing.JCheckBox;
13
import javax.swing.JLabel;
14
import javax.swing.JPanel;
15
import javax.swing.JScrollPane;
16
import javax.swing.border.TitledBorder;
17

    
18
import com.iver.andami.PluginServices;
19
import com.iver.andami.ui.mdiManager.IWindow;
20
import com.iver.andami.ui.mdiManager.WindowInfo;
21
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
22
import com.iver.cit.gvsig.fmap.layers.FLayer;
23

    
24
/**
25
 * Panel to select the new layer atributes
26
 * @author Anabel Moreno
27
 *
28
 */
29
public class LayerAtributes extends JPanel implements IWindow, ActionListener {
30

    
31
        /**
32
         * 
33
         */
34
        private static final long serialVersionUID = 1L;
35

    
36
        private JPanel topPanel = new JPanel();
37

    
38
        private JPanel centerPanel = new JPanel();
39

    
40
        private JPanel bottomPanel = new JPanel();
41

    
42
        private JScrollPane scroll = new JScrollPane();
43

    
44
        private JPanel titlePanel = new JPanel();
45

    
46
        private JCheckBox selAllBox;
47

    
48
        private FLayer layer;
49

    
50
        private JLabel nomLayer, typLayer;
51

    
52
        private JButton exit, inverSel, cancel;
53

    
54
        private PanelAtribIntoScroll atrbScroll;
55

    
56
        private ArrayList arrLayers = new ArrayList();
57

    
58
        private int atrSelec, atribTot;
59

    
60
        private ArrayList selectAtrib;
61

    
62
        private FieldDescription[] atribSel;
63

    
64
        private FieldDescription[] atribTotal;
65

    
66
        private int cont;
67

    
68
        private boolean okPress = false;
69

    
70
        private static int PANEL_WIDTH = 300;
71

    
72
        private static int PANEL_HEIGHT = 250;
73

    
74
        private static int TOP_PANEL_HEIGHT = 20;
75

    
76
        private static int BOTTOM_PANEL_HEIGHT = 35;
77

    
78
        private static int CENTER_PANEL_HEIGHT = 195;
79

    
80
        private static int TITTLE_CENTER_PANEL_HEIGHT = 24;
81

    
82
        private static int INVERTSEL_X = 10;
83

    
84
        private static int EXIT_X = 110;
85

    
86
        private static int CANCEL_X = 210;
87

    
88
        private static int BUTTON_Y = 5;
89

    
90
        private static int BUTTON_W = 80;
91

    
92
        private static int BUTTON_H = 25;
93

    
94
        private static int LABEL_Y = 5;
95

    
96
        private static int SELALLBX_X = 20;
97

    
98
        private static int SELALLBX_W = 17;
99

    
100
        private static int SELALLBX_H = 13;
101

    
102
        private static int NOMLYR_X = 60;
103

    
104
        private static int NOMLYR_W = 80;
105

    
106
        private static int NOMLYR_H = 12;
107

    
108
        private static int TYPLYR_X = 170;
109

    
110
        private static int TYPLYR_W = 40;
111

    
112
        private static int TYPLYR_H = 12;
113

    
114
        
115
        
116
        public WindowInfo getWindowInfo() {
117

    
118
                WindowInfo viewAtrib = new WindowInfo(WindowInfo.MODALDIALOG);
119
                viewAtrib.setWidth(306);
120
                viewAtrib.setHeight(256);
121
                viewAtrib.setTitle(PluginServices.getText(this, "atriblayer"));
122
                return viewAtrib;
123
        }
124

    
125
        public boolean isOkPress() {
126

    
127
                return okPress;
128
        }
129

    
130
        /**
131
         * Window to select the layers atributes
132
         * 
133
         * @param layer1,
134
         *            layer selected
135
         * @param arrSelect,list
136
         *            with the description of the layer
137
         * @param cont1,
138
         *            number of atributes selected
139
         */
140
        public LayerAtributes(FLayer layer_wn, ArrayList arrSelect, int cont1) {
141

    
142
                super();
143
                arrLayers.add(layer);
144
                layer = layer_wn;
145
                selectAtrib = arrSelect;
146
                cont = cont1;
147

    
148
                /* PRINCIPAL PANEL */
149
                setSize(PANEL_WIDTH, PANEL_HEIGHT);
150
                this.setLayout(new BorderLayout());
151

    
152
                /* TOP PANEL */
153
                topPanel.setSize(PANEL_WIDTH, TOP_PANEL_HEIGHT);
154

    
155
                /* BOTTOM PANEL */
156
                bottomPanel.setPreferredSize(new Dimension(PANEL_WIDTH,
157
                                BOTTOM_PANEL_HEIGHT));
158
                bottomPanel.setLayout(null);
159

    
160
                inverSel = new JButton(PluginServices.getText(this, "invertSet"));
161
                inverSel.setBounds(INVERTSEL_X, BUTTON_Y, BUTTON_W, BUTTON_H);
162
                bottomPanel.add(inverSel);
163
                inverSel.addActionListener(this);
164

    
165
                exit = new JButton(PluginServices.getText(this, "ok"));
166
                exit.setBounds(EXIT_X, BUTTON_Y, BUTTON_W, BUTTON_H);
167
                bottomPanel.add(exit);
168
                exit.addActionListener(this);
169

    
170
                cancel = new JButton(PluginServices.getText(this, "cancel"));
171
                cancel.setBounds(CANCEL_X, BUTTON_Y, BUTTON_W, BUTTON_H);
172
                bottomPanel.add(cancel);
173
                cancel.addActionListener(this);
174

    
175
                
176
                /* CENTER PANEL */
177
                centerPanel.setSize(new Dimension(PANEL_WIDTH, CENTER_PANEL_HEIGHT));
178
                centerPanel.setLayout(new BorderLayout());
179
                
180
                TitledBorder title = BorderFactory.createTitledBorder(layer.getName());
181
                title.setTitleColor(Color.BLUE);
182
                centerPanel.setBorder(title);
183

    
184
                selAllBox = new JCheckBox();
185
                selAllBox.addActionListener(this);
186
                selAllBox.setSelected(true);
187
                selAllBox.setBackground(Color.LIGHT_GRAY);
188
                nomLayer = new JLabel(PluginServices.getText(this, "nAtrib"));
189
                typLayer = new JLabel(PluginServices.getText(this, "tAtrib"));
190
                titlePanel.setPreferredSize(new Dimension(PANEL_WIDTH,
191
                                TITTLE_CENTER_PANEL_HEIGHT));
192
                titlePanel.setLayout(null);
193
                selAllBox.setBounds(SELALLBX_X, LABEL_Y, SELALLBX_W, SELALLBX_H);
194
                nomLayer.setBounds(NOMLYR_X, LABEL_Y, NOMLYR_W, NOMLYR_H);
195
                typLayer.setBounds(TYPLYR_X, LABEL_Y, TYPLYR_W, TYPLYR_H);
196

    
197
                titlePanel.add(nomLayer);
198
                titlePanel.add(typLayer);
199
                titlePanel.add(selAllBox);
200
                titlePanel.setBackground(Color.LIGHT_GRAY);
201

    
202
                atrbScroll = new PanelAtribIntoScroll(layer, arrSelect, cont, this);
203
                scroll.setViewportView(atrbScroll.getPanel());
204

    
205
                centerPanel.add(scroll, BorderLayout.CENTER);
206
                centerPanel.add(titlePanel, BorderLayout.NORTH);
207

    
208
                /* adds */
209
                this.add(topPanel, BorderLayout.NORTH);
210
                this.add(centerPanel, BorderLayout.CENTER);
211
                this.add(bottomPanel, BorderLayout.SOUTH);
212

    
213
        }
214

    
215
        /**
216
         * @return number of layer`s atributes selected
217
         */
218
        public int getAtrSelected() {
219

    
220
                return atrSelec;
221
        }
222

    
223
        /**
224
         * @return number of all layer`s atributes
225
         */
226
        public int getAtrib() {
227

    
228
                return atribTot;
229
        }
230

    
231
        /**
232
         * @return a list with the layer`s atributes selected
233
         */
234
        public ArrayList getSelectAtrib() {
235

    
236
                return selectAtrib;
237
        }
238

    
239
        /**
240
         * @return a new layer description with the atributes selected
241
         */
242
        public FieldDescription[] getAtribSelected() {
243

    
244
                return atribSel;
245
        }
246

    
247
        /**
248
         * to activate checkbox all selected, and enabled ok button
249
         * 
250
         * @return true if any atribute is selected and false if any atribute is
251
         *         selected
252
         */
253
        public boolean dimArrBx() {
254

    
255
                FieldDescription[] aux = atrbScroll.getAtribSelected();
256
                if (aux.length == 0) {
257
                        selAllBox.setSelected(false);
258
                        return false;
259
                } else {
260

    
261
                        selAllBox.setSelected(true);
262
                        return true;
263
                }
264
        }
265

    
266
        /**
267
         * @return a layer description with all original atributes
268
         */
269
        public FieldDescription[] getAtribTotal() {
270

    
271
                atribTotal = atrbScroll.getAtribTotal();
272
                return atribTotal;
273
        }
274

    
275
        public void actionPerformed(ActionEvent arg0) {
276

    
277
                Object src = arg0.getSource();
278

    
279
                if (src == exit) {
280

    
281
                        okPress = true;
282
                        selectAtrib = atrbScroll.getSelectionAtributs();
283

    
284
                        // array fields layer
285
                        atribSel = atrbScroll.getAtribSelected();
286

    
287
                        atrSelec = atrbScroll.getNumAtribSelected();
288
                        atribTot = atrbScroll.getNumAtrib();
289
                        PluginServices.getMDIManager().closeWindow(this);
290
                        return;
291
                }
292

    
293
                if (src == selAllBox) {
294

    
295
                        ArrayList arrAux = atrbScroll.getArrBox();
296
                        if (selAllBox.isSelected() == true) {
297

    
298
                                for (int i = 0; i < arrAux.size(); i++) {
299

    
300
                                        JCheckBox aux = (JCheckBox) arrAux.get(i);
301
                                        aux.setSelected(true);
302
                                }
303
                                exit.setEnabled(true);
304
                        }
305

    
306
                        if (selAllBox.isSelected() == false) {
307

    
308
                                for (int i = 0; i < arrAux.size(); i++) {
309

    
310
                                        JCheckBox aux = (JCheckBox) arrAux.get(i);
311
                                        aux.setSelected(false);
312
                                }
313
                                exit.setEnabled(false);
314
                        }
315

    
316
                }
317

    
318
                if (src == cancel) {
319

    
320
                        PluginServices.getMDIManager().closeWindow(this);
321
                        return;
322
                }
323

    
324
                if (src == inverSel) {
325

    
326
                        atrbScroll.setInvSelected();
327
                        ArrayList arrAux = atrbScroll.getArrBox();
328
                        int contaux = 0;
329
                        int dim = arrAux.size();
330
                        for (int i = 0; i < dim; i++) {
331

    
332
                                JCheckBox boxAux = (JCheckBox) arrAux.get(i);
333
                                if (boxAux.isSelected() == true) {
334
                                        contaux++;
335
                                }
336
                        }
337
                        exit.setEnabled(dimArrBx());
338
                        return;
339
                }
340

    
341
                if (src instanceof JCheckBox) {
342

    
343
                        exit.setEnabled(dimArrBx());
344
                }
345
        }
346
}