root / import / ext3D / trunk / ext3D / src / com / iver / ai2 / gvsig3d / gui / TransparencyPanel.java @ 15265
History | View | Annotate | Download (9.01 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.ai2.gvsig3d.gui; |
42 |
|
43 |
import java.awt.Dimension; |
44 |
import java.awt.GridBagConstraints; |
45 |
import java.awt.GridBagLayout; |
46 |
import java.awt.Insets; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.util.Dictionary; |
49 |
import java.util.Hashtable; |
50 |
|
51 |
import javax.swing.BorderFactory; |
52 |
import javax.swing.JLabel; |
53 |
import javax.swing.JPanel; |
54 |
import javax.swing.JSlider; |
55 |
import javax.swing.event.ChangeEvent; |
56 |
import javax.swing.event.ChangeListener; |
57 |
|
58 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
59 |
import org.gvsig.gui.beans.swing.JButton; |
60 |
|
61 |
import com.iver.ai2.gvsig3d.ProjectView3D; |
62 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
63 |
import com.iver.andami.PluginServices; |
64 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
65 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
66 |
import com.iver.cit.gvsig.fmap.MapContext; |
67 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
68 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
69 |
|
70 |
/**
|
71 |
* Dialogo donde se muestran las propiedades de una vista
|
72 |
*
|
73 |
* @author Fernando Gonz?lez Cort?s
|
74 |
*/
|
75 |
public class TransparencyPanel extends GridBagLayoutPanel implements |
76 |
SingletonWindow, ChangeListener {
|
77 |
|
78 |
private ProjectView3D view3D;
|
79 |
|
80 |
private int width = 250; |
81 |
|
82 |
private int height = 100; |
83 |
|
84 |
private GridBagLayoutPanel okCancelPanel;
|
85 |
|
86 |
private JButton okButton; |
87 |
|
88 |
private JSlider sliderTrans; |
89 |
|
90 |
private int order; |
91 |
|
92 |
private Layer3DProps layer3DProps;
|
93 |
|
94 |
private float opacity; |
95 |
|
96 |
private SliderUpdate runnable;
|
97 |
|
98 |
private FLayer lyr3D;
|
99 |
|
100 |
/**
|
101 |
* This is the default constructor
|
102 |
*
|
103 |
* @param f
|
104 |
* Frame padre del dialogo
|
105 |
* @param v
|
106 |
* Vista que se representa
|
107 |
*/
|
108 |
public TransparencyPanel(IProjectView v) {
|
109 |
|
110 |
view3D = (ProjectView3D) v; |
111 |
|
112 |
// UpdateOrder();
|
113 |
// cogemos la capa q esta seleccionada
|
114 |
|
115 |
MapContext mapa = view3D.getMapContext(); |
116 |
|
117 |
// Getting all selected Extent
|
118 |
FLayer[] selectedExtent = mapa.getLayers().getActives();
|
119 |
|
120 |
if (selectedExtent.length == 1 && selectedExtent[0].isAvailable()) { |
121 |
|
122 |
lyr3D = (FLayer) selectedExtent[0];
|
123 |
layer3DProps = Layer3DProps.getLayer3DProps(lyr3D); |
124 |
|
125 |
order = layer3DProps.getOrder(); |
126 |
opacity = layer3DProps.getOpacity(); |
127 |
|
128 |
} |
129 |
initialize(); |
130 |
|
131 |
} |
132 |
|
133 |
private void UpdateOrder() { |
134 |
|
135 |
// cogemos la capa q esta seleccionada
|
136 |
|
137 |
MapContext mapa = view3D.getMapContext(); |
138 |
|
139 |
// Getting all selected Extent
|
140 |
FLayer[] selectedExtent = mapa.getLayers().getActives();
|
141 |
FLayer lyr3DAux = null;
|
142 |
|
143 |
if (selectedExtent.length == 1 && selectedExtent[0].isAvailable()) { |
144 |
|
145 |
lyr3DAux = (FLayer) selectedExtent[0];
|
146 |
if (!(lyr3DAux.getName().equals(lyr3D.getName()))){
|
147 |
lyr3D = lyr3DAux; |
148 |
layer3DProps = Layer3DProps.getLayer3DProps(lyr3D); |
149 |
|
150 |
order = layer3DProps.getOrder(); |
151 |
opacity = layer3DProps.getOpacity(); |
152 |
// sliderTrans.setValue((int) opacity * 255);
|
153 |
|
154 |
} |
155 |
} |
156 |
|
157 |
} |
158 |
|
159 |
/**
|
160 |
* This method initializes this
|
161 |
*/
|
162 |
private void initialize() { |
163 |
|
164 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
165 |
gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
|
166 |
gridBagConstraints1.gridy = 2;
|
167 |
gridBagConstraints1.weightx = 1.0;
|
168 |
gridBagConstraints1.gridx = 1;
|
169 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
170 |
gridBagConstraints.gridx = 1;
|
171 |
gridBagConstraints.gridheight = 2;
|
172 |
gridBagConstraints.gridwidth = 2;
|
173 |
gridBagConstraints.insets = new Insets(15, 0, 0, 0); |
174 |
gridBagConstraints.gridy = 3;
|
175 |
|
176 |
this.add(getSliderTrans(),gridBagConstraints1);
|
177 |
this.add(getOkCancelPanel(),gridBagConstraints);
|
178 |
// jContentPane = new JPanel();
|
179 |
// jContentPane.setLayout(new GridBagLayout());
|
180 |
// jContentPane.add(getJButton(), gridBagConstraints);
|
181 |
// jContentPane.add(getJSlider(), gridBagConstraints1);
|
182 |
|
183 |
|
184 |
|
185 |
// Inicialize component
|
186 |
setName(PluginServices.getText(this, "Transparency")); |
187 |
// Introducing the margin
|
188 |
// setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
|
189 |
// Dimension of the panel
|
190 |
// setSize(new Dimension(width, height));
|
191 |
this.setPreferredSize(new Dimension(width, height)); |
192 |
this.setSize(new Dimension(width, height)); |
193 |
|
194 |
// ADDING COMPONENTS
|
195 |
|
196 |
// this.addComponent(getSliderTrans(), new Insets(2, 5, 2, 5));
|
197 |
//
|
198 |
// // Accept buton
|
199 |
// this.addComponent(getOkCancelPanel(), new Insets(2, 5, 2, 5));
|
200 |
|
201 |
// Launching slider update
|
202 |
// Create the object with the run() method
|
203 |
runnable = new SliderUpdate();
|
204 |
|
205 |
// Create the thread supplying it with the runnable object
|
206 |
Thread thread = new Thread(runnable); |
207 |
|
208 |
// Start the thread
|
209 |
thread.start(); |
210 |
|
211 |
} |
212 |
|
213 |
private javax.swing.JSlider getSliderTrans() {
|
214 |
if (sliderTrans == null) { |
215 |
sliderTrans = new JSlider(JSlider.HORIZONTAL, 0, 255, |
216 |
(int) opacity * 255); |
217 |
// Create the label table
|
218 |
Dictionary labelTable = new Hashtable(); |
219 |
labelTable.put(new Integer(50), new JLabel("Transparente")); |
220 |
labelTable.put(new Integer(215), new JLabel("Opaco")); |
221 |
// Adding table to slider
|
222 |
sliderTrans.setLabelTable(labelTable); |
223 |
// Activate the lables
|
224 |
sliderTrans.setPaintLabels(true);
|
225 |
// Add Change linstener
|
226 |
sliderTrans.addChangeListener(this);
|
227 |
|
228 |
} |
229 |
int a = (int) (opacity * 255); |
230 |
sliderTrans.setValue(a); |
231 |
return sliderTrans;
|
232 |
} |
233 |
|
234 |
public void stateChanged(ChangeEvent e) { |
235 |
// this.UpdateOrder();
|
236 |
JSlider source = (JSlider) e.getSource(); |
237 |
int trans = (int) source.getValue(); |
238 |
// System.out.println("valor de la transparencia capturada " + trans);
|
239 |
UpdateOrder(); |
240 |
// System.out.println("Activado refresco automatico");
|
241 |
// Alpha value
|
242 |
opacity = (float) trans / 255f; |
243 |
// Setting opaciti in layer properties
|
244 |
layer3DProps.setOpacity(opacity); |
245 |
// Notify the opacity to planet
|
246 |
view3D.getPlanet().setTextureOpacityLayer(order, opacity); |
247 |
// Repainting canvas
|
248 |
view3D.getCanvas3d().repaint(); |
249 |
|
250 |
this.repaint();
|
251 |
} |
252 |
|
253 |
private GridBagLayoutPanel getOkCancelPanel() {
|
254 |
if (okCancelPanel == null) { |
255 |
ActionListener okAction, cancelAction, applyAction;
|
256 |
okAction = new java.awt.event.ActionListener() {
|
257 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
258 |
UpdateOrder(); |
259 |
// Alpha value
|
260 |
float a = opacity;
|
261 |
// Setting opaciti in layer properties
|
262 |
layer3DProps.setOpacity(a); |
263 |
// Notify the opacity to planet
|
264 |
view3D.getPlanet().setTextureOpacityLayer(order, a); |
265 |
// Repainting canvas
|
266 |
view3D.getCanvas3d().repaint(); |
267 |
// Stop thread
|
268 |
runnable.end(); |
269 |
PluginServices.getMDIManager().closeWindow( |
270 |
TransparencyPanel.this); |
271 |
} |
272 |
}; |
273 |
okCancelPanel = new GridBagLayoutPanel();
|
274 |
okCancelPanel.setAlignmentX(GridBagLayoutPanel.RIGHT_ALIGNMENT); |
275 |
okButton = new JButton(); |
276 |
okButton.setLabel(PluginServices.getText(this, "Close")); |
277 |
okButton.addActionListener(okAction); |
278 |
|
279 |
okCancelPanel.addComponent(okButton); |
280 |
} |
281 |
return okCancelPanel;
|
282 |
} |
283 |
|
284 |
public Object getWindowModel() { |
285 |
// TODO Auto-generated method stub
|
286 |
return view3D;
|
287 |
} |
288 |
|
289 |
public WindowInfo getWindowInfo() {
|
290 |
WindowInfo m_viewinfo = new WindowInfo();
|
291 |
m_viewinfo.setTitle(PluginServices.getText(this, "Transparency")); |
292 |
m_viewinfo.setHeight(height); |
293 |
m_viewinfo.setWidth(width); |
294 |
return m_viewinfo;
|
295 |
} |
296 |
|
297 |
public class SliderUpdate implements Runnable { |
298 |
|
299 |
private boolean finish = false; |
300 |
|
301 |
ProjectView3D view; |
302 |
|
303 |
JSlider slider;
|
304 |
|
305 |
public SliderUpdate() {
|
306 |
} |
307 |
|
308 |
// This method is called when the thread runs
|
309 |
public void run() { |
310 |
while (true) { |
311 |
try {
|
312 |
Thread.sleep(500); |
313 |
synchronized (this) { |
314 |
if (finish) {
|
315 |
break;
|
316 |
} |
317 |
} |
318 |
} catch (InterruptedException e) { |
319 |
|
320 |
e.printStackTrace(); |
321 |
} |
322 |
// aki codigo de comprobacion
|
323 |
UpdateOrder(); |
324 |
sliderTrans.setValue((int)(opacity * 255)); |
325 |
sliderTrans.repaint(); |
326 |
} |
327 |
} |
328 |
|
329 |
public synchronized void end() { |
330 |
finish = true;
|
331 |
} |
332 |
|
333 |
} |
334 |
|
335 |
} |