Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / RasterTransparencyPanel.java @ 2669

History | View | Annotate | Download (14.9 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.ui.raster;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Color;
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
30

    
31
import javax.swing.JCheckBox;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.JSlider;
35
import javax.swing.JTextField;
36

    
37

    
38
/**
39
 * Dialogo para asignar la transparencia por pixel y global al raster
40
 * @author Nacho Brodin <brodin_ign@gva.es>
41
 */
42
public class RasterTransparencyPanel extends JPanel {
43
    final private static long serialVersionUID = -3370601314380922368L;
44

    
45
    /**
46
     * Nombre del panel
47
     */
48
    public String nom = "Transparencia";
49
    FilterRasterDialogPanel parent = null;
50

    
51
    /**
52
     * N?mero de bandas del raster
53
     */
54
    public int nBands = 3;
55
    private String[] nameBands = { "Rojo", "Verde", "Azul" };
56
    private JPanel jPanel = null;
57
    private JPanel jPanel1 = null;
58
    private JPanel jPanel2 = null;
59
    private JPanel jPanel3 = null;
60
    private JCheckBox cbTransparencia = null;
61

    
62
    /**
63
     * Label p?blico para traducci?n
64
     */
65
    public JLabel redValue = null;
66
    private JTextFieldExt tRojo = null;
67

    
68
    /**
69
     * Label p?blico para traducci?n
70
     */
71
    public JLabel greenValue = null;
72

    
73
    /**
74
     * Label p?blico para traducci?n
75
     */
76
    public JLabel blueValue = null;
77

    
78
    /**
79
     * Label p?blico para traducci?n
80
     */
81
    public JPanel jPanel4 = null;
82

    
83
    /**
84
     * Label p?blico para traducci?n
85
     */
86
    public JLabel range = null;
87

    
88
    /**
89
     * Label p?blico para traducci?n
90
     */
91
    public JLabel jLabel4 = null;
92
    private JTextFieldExt tVerde = null;
93
    private JTextFieldExt tAzul = null;
94
    private JCheckBox cbOpacidad = null;
95
    private JSlider slOpacidad = null;
96
    private JTextField tOpacidad = null;
97
    private JPanel jPanel5 = null;
98
    private JPanel jPanel6 = null;
99

    
100
    /**
101
     * Constructor. Asigna la variable panel que contiene este
102
     * @param parent FilterRasterDialogPanel
103
     */
104
    public RasterTransparencyPanel(FilterRasterDialogPanel parent) {
105
        this.parent = parent;
106
        initialize();
107
    }
108

    
109
    /**
110
     * This method initializes this
111
     *
112
     * @return void
113
     */
114
    private void initialize() {
115
        this.setLayout(new BorderLayout());
116
        this.setBounds(0, 0, 445, 239);
117
        this.setPreferredSize(new java.awt.Dimension(445, 239));
118
        this.add(getJPanel(), java.awt.BorderLayout.CENTER);
119
        initControls();
120
    }
121

    
122
    /**
123
     * Asigna el n?mero de bandas de la imagen
124
     * @param nBands
125
     */
126
    public void setBands(int nBands) {
127
        this.nBands = nBands;
128
    }
129

    
130
    /**
131
     * Asigna el n?mero de bandas de la imagen
132
     * @param nBands
133
     */
134
    public void setNameBands(String[] nameBands) {
135
        this.nameBands = nameBands;
136
    }
137

    
138
    /**
139
     * Inicializa controles a sus valores por defecto
140
     */
141
    public void initControls() {
142
        this.getOpacityText().setText("100");
143
        this.setActiveOpacityControl(false);
144
        this.setActiveTransparencyControl(false);
145
    }
146

    
147
    /**
148
     * Esta funci?n no est? en uso.
149
     * Oculta los controles de transparencia por bandas en caso de que haya menos de 3 bandas.
150
     *
151
     */
152
    public void updateTextBox() {
153
        if (parent.nbands == 1) {
154
            this.getTRojo().setVisible(true);
155
            this.getTVerde().setVisible(false);
156
            this.getTAzul().setVisible(false);
157
            redValue.setVisible(true);
158
            greenValue.setVisible(false);
159
            blueValue.setVisible(false);
160
        }
161

    
162
        if (parent.nbands == 2) {
163
            this.getTRojo().setVisible(true);
164
            this.getTVerde().setVisible(true);
165
            this.getTAzul().setVisible(false);
166
            redValue.setVisible(true);
167
            greenValue.setVisible(true);
168
            blueValue.setVisible(false);
169
        }
170

    
171
        if (parent.nbands >= 3) {
172
            this.getTRojo().setVisible(true);
173
            this.getTVerde().setVisible(true);
174
            this.getTAzul().setVisible(true);
175
            redValue.setVisible(true);
176
            greenValue.setVisible(true);
177
            blueValue.setVisible(true);
178
        }
179
    }
180

    
181
    /**
182
     * This method initializes jPanel
183
     *
184
     * @return javax.swing.JPanel
185
     */
186
    private JPanel getJPanel() {
187
        if (jPanel == null) {
188
            GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
189
            GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
190
            GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
191
            GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
192
            GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
193
            GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
194
            jPanel = new JPanel();
195
            jPanel.setLayout(new GridBagLayout());
196
            gridBagConstraints5.fill = java.awt.GridBagConstraints.NONE;
197
            gridBagConstraints5.ipady = 0;
198
            gridBagConstraints5.gridheight = 1;
199
            gridBagConstraints5.gridwidth = 0;
200
            gridBagConstraints5.anchor = java.awt.GridBagConstraints.WEST;
201
            gridBagConstraints5.insets = new java.awt.Insets(0, 0, 0, 0);
202
            gridBagConstraints6.gridwidth = 0;
203
            gridBagConstraints6.anchor = java.awt.GridBagConstraints.WEST;
204
            gridBagConstraints7.gridwidth = 1;
205
            gridBagConstraints7.insets = new java.awt.Insets(20, 0, 0, 0);
206
            gridBagConstraints8.gridwidth = 0;
207
            gridBagConstraints8.anchor = java.awt.GridBagConstraints.WEST;
208
            jPanel.setPreferredSize(new java.awt.Dimension(333, 113));
209
            gridBagConstraints9.gridx = 0;
210
            gridBagConstraints9.gridy = 1;
211
            gridBagConstraints9.insets = new java.awt.Insets(0, 180, 0, 0);
212
            gridBagConstraints1.gridx = 0;
213
            gridBagConstraints1.gridy = 2;
214
            gridBagConstraints1.insets = new java.awt.Insets(0, 180, 0, 0);
215
            jPanel.add(getJPanel1(), gridBagConstraints5);
216
            jPanel.add(getJPanel2(), gridBagConstraints6);
217
            jPanel.add(getJPanel3(), gridBagConstraints8);
218
            jPanel.add(getJPanel4(), gridBagConstraints7);
219
            jPanel.add(getJPanel5(), gridBagConstraints9);
220
            jPanel.add(getJPanel6(), gridBagConstraints1);
221
        }
222

    
223
        return jPanel;
224
    }
225

    
226
    /**
227
     * This method initializes jPanel1
228
     *
229
     * @return javax.swing.JPanel
230
     */
231
    private JPanel getJPanel1() {
232
        if (jPanel1 == null) {
233
            redValue = new JLabel();
234
            jPanel1 = new JPanel();
235
            jPanel1.setLayout(new BorderLayout());
236
            redValue.setText("Valor Rojo: ");
237
            jPanel1.setPreferredSize(new java.awt.Dimension(170, 42));
238
            jPanel1.add(getTransparencyCheck(), java.awt.BorderLayout.NORTH);
239
            jPanel1.add(redValue, java.awt.BorderLayout.WEST);
240
            jPanel1.add(getTRojo(), java.awt.BorderLayout.EAST);
241
        }
242

    
243
        return jPanel1;
244
    }
245

    
246
    /**
247
     * This method initializes jPanel2
248
     *
249
     * @return javax.swing.JPanel
250
     */
251
    private JPanel getJPanel2() {
252
        if (jPanel2 == null) {
253
            greenValue = new JLabel();
254
            jPanel2 = new JPanel();
255
            jPanel2.setLayout(new BorderLayout());
256
            greenValue.setText("Valor Verde: ");
257
            jPanel2.setPreferredSize(new java.awt.Dimension(170, 19));
258
            jPanel2.add(greenValue, java.awt.BorderLayout.WEST);
259
            jPanel2.add(getTVerde(), java.awt.BorderLayout.EAST);
260
        }
261

    
262
        return jPanel2;
263
    }
264

    
265
    /**
266
     * This method initializes jPanel3
267
     *
268
     * @return javax.swing.JPanel
269
     */
270
    private JPanel getJPanel3() {
271
        if (jPanel3 == null) {
272
            blueValue = new JLabel();
273
            jPanel3 = new JPanel();
274
            jPanel3.setLayout(new BorderLayout());
275
            blueValue.setText("Valor Azul: ");
276
            jPanel3.setPreferredSize(new java.awt.Dimension(170, 19));
277
            jPanel3.add(blueValue, java.awt.BorderLayout.WEST);
278
            jPanel3.add(getTAzul(), java.awt.BorderLayout.EAST);
279
        }
280

    
281
        return jPanel3;
282
    }
283

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

    
295
        return cbTransparencia;
296
    }
297

    
298
    /**
299
     * This method initializes jTextField
300
     *
301
     * @return javax.swing.JTextField
302
     */
303
    public JTextFieldExt getTRojo() {
304
        if (tRojo == null) {
305
            tRojo = new JTextFieldExt(this.getBackground());
306
            tRojo.setPreferredSize(new java.awt.Dimension(80, 19));
307
        }
308

    
309
        return tRojo;
310
    }
311

    
312
    /**
313
     * This method initializes jTextField1
314
     *
315
     * @return javax.swing.JTextField
316
     */
317
    public JTextFieldExt getTVerde() {
318
        if (tVerde == null) {
319
            tVerde = new JTextFieldExt(this.getBackground());
320
            tVerde.setPreferredSize(new java.awt.Dimension(80, 19));
321
        }
322

    
323
        return tVerde;
324
    }
325

    
326
    /**
327
     * This method initializes jTextField2
328
     *
329
     * @return javax.swing.JTextField
330
     */
331
    public JTextFieldExt getTAzul() {
332
        if (tAzul == null) {
333
            tAzul = new JTextFieldExt(this.getBackground());
334
            tAzul.setPreferredSize(new java.awt.Dimension(80, 19));
335
        }
336

    
337
        return tAzul;
338
    }
339

    
340
    /**
341
     * This method initializes jPanel4
342
     *
343
     * @return javax.swing.JPanel
344
     */
345
    private JPanel getJPanel4() {
346
        if (jPanel4 == null) {
347
            jPanel4 = new JPanel();
348
            jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,
349
                                                                         1));
350
            jPanel4.setPreferredSize(new java.awt.Dimension(415, 35));
351
            jPanel4.add(getOpacityCheck(), null);
352
            jPanel4.add(getOpacitySlider(), null);
353
            jPanel4.add(getOpacityText(), null);
354
        }
355

    
356
        return jPanel4;
357
    }
358

    
359
    /**
360
     * This method initializes jCheckBox1
361
     *
362
     * @return javax.swing.JCheckBox
363
     */
364
    public JCheckBox getOpacityCheck() {
365
        if (cbOpacidad == null) {
366
            cbOpacidad = new JCheckBox();
367
            cbOpacidad.setText("Opacidad");
368
        }
369

    
370
        return cbOpacidad;
371
    }
372

    
373
    /**
374
     * This method initializes jSlider
375
     *
376
     * @return javax.swing.JSlider
377
     */
378
    public JSlider getOpacitySlider() {
379
        if (slOpacidad == null) {
380
            slOpacidad = new JSlider();
381
            slOpacidad.setPreferredSize(new java.awt.Dimension(280, 16));
382
        }
383

    
384
        return slOpacidad;
385
    }
386

    
387
    /**
388
     * This method initializes jTextField3
389
     *
390
     * @return javax.swing.JTextField
391
     */
392
    public JTextField getOpacityText() {
393
        if (tOpacidad == null) {
394
            tOpacidad = new JTextField();
395
            tOpacidad.setPreferredSize(new java.awt.Dimension(30, 19));
396
        }
397

    
398
        return tOpacidad;
399
    }
400

    
401
    /**
402
     * This method initializes jPanel5
403
     *
404
     * @return javax.swing.JPanel
405
     */
406
    private JPanel getJPanel5() {
407
        if (jPanel5 == null) {
408
            range = new JLabel();
409
            jPanel5 = new JPanel();
410
            range.setText("Usa un rango: 1,3,5:8");
411
            jPanel5.setPreferredSize(new java.awt.Dimension(161, 21));
412
            jPanel5.add(range, null);
413
        }
414

    
415
        return jPanel5;
416
    }
417

    
418
    /**
419
     * Activa/Desactiva los controles de opacidad
420
     * @param active
421
     */
422
    public void setActiveOpacityControl(boolean active) {
423
        this.getOpacityCheck().setSelected(active);
424
        this.getOpacitySlider().setEnabled(active);
425
        this.getOpacityText().setEnabled(active);
426
    }
427

    
428
    /**
429
     * Activa/Desactiva los controles de transparencia
430
     * @param active
431
     */
432
    public void setActiveTransparencyControl(boolean active) {
433
        this.getTransparencyCheck().setSelected(active);
434
        this.getTRojo().setEnabled(active);
435

    
436
        if ((active && (parent.nbands >= 2)) || !active) {
437
            this.getTVerde().setEnabled(active);
438
        } else {
439
            this.getTVerde().setEnabled(false);
440
        }
441

    
442
        if ((active && (parent.nbands >= 3)) || !active) {
443
            this.getTAzul().setEnabled(active);
444
        } else {
445
            this.getTAzul().setEnabled(false);
446
        }
447
    }
448

    
449
    /**
450
     * Asigna el valor de opacidad a los controles de la ventana
451
     * para que cuando esta se abra tenga los valores seleccionados en la
452
     * imagen.
453
     * @param alpha
454
     */
455
    public void setOpacity(int alpha) {
456
        int opacityPercent = (int) ((alpha * 100) / 255);
457
        this.getOpacityText().setText(String.valueOf(opacityPercent));
458
        this.getOpacitySlider().setValue(opacityPercent);
459
        this.setActiveOpacityControl(true);
460

    
461
        if (opacityPercent == 100) {
462
            this.setActiveOpacityControl(false);
463
        }
464
    }
465

    
466
    /**
467
     * This method initializes jPanel6
468
     *
469
     * @return javax.swing.JPanel
470
     */
471
    private JPanel getJPanel6() {
472
        if (jPanel6 == null) {
473
            jLabel4 = new JLabel();
474
            jPanel6 = new JPanel();
475
            jPanel6.setPreferredSize(new java.awt.Dimension(161, 20));
476
            jLabel4.setText("Valor de pixel: 0 a 255");
477
            jPanel6.add(jLabel4, null);
478
        }
479

    
480
        return jPanel6;
481
    }
482

    
483
    public class JTextFieldExt extends JTextField {
484
        final private static long serialVersionUID = -3370601314380922368L;
485
        private Color color = null;
486

    
487
        public JTextFieldExt(Color color) {
488
            this.color = color;
489
        }
490

    
491
        public JTextFieldExt() {
492
            super();
493
        }
494

    
495
        public void setEnabled(boolean enabled) {
496
            super.setEnabled(enabled);
497

    
498
            if (!enabled) {
499
                if (color == null) {
500
                    this.setBackground(new Color(210, 210, 210));
501
                } else {
502
                    this.setBackground(color);
503
                }
504
            } else {
505
                this.setBackground(new Color(255, 255, 255));
506
            }
507
        }
508
    }
509
} //  @jve:decl-index=0:visual-constraint="36,15"