Statistics
| Revision:

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

History | View | Annotate | Download (14.2 KB)

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

    
3
import java.awt.Color;
4
import java.awt.Dimension;
5
import java.awt.SystemColor;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
8
import java.awt.geom.Rectangle2D;
9
import java.net.URL;
10
import java.util.ArrayList;
11

    
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JCheckBox;
15
import javax.swing.JComboBox;
16
import javax.swing.JLabel;
17
import javax.swing.JPanel;
18

    
19
import org.apache.log4j.Logger;
20

    
21
import com.iver.andami.PluginServices;
22
import com.iver.cit.gvsig.fmap.DriverException;
23
import com.iver.cit.gvsig.fmap.core.FShape;
24
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
25
import com.iver.cit.gvsig.fmap.layers.FLayer;
26
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
27
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
28
import com.iver.cit.gvsig.fmap.layers.FLyrWMS;
29

    
30
import es.prodevelop.gvsig.exportMobile.CreateImage;
31
import es.prodevelop.gvsig.exportMobile.LayerObject;
32
import es.prodevelop.gvsig.exportMobile.ui.order.ArrayStringOrd;
33
import es.prodevelop.gvsig.exportMobile.ui.order.FLayerWithNewName;
34

    
35
/**
36
 * SubPanel to the principal panel extension
37
 * @author Anabel Moreno
38
 *
39
 */
40

    
41
public class PanelIntoScroll implements ActionListener {
42
        
43
        private static Logger logger = Logger.getLogger(PanelIntoScroll.class.getName()); 
44
        private static Color color1 = new Color(234,234,234,234);
45
        private static Color color2 = new Color(254,237,214);
46
        SystemColor a;
47

    
48
        private int height,width;
49
        
50
        private boolean into = true;
51
        
52
        private JPanel newPanel = new JPanel();
53
                
54
        private JComboBox comboActions;
55

    
56
        private JButton chooseAtrib;
57

    
58
        private JCheckBox export;
59

    
60
        private JLabel name, icon, atribute;
61
        
62
        private ArrayList arrLayers = new ArrayList();
63
        
64
        private FLayer layer;
65

    
66
        private String nameLayer;
67

    
68
        private ArrayList arrExports = new ArrayList();
69

    
70
        private int numAtribTot, numAtribSelect;
71

    
72
        private LayerAtributes atribPanel;
73

    
74
        private PanelAtribIntoScroll atriLayer;
75

    
76
        private ArrayList arrLabel = new ArrayList();
77

    
78
        private FLayer lyr;
79

    
80
        private boolean open = false;
81

    
82
        private ArrayList allAtrib = new ArrayList();
83

    
84
        private FieldDescription[] arrDescrLyr;
85

    
86
        private int auxabrt, atr;
87

    
88
        private int[] arrOpen;
89

    
90
        private ExportPanel parent;
91

    
92
        private LayerInView lyrVw;
93

    
94
        private Rectangle2D rectangle;
95

    
96
        private boolean lyrIntoView;
97
        
98
        private ArrayList newArrayLayers = new ArrayList();
99

    
100
        private static int PANEL_WIDTH = 500;
101
        
102
        private static int COMPONENT_Y = 3;
103

    
104
        private static int AUX = 20;
105
        
106
        private static int AUX2 = 26;
107

    
108
        public static int EXPORT_X = 8;
109
        private static int EXPORT_W = 17;
110
        private static int EXPORT_H = 13;
111

    
112
        private static int HEIGHT = 20;
113
        public static int NAME_X = 145;
114
        private static int NAME_W = 200;
115
        
116
        public static int IN_VIEW_X = 88;
117

    
118
        public static int ATRIB_X = 350;
119
        private static int ATRIB_W = 50;
120

    
121
        public static int CHATRB_X = 385;
122
        private static int CHATRB_W = 20;
123

    
124
        public static int CMBOATR_X = 430;
125
        private static int CMBOATR_W = 100;
126

    
127
        public static int ICON_X = 45;
128

    
129
        private static String VECTORIAL = "Capa Vectorial";
130

    
131
        private static String RASTER = "Capa no Vectorial";
132
        
133
        private static String WMS = "WMS";
134

    
135
        
136
        /**
137
         * Panel into ExportPanel (scroll)
138
         * 
139
         * @param arLayers,
140
         *            layer list
141
         * @param pa,
142
         *            parent
143
         * @param rect,
144
         *            rectangle
145
         */
146
        public PanelIntoScroll(ArrayList arLayers, ExportPanel pa, Rectangle2D rect) {
147

    
148
                rectangle = rect;
149
                parent = pa;
150
                arrLayers = arLayers;
151
                int dim = arrLayers.size();
152
                arrOpen = new int[dim];
153
                
154
                newPanel.setLayout(null);
155
                newPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ((dim + 1) * AUX)));
156
                newPanel.setBackground(Color.WHITE);
157

    
158
                ArrayStringOrd arrays = new ArrayStringOrd(arLayers);
159
                ArrayList arrNames = arrays.getArrayStrings();
160
                
161
                
162
                for (int i=0; i < arrLayers.size(); i++) {
163

    
164
                        JPanel layerPanel = new JPanel();
165
                        layerPanel.setLayout(null);
166
                        layerPanel.setBounds(0, AUX2*i, 600, AUX2);
167
                        
168
                        layer = (FLayer) ((FLayerWithNewName)arrLayers.get(i)).getLayer();
169
                        nameLayer = layer.getName();
170

    
171
                        export = new JCheckBox();
172
                        export.setBounds(EXPORT_X, COMPONENT_Y+3, EXPORT_W, EXPORT_H);
173
                        export.addActionListener(parent);
174
                        export.addActionListener(this);
175

    
176
                        name = new JLabel(nameLayer);
177
                        name.setBounds(NAME_X, COMPONENT_Y, NAME_W, HEIGHT);
178

    
179
                        if (open == true) {
180

    
181
                                atribute = new JLabel(numAtribSelect + "/" + numAtribTot);
182
                                atribute.setBounds(ATRIB_X, COMPONENT_Y, ATRIB_W, HEIGHT);
183
                                arrLabel.add(atribute);
184
                                
185
                        } else {
186

    
187
                                ArrayList auxArr = new ArrayList();
188
                                allAtrib.add(auxArr);
189
                                auxabrt = 0;
190
                                arrOpen[i] = auxabrt;
191
                                atriLayer = new PanelAtribIntoScroll(layer, auxArr, auxabrt,null);
192
                                numAtribTot = atriLayer.getNumAtrib();
193
                                numAtribSelect = atriLayer.getNumAtribSelected();
194
                                atribute = new JLabel(numAtribSelect + "/" + numAtribTot);
195
                                atribute.setBounds(ATRIB_X, COMPONENT_Y, ATRIB_W, HEIGHT);
196
                                arrLabel.add(atribute);
197

    
198
                        }
199

    
200
                        chooseAtrib = new JButton("...");
201
                        chooseAtrib.setBounds(CHATRB_X, COMPONENT_Y, CHATRB_W, HEIGHT);
202
                        chooseAtrib.addActionListener(this);
203

    
204
                        comboActions = new JComboBox();
205
                        comboActions.setBounds(CMBOATR_X, COMPONENT_Y, CMBOATR_W, HEIGHT);        
206
//                        comboActions.addItem(PluginServices.getText(this,"select" ));
207
//                        comboActions.addItem(PluginServices.getText(this,"cut" ));
208
//                        comboActions.addItem(PluginServices.getText(this, "allyr"));
209
//                        comboActions.repaint();
210

    
211
//                        if (layer.isVisible() == true) 
212
//                                export.setSelected(true);
213
//                        else 
214
//                                export.setSelected(false);
215
//                        
216
                        
217
                        // ICON TO SHOW
218
                        if (layer instanceof FLyrVect) {
219

    
220
                                CreateImage image = new CreateImage();
221
                                URL path = image.createResourceUrl("images/icolayerV.PNG");
222
                                ImageIcon imIcon = image.createImageIcon(path, VECTORIAL);
223
                                height = imIcon.getIconHeight();
224
                                width = imIcon.getIconWidth();
225
                                icon = new JLabel(imIcon, JLabel.CENTER);
226
                                comboActions.addItem(PluginServices.getText(this,"select" ));
227
                                comboActions.addItem(PluginServices.getText(this,"cut" ));
228
                                comboActions.addItem(PluginServices.getText(this, "allyr"));
229
                                comboActions.repaint();
230
                                
231
                        } 
232
                        if (layer instanceof FLyrRaster){
233
                                
234
                                CreateImage image = new CreateImage();
235
                                URL path = image.createResourceUrl("images/lyrR.PNG");
236
                                ImageIcon imIcon = image.createImageIcon(path, RASTER);
237
                                height = imIcon.getIconHeight();
238
                                width = imIcon.getIconWidth();
239
                                icon = new JLabel(imIcon, JLabel.CENTER);
240
                                chooseAtrib.setEnabled(false);
241
                                comboActions.addItem(PluginServices.getText(this,"cut" ));
242
                                comboActions.addItem(PluginServices.getText(this, "allyr"));
243
                                comboActions.repaint();
244
//                                comboActions.removeItemAt(0);
245
//                                comboActions.setEnabled(true);
246
//                                comboActions.repaint();
247
                        
248
                                
249
                        }
250
                        if (layer instanceof FLyrWMS){
251
                                
252
                                CreateImage image = new CreateImage();
253
                                URL path = image.createResourceUrl("images/icoWMS.png");
254
                                ImageIcon imIcon = image.createImageIcon(path, WMS);
255
                                height = imIcon.getIconHeight();
256
                                width = imIcon.getIconWidth();
257
                                icon = new JLabel(imIcon, JLabel.CENTER);
258
                                chooseAtrib.setEnabled(false);
259
                                comboActions.addItem(PluginServices.getText(this,"config"));
260
                                comboActions.setEnabled(false);
261
//                                comboActions.removeAllItems();
262
//                                comboActions.addItem(PluginServices.getText(this,"config"));
263
//                                comboActions.setSelectedIndex(0);
264
//                                comboActions.setEnabled(false);
265
                                comboActions.repaint();
266
                                
267
                        }
268
                        icon.setBounds(ICON_X, COMPONENT_Y+1, height, width);
269

    
270
                        
271
                        if ((layer.isVisible() == true) && (validGeometryType(layer))) {
272
                                export.setSelected(true);
273
                                if((layer instanceof FLyrVect)||(layer instanceof FLyrRaster)){
274
                                        comboActions.setEnabled(true);
275
                                        comboActions.repaint();
276
                                        chooseAtrib.setEnabled(true);
277
                                }
278
                                
279
                        }
280
                        else {
281
                                export.setSelected(false);
282
                                chooseAtrib.setEnabled(false);
283
                                comboActions.setEnabled(false);
284
                                comboActions.repaint();
285
                        }
286
                        
287
                        
288
                        
289
//                        if(export.isSelected()==false){
290
//                                
291
//                                chooseAtrib.setEnabled(false);
292
//                                comboActions.setEnabled(false);
293
//                                
294
//                        }
295
//                        else{
296
//                                
297
//                                chooseAtrib.setEnabled(true);
298
//                                comboActions.setEnabled(true);
299
//                                
300
//                        }
301
                                                
302
                        if((i%2)==1){
303
                                
304
                                layerPanel.setBackground(color1);
305
                                export.setBackground(color1);
306
                                chooseAtrib.setBackground(color1);
307
                        }
308
                        else{
309
                                layerPanel.setBackground(color2);
310
                                export.setBackground(color2);
311
                                chooseAtrib.setBackground(color2);
312
                        }
313
                        
314
                        JLabel isInto = paintImage(layer, rectangle,layerPanel,comboActions);
315

    
316
                        //         adds panel components
317
                        layerPanel.add(export);
318
                        layerPanel.add(name);
319
                        layerPanel.add(icon);
320
                        layerPanel.add(atribute);
321
                        layerPanel.add(chooseAtrib);
322
                        layerPanel.add(comboActions);
323
                        
324
                        newPanel.add(layerPanel);
325
                        arrExports.add(export);
326
                        
327
                        //New layer object
328
                        String newname = (String) arrNames.get(i);
329
                        LayerObject layerObj = new LayerObject(
330
                                        export,
331
                                        newname,
332
                                        comboActions,
333
                                        layer,
334
                                        chooseAtrib,
335
                                        layerPanel);
336
                        layerObj.setImage(isInto);
337
                        if(layerObj.getLyr() instanceof FLyrVect){
338
                                layerObj.setDescription(atriLayer.getAtribSelected());
339
                        }
340
                        else
341
                                layerObj.setDescription(null);
342
                        //add object to array
343
                        newArrayLayers.add(layerObj);
344
                                                                
345
                }
346
        }
347

    
348
        private boolean validGeometryType(FLayer lyr) {
349
                
350
                if (! (lyr instanceof FLyrVect)) {
351
                        return true;
352
                } else {
353
                        /*
354
                        int shp_type = FShape.NULL;
355
                        
356
                        try {
357
                                shp_type = ((FLyrVect) lyr).getShapeType();
358
                        } catch (DriverException e) {
359
                                logger.error("While getting shp type: " + e.getMessage());
360
                                return false;
361
                        }
362
                        
363
                        return (
364
                                        (shp_type == FShape.POLYGON)
365
                                        || (shp_type == FShape.LINE)
366
                                        || (shp_type== FShape.POINT));*/
367
                        return true;
368
                }
369
        }
370

    
371
        /**
372
         * If layer intersects with the view`s bounds ( rectangle ) paint a tik
373
         * image, but if not intersects paint a X image.
374
         * 
375
         * @param layer,
376
         *            to work
377
         * @param rectang,
378
         *            look if layer intersects with rectangle
379
         */
380
        public JLabel paintImage(FLayer layer, Rectangle2D rectang,JPanel parentPanel,JComboBox comboA) {
381

    
382
                lyrVw = new LayerInView(layer, rectang);
383
                lyrIntoView = lyrVw.isInView();
384
                JLabel isInto;
385
                
386
                if (lyrIntoView == true) {
387

    
388
                        CreateImage image = new CreateImage();
389
                        URL path = image.createResourceUrl("images/tik.png");
390
                        ImageIcon img = image.createImageIcon(path, "image into view");
391
                        int heightInto = img.getIconHeight();
392
                        int widthInto = img.getIconWidth();
393
                        isInto = new JLabel(img, JLabel.CENTER);
394
                        isInto.setBounds(IN_VIEW_X, COMPONENT_Y, heightInto, widthInto);
395
                        into=true;
396
                        
397
                } else {
398
                        
399
                        CreateImage image = new CreateImage();
400
                        URL path = image.createResourceUrl("images/remove.png");
401
                        ImageIcon img = image.createImageIcon(path, "image out of view");
402
                        int heightInto = img.getIconHeight();
403
                        int widthInto = img.getIconWidth();
404
                        isInto = new JLabel(img, JLabel.CENTER);
405
                        isInto.setBounds(IN_VIEW_X, COMPONENT_Y, heightInto, widthInto);
406
                        into=false;
407
                        
408
                }
409
                
410
                if((into == false)){
411
                        
412
                        comboA.removeAllItems();
413
                        comboA.addItem(PluginServices.getText(this, "allyr"));
414
                        
415
                }
416
                else{
417
                        comboA.setEnabled(true);
418
                        comboA.setSelectedIndex(0);
419
                }
420
                
421
                // ---------------- jldominguez - we are not going to cut rasters:
422
                if (layer instanceof FLyrRaster) {
423
                        comboA.removeAllItems();
424
                        comboA.addItem(PluginServices.getText(this, "allyr"));
425
                }
426
                // ---------------- 
427

    
428
                parentPanel.add(isInto);
429
                return isInto;
430
        }
431
        
432
        
433
        public int getSelectedIndex(){
434
                
435
                return comboActions.getSelectedIndex();
436
        }
437
        
438
                
439
        /**
440
         * @return boxs list of all layers
441
         */
442
        public ArrayList getarrBox() {
443

    
444
                return arrExports;
445
        }
446
        
447
        
448
        /**
449
         * @return panel scroll
450
         */
451
        public JPanel getPanel() {
452

    
453
                return newPanel;
454
        }
455
        
456
        /**
457
         * @return array layers
458
         */
459
        public ArrayList getNewArrayLayers(){
460
                
461
                return newArrayLayers;
462
        }
463

    
464
        
465
        public void actionPerformed(ActionEvent arg0) {
466

    
467
                Object src = arg0.getSource();
468

    
469
                //all type of layers
470
                for (int i = 0; i < newArrayLayers.size(); i++) {
471

    
472
                        LayerObject lyrObj = (LayerObject) newArrayLayers.get(i);
473
                        lyr = lyrObj.getLyr();
474
                        JCheckBox boxExp = lyrObj.getBox();
475
                        JComboBox combo = lyrObj.getCombo();
476
                        JButton button = lyrObj.getButton();
477

    
478
                        if (src == boxExp) {
479

    
480
                                if(boxExp.isSelected()==true){
481
                                        boxExp.setSelected(false);
482
                                        if ((lyr instanceof FLyrVect)){
483
                                                
484
                                                combo.setEnabled(true);
485
                                                button.setEnabled(true);
486
                                                lyrObj.setBoxStatus(true);
487
                                        }        
488
                                        if(lyr instanceof FLyrRaster){
489
                                                
490
                                                combo.setEnabled(true);
491
                                                button.setEnabled(false);
492
                                                lyrObj.setBoxStatus(true);
493
                                        }
494
                                }
495
                                else{
496
                                        boxExp.setSelected(true);
497
                                        combo.setEnabled(false);
498
                                        button.setEnabled(false);
499
                                        lyrObj.setBoxStatus(false);
500
                                }
501
                                        
502
                                return;
503
                        }
504

    
505
                        // if push atributes button
506
                        if (src == button) {
507

    
508
                                JLabel label = (JLabel) arrLabel.get(i);
509
                                open = true;
510
                                atr = arrOpen[i];
511

    
512
                                atr++;
513

    
514
                                // show panel
515
                                atribPanel = new LayerAtributes(lyrObj.getLyr(), (ArrayList) allAtrib
516
                                                .get(i), atr);
517
                                ArrayList aux = atribPanel.getSelectAtrib();
518
                                PluginServices.getMDIManager().addWindow(atribPanel);
519

    
520
                                // when close the panel the label atribute has to change
521
                                if (atribPanel.isOkPress()) {
522

    
523
                                        aux = atribPanel.getSelectAtrib();
524
                                        allAtrib.set(i, aux);
525
                                        numAtribTot = atribPanel.getAtrib();
526
                                        numAtribSelect = atribPanel.getAtrSelected();
527
                                        label.setText(numAtribSelect + "/" + numAtribTot);
528

    
529
                                        newPanel.repaint();
530
                                        arrOpen[i] = atr;
531

    
532
                                        // get selected atributes FieldDescription[]
533
                                        arrDescrLyr = atribPanel.getAtribSelected();
534

    
535
                                        // add the new layer`s fieldDescription into a new list
536
                                        lyrObj.setDescription(arrDescrLyr);
537
                                        
538
                                }
539

    
540
                                else {
541

    
542
                                        numAtribSelect = atriLayer.getNumAtribSelected();
543
                                        atribute = new JLabel(numAtribSelect + "/" + numAtribTot);
544
                                        newPanel.repaint();
545
                                        atr++;
546
                                }
547
                                return;
548
                        }
549
                }
550
        }
551
}