root / import / ext3D / trunk / ext3D / src / com / iver / ai2 / gvsig3d / gui / TransparencyPanel.java @ 15265
History | View | Annotate | Download (9.01 KB)
1 | 15200 | mten | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 14996 | julio | *
|
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 | 15200 | mten | * Av. Blasco Ib??ez, 50
|
24 | 14996 | julio | * 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 | 15265 | julio | import java.awt.GridBagConstraints; |
45 | import java.awt.GridBagLayout; |
||
46 | 14996 | julio | import java.awt.Insets; |
47 | import java.awt.event.ActionListener; |
||
48 | 15152 | julio | import java.util.Dictionary; |
49 | import java.util.Hashtable; |
||
50 | 14996 | julio | |
51 | import javax.swing.BorderFactory; |
||
52 | import javax.swing.JLabel; |
||
53 | 15265 | julio | import javax.swing.JPanel; |
54 | 14996 | julio | 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 | 15200 | mten | * @author Fernando Gonz?lez Cort?s
|
74 | 14996 | julio | */
|
75 | public class TransparencyPanel extends GridBagLayoutPanel implements |
||
76 | SingletonWindow, ChangeListener {
|
||
77 | |||
78 | private ProjectView3D view3D;
|
||
79 | |||
80 | 15265 | julio | private int width = 250; |
81 | 14996 | julio | |
82 | 15265 | julio | private int height = 100; |
83 | 14996 | julio | |
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 | 15139 | julio | |
96 | 15195 | julio | private SliderUpdate runnable;
|
97 | 14996 | julio | |
98 | 15195 | julio | private FLayer lyr3D;
|
99 | 14997 | julio | |
100 | 14996 | julio | /**
|
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 | 15195 | julio | |
110 | 14996 | julio | view3D = (ProjectView3D) v; |
111 | |||
112 | 15195 | julio | // UpdateOrder();
|
113 | // cogemos la capa q esta seleccionada
|
||
114 | |||
115 | 14996 | julio | MapContext mapa = view3D.getMapContext(); |
116 | |||
117 | // Getting all selected Extent
|
||
118 | FLayer[] selectedExtent = mapa.getLayers().getActives();
|
||
119 | |||
120 | 15021 | julio | if (selectedExtent.length == 1 && selectedExtent[0].isAvailable()) { |
121 | 14996 | julio | |
122 | 15195 | julio | lyr3D = (FLayer) selectedExtent[0];
|
123 | 15139 | julio | layer3DProps = Layer3DProps.getLayer3DProps(lyr3D); |
124 | |||
125 | 14996 | julio | order = layer3DProps.getOrder(); |
126 | 15195 | julio | opacity = layer3DProps.getOpacity(); |
127 | 14996 | julio | |
128 | } |
||
129 | initialize(); |
||
130 | 15195 | julio | |
131 | 14996 | julio | } |
132 | 15195 | julio | |
133 | private void UpdateOrder() { |
||
134 | |||
135 | // cogemos la capa q esta seleccionada
|
||
136 | |||
137 | 15187 | julio | MapContext mapa = view3D.getMapContext(); |
138 | 14996 | julio | |
139 | 15187 | julio | // Getting all selected Extent
|
140 | FLayer[] selectedExtent = mapa.getLayers().getActives();
|
||
141 | 15195 | julio | FLayer lyr3DAux = null;
|
142 | 15187 | julio | |
143 | if (selectedExtent.length == 1 && selectedExtent[0].isAvailable()) { |
||
144 | |||
145 | 15195 | julio | 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 | 15187 | julio | } |
156 | |||
157 | } |
||
158 | |||
159 | 14996 | julio | /**
|
160 | * This method initializes this
|
||
161 | */
|
||
162 | private void initialize() { |
||
163 | 15265 | julio | |
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 | 14996 | julio | // Inicialize component
|
186 | 15099 | julio | setName(PluginServices.getText(this, "Transparency")); |
187 | 14996 | julio | // Introducing the margin
|
188 | 15265 | julio | // setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
|
189 | 14996 | julio | // Dimension of the panel
|
190 | // setSize(new Dimension(width, height));
|
||
191 | this.setPreferredSize(new Dimension(width, height)); |
||
192 | 15265 | julio | this.setSize(new Dimension(width, height)); |
193 | 14996 | julio | |
194 | // ADDING COMPONENTS
|
||
195 | |||
196 | 15265 | julio | // this.addComponent(getSliderTrans(), new Insets(2, 5, 2, 5));
|
197 | //
|
||
198 | // // Accept buton
|
||
199 | // this.addComponent(getOkCancelPanel(), new Insets(2, 5, 2, 5));
|
||
200 | 14996 | julio | |
201 | 15195 | julio | // Launching slider update
|
202 | // Create the object with the run() method
|
||
203 | runnable = new SliderUpdate();
|
||
204 | 14996 | julio | |
205 | 15195 | julio | // Create the thread supplying it with the runnable object
|
206 | Thread thread = new Thread(runnable); |
||
207 | 14997 | julio | |
208 | 15195 | julio | // Start the thread
|
209 | thread.start(); |
||
210 | |||
211 | 14997 | julio | } |
212 | |||
213 | 14996 | julio | private javax.swing.JSlider getSliderTrans() {
|
214 | if (sliderTrans == null) { |
||
215 | sliderTrans = new JSlider(JSlider.HORIZONTAL, 0, 255, |
||
216 | (int) opacity * 255); |
||
217 | 15152 | julio | // Create the label table
|
218 | Dictionary labelTable = new Hashtable(); |
||
219 | labelTable.put(new Integer(50), new JLabel("Transparente")); |
||
220 | 15265 | julio | labelTable.put(new Integer(215), new JLabel("Opaco")); |
221 | 15152 | julio | // Adding table to slider
|
222 | sliderTrans.setLabelTable(labelTable); |
||
223 | // Activate the lables
|
||
224 | sliderTrans.setPaintLabels(true);
|
||
225 | // Add Change linstener
|
||
226 | 14996 | julio | 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 | 15195 | julio | // this.UpdateOrder();
|
236 | 14996 | julio | JSlider source = (JSlider) e.getSource(); |
237 | 14997 | julio | int trans = (int) source.getValue(); |
238 | 15195 | julio | // 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 | 15199 | rgaitan | view3D.getPlanet().setTextureOpacityLayer(order, opacity); |
247 | 15195 | julio | // Repainting canvas
|
248 | view3D.getCanvas3d().repaint(); |
||
249 | |||
250 | 15152 | julio | this.repaint();
|
251 | 14996 | julio | } |
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 | 15187 | julio | UpdateOrder(); |
259 | 14996 | julio | // Alpha value
|
260 | 15152 | julio | float a = opacity;
|
261 | 14996 | julio | // Setting opaciti in layer properties
|
262 | layer3DProps.setOpacity(a); |
||
263 | // Notify the opacity to planet
|
||
264 | 15199 | rgaitan | view3D.getPlanet().setTextureOpacityLayer(order, a); |
265 | 14996 | julio | // Repainting canvas
|
266 | view3D.getCanvas3d().repaint(); |
||
267 | 15195 | julio | // Stop thread
|
268 | runnable.end(); |
||
269 | 14996 | julio | PluginServices.getMDIManager().closeWindow( |
270 | TransparencyPanel.this); |
||
271 | } |
||
272 | }; |
||
273 | okCancelPanel = new GridBagLayoutPanel();
|
||
274 | okCancelPanel.setAlignmentX(GridBagLayoutPanel.RIGHT_ALIGNMENT); |
||
275 | okButton = new JButton(); |
||
276 | 15195 | julio | okButton.setLabel(PluginServices.getText(this, "Close")); |
277 | 14996 | julio | okButton.addActionListener(okAction); |
278 | |||
279 | 15195 | julio | okCancelPanel.addComponent(okButton); |
280 | 14996 | julio | } |
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 | 15099 | julio | m_viewinfo.setTitle(PluginServices.getText(this, "Transparency")); |
292 | 14996 | julio | m_viewinfo.setHeight(height); |
293 | m_viewinfo.setWidth(width); |
||
294 | return m_viewinfo;
|
||
295 | } |
||
296 | |||
297 | 15195 | julio | 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 | } |