Revision 12154 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/properties/panels/TransparencyPanel.java
TransparencyPanel.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
import com.iver.andami.PluginServices; |
35 | 35 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
36 |
|
|
37 | 36 |
/** |
38 | 37 |
* Dialogo para asignar la transparencia por pixel y global al raster. |
39 | 38 |
* |
40 | 39 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
41 | 40 |
*/ |
42 |
public class TransparencyPanel extends JPanel implements ActionListener, IRegistrablePanel, ChangeListener{ |
|
43 |
final private static long serialVersionUID = 0; |
|
44 |
private IRasterProperties op = null; |
|
45 |
/** |
|
46 |
* Nombre del panel |
|
47 |
*/ |
|
48 |
private String id = "transparencia"; |
|
49 |
/** |
|
50 |
* N?mero de bandas del raster |
|
51 |
*/ |
|
52 |
public int nBands = 3; |
|
53 |
private JCheckBox cbTransparencia = null; |
|
54 |
private TransparencySelectionPanel pTransSelect = null; |
|
55 |
private TranspByPixelPanel pTranspByPixel = null; |
|
56 |
private CheckSliderTextContainer pOpacity = null; |
|
57 |
private TransparencyControl tControl = null; |
|
41 |
public class TransparencyPanel extends JPanel implements ActionListener, IRegistrablePanel, ChangeListener { |
|
42 |
private static final long serialVersionUID = -4556920949255458471L; |
|
43 |
private IRasterProperties op = null; |
|
58 | 44 |
|
59 |
/** |
|
60 |
* Constructor. |
|
61 |
*/ |
|
62 |
public TransparencyPanel() { |
|
63 |
id = PluginServices.getText(this, id); |
|
64 |
tControl = new TransparencyControl(this); |
|
65 |
initialize(); |
|
66 |
} |
|
45 |
/** |
|
46 |
* Nombre del panel |
|
47 |
*/ |
|
48 |
private String id = "transparencia"; |
|
67 | 49 |
|
68 |
/** |
|
69 |
* This method initializes this |
|
70 |
* |
|
71 |
* @return void |
|
72 |
*/ |
|
73 |
private void initialize() { |
|
74 |
this.setLayout(new BorderLayout()); |
|
75 |
this.add(getPTranspByPixel(), BorderLayout.CENTER); |
|
76 |
this.add(getOpacityPanel(), BorderLayout.NORTH); |
|
77 |
this.add(getSelectionPanel(), BorderLayout.SOUTH); |
|
78 |
initControls(); |
|
79 |
} |
|
50 |
/** |
|
51 |
* N?mero de bandas del raster |
|
52 |
*/ |
|
53 |
public int nBands = 3; |
|
54 |
private JCheckBox cbTransparencia = null; |
|
55 |
private TransparencySelectionPanel pTransSelect = null; |
|
56 |
private TranspByPixelPanel pTranspByPixel = null; |
|
57 |
private CheckSliderTextContainer pOpacity = null; |
|
58 |
private TransparencyControl tControl = null; |
|
80 | 59 |
|
81 |
/** |
|
82 |
* Asigna el n?mero de bandas de la imagen |
|
83 |
* @param nBands |
|
84 |
*/ |
|
85 |
public void setBands(int nBands) { |
|
86 |
this.nBands = nBands; |
|
87 |
} |
|
60 |
/** |
|
61 |
* Constructor. |
|
62 |
*/ |
|
63 |
public TransparencyPanel() { |
|
64 |
id = PluginServices.getText(this, id); |
|
65 |
tControl = new TransparencyControl(this); |
|
66 |
initialize(); |
|
67 |
} |
|
88 | 68 |
|
89 |
/** |
|
90 |
* Inicializa controles a sus valores por defecto |
|
91 |
*/ |
|
92 |
public void initControls() { |
|
93 |
this.setActiveTransparencyControl(false); |
|
94 |
} |
|
69 |
/** |
|
70 |
* This method initializes this |
|
71 |
* @return void |
|
72 |
*/ |
|
73 |
private void initialize() { |
|
74 |
this.setLayout(new BorderLayout()); |
|
75 |
this.add(getPTranspByPixel(), BorderLayout.CENTER); |
|
76 |
this.add(getOpacityPanel(), BorderLayout.NORTH); |
|
77 |
//this.add(getSelectionPanel(), BorderLayout.SOUTH); |
|
78 |
initControls(); |
|
79 |
} |
|
95 | 80 |
|
96 |
/** |
|
97 |
* This method initializes jCheckBox |
|
98 |
* |
|
99 |
* @return javax.swing.JCheckBox |
|
100 |
*/ |
|
101 |
public JCheckBox getTransparencyCheck() { |
|
102 |
if (cbTransparencia == null) { |
|
103 |
cbTransparencia = new JCheckBox(); |
|
104 |
cbTransparencia.setText("Activar"); |
|
105 |
cbTransparencia.addActionListener(this); |
|
106 |
} |
|
81 |
/** |
|
82 |
* Asigna el n?mero de bandas de la imagen |
|
83 |
* @param nBands |
|
84 |
*/ |
|
85 |
public void setBands(int nBands) { |
|
86 |
this.nBands = nBands; |
|
87 |
} |
|
107 | 88 |
|
108 |
return cbTransparencia; |
|
89 |
/** |
|
90 |
* Inicializa controles a sus valores por defecto |
|
91 |
*/ |
|
92 |
public void initControls() { |
|
93 |
this.setActiveTransparencyControl(false); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* This method initializes jCheckBox |
|
98 |
* @return javax.swing.JCheckBox |
|
99 |
*/ |
|
100 |
public JCheckBox getTransparencyCheck() { |
|
101 |
if (cbTransparencia == null) { |
|
102 |
cbTransparencia = new JCheckBox(); |
|
103 |
cbTransparencia.setText("Activar"); |
|
104 |
cbTransparencia.addActionListener(this); |
|
109 | 105 |
} |
110 | 106 |
|
111 |
/** |
|
112 |
* This method initializes TranspOpacitySliderPanel |
|
113 |
* |
|
114 |
* @return javax.swing.JPanel |
|
115 |
*/ |
|
116 |
public CheckSliderTextContainer getOpacityPanel() { |
|
117 |
if (pOpacity == null) { |
|
118 |
pOpacity = new CheckSliderTextContainer(0, 100, 100, false, PluginServices.getText(this, "activar"), false); |
|
119 |
pOpacity.setDecimal(false); |
|
120 |
pOpacity.setBorder(PluginServices.getText(this, "opacidad")); |
|
121 |
pOpacity.addChangeListener(this); |
|
122 |
} |
|
107 |
return cbTransparencia; |
|
108 |
} |
|
123 | 109 |
|
124 |
return pOpacity; |
|
110 |
/** |
|
111 |
* This method initializes TranspOpacitySliderPanel |
|
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 |
pOpacity.addChangeListener(this); |
|
125 | 120 |
} |
126 | 121 |
|
127 |
/** |
|
128 |
* This method initializes TranspOpacitySliderPanel |
|
129 |
* |
|
130 |
* @return javax.swing.JPanel |
|
131 |
*/ |
|
132 |
public TransparencySelectionPanel getSelectionPanel() { |
|
133 |
if (pTransSelect == null) |
|
134 |
pTransSelect = new TransparencySelectionPanel(); |
|
122 |
return pOpacity; |
|
123 |
} |
|
135 | 124 |
|
136 |
return pTransSelect; |
|
137 |
} |
|
125 |
/** |
|
126 |
* This method initializes TranspOpacitySliderPanel |
|
127 |
* @return javax.swing.JPanel |
|
128 |
*/ |
|
129 |
public TransparencySelectionPanel getSelectionPanel() { |
|
130 |
if (pTransSelect == null) |
|
131 |
pTransSelect = new TransparencySelectionPanel(); |
|
138 | 132 |
|
139 |
/** |
|
140 |
* Activa/Desactiva los controles de transparencia |
|
141 |
* @param active |
|
142 |
*/ |
|
143 |
public void setActiveTransparencyControl(boolean active) { |
|
144 |
this.getTransparencyCheck().setSelected(active); |
|
145 |
TranspByPixelRGBInputPanel rgbPanel = this.getPTranspByPixel().getPRGBInput(); |
|
146 |
rgbPanel.getTRed().setEnabled(active); |
|
133 |
return pTransSelect; |
|
134 |
} |
|
147 | 135 |
|
148 |
if(op != null){ |
|
149 |
if (op.getBandCount() == 2) { |
|
150 |
rgbPanel.getTGreen().setEnabled(active); |
|
151 |
rgbPanel.getTBlue().setEnabled(false); |
|
152 |
} |
|
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); |
|
153 | 144 |
|
154 |
if (op.getBandCount() == 3) { |
|
155 |
rgbPanel.getTGreen().setEnabled(active); |
|
156 |
rgbPanel.getTBlue().setEnabled(active); |
|
157 |
} |
|
158 |
} |
|
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 |
} |
|
159 | 155 |
} |
156 |
} |
|
160 | 157 |
|
161 |
/** |
|
162 |
* This method initializes jPanel2 |
|
163 |
* |
|
164 |
* @return javax.swing.JPanel |
|
158 |
/** |
|
159 |
* This method initializes jPanel2 |
|
160 |
* @return javax.swing.JPanel |
|
165 | 161 |
*/ |
166 | 162 |
public TranspByPixelPanel getPTranspByPixel() { |
167 | 163 |
if (pTranspByPixel == null) |
... | ... | |
171 | 167 |
} |
172 | 168 |
|
173 | 169 |
/** |
174 |
* Ajusta el tama?o de todos los componentes a partir del tama?o |
|
175 |
* introducido para el panel. |
|
176 |
* @param w |
|
177 |
* @param h |
|
170 |
* Eventos sobre TextField y CheckBox. Controla eventos de checkbox de |
|
171 |
* opacidad, transparencia, recorte de colas y los textfield de opacidad, |
|
172 |
* valores de transparencia por banda y porcentaje de recorte. |
|
178 | 173 |
*/ |
179 |
public void setComponentSize(int w, int h){ |
|
180 |
|
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* Eventos sobre TextField y CheckBox. Controla eventos de checkbox de opacidad, transparencia, |
|
185 |
* recorte de colas y los textfield de opacidad, valores de transparencia por banda y |
|
186 |
* porcentaje de recorte. |
|
187 |
*/ |
|
188 | 174 |
public void actionPerformed(ActionEvent e) { |
189 |
//Evento sobre el checkbox de transparencia |
|
190 |
if (e.getSource().equals(getTransparencyCheck())) {
|
|
191 |
//Check de opacidad activado -> Activar controles de opacidad
|
|
192 |
if (getTransparencyCheck().isSelected()) {
|
|
193 |
getPTranspByPixel().setControlEnabled(true);
|
|
194 |
getPTranspByPixel().getPRGBInput().setActiveBands(nBands);
|
|
195 |
}else
|
|
196 |
getPTranspByPixel().setControlEnabled(false);
|
|
197 |
}
|
|
175 |
// Evento sobre el checkbox de transparencia
|
|
176 |
if (e.getSource().equals(getTransparencyCheck())) { |
|
177 |
// Check de opacidad activado -> Activar controles de opacidad
|
|
178 |
if (getTransparencyCheck().isSelected()) { |
|
179 |
getPTranspByPixel().setControlEnabled(true); |
|
180 |
getPTranspByPixel().getPRGBInput().setActiveBands(nBands); |
|
181 |
} else
|
|
182 |
getPTranspByPixel().setControlEnabled(false); |
|
183 |
} |
|
198 | 184 |
} |
199 | 185 |
|
200 | 186 |
/** |
201 | 187 |
* Obtiene el interfaz de operaciones raster |
202 | 188 |
* @return FLyrRasterSE |
203 | 189 |
*/ |
204 |
public IRasterProperties getRasterOperations(){ |
|
190 |
public IRasterProperties getRasterOperations() {
|
|
205 | 191 |
return op; |
206 | 192 |
} |
207 | 193 |
|
... | ... | |
209 | 195 |
* Obtiene la capa si existe esta. |
210 | 196 |
* @return FLayer si existe una capa o null si no existe. |
211 | 197 |
*/ |
212 |
public FLayer getLayer(){ |
|
213 |
if(op instanceof FLayer) |
|
214 |
return (FLayer)op; |
|
198 |
public FLayer getLayer() {
|
|
199 |
if (op instanceof FLayer)
|
|
200 |
return (FLayer) op;
|
|
215 | 201 |
return null; |
216 | 202 |
} |
217 | 203 |
|
218 |
/*
|
|
219 |
* (non-Javadoc)
|
|
220 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
|
221 |
*/
|
|
204 |
/* |
|
205 |
* (non-Javadoc)
|
|
206 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
|
207 |
*/
|
|
222 | 208 |
public void setLayer(FLayer lyr) { |
223 |
if(lyr instanceof IRasterProperties){
|
|
224 |
op = (IRasterProperties)lyr; |
|
209 |
if (lyr instanceof IRasterProperties) {
|
|
210 |
op = (IRasterProperties) lyr;
|
|
225 | 211 |
tControl.setTransparencyObject(op.getRenderTransparency()); |
226 | 212 |
} |
227 | 213 |
} |
... | ... | |
260 | 246 |
|
261 | 247 |
/* |
262 | 248 |
* (non-Javadoc) |
263 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
|
|
249 |
* @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
|
|
264 | 250 |
*/ |
265 |
public void selectTab(String id) { |
|
266 |
} |
|
267 |
|
|
268 | 251 |
public void stateChanged(ChangeEvent e) { |
269 |
apply();
|
|
252 |
tControl.onlyApply();
|
|
270 | 253 |
} |
254 |
|
|
255 |
/* |
|
256 |
* (non-Javadoc) |
|
257 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String) |
|
258 |
*/ |
|
259 |
public void selectTab(String id) {} |
|
260 |
|
|
261 |
/* |
|
262 |
* (non-Javadoc) |
|
263 |
* @see org.gvsig.rastertools.properties.dialog.IResizable#setComponentSize(int, int) |
|
264 |
*/ |
|
265 |
public void setComponentSize(int w, int h) {} |
|
271 | 266 |
} |
Also available in: Unified diff