Statistics
| Revision:

root / tags / v1_1_Build_1001 / libraries / libCq_CMS_praster / src / org / cresques / ui / filter / EnhancedPanel.java @ 11984

History | View | Annotate | Download (16.8 KB)

1
/*
2
 * Created on 31-ago-2006
3
 */
4
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 */
22
package org.cresques.ui.filter;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.FlowLayout;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.Image;
29
import java.awt.event.ComponentEvent;
30
import java.awt.event.ComponentListener;
31

    
32
import javax.swing.ButtonGroup;
33
import javax.swing.ImageIcon;
34
import javax.swing.JCheckBox;
35
import javax.swing.JLabel;
36
import javax.swing.JPanel;
37
import javax.swing.JRadioButton;
38
import javax.swing.JSlider;
39
import javax.swing.JTextField;
40

    
41

    
42

    
43
/**
44
 * Panel que contiene los elementos para el dialogo del filtro de realce
45
 * @author Nacho Brodin <brodin_ign@gva.es>
46
 */
47
public class EnhancedPanel extends JPanel implements ComponentListener{
48
    final private static long serialVersionUID = -3370601314380922368L;
49
    /**
50
     * Nombre del panel
51
     */
52
    private String nom = "Realce";
53
    FilterRasterDialogPanel parent = null;
54
    private JPanel jPanel = null;
55
    private JPanel jPanel1 = null;
56
    private JPanel jPanel2 = null;
57
    private JPanel jPanel3 = null;
58
    private JRadioButton jRadioButton = null;
59
    private JRadioButton jRadioButton1 = null;
60
    private JCheckBox jCheckBox = null;
61
    
62
    /**
63
     * Variable accesible para la traducci?n
64
     */
65
    public JLabel lLineal = null;
66
    
67
    /**
68
     * Variable accesible para la traducci?n
69
     */
70
    public JLabel lWithoutEnhanced = null;
71
    
72
    /**
73
     * Variable accesible para la traducci?n
74
     */
75
    public JPanel pGeneralEnhanced = null;
76
    private ButtonGroup grupo = new ButtonGroup();
77
    private Image iconoLineal = null;
78
    private Image iconoSinRealce = null;
79
    private JPanel jPanel5 = null;
80
    private JSlider jSlider = null;
81
    private JTextField jTextField = null;
82
    private JPanel jPanel6 = null;
83
    private JCheckBox jCheckBox1 = null;
84
    
85
    /**
86
     * Variable accesible para la traducci?n
87
     */
88
    public JLabel lCut = null;
89
    
90
    /**
91
     * Variable accesible para la traducci?n
92
     */
93
    public JPanel pTail = null;
94
    
95
    /**
96
     * Variable accesible para la traducci?n
97
     */
98
    public JLabel lQueue = null;
99
    
100
    /**
101
     * Variable accesible para su traducci?n
102
     */
103
    public JPanel pSlider = null;
104
    
105
    /**
106
     * Variable accesible para la traducci?n
107
     */
108
    public JPanel pRemove = null;
109
    
110
    /**
111
     * Variable accesible para la traducci?n
112
     */
113
    public JLabel lRemove = null;
114

    
115
    /**
116
     * Constructor.
117
     * @param parent
118
     */
119
    public EnhancedPanel(FilterRasterDialogPanel parent) {
120
        this.parent = parent;
121
        initialize();
122
    }
123

    
124
    /**
125
     * This method initializes this
126
     *
127
     * @return void
128
     */
129
    private void initialize() {
130
        this.setLayout(new BorderLayout());
131
        this.setSize(445, 239);
132
        this.setPreferredSize(new java.awt.Dimension(445, 239));
133
        this.add(getJPanel(), java.awt.BorderLayout.CENTER);
134

    
135
        initControls();
136
        this.addComponentListener(this);
137
    }
138

    
139
    /**
140
     * Obtiene el nombre del panel
141
     * @return Cadena con el nombre del panel
142
     */
143
    public String getName(){
144
            return this.nom;
145
    }
146
    
147
    /**
148
     * Inicializa controles a sus valores por defecto
149
     */
150
    public void initControls() {
151
        jRadioButton1.setSelected(true);
152
        this.getTailText().setText("0.0");
153
        this.getTailSlider().setValue(0);
154
        this.setActiveTailControl(false);
155
        this.getTailCheck().setEnabled(false);
156
        this.getRemoveCheck().setEnabled(false);
157
    }
158

    
159
    /**
160
     * This method initializes jPanel
161
     *
162
     * @return javax.swing.JPanel
163
     */
164
    private JPanel getJPanel() {
165
        if (jPanel == null) {
166
            GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
167
            gridBagConstraints1.insets = new java.awt.Insets(40,3,69,8);
168
            gridBagConstraints1.gridy = 0;
169
            gridBagConstraints1.gridx = 1;
170
            GridBagConstraints gridBagConstraints = new GridBagConstraints();
171
            gridBagConstraints.insets = new java.awt.Insets(5,7,34,2);
172
            gridBagConstraints.gridy = 0;
173
            gridBagConstraints.gridx = 0;
174
            GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
175
            jPanel = new JPanel();
176
            jPanel.setLayout(new GridBagLayout());
177
            gridBagConstraints4.gridx = 0;
178
            gridBagConstraints4.gridy = 0;
179
            jPanel.setPreferredSize(new java.awt.Dimension(445, 239));
180
            jPanel.add(getJPanel4(), gridBagConstraints);
181
            jPanel.add(getJPanel8(), gridBagConstraints1);
182
        }
183

    
184
        return jPanel;
185
    }
186

    
187
    /**
188
     * This method initializes jPanel1
189
     *
190
     * @return javax.swing.JPanel
191
     */
192
    private JPanel getJPanel1() {
193
        if (jPanel1 == null) {
194
            lLineal = new JLabel("Lineal directo",
195
                                new ImageIcon("images/lineal.gif"),
196
                                JLabel.CENTER);
197
            jPanel1 = new JPanel();
198
            jPanel1.setLayout(new BorderLayout());
199
            jPanel1.add(getLinealDirectoRadioButton(),
200
                        java.awt.BorderLayout.WEST);
201
            jPanel1.add(lLineal, java.awt.BorderLayout.EAST);
202
        }
203

    
204
        return jPanel1;
205
    }
206

    
207
    /**
208
     * This method initializes jPanel2
209
     *
210
     * @return javax.swing.JPanel
211
     */
212
    private JPanel getJPanel2() {
213
        if (jPanel2 == null) {
214
            jPanel2 = new JPanel();
215
            jPanel2.setLayout(new BorderLayout());
216
            jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,
217
                                                                         1));
218
            jPanel2.setPreferredSize(new java.awt.Dimension(220, 95));
219
            jPanel2.add(getJPanel5(), java.awt.BorderLayout.CENTER);
220
            jPanel2.add(getJPanel6(), java.awt.BorderLayout.SOUTH);
221
            jPanel2.add(getJPanel7(), java.awt.BorderLayout.NORTH);
222
        }
223

    
224
        return jPanel2;
225
    }
226

    
227
    /**
228
     * This method initializes jPanel3
229
     *
230
     * @return javax.swing.JPanel
231
     */
232
    private JPanel getJPanel3() {
233
        if (jPanel3 == null) {
234
            lWithoutEnhanced = new JLabel("Sin Realce",
235
                                 new ImageIcon("images/sinrealce.gif"),
236
                                 JLabel.CENTER);
237
            jPanel3 = new JPanel();
238
            jPanel3.setLayout(new BorderLayout());
239
            jPanel3.add(getSinRealceRadioButton(), java.awt.BorderLayout.WEST);
240
            jPanel3.add(lWithoutEnhanced, java.awt.BorderLayout.EAST);
241
        }
242

    
243
        return jPanel3;
244
    }
245

    
246
    /**
247
     * This method initializes jRadioButton
248
     *
249
     * @return javax.swing.JRadioButton
250
     */
251
    public JRadioButton getLinealDirectoRadioButton() {
252
        if (jRadioButton == null) {
253
            jRadioButton = new JRadioButton();
254
            grupo.add(jRadioButton);
255
        }
256

    
257
        return jRadioButton;
258
    }
259

    
260
    /**
261
     * This method initializes jRadioButton1
262
     *
263
     * @return javax.swing.JRadioButton
264
     */
265
    public JRadioButton getSinRealceRadioButton() {
266
        if (jRadioButton1 == null) {
267
            jRadioButton1 = new JRadioButton();
268
            jRadioButton1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
269
            grupo.add(jRadioButton1);
270
        }
271

    
272
        return jRadioButton1;
273
    }
274

    
275
    /**
276
     * This method initializes jCheckBox
277
     *
278
     * @return javax.swing.JCheckBox
279
     */
280
    public JCheckBox getTailCheck() {
281
        if (jCheckBox == null) {
282
            jCheckBox = new JCheckBox();
283
        }
284

    
285
        return jCheckBox;
286
    }
287

    
288
    /**
289
     * This method initializes jPanel4
290
     *
291
     * @return javax.swing.JPanel
292
     */
293
    private JPanel getJPanel4() {
294
        if (pGeneralEnhanced == null) {
295
            GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
296
            GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
297
            pGeneralEnhanced = new JPanel();
298
            pGeneralEnhanced.setLayout(new GridBagLayout());
299
            gridBagConstraints9.gridx = 0;
300
            gridBagConstraints9.gridy = 0;
301
            gridBagConstraints9.insets = new java.awt.Insets(5, 0, 5, 2);
302
            gridBagConstraints9.anchor = java.awt.GridBagConstraints.WEST;
303
            gridBagConstraints10.gridx = 0;
304
            gridBagConstraints10.gridy = 1;
305
            gridBagConstraints10.insets = new java.awt.Insets(5, 0, 5, 5);
306
            pGeneralEnhanced.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0,
307
                                                                          0, 0));
308
            pGeneralEnhanced.setPreferredSize(new java.awt.Dimension(175, 200));
309
            pGeneralEnhanced.add(getJPanel3(), gridBagConstraints9);
310
            pGeneralEnhanced.add(getJPanel1(), gridBagConstraints10);
311
        }
312

    
313
        return pGeneralEnhanced;
314
    }
315

    
316
    /**
317
     * This method initializes jPanel5
318
     *
319
     * @return javax.swing.JPanel
320
     */
321
    private JPanel getJPanel5() {
322
        if (jPanel5 == null) {
323
            jPanel5 = new JPanel();
324
            jPanel5.add(getTailSlider(), null);
325
        }
326

    
327
        return jPanel5;
328
    }
329

    
330
    /**
331
     * This method initializes jSlider
332
     *
333
     * @return javax.swing.JSlider
334
     */
335
    public JSlider getTailSlider() {
336
        if (jSlider == null) {
337
            jSlider = new JSlider();
338
            jSlider.setPreferredSize(new java.awt.Dimension(240, 16));
339
        }
340

    
341
        return jSlider;
342
    }
343

    
344
    /**
345
     * This method initializes jTextField
346
     *
347
     * @return javax.swing.JTextField
348
     */
349
    public JTextField getTailText() {
350
        if (jTextField == null) {
351
            jTextField = new JTextField();
352
            jTextField.setPreferredSize(new java.awt.Dimension(40, 19));
353
            jTextField.setText("0.0");
354
        }
355

    
356
        return jTextField;
357
    }
358

    
359
    /**
360
     * Activa/Desactiva los controles de Recorte de colas
361
     * @param active
362
     */
363
    public void setActiveTailControl(boolean active) {
364
        this.getTailSlider().setEnabled(active);
365
        this.getTailText().setEnabled(active);
366
        this.lQueue.setEnabled(active);
367
        this.lCut.setEnabled(active);
368
    }
369

    
370
    /**
371
     *
372
     * @param active
373
     */
374
    public void setActiveRemoveCheck(boolean active) {
375
        this.getRemoveCheck().setEnabled(active);
376
        this.lRemove.setEnabled(active);
377
    }
378

    
379
    /**
380
     * Asigna el procentaje de recorte de colas aplicado
381
     * @param tail
382
     */
383
    public void setPercentTail(int tail) {
384
        jTextField.setText(String.valueOf(tail));
385
        jSlider.setValue(tail);
386
    }
387

    
388
    /**
389
     * Asigna el filtro seleccionado cuando se abre el dialogo
390
     * @param filter
391
     */
392
    public void setSelectedFilter(int filter) {
393
        switch (filter) {
394
        case 0:
395
            jRadioButton1.setSelected(true); //Sin realce
396
            jCheckBox.setEnabled(false);
397
            setActiveTailControl(false);
398
            this.setActiveRemoveCheck(false);
399

    
400
            break;
401

    
402
        case 1:
403
            this.getRemoveCheck().setSelected(true);
404

    
405
        case 2:
406
            jRadioButton.setSelected(true); //Realce lineal
407
            this.getTailCheck().setEnabled(true);
408
            this.setActiveRemoveCheck(true);
409

    
410
            if (!this.getTailText().getText().equals("") &&
411
                    !this.getTailText().getText().equals("0.0")) {
412
                this.getTailCheck().setSelected(true);
413
                this.setActiveTailControl(true);
414
            }
415

    
416
            break;
417
        }
418
    }
419

    
420
    /**
421
     * This method initializes jPanel6
422
     *
423
     * @return javax.swing.JPanel
424
     */
425
    private JPanel getJPanel6() {
426
        if (jPanel6 == null) {
427
            FlowLayout flowLayout3 = new FlowLayout();
428
            lCut = new JLabel();
429
            jPanel6 = new JPanel();
430
            jPanel6.setLayout(flowLayout3);
431
            lCut.setText("% recorte");
432
            flowLayout3.setAlignment(java.awt.FlowLayout.LEFT);
433
            jPanel6.add(getTailText(), null);
434
            jPanel6.add(lCut, null);
435
        }
436

    
437
        return jPanel6;
438
    }
439

    
440
    /**
441
     * This method initializes jCheckBox1
442
     *
443
     * @return javax.swing.JCheckBox
444
     */
445
    public JCheckBox getRemoveCheck() {
446
        if (jCheckBox1 == null) {
447
            jCheckBox1 = new JCheckBox();
448
        }
449

    
450
        return jCheckBox1;
451
    }
452

    
453
    /**
454
     * This method initializes jPanel7
455
     *
456
     * @return javax.swing.JPanel
457
     */
458
    private JPanel getJPanel7() {
459
        if (pTail == null) {
460
                lQueue = new JLabel();
461

    
462
            FlowLayout flowLayout1 = new FlowLayout();
463
            pTail = new JPanel();
464
            pTail.setLayout(flowLayout1);
465
            lQueue.setText("Recorte de colas");
466
            flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);
467
            pTail.add(getTailCheck(), null);
468
            pTail.add(lQueue, null);
469
        }
470

    
471
        return pTail;
472
    }
473

    
474
    /**
475
     * This method initializes jPanel8
476
     *
477
     * @return javax.swing.JPanel
478
     */
479
    private JPanel getJPanel8() {
480
        if (pSlider == null) {
481
                GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
482
                gridBagConstraints3.insets = new java.awt.Insets(0,0,2,0);
483
                gridBagConstraints3.gridy = 0;
484
                gridBagConstraints3.ipadx = 101;
485
                gridBagConstraints3.gridx = 0;
486
                GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
487
                gridBagConstraints2.insets = new java.awt.Insets(2,0,0,0);
488
                gridBagConstraints2.gridy = 1;
489
                gridBagConstraints2.ipadx = 30;
490
                gridBagConstraints2.gridx = 0;
491
                pSlider = new JPanel();
492
                pSlider.setLayout(new GridBagLayout());
493
                pSlider.setPreferredSize(new java.awt.Dimension(250, 130));
494
                pSlider.add(getJPanel2(), gridBagConstraints2);
495
                pSlider.add(getJPanel9(), gridBagConstraints3);
496
        }
497

    
498
        return pSlider;
499
    }
500

    
501
    /**
502
     * This method initializes jPanel9
503
     *
504
     * @return javax.swing.JPanel
505
     */
506
    private JPanel getJPanel9() {
507
        if (pRemove == null) {
508
            lRemove = new JLabel();
509

    
510
            FlowLayout flowLayout11 = new FlowLayout();
511
            pRemove = new JPanel();
512
            pRemove.setLayout(flowLayout11);
513
            lRemove.setText("Eliminar Extremos");
514
            flowLayout11.setAlignment(java.awt.FlowLayout.LEFT);
515
            pRemove.add(getRemoveCheck(), null);
516
            pRemove.add(lRemove, null);
517
        }
518

    
519
        return pRemove;
520
    }
521

    
522
        public void componentHidden(ComponentEvent e) {
523
                // TODO Auto-generated method stub
524
                
525
        }
526

    
527
        public void componentMoved(ComponentEvent e) {
528
                // TODO Auto-generated method stub
529
                
530
        }
531
        /**
532
         * Redimesiona el panel cuando hay un cambio en el tama?o de su
533
         * contenedor.
534
         */
535
        public void componentResized(ComponentEvent e) {
536
                if(e.getSource() == this){
537
                        int difWidth = this.getWidth() - 445;
538
                        int difHeight = this.getHeight() - 239;
539
                        this.pGeneralEnhanced.setLocation(this.pGeneralEnhanced.getX() - difWidth/2, this.pGeneralEnhanced.getY() - difHeight/2);
540
                        this.pGeneralEnhanced.setSize(this.pGeneralEnhanced.getWidth() + difWidth/2, this.pGeneralEnhanced.getHeight() + difHeight/2);
541
                        this.jPanel3.setLocation(this.jPanel3.getX() + difWidth/4, this.jPanel3.getY() + difHeight/2);
542
                        this.jPanel1.setLocation(this.jPanel1.getX() + difWidth/4, this.jPanel1.getY() + difHeight/2);
543
                        this.pSlider.setLocation(this.pSlider.getX(), this.pSlider.getY()-difHeight/2);
544
                        this.pSlider.setSize(this.pSlider.getWidth() + difWidth/2, this.pSlider.getHeight() + difHeight );
545
                        this.jPanel2.setSize(this.jPanel2.getWidth() + difWidth/2, this.jPanel2.getHeight() + difHeight );
546
                        this.pTail.setLocation(this.pTail.getX(), this.pTail.getY() + difHeight/2);
547
                        this.jPanel5.setLocation(this.jPanel5.getX(), this.jPanel5.getY() + difHeight/2);
548
                        this.jPanel6.setLocation(this.jPanel6.getX(), this.jPanel6.getY() + difHeight/2);
549
                        this.jPanel5.setSize(this.jPanel5.getWidth() + difWidth/2, this.jPanel5.getHeight());
550
                        this.jSlider.setSize(this.jSlider.getWidth() + difWidth/2, this.jSlider.getHeight());
551
                        //System.out.println("--->"+this.pSlider.getX()+"---"+pSlider.getY());
552
                }
553
                
554
        }
555

    
556
        public void componentShown(ComponentEvent e) {
557
                // TODO Auto-generated method stub
558
                
559
        }
560
} //  @jve:decl-index=0:visual-constraint="36,15"