Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TransparencyPanel.java @ 10886

History | View | Annotate | Download (7.33 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
package org.gvsig.rastertools.properties.panels;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
24

    
25
import javax.swing.JCheckBox;
26
import javax.swing.JPanel;
27

    
28
import org.gvsig.gui.beans.checkslidertext.CheckSliderTextContainer;
29
import org.gvsig.raster.shared.IRasterProperties;
30
import org.gvsig.rastertools.properties.dialog.IRegistrablePanel;
31

    
32
import com.iver.andami.PluginServices;
33
import com.iver.cit.gvsig.fmap.layers.FLayer;
34

    
35
/**
36
 * Dialogo para asignar la transparencia por pixel y global al raster.
37
 * 
38
 * @author Nacho Brodin (nachobrodin@gmail.com)
39
 */
40
public class TransparencyPanel extends JPanel implements ActionListener, IRegistrablePanel{
41
    final private static long                         serialVersionUID = 0;
42
    private IRasterProperties                        op = null;
43
    /**
44
     * Nombre del panel
45
     */
46
    private String                                                 id = "transparencia";
47
    /**
48
     * N?mero de bandas del raster
49
     */
50
    public int                                                         nBands = 3;
51
    private JCheckBox                                         cbTransparencia = null;
52
    private TransparencySelectionPanel        pTransSelect = null;
53
        private TranspByPixelPanel                         pTranspByPixel = null;
54
        private CheckSliderTextContainer        pOpacity = null;
55
        private TransparencyControl                        tControl = null;
56
                
57
    /**
58
     * Constructor. 
59
     */
60
    public TransparencyPanel() {
61
            id = PluginServices.getText(this, id);
62
            tControl = new TransparencyControl(this);
63
        initialize();
64
    }
65

    
66
    /**
67
     * This method initializes this
68
     *
69
     * @return void
70
     */
71
    private void initialize() {
72
            this.setLayout(new BorderLayout());
73
            this.add(getPTranspByPixel(), BorderLayout.CENTER);
74
            this.add(getOpacityPanel(), BorderLayout.NORTH);
75
            this.add(getSelectionPanel(), BorderLayout.SOUTH);
76
        initControls();
77
    }
78
    
79
    /**
80
     * Asigna el n?mero de bandas de la imagen
81
     * @param nBands
82
     */
83
    public void setBands(int nBands) {
84
        this.nBands = nBands;
85
    }
86

    
87
    /**
88
     * Inicializa controles a sus valores por defecto
89
     */
90
    public void initControls() {
91
        this.setActiveTransparencyControl(false);
92
    }
93

    
94
    /**
95
     * This method initializes jCheckBox
96
     *
97
     * @return javax.swing.JCheckBox
98
     */
99
    public JCheckBox getTransparencyCheck() {
100
        if (cbTransparencia == null) {
101
            cbTransparencia = new JCheckBox();
102
            cbTransparencia.setText("Activar");
103
            cbTransparencia.addActionListener(this);
104
        }
105

    
106
        return cbTransparencia;
107
    }
108

    
109
    /**
110
     * This method initializes TranspOpacitySliderPanel
111
     *
112
     * @return javax.swing.JPanel
113
     */
114
    public CheckSliderTextContainer getOpacityPanel() {
115
        if (pOpacity == null) {
116
                pOpacity = new CheckSliderTextContainer(0, 100, 100, false, PluginServices.getText(this, "activar"), false);
117
                pOpacity.setDecimal(false);
118
                pOpacity.setBorder(PluginServices.getText(this, "opacidad"));
119
        }
120
        
121
        return pOpacity;
122
    }
123

    
124
    /**
125
     * This method initializes TranspOpacitySliderPanel
126
     *
127
     * @return javax.swing.JPanel
128
     */
129
    public TransparencySelectionPanel getSelectionPanel() {
130
        if (pTransSelect == null) 
131
                pTransSelect = new TransparencySelectionPanel();
132
        
133
        return pTransSelect;
134
    }
135
    
136
    /**
137
     * Activa/Desactiva los controles de transparencia
138
     * @param active
139
     */
140
    public void setActiveTransparencyControl(boolean active) {
141
        this.getTransparencyCheck().setSelected(active);
142
        TranspByPixelRGBInputPanel rgbPanel = this.getPTranspByPixel().getPRGBInput();
143
        rgbPanel.getTRed().setEnabled(active);
144
        
145
        if(op != null){
146
                if (op.getBandCount() == 2) {
147
                        rgbPanel.getTGreen().setEnabled(active);
148
                        rgbPanel.getTBlue().setEnabled(false);
149
                }
150
        
151
                if (op.getBandCount() == 3) {
152
                        rgbPanel.getTGreen().setEnabled(active);
153
                        rgbPanel.getTBlue().setEnabled(active);
154
                }
155
        }
156
    }
157

    
158
           /**
159
         * This method initializes jPanel2        
160
         *         
161
         * @return javax.swing.JPanel        
162
         */
163
        public TranspByPixelPanel getPTranspByPixel() {
164
                if (pTranspByPixel == null) 
165
                        pTranspByPixel = new TranspByPixelPanel();
166
                
167
                return pTranspByPixel;
168
        }
169

    
170
        /**
171
         * Ajusta el tama?o de todos los componentes a partir del tama?o
172
         * introducido para el panel.
173
         * @param w
174
         * @param h
175
         */
176
        public void setComponentSize(int w, int h){
177
                                
178
        }
179

    
180
        /**
181
     * Eventos sobre TextField y CheckBox. Controla eventos de checkbox de opacidad, transparencia,
182
     * recorte de colas y los textfield de opacidad, valores de transparencia por banda y
183
     * porcentaje de recorte.
184
     */
185
        public void actionPerformed(ActionEvent e) {
186
                //Evento sobre el checkbox de transparencia
187
            if (e.getSource().equals(getTransparencyCheck())) {
188
                   //Check de opacidad activado -> Activar controles de opacidad
189
                   if (getTransparencyCheck().isSelected()) {
190
                           getPTranspByPixel().setControlEnabled(true);
191
                           getPTranspByPixel().getPRGBInput().setActiveBands(nBands);
192
                   }else
193
                           getPTranspByPixel().setControlEnabled(false);
194
            }
195
        }
196
     
197
        /**
198
         * Obtiene el interfaz de operaciones raster
199
         * @return FLyrRasterSE
200
         */
201
        public IRasterProperties getRasterOperations(){
202
                return op;
203
        }
204
        
205
        /**
206
         * Obtiene la capa si existe esta.
207
         * @return FLayer si existe una capa o null si no existe.
208
         */
209
        public FLayer getLayer(){
210
                if(op instanceof FLayer)
211
                        return (FLayer)op;
212
                return null;
213
        }
214
        
215
   /*
216
    *  (non-Javadoc)
217
    * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
218
    */
219
        public void setLayer(FLayer lyr) {
220
                if(lyr instanceof IRasterProperties){
221
                        op = (IRasterProperties)lyr;
222
                        tControl.setTransparencyObject(op.getRenderTransparency());
223
                }
224
        }
225

    
226
        /*
227
         *  (non-Javadoc)
228
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#accept()
229
         */
230
        public void accept() {
231
                tControl.accept();                        
232
        }
233

    
234
        /*
235
         *  (non-Javadoc)
236
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#apply()
237
         */
238
        public void apply() {
239
                tControl.apply();                
240
        }
241

    
242
        /*
243
         *  (non-Javadoc)
244
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#cancel()
245
         */
246
        public void cancel() {
247
                tControl.cancel();        
248
        }
249

    
250
        /*
251
         *  (non-Javadoc)
252
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
253
         */
254
        public String getID() {
255
                return id;
256
        }
257
    
258
        /*
259
         * (non-Javadoc)
260
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
261
         */
262
        public void selectTab(String id) {
263
        }
264
} //  @jve:decl-index=0:visual-constraint="36,15"