Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1014 / libraries / libCq_CMS_praster / src / org / cresques / ui / BrightnessContrast / EnhancedBrightnessContrastPanel.java @ 13593

History | View | Annotate | Download (16.2 KB)

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

    
20
package org.cresques.ui.BrightnessContrast;
21

    
22
import java.awt.FlowLayout;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

    
28
import javax.swing.JCheckBox;
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
31

    
32
import org.cresques.filter.IStackManager;
33
import org.cresques.filter.RasterFilterStackManager;
34
import org.cresques.filter.enhancement.BrightnessContrastStackManager;
35
import org.cresques.io.GeoRasterFile;
36
import org.cresques.ui.filter.FilterRasterDialogPanel;
37
import org.cresques.ui.raster.IResize;
38

    
39

    
40
/**
41
 * Panel para los controles de brillo, contrase y realce.
42
 * @author Miguel Angel Querol Carratal? <querol_mig@gva.es>
43
 *
44
 */
45
public class EnhancedBrightnessContrastPanel extends JPanel implements ActionListener, IResize{
46

    
47
        private int                                                        wComp = 445, hComp = 239;
48
        private int                                                        wPanels = (int)Math.round(wComp / 2) - 13, hPanels = hComp - 16;
49
        private int                                                        wBright = wPanels - 22, hBright = hPanels - 73;
50
        private int                                                        wEnhan = wBright, hEnhan = hPanels - 123;
51
        private int                                                        wBCheck = wPanels - 28;
52
        private int                                                        wSlider = wBright - 8, hSlider = 45;
53
        
54
        private String nom = "Realce";
55
        private JPanel pBrightCont = null;
56
        private JPanel pEnhanced = null;
57
        public LabelSliderText lstBrightness = null;
58
        public LabelSliderText lstContrast = null;
59
        private JPanel pBCCheck = null;
60
        private JPanel pBCSlider = null;
61
        private JPanel jPanel1 = null;
62
        private JCheckBox cBrightC = null;
63
        public JLabel lBrightC = null;
64
        private JPanel pEnCheck = null;
65
        private JPanel pEnSlider = null;
66
        private JCheckBox cEnhanced = null;
67
        private JPanel pDelInt = null;
68
        private JCheckBox jCheckBox = null;
69
        
70
        private BrightnessContrastStackManager bcManager = null;
71
        private JCheckBox jCheckBox1 = null;
72
        public JLabel lpreview = null;
73
        public RasterFilterStackManager rasterStackManager = null;
74
        public JLabel lLineal = null;
75
        public JLabel lRemove = null;
76
        public CheckSliderText cstEnhanced = null;
77
        private FilterRasterDialogPanel parent = null;
78
        
79
        public static final int h = 239;
80
        public static final int w = 445;
81
        
82
        /**
83
         * This is the default constructor
84
         */
85
        public EnhancedBrightnessContrastPanel() {
86
                super();
87
                initialize();
88
        }
89

    
90
        /**
91
         * This is the default constructor
92
         */
93
        public EnhancedBrightnessContrastPanel(FilterRasterDialogPanel parent) {
94
                super();
95
                this.parent = parent;
96
                initialize();
97
        }
98
        
99
        /**
100
         * This method initializes this
101
         * 
102
         * @return void
103
         */
104
        private void initialize() {
105
                GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
106
                gridBagConstraints3.insets = new java.awt.Insets(0,4,0,4);
107
                gridBagConstraints3.gridy = 0;
108
                gridBagConstraints3.gridx = 1;
109
                GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
110
                gridBagConstraints2.insets = new java.awt.Insets(0,4,0,4);
111
                gridBagConstraints2.gridy = 0;
112
                gridBagConstraints2.gridx = 0;
113
                this.setLayout(new GridBagLayout());
114
                this.setSize(wComp, hComp);
115
                this.setPreferredSize(new java.awt.Dimension(wComp,hComp));
116
                this.add(getPBrightCont(), gridBagConstraints2);
117
                this.add(getPEnhanced(), gridBagConstraints3);
118
                
119
                this.getCBrightC().addActionListener(this);
120
                this.getCEnhanced().addActionListener(this);
121
                //this.addComponentListener(this);
122
                //this.getLabelSliderText().getJTextField().addActionListener(this);
123
                //this.getLabelSliderText1().getJTextField().addActionListener(this);
124
        }
125
        
126
        /**
127
         * This method initializes jPanel        
128
         *         
129
         * @return javax.swing.JPanel        
130
         */
131
        public JPanel getPBrightCont() {
132
                if (pBrightCont == null) {
133
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
134
                        gridBagConstraints4.gridx = 0;
135
                        gridBagConstraints4.insets = new java.awt.Insets(4,0,8,0);
136
                        gridBagConstraints4.gridy = 1;
137
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
138
                        gridBagConstraints.gridx = 0;
139
                        gridBagConstraints.insets = new java.awt.Insets(0,8,4,8);
140
                        gridBagConstraints.gridy = 0;
141
                        pBrightCont = new JPanel();
142
                        pBrightCont.setLayout(new GridBagLayout());
143
                        pBrightCont.setPreferredSize(new java.awt.Dimension(wPanels,hPanels));
144
                        pBrightCont.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Brillo y contraste", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
145
                        pBrightCont.add(getPBCCheck(), gridBagConstraints);
146
                        pBrightCont.add(getPBCSlider(), gridBagConstraints4);
147
                }
148
                return pBrightCont;
149
        }
150

    
151
        /**
152
         * This method initializes jPanel1        
153
         *         
154
         * @return javax.swing.JPanel        
155
         */
156
        public JPanel getPEnhanced() {
157
                if (pEnhanced == null) {
158
                        GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
159
                        gridBagConstraints12.gridx = 0;
160
                        gridBagConstraints12.insets = new java.awt.Insets(4,4,59,4);
161
                        gridBagConstraints12.gridy = 1;
162
                        GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
163
                        gridBagConstraints11.gridx = 0;
164
                        gridBagConstraints11.insets = new java.awt.Insets(0,8,4,8);
165
                        gridBagConstraints11.gridy = 0;
166
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
167
                        gridBagConstraints1.gridx = 0;
168
                        gridBagConstraints1.gridy = 0;
169
                        pEnhanced = new JPanel();
170
                        pEnhanced.setLayout(new GridBagLayout());
171
                        pEnhanced.setPreferredSize(new java.awt.Dimension(wPanels,hPanels));
172
                        pEnhanced.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Realce", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
173
                        pEnhanced.add(getPEnCheck(), gridBagConstraints11);
174
                        pEnhanced.add(getPEnSlider(), gridBagConstraints12);
175
                }
176
                return pEnhanced;
177
        }
178

    
179
        /**
180
         * inicializa el conponente LabelSliderText
181
         */
182
        public LabelSliderText getLabelSliderText(){
183
                if(lstBrightness == null){
184
                        lstBrightness = new LabelSliderText();
185
                        lstBrightness.setName("Brillo");
186
                        lstBrightness.setSliderRange(-255,255);
187
                        lstBrightness.setSliderValue(0);
188
                }
189
                return lstBrightness;
190
        }
191

    
192
        /**
193
         * inicializa el conponente LabelSliderText
194
         */
195
        public LabelSliderText getLabelSliderText1(){
196
                if (lstContrast == null){
197
                        lstContrast = new LabelSliderText();
198
                        lstContrast.setName("Contraste");
199
                        lstContrast.setPreferredSize(new java.awt.Dimension(180,45));
200
                        lstContrast.setSliderRange(-255,255);
201
                        lstContrast.setSliderValue(0);
202
                }
203
                return lstContrast;
204
        }
205

    
206
        /**
207
         * This method initializes jPanel1        
208
         *         
209
         * @return javax.swing.JPanel        
210
         */
211
        private JPanel getPBCCheck() {
212
                if (pBCCheck == null) {
213
                        FlowLayout flowLayout = new FlowLayout();
214
                        flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
215
                        flowLayout.setVgap(0);
216
                        flowLayout.setHgap(0);
217
                        lBrightC = new JLabel();
218
                        lBrightC.setText("Activar");
219
                        lBrightC.setPreferredSize(new java.awt.Dimension(160,15));
220
                        pBCCheck = new JPanel();
221
                        pBCCheck.setLayout(flowLayout);
222
                        pBCCheck.setPreferredSize(new java.awt.Dimension(wBCheck,25));
223
                        pBCCheck.add(getCBrightC(), null);
224
                        pBCCheck.add(lBrightC, null);
225
                }
226
                return pBCCheck;
227
        }
228

    
229
        /**
230
         * This method initializes jPanel3        
231
         *         
232
         * @return javax.swing.JPanel        
233
         */
234
        private JPanel getPBCSlider() {
235
                if (pBCSlider == null) {
236
                        GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
237
                        gridBagConstraints7.gridx = 0;
238
                        gridBagConstraints7.insets = new java.awt.Insets(0,0,2,0);
239
                        gridBagConstraints7.gridy = 0;
240
                        GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
241
                        gridBagConstraints6.gridx = 0;
242
                        gridBagConstraints6.insets = new java.awt.Insets(10,0,8,0);
243
                        gridBagConstraints6.gridy = 2;
244
                        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
245
                        gridBagConstraints5.gridx = 0;
246
                        gridBagConstraints5.insets = new java.awt.Insets(0,0,0,0);
247
                        gridBagConstraints5.gridy = 1;
248
                        pBCSlider = new JPanel();
249
                        pBCSlider.setLayout(new GridBagLayout());
250
                        pBCSlider.setPreferredSize(new java.awt.Dimension(wBright,hBright));
251
                        pBCSlider.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
252
                        pBCSlider.add(getLabelSliderText(), gridBagConstraints7);
253
                        pBCSlider.add(getLabelSliderText1(), gridBagConstraints5);
254
                        pBCSlider.add(getJPanel1(), gridBagConstraints6);
255
                        this.setBCControlEnabled(false);
256
                }
257
                return pBCSlider;
258
        }
259

    
260
        /**
261
         * This method initializes jPanel1        
262
         *         
263
         * @return javax.swing.JPanel        
264
         */
265
        private JPanel getJPanel1() {
266
                if (jPanel1 == null) {
267
                        FlowLayout flowLayout1 = new FlowLayout();
268
                        flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);
269
                        flowLayout1.setVgap(0);
270
                        flowLayout1.setHgap(0);
271
                        lpreview = new JLabel();
272
                        lpreview.setText("Previsualizacion");
273
                        lpreview.setPreferredSize(new java.awt.Dimension(150,15));
274
                        lpreview.setSize(new java.awt.Dimension(160,15));
275
                        jPanel1 = new JPanel();
276
                        jPanel1.setLayout(flowLayout1);
277
                        jPanel1.setPreferredSize(new java.awt.Dimension(wSlider,25));
278
                        jPanel1.add(getJCheckBox1(), null);
279
                        jPanel1.add(lpreview, null);
280
                }
281
                return jPanel1;
282
        }
283

    
284
        /**
285
         * This method initializes jCheckBox        
286
         *         
287
         * @return javax.swing.JCheckBox        
288
         */
289
        public JCheckBox getCBrightC() {
290
                if (cBrightC == null) {
291
                        cBrightC = new JCheckBox();
292
                }
293
                return cBrightC;
294
        }
295

    
296
        /**
297
         * This method initializes jPanel        
298
         *         
299
         * @return javax.swing.JPanel        
300
         */
301
        private JPanel getPEnCheck() {
302
                if (pEnCheck == null) {
303
                        FlowLayout flowLayout2 = new FlowLayout();
304
                        flowLayout2.setHgap(0);
305
                        flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
306
                        flowLayout2.setVgap(0);
307
                        lLineal = new JLabel();
308
                        lLineal.setText("Lineal Directo");
309
                        lLineal.setPreferredSize(new java.awt.Dimension(160,15));
310
                        pEnCheck = new JPanel();
311
                        pEnCheck.setLayout(flowLayout2);
312
                        pEnCheck.setPreferredSize(new java.awt.Dimension(wBCheck,25));
313
                        pEnCheck.add(getCEnhanced(), null);
314
                        pEnCheck.add(lLineal, null);
315
                }
316
                return pEnCheck;
317
        }
318

    
319
        /**
320
         * This method initializes jPanel2        
321
         *         
322
         * @return javax.swing.JPanel        
323
         */
324
        private JPanel getPEnSlider() {
325
                if (pEnSlider == null) {
326
                        GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
327
                        gridBagConstraints18.insets = new java.awt.Insets(2,0,0,0);
328
                        gridBagConstraints18.gridy = 1;
329
                        gridBagConstraints18.gridx = 0;
330
                        GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
331
                        gridBagConstraints15.insets = new java.awt.Insets(0,0,2,0);
332
                        gridBagConstraints15.gridy = 0;
333
                        gridBagConstraints15.gridx = 0;
334
                        pEnSlider = new JPanel();
335
                        pEnSlider.setLayout(new GridBagLayout());
336
                        pEnSlider.setPreferredSize(new java.awt.Dimension(wEnhan,hEnhan));
337
                        pEnSlider.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
338
                        pEnSlider.add(getPDelInt(), gridBagConstraints15);
339
                        pEnSlider.add(getCheckSliderText(), gridBagConstraints18);
340
                        this.setEControlEnabled(false);
341
                }
342
                return pEnSlider;
343
        }
344

    
345
        /**
346
         * This method initializes jCheckBox        
347
         *         
348
         * @return javax.swing.JCheckBox        
349
         */
350
        public JCheckBox getCEnhanced() {
351
                if (cEnhanced == null) {
352
                        cEnhanced = new JCheckBox();
353
                }
354
                return cEnhanced;
355
        }
356

    
357
        /**
358
         * This method initializes jPanel3        
359
         *         
360
         * @return javax.swing.JPanel        
361
         */
362
        private JPanel getPDelInt() {
363
                if (pDelInt == null) {
364
                        FlowLayout flowLayout3 = new FlowLayout();
365
                        flowLayout3.setAlignment(java.awt.FlowLayout.LEFT);
366
                        flowLayout3.setVgap(0);
367
                        flowLayout3.setHgap(5);
368
                        lRemove = new JLabel();
369
                        lRemove.setText("Eliminar Extremos");
370
                        lRemove.setPreferredSize(new java.awt.Dimension(150,15));
371
                        pDelInt = new JPanel();
372
                        pDelInt.setLayout(flowLayout3);
373
                        pDelInt.setPreferredSize(new java.awt.Dimension(wSlider + 1,25));
374
                        pDelInt.add(getJCheckBox(), null);
375
                        pDelInt.add(lRemove, null);
376
                }
377
                return pDelInt;
378
        }
379

    
380
        /**
381
         * This method initializes jCheckBox        
382
         *         
383
         * @return javax.swing.JCheckBox        
384
         */
385
        public JCheckBox getJCheckBox() {
386
                if (jCheckBox == null) {
387
                        jCheckBox = new JCheckBox();
388
                }
389
                return jCheckBox;
390
        }
391
        
392
        /**
393
         * inicializa el conponente CheckSliderText
394
         */
395
        public CheckSliderText getCheckSliderText(){
396
                String rcName = "Recorte de colas"; 
397
                if (cstEnhanced == null){
398
                        cstEnhanced = new CheckSliderText();
399
                        cstEnhanced.setName(rcName);
400
                        cstEnhanced.setSliderValue(0);
401
                        cstEnhanced.setSliderRange(0,50);
402
                        cstEnhanced.setDecimal(true);
403
                        cstEnhanced.setTextValue("0.0");
404
                        
405
                }
406
                return cstEnhanced;
407
        }
408

    
409
        
410
        public void setComponentSize(int w,  int h){
411
                wComp = w; hComp = h;
412
                wPanels = (int)Math.round(wComp / 2) - 13; hPanels = hComp - 16;
413
                wBright = wPanels - 22; hBright = hPanels - 73;
414
                wEnhan = wBright; hEnhan = hPanels - 123;
415
                wBCheck = wPanels - 28;
416
                wSlider = wBright - 9; hSlider = 45;
417
                
418
                this.setSize(wComp, hComp);
419
                this.setPreferredSize(new java.awt.Dimension(wComp,hComp));
420
                pBrightCont.setPreferredSize(new java.awt.Dimension(wPanels,hPanels));
421
                pEnhanced.setPreferredSize(new java.awt.Dimension(wPanels,hPanels));
422
                pBCCheck.setPreferredSize(new java.awt.Dimension(wBCheck,25));
423
                pBCSlider.setPreferredSize(new java.awt.Dimension(wBright,hBright));
424
                this.lstBrightness.setComponentSize(wSlider, hSlider);
425
                this.lstContrast.setComponentSize(wSlider, hSlider);
426
                jPanel1.setPreferredSize(new java.awt.Dimension(wSlider,25));
427
                pEnSlider.setPreferredSize(new java.awt.Dimension(wEnhan,hEnhan));
428
                pEnCheck.setPreferredSize(new java.awt.Dimension(wBCheck,25));
429
                this.cstEnhanced.setComponentSize(wSlider, hSlider);
430
                pDelInt.setPreferredSize(new java.awt.Dimension(wSlider + 1,25));
431
                
432
                
433
        }
434
        
435
        
436
        /**
437
         * Habilita o dehabilita el panel de brillo y contraste
438
         * @param active
439
         */
440
        public void setBCControlEnabled(boolean active){
441
                this.lstBrightness.setControlEnabled(active);
442
                this.lstContrast.setControlEnabled(active);
443
                this.getJCheckBox1().setEnabled(active);
444
                this.lpreview.setEnabled(active);
445
        }
446
        
447
        /**
448
         * Habilita o dehabilita el panel de realce
449
         * @param active
450
         */
451
        public void setEControlEnabled(boolean active){
452
                this.jCheckBox.setEnabled(active);
453
                this.lRemove.setEnabled(active);
454
                this.cstEnhanced.setControlEnabled(active);                
455
        }
456
        
457
        /**
458
         * Habilita o deshabilita el todo el panel
459
         * @param active
460
         */
461
        public void setControlEnabled(boolean active){
462
                this.setBCControlEnabled(active);
463
                this.setEControlEnabled(active);
464
                this.cBrightC.setEnabled(active);
465
                this.cEnhanced.setEnabled(active);
466
                this.lBrightC.setEnabled(active);
467
                this.lLineal.setEnabled(active);
468
                this.pBrightCont.setEnabled(active);
469
                this.pEnhanced.setEnabled(active);
470
        }
471
        
472
        public void actionPerformed(ActionEvent e) {
473
                if(e.getSource() == this.getCBrightC()){
474
                        this.setBCControlEnabled(this.getCBrightC().isSelected());
475
                }
476
                if(e.getSource() == cEnhanced){
477
                        this.setEControlEnabled(this.getCEnhanced().isSelected());
478
                }
479
        } 
480
        
481
        /**
482
         * Asigna a este panel un stack manager
483
         * @param p
484
         */
485
        public void setBrightnessContrastStackManager (BrightnessContrastStackManager p){
486
                this.bcManager = p;
487
        }
488
        
489
        
490
        //-------------------------------------------------------------------------------
491

    
492
        public void setStackManager(RasterFilterStackManager stackManager) {
493
                // TODO Auto-generated method stub
494
                
495
        }
496
        
497
        public IStackManager getStackManager() {
498
                // TODO Auto-generated method stub
499
                return bcManager;
500
        }
501

    
502
        
503
        //----------------------------------------------------------------------------------
504
        
505
        
506
        public void removeFile(String file) {
507
                // TODO Auto-generated method stub
508
                
509
        }
510
        
511
        public void addFiles(GeoRasterFile[] files) {
512
                // TODO Auto-generated method stub
513
                
514
        }
515

    
516
        /**
517
         * This method initializes jCheckBox1        
518
         *         
519
         * @return javax.swing.JCheckBox        
520
         */
521
        public JCheckBox getJCheckBox1() {
522
                if (jCheckBox1 == null) {
523
                        jCheckBox1 = new JCheckBox();
524
                        jCheckBox1.setSelected(true);
525
                }
526
                return jCheckBox1;
527
        }
528
        
529
         /**
530
     * Obtiene el nombre del panel
531
     * @return Cadena con el nombre del panel
532
     */
533
    public String getName(){
534
            return this.nom;
535
    }   
536
        
537
}
538