Revision 22039
trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/camera/ProjectCamera.java | ||
---|---|---|
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 org.gvsig.gvsig3d.camera; |
|
42 |
|
|
43 |
import org.gvsig.osgvp.Vec3; |
|
44 |
import org.gvsig.osgvp.viewer.Camera; |
|
45 |
|
|
46 |
import com.iver.utiles.IPersistence; |
|
47 |
import com.iver.utiles.XMLEntity; |
|
48 |
|
|
49 |
/** |
|
50 |
* DOCUMENT ME! |
|
51 |
* |
|
52 |
* @author |
|
53 |
*/ |
|
54 |
public class ProjectCamera implements IPersistence { |
|
55 |
// private Object camera; |
|
56 |
|
|
57 |
private Camera camera; |
|
58 |
|
|
59 |
private String description; |
|
60 |
|
|
61 |
/** |
|
62 |
* DOCUMENT ME! |
|
63 |
* |
|
64 |
* @return |
|
65 |
*/ |
|
66 |
public String getDescription() { |
|
67 |
return description; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* DOCUMENT ME! |
|
72 |
* |
|
73 |
* @param string |
|
74 |
*/ |
|
75 |
public void setDescription(String string) { |
|
76 |
description = string; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* @see java.lang.Object#toString() |
|
81 |
*/ |
|
82 |
public String toString() { |
|
83 |
return description; |
|
84 |
} |
|
85 |
|
|
86 |
public Camera getCamera() { |
|
87 |
return camera; |
|
88 |
} |
|
89 |
|
|
90 |
public void setCamera(Camera camera) { |
|
91 |
this.camera = camera; |
|
92 |
} |
|
93 |
|
|
94 |
public String getClassName() { |
|
95 |
return this.getClass().getName(); |
|
96 |
} |
|
97 |
|
|
98 |
public XMLEntity getXMLEntity() { |
|
99 |
XMLEntity xml = new XMLEntity(); |
|
100 |
xml.putProperty("className", this.getClassName()); |
|
101 |
|
|
102 |
xml.putProperty("description", this.getDescription()); |
|
103 |
// Saving camera propeties |
|
104 |
|
|
105 |
// Eye |
|
106 |
xml.putProperty("eyeX", this.camera.getEye().x()); |
|
107 |
xml.putProperty("eyeY", this.camera.getEye().y()); |
|
108 |
xml.putProperty("eyeZ", this.camera.getEye().z()); |
|
109 |
// Center |
|
110 |
xml.putProperty("centerX", this.camera.getCenter().x()); |
|
111 |
xml.putProperty("centerY", this.camera.getCenter().y()); |
|
112 |
xml.putProperty("centerZ", this.camera.getCenter().z()); |
|
113 |
// Up |
|
114 |
xml.putProperty("upX", this.camera.getUp().x()); |
|
115 |
xml.putProperty("upY", this.camera.getUp().y()); |
|
116 |
xml.putProperty("upZ", this.camera.getUp().z()); |
|
117 |
|
|
118 |
return xml; |
|
119 |
} |
|
120 |
|
|
121 |
public void setXMLEntity(XMLEntity xml) { |
|
122 |
if (xml.contains("description")) |
|
123 |
this.setDescription(xml.getStringProperty("description")); |
|
124 |
|
|
125 |
// Getting camera properties |
|
126 |
camera = new Camera(); |
|
127 |
|
|
128 |
// Variables auxiliares |
|
129 |
Vec3 center = new Vec3(), |
|
130 |
eye = new Vec3(), |
|
131 |
up = new Vec3(); |
|
132 |
|
|
133 |
// Eye |
|
134 |
if (xml.contains("eyeX")) |
|
135 |
eye.setX(xml.getDoubleProperty("eyeX")); |
|
136 |
if (xml.contains("eyeY")) |
|
137 |
eye.setY(xml.getDoubleProperty("eyeY")); |
|
138 |
if (xml.contains("eyeZ")) |
|
139 |
eye.setZ(xml.getDoubleProperty("eyeZ")); |
|
140 |
|
|
141 |
// Center |
|
142 |
if (xml.contains("centerX")) |
|
143 |
center.setX(xml.getDoubleProperty("centerX")); |
|
144 |
if (xml.contains("centerY")) |
|
145 |
center.setY(xml.getDoubleProperty("centerY")); |
|
146 |
if (xml.contains("centerZ")) |
|
147 |
center.setZ(xml.getDoubleProperty("centerZ")); |
|
148 |
|
|
149 |
// Up |
|
150 |
if (xml.contains("upX")) |
|
151 |
up.setX(xml.getDoubleProperty("upX")); |
|
152 |
if (xml.contains("upY")) |
|
153 |
up.setY(xml.getDoubleProperty("upY")); |
|
154 |
if (xml.contains("upZ")) |
|
155 |
up.setZ(xml.getDoubleProperty("upZ")); |
|
156 |
|
|
157 |
this.camera.setViewByLookAt(eye, center, up); |
|
158 |
|
|
159 |
} |
|
160 |
} |
trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/resources/ResourcesFactory.java | ||
---|---|---|
1 |
package org.gvsig.gvsig3d.resources; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
/** |
|
6 |
* @author julio |
|
7 |
* |
|
8 |
* This class is a factory to find resources in 3D extensions |
|
9 |
* |
|
10 |
*/ |
|
11 |
public class ResourcesFactory { |
|
12 |
|
|
13 |
private static String textPath; |
|
14 |
|
|
15 |
private static String extPath; |
|
16 |
|
|
17 |
static { |
|
18 |
extPath = "/gvSIG/extensiones/com.iver.ai2.gvsig3dgui/resources/"; |
|
19 |
|
|
20 |
textPath = System.getProperty("user.dir") + extPath; |
|
21 |
} |
|
22 |
|
|
23 |
/** |
|
24 |
* Method to get Path resources directory |
|
25 |
* |
|
26 |
* @return |
|
27 |
*/ |
|
28 |
public static String getResourcesPath() { |
|
29 |
return textPath; |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Method to get path to specific resource |
|
34 |
* |
|
35 |
* @param name |
|
36 |
* Name of resource |
|
37 |
* @return All path resource |
|
38 |
*/ |
|
39 |
public static String getResourcePath(String name) { |
|
40 |
return textPath + name; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Method to get a list of all resources |
|
45 |
* |
|
46 |
* @return String array with all resources |
|
47 |
*/ |
|
48 |
public static String[] getResources() { |
|
49 |
String[] resourcesList; |
|
50 |
|
|
51 |
File dir = new File(ResourcesFactory.getResourcesPath()); |
|
52 |
|
|
53 |
resourcesList = dir.list(); |
|
54 |
if (resourcesList == null) { |
|
55 |
// Either dir does not exist or is not a directory |
|
56 |
} else { |
|
57 |
for (int i = 0; i < resourcesList.length; i++) { |
|
58 |
// Get filename of file or directory |
|
59 |
String filename = resourcesList[i]; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
return resourcesList; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Method to verify if this resource exits |
|
68 |
* |
|
69 |
* @param name |
|
70 |
* Name of resource |
|
71 |
* @return True or false |
|
72 |
*/ |
|
73 |
public static boolean exitsResouce(String name) { |
|
74 |
boolean exit = false; |
|
75 |
String[] resourcesList = ResourcesFactory.getResources(); |
|
76 |
if (resourcesList != null) { |
|
77 |
|
|
78 |
for (int i = 0; i < resourcesList.length; i++) { |
|
79 |
// Get filename of file or directory |
|
80 |
String filename = resourcesList[i]; |
|
81 |
if (filename.equals(name)) |
|
82 |
return true; |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
return exit; |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Method to set the extension path |
|
91 |
* |
|
92 |
* @param extPath |
|
93 |
*/ |
|
94 |
public static void setExtPath(String extPath) { |
|
95 |
ResourcesFactory.extPath = extPath; |
|
96 |
textPath = System.getProperty("user.dir") + extPath; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Method to get the extension path |
|
101 |
* |
|
102 |
* @param extPath |
|
103 |
*/ |
|
104 |
public static String getExtPath() { |
|
105 |
return ResourcesFactory.extPath; |
|
106 |
} |
|
107 |
} |
trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/gui/VectorLayerMenu.java | ||
---|---|---|
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 org.gvsig.gvsig3d.gui; |
|
42 |
|
|
43 |
import java.awt.BorderLayout; |
|
44 |
import java.awt.Checkbox; |
|
45 |
import java.awt.Component; |
|
46 |
import java.awt.Dimension; |
|
47 |
import java.awt.GridBagConstraints; |
|
48 |
import java.awt.GridBagLayout; |
|
49 |
import java.awt.Insets; |
|
50 |
import java.awt.event.ActionEvent; |
|
51 |
import java.awt.event.ItemEvent; |
|
52 |
import java.awt.event.ItemListener; |
|
53 |
import java.awt.event.MouseEvent; |
|
54 |
import java.awt.event.MouseListener; |
|
55 |
|
|
56 |
import javax.swing.JDialog; |
|
57 |
import javax.swing.JFrame; |
|
58 |
import javax.swing.JLabel; |
|
59 |
import javax.swing.JPanel; |
|
60 |
import javax.swing.JTextField; |
|
61 |
|
|
62 |
import org.gvsig.gui.beans.swing.JButton; |
|
63 |
import org.gvsig.gvsig3d.map3d.layers.Layer3DProps; |
|
64 |
|
|
65 |
import com.iver.andami.PluginServices; |
|
66 |
|
|
67 |
/** |
|
68 |
* Dialogo donde se muestran las propiedades de una vista |
|
69 |
* |
|
70 |
* @author Fernando Gonz?lez Cort?s |
|
71 |
*/ |
|
72 |
public class VectorLayerMenu extends JDialog implements MouseListener, |
|
73 |
ItemListener { |
|
74 |
|
|
75 |
// private int width = 273; |
|
76 |
// |
|
77 |
// private int height = 179; |
|
78 |
// |
|
79 |
private int width = 285; |
|
80 |
|
|
81 |
private int height = 190; |
|
82 |
|
|
83 |
private Checkbox aButton; // @jve:decl-index=0:visual-constraint="359,41" |
|
84 |
|
|
85 |
private Checkbox bButton; |
|
86 |
|
|
87 |
private JTextField heigthField; |
|
88 |
|
|
89 |
private Layer3DProps props3D; |
|
90 |
|
|
91 |
private Object panel; |
|
92 |
|
|
93 |
private JDialog jDialog = null; // @jve:decl-index=0:visual-constraint="519,70" |
|
94 |
|
|
95 |
private JPanel jContentPane = null; |
|
96 |
|
|
97 |
private JButton boton; |
|
98 |
|
|
99 |
private JLabel jLabel1; |
|
100 |
|
|
101 |
private String name; |
|
102 |
|
|
103 |
/** |
|
104 |
* This is the default constructor |
|
105 |
* |
|
106 |
* @param nombre |
|
107 |
* |
|
108 |
* @param f |
|
109 |
* Frame padre del dialogo |
|
110 |
* @param v |
|
111 |
* Vista que se representa |
|
112 |
*/ |
|
113 |
public VectorLayerMenu(Layer3DProps props, String nombre) { |
|
114 |
|
|
115 |
props3D = props; |
|
116 |
|
|
117 |
name = nombre; |
|
118 |
|
|
119 |
initialize(); |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* This method initializes this |
|
125 |
*/ |
|
126 |
private void initialize() { |
|
127 |
// Inicialize component |
|
128 |
this.setTitle(PluginServices.getText(this, "Layer_Properties") + ":" |
|
129 |
+ name); |
|
130 |
// Introducing the margin |
|
131 |
this.setSize(new Dimension(width, height)); |
|
132 |
// Dimension of the panel only for java 1.5 |
|
133 |
// this.setPreferredSize(new Dimension(width, height)); |
|
134 |
this.setResizable(false); |
|
135 |
|
|
136 |
JFrame a = (JFrame) PluginServices.getMainFrame(); |
|
137 |
double posX = a.getBounds().getCenterX(); |
|
138 |
double posY = a.getBounds().getCenterY(); |
|
139 |
this.setLocation(((int) posX) - (width / 2), ((int) posY) |
|
140 |
- (height / 2)); |
|
141 |
panel = new JPanel(); |
|
142 |
this.getContentPane().add((Component) panel, BorderLayout.CENTER); |
|
143 |
|
|
144 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
145 |
gridBagConstraints.gridx = 0; |
|
146 |
gridBagConstraints.insets = new Insets(0, 25, 0, 0); |
|
147 |
gridBagConstraints.anchor = GridBagConstraints.WEST; |
|
148 |
gridBagConstraints.fill = GridBagConstraints.VERTICAL; |
|
149 |
gridBagConstraints.gridy = 0; |
|
150 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
|
151 |
gridBagConstraints3.gridx = 0; |
|
152 |
gridBagConstraints3.insets = new Insets(12, 0, 0, 0); |
|
153 |
gridBagConstraints3.gridy = 4; |
|
154 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
155 |
gridBagConstraints2.fill = GridBagConstraints.VERTICAL; |
|
156 |
gridBagConstraints2.gridy = 3; |
|
157 |
gridBagConstraints2.weightx = 1.0; |
|
158 |
gridBagConstraints2.gridwidth = 1; |
|
159 |
gridBagConstraints2.ipadx = 93; |
|
160 |
gridBagConstraints2.insets = new Insets(8, 0, 0, 0); |
|
161 |
gridBagConstraints2.gridx = 0; |
|
162 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
163 |
gridBagConstraints1.gridx = 0; |
|
164 |
gridBagConstraints1.insets = new Insets(0, 25, 0, 0); |
|
165 |
gridBagConstraints1.anchor = GridBagConstraints.WEST; |
|
166 |
gridBagConstraints1.fill = GridBagConstraints.VERTICAL; |
|
167 |
gridBagConstraints1.gridy = 1; |
|
168 |
|
|
169 |
GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
|
170 |
gridBagConstraints4.gridx = 0; |
|
171 |
gridBagConstraints4.insets = new Insets(0, 25, 0, 0); |
|
172 |
gridBagConstraints4.anchor = GridBagConstraints.WEST; |
|
173 |
gridBagConstraints4.fill = GridBagConstraints.VERTICAL; |
|
174 |
gridBagConstraints4.gridy = 2; |
|
175 |
|
|
176 |
jContentPane = new JPanel(); |
|
177 |
jContentPane.setLayout(new GridBagLayout()); |
|
178 |
jContentPane.add(getJCheckBox1(), gridBagConstraints1); |
|
179 |
jLabel1 = new JLabel("Altura en metros:"); |
|
180 |
jLabel1.setEnabled(false); |
|
181 |
jContentPane.add(jLabel1, gridBagConstraints4); |
|
182 |
jContentPane.add(getJTextField(), gridBagConstraints2); |
|
183 |
jContentPane.add(getJButton(), gridBagConstraints3); |
|
184 |
jContentPane.add(getJCheckBox(), gridBagConstraints); |
|
185 |
this.setModal(true); |
|
186 |
this.setAlwaysOnTop(true); |
|
187 |
this.getContentPane().add(jContentPane); |
|
188 |
|
|
189 |
} |
|
190 |
|
|
191 |
private Checkbox getJCheckBox1() { |
|
192 |
if (bButton == null) { |
|
193 |
bButton = new Checkbox(PluginServices.getText(this, "Heigth_Z"), |
|
194 |
false); |
|
195 |
bButton.setEnabled(false); |
|
196 |
bButton.addItemListener(this); |
|
197 |
} |
|
198 |
return bButton; |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* This method initializes jTextField |
|
203 |
* |
|
204 |
* @return javax.swing.JTextField |
|
205 |
*/ |
|
206 |
private JTextField getJTextField() { |
|
207 |
if (heigthField == null) { |
|
208 |
heigthField = new JTextField(); |
|
209 |
heigthField.setText("10000"); |
|
210 |
heigthField.setEnabled(false); |
|
211 |
|
|
212 |
} |
|
213 |
return heigthField; |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* This method initializes jButton |
|
218 |
* |
|
219 |
* @return javax.swing.JButton |
|
220 |
*/ |
|
221 |
private JButton getJButton() { |
|
222 |
if (boton == null) { |
|
223 |
boton = new JButton(PluginServices.getText(this, "Accept")); |
|
224 |
|
|
225 |
boton.addMouseListener(this); |
|
226 |
} |
|
227 |
return boton; |
|
228 |
} |
|
229 |
|
|
230 |
/** |
|
231 |
* This method initializes jCheckBox |
|
232 |
* |
|
233 |
* @return javax.swing.JCheckBox |
|
234 |
*/ |
|
235 |
private Checkbox getJCheckBox() { |
|
236 |
if (aButton == null) { |
|
237 |
aButton = new Checkbox( |
|
238 |
PluginServices.getText(this, "Raster_layer"), true); |
|
239 |
aButton.addItemListener(this); |
|
240 |
} |
|
241 |
return aButton; |
|
242 |
} |
|
243 |
|
|
244 |
private Checkbox getJLabel() { |
|
245 |
if (jLabel1 == null) { |
|
246 |
jLabel1 = new JLabel(); |
|
247 |
jLabel1.setText("Altura en metros:"); |
|
248 |
} |
|
249 |
return aButton; |
|
250 |
} |
|
251 |
|
|
252 |
public void itemStateChanged(ItemEvent arg0) { |
|
253 |
|
|
254 |
bButton.setEnabled(!aButton.getState()); |
|
255 |
aButton.setEnabled(!bButton.getState()); |
|
256 |
heigthField.setEnabled(!aButton.getState()); |
|
257 |
heigthField.setEnabled(!(bButton.getState() || aButton.getState())); |
|
258 |
|
|
259 |
jLabel1.setEnabled(!aButton.getState()); |
|
260 |
jLabel1.setEnabled(!(bButton.getState() || aButton.getState())); |
|
261 |
|
|
262 |
} |
|
263 |
|
|
264 |
public void actionPerformed(ActionEvent e) { |
|
265 |
// TODO Auto-generated method stub |
|
266 |
|
|
267 |
} |
|
268 |
|
|
269 |
public void mouseClicked(MouseEvent e) { |
|
270 |
// TODO Auto-generated method stub |
|
271 |
|
|
272 |
if (aButton.getState()) { |
|
273 |
props3D.setType(Layer3DProps.layer3DImage); |
|
274 |
} else { |
|
275 |
props3D.setType(Layer3DProps.layer3DVector); |
|
276 |
if (!bButton.getState()) { |
|
277 |
props3D.setZEnable(false); |
|
278 |
int h = Integer.parseInt(heigthField.getText()); |
|
279 |
if (h >= 0) |
|
280 |
props3D.setHeigth(h); |
|
281 |
} else { |
|
282 |
props3D.setZEnable(true); |
|
283 |
} |
|
284 |
} |
|
285 |
this.dispose(); |
|
286 |
} |
|
287 |
|
|
288 |
public void mouseEntered(MouseEvent e) { |
|
289 |
// TODO Auto-generated method stub |
|
290 |
|
|
291 |
} |
|
292 |
|
|
293 |
public void mouseExited(MouseEvent e) { |
|
294 |
// TODO Auto-generated method stub |
|
295 |
|
|
296 |
} |
|
297 |
|
|
298 |
public void mousePressed(MouseEvent e) { |
|
299 |
// TODO Auto-generated method stub |
|
300 |
|
|
301 |
} |
|
302 |
|
|
303 |
public void mouseReleased(MouseEvent e) { |
|
304 |
// TODO Auto-generated method stub |
|
305 |
|
|
306 |
} |
|
307 |
|
|
308 |
/** |
|
309 |
* This method initializes jContentPane |
|
310 |
* |
|
311 |
* @return javax.swing.JPanel |
|
312 |
*/ |
|
313 |
private JPanel getJContentPane() { |
|
314 |
if (jContentPane == null) { |
|
315 |
jContentPane = new JPanel(); |
|
316 |
jContentPane.setLayout(new BorderLayout()); |
|
317 |
jContentPane.add(bButton, BorderLayout.CENTER); |
|
318 |
} |
|
319 |
return jContentPane; |
|
320 |
} |
|
321 |
} // @jve:decl-index=0:visual-constraint="10,10" |
trunk/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/map3d/layers/Layer3DProps.java | ||
---|---|---|
1 |
package org.gvsig.gvsig3d.map3d.layers; |
|
2 |
|
|
3 |
import java.awt.Component; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileNotFoundException; |
|
6 |
import java.io.FileReader; |
|
7 |
import java.io.FileWriter; |
|
8 |
import java.util.HashMap; |
|
9 |
import java.util.Hashtable; |
|
10 |
import java.util.Vector; |
|
11 |
|
|
12 |
import javax.swing.JOptionPane; |
|
13 |
|
|
14 |
import org.cresques.cts.IProjection; |
|
15 |
import org.exolab.castor.xml.Marshaller; |
|
16 |
import org.gvsig.cacheservice.CacheService; |
|
17 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
|
18 |
import org.gvsig.gvsig3d.gui.VectorLayerMenu; |
|
19 |
|
|
20 |
import com.iver.andami.PluginServices; |
|
21 |
import com.iver.andami.messages.NotificationManager; |
|
22 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
23 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
|
24 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
25 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
|
26 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
|
27 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
|
28 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
|
29 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
|
30 |
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
|
31 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
|
32 |
import com.iver.utiles.IPersistence; |
|
33 |
import com.iver.utiles.XMLEntity; |
|
34 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
|
35 |
|
|
36 |
public class Layer3DProps implements IPersistence { |
|
37 |
|
|
38 |
// types of 3D layers |
|
39 |
public static final int layer3DImage = 0; |
|
40 |
public static final int layer3DElevation = 1; |
|
41 |
public static final int layer3DVector = 2; |
|
42 |
|
|
43 |
// public static String m_cacheDir = "c:/data/cache"; // TEST |
|
44 |
// Create a .data directorio in user home for caching elements |
|
45 |
public static String m_cacheDir = System.getProperty("user.home") |
|
46 |
+ "/gvSIG/.data/cache"; |
|
47 |
|
|
48 |
protected int m_tocOrder; // index of layer in TOC (drawing priority) |
|
49 |
protected int m_planetOrder; // current stage of layer in planet. |
|
50 |
// Can be temporarily different from the TOC order while moving groups of layers |
|
51 |
|
|
52 |
protected float m_opacity = 1.0f; // Opacity of layer default 1.0 |
|
53 |
protected float m_verticalEx = 10.0f; // Opacity of layer default 1.0 |
|
54 |
protected float m_heigth = 100; // Opacity of layer default 1.0 |
|
55 |
protected int m_type; // see type enumeration above |
|
56 |
protected String m_cacheName = "default"; |
|
57 |
protected FLayer m_layer; |
|
58 |
protected CacheService m_cacheService; |
|
59 |
private boolean m_bChooseType = true; |
|
60 |
|
|
61 |
private boolean m_Zenable = false; |
|
62 |
|
|
63 |
// used by FLayers3D (3D group layer) to flag when they are actually hooked to TOC or not |
|
64 |
private boolean m_hooked = false; |
|
65 |
|
|
66 |
private int option; |
|
67 |
|
|
68 |
private VectorLayerMenu vectorLayerMenu; |
|
69 |
|
|
70 |
public Layer3DProps() { |
|
71 |
m_tocOrder = -1; // not set |
|
72 |
m_planetOrder = -1; |
|
73 |
} |
|
74 |
|
|
75 |
public static Layer3DProps getLayer3DProps(FLayer layer) { |
|
76 |
FLyrDefault baseLayer = (FLyrDefault) layer; |
|
77 |
Object propsObj = baseLayer.getProperty("3DLayerExtension"); |
|
78 |
Layer3DProps props3D = null; |
|
79 |
if (propsObj != null) { |
|
80 |
try { |
|
81 |
props3D = (Layer3DProps) propsObj; |
|
82 |
} catch (Exception e) { |
|
83 |
props3D = null; |
|
84 |
} |
|
85 |
} |
|
86 |
return props3D; |
|
87 |
} |
|
88 |
|
|
89 |
public void setChooseType(boolean bChoose) { |
|
90 |
m_bChooseType = bChoose; |
|
91 |
} |
|
92 |
|
|
93 |
public boolean getHooked() { |
|
94 |
return m_hooked; |
|
95 |
} |
|
96 |
|
|
97 |
public void setHooked(boolean hooked) { |
|
98 |
m_hooked = hooked; |
|
99 |
} |
|
100 |
|
|
101 |
public void setLayer(FLayer layer) { |
|
102 |
|
|
103 |
if (m_layer == layer) |
|
104 |
return; |
|
105 |
|
|
106 |
m_layer = layer; |
|
107 |
|
|
108 |
// find out data type |
|
109 |
if (m_bChooseType) { |
|
110 |
m_bChooseType = false; |
|
111 |
m_type = layer3DImage; |
|
112 |
boolean bCanBeElev = false; |
|
113 |
|
|
114 |
// TODO Un toggle this comment to use WMS extensions |
|
115 |
|
|
116 |
if (layer instanceof FLyrWMS) { |
|
117 |
FLyrWMS wmsLayer = (FLyrWMS) layer; |
|
118 |
String format = wmsLayer.getFormat(); |
|
119 |
if (format.regionMatches(true, 0, "image/geotiff", 0, 13) || |
|
120 |
format.regionMatches(true, 0, "image/tiff", 0, 10)) |
|
121 |
bCanBeElev = true; |
|
122 |
} else if (layer instanceof FLyrWCS) { |
|
123 |
FLyrWCS wcsLayer = (FLyrWCS) layer; |
|
124 |
String format = wcsLayer.getFileFormat(); |
|
125 |
Hashtable props = wcsLayer.getProperties(); |
|
126 |
String params = (String) props.get("parameter"); |
|
127 |
if (format.compareToIgnoreCase("GEOTIFF_INT16") == 0 |
|
128 |
&& params.length() == 0) |
|
129 |
bCanBeElev = true; |
|
130 |
} |
|
131 |
// FEATURES |
|
132 |
else /**/ if (layer instanceof ClassifiableVectorial) { |
|
133 |
|
|
134 |
vectorLayerMenu = new VectorLayerMenu(this,layer.getName()); |
|
135 |
vectorLayerMenu.setModal(true); |
|
136 |
vectorLayerMenu.pack(); |
|
137 |
vectorLayerMenu.setVisible(true); |
|
138 |
|
|
139 |
|
|
140 |
// PluginServices.getMDIManager().addWindow(vectorLayerMenu); |
|
141 |
|
|
142 |
|
|
143 |
// // choose rasterization of 3D |
|
144 |
// option = JOptionPane.showConfirmDialog( |
|
145 |
// (Component) PluginServices.getMainFrame(), |
|
146 |
// PluginServices |
|
147 |
// .getText(this, "Rasterize_layer_question"), |
|
148 |
// PluginServices.getText(this, "Layer_options"), |
|
149 |
// JOptionPane.YES_NO_OPTION); |
|
150 |
// |
|
151 |
// if (option == JOptionPane.YES_OPTION) |
|
152 |
// m_type = layer3DImage; |
|
153 |
// else |
|
154 |
// m_type = layer3DVector; |
|
155 |
// |
|
156 |
// if (m_type == layer3DVector) { |
|
157 |
// String Altura = JOptionPane.showInputDialog(PluginServices |
|
158 |
// .getText(this, PluginServices.getText(this, |
|
159 |
// "Heigth_layer_question")), "1000"); |
|
160 |
// |
|
161 |
// if (Altura != null) { |
|
162 |
// int h = Integer.parseInt(Altura); |
|
163 |
// if (h >= 0) |
|
164 |
// m_heigth = h; |
|
165 |
// } |
|
166 |
// } |
|
167 |
|
|
168 |
} else if (layer instanceof FLyrRasterSE) { |
|
169 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) layer; |
|
170 |
if (rasterLayer.getBandCount() == 1) |
|
171 |
bCanBeElev = true; |
|
172 |
|
|
173 |
} |
|
174 |
|
|
175 |
if (m_type == layer3DImage && bCanBeElev) { |
|
176 |
option = JOptionPane.showConfirmDialog( |
|
177 |
(Component) PluginServices.getMainFrame(), |
|
178 |
PluginServices |
|
179 |
.getText(this, "Elevation_layer_question"), |
|
180 |
PluginServices.getText(this, "Layer_options"), |
|
181 |
JOptionPane.YES_NO_OPTION); |
|
182 |
|
|
183 |
if (option == JOptionPane.YES_OPTION) |
|
184 |
m_type = layer3DElevation; |
|
185 |
} |
|
186 |
|
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
public void initCacheName(int planetType, IProjection viewProj,int geocentricCoordinates) { |
|
191 |
// TODO: use full path of source or service, not just layer name |
|
192 |
|
|
193 |
String typeStr; |
|
194 |
if (planetType == geocentricCoordinates) |
|
195 |
typeStr = "Sph"; |
|
196 |
else |
|
197 |
typeStr = "Pla" + viewProj.getAbrev(); |
|
198 |
|
|
199 |
if (m_type == layer3DElevation) |
|
200 |
typeStr += "Elev"; |
|
201 |
else if (m_type == layer3DVector) |
|
202 |
typeStr += "Vect"; |
|
203 |
|
|
204 |
String layerInfo = m_layer.getName(); |
|
205 |
// TODO Un toggle this comment to use WMS extension |
|
206 |
|
|
207 |
if (m_layer instanceof FLyrWMS) { |
|
208 |
FLyrWMS wmsLayer = (FLyrWMS) m_layer; |
|
209 |
|
|
210 |
// Getting wms layer properties |
|
211 |
HashMap props = wmsLayer.getProperties(); |
|
212 |
Vector styles; |
|
213 |
// Getting styles |
|
214 |
styles = (Vector) (props.get("styles")); |
|
215 |
|
|
216 |
// Adding styles to cache path |
|
217 |
String layerStyle = ""; |
|
218 |
if (styles != null) { |
|
219 |
styles.size(); |
|
220 |
for (int i = 0; i < styles.size(); i++) { |
|
221 |
String ele = (String) styles.get(i); |
|
222 |
layerStyle += ele; |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 |
layerInfo = wmsLayer.getHost().toString() |
|
227 |
+ wmsLayer.getLayerQuery() + "_" + layerStyle; |
|
228 |
|
|
229 |
} else { |
|
230 |
layerInfo = m_layer.getName(); |
|
231 |
} |
|
232 |
/**/ |
|
233 |
m_cacheName = typeStr + "_" + layerInfo; |
|
234 |
|
|
235 |
m_cacheName = m_cacheName.replace('/', '_'); |
|
236 |
m_cacheName = m_cacheName.replace(':', '_'); |
|
237 |
m_cacheName = m_cacheName.replace('\\', '_'); |
|
238 |
m_cacheName = m_cacheName.replace('*', '_'); |
|
239 |
m_cacheName = m_cacheName.replace('<', '_'); |
|
240 |
m_cacheName = m_cacheName.replace('>', '_'); |
|
241 |
m_cacheName = m_cacheName.replace('?', '_'); |
|
242 |
m_cacheName = m_cacheName.replace('"', '_'); |
|
243 |
m_cacheName = m_cacheName.replace('|', '_'); |
|
244 |
|
|
245 |
// filter strange characters out of the cache name |
|
246 |
int iChar; |
|
247 |
for (iChar = 0; iChar < m_cacheName.length(); iChar++) { |
|
248 |
char c = m_cacheName.charAt(iChar); |
|
249 |
boolean bIsLow = (c >= 'a') && (c <= 'z'); |
|
250 |
boolean bIsUp = (c >= 'A') && (c <= 'Z'); |
|
251 |
boolean bIsNum = (c >= '0') && (c <= '9'); |
|
252 |
if (!bIsLow && !bIsUp && !bIsNum && c != '_' && c != '.') { |
|
253 |
int newCInt = java.lang.Math.abs((int) (c) - (int) 'A'); |
|
254 |
newCInt = (newCInt % 26) + (int) 'A'; |
|
255 |
char newC = (char) newCInt; |
|
256 |
m_cacheName = m_cacheName.replace(c, newC); |
|
257 |
} |
|
258 |
} |
|
259 |
} |
|
260 |
|
|
261 |
public CacheService getCacheService() { |
|
262 |
return m_cacheService; |
|
263 |
} |
|
264 |
|
|
265 |
public void setCacheService(CacheService srv) { |
|
266 |
m_cacheService = srv; |
|
267 |
} |
|
268 |
|
|
269 |
public void setType(int type) { |
|
270 |
m_type = type; |
|
271 |
} |
|
272 |
|
|
273 |
public int getType() { |
|
274 |
return m_type; |
|
275 |
} |
|
276 |
|
|
277 |
public void setTocOrder(int order) { |
|
278 |
m_tocOrder = order; |
|
279 |
} |
|
280 |
|
|
281 |
public int getTocOrder() { |
|
282 |
return m_tocOrder; |
|
283 |
} |
|
284 |
|
|
285 |
public void setPlanetOrder(int order) { |
|
286 |
m_planetOrder = order; |
|
287 |
} |
|
288 |
|
|
289 |
public int getPlanetOrder() { |
|
290 |
return m_planetOrder; |
|
291 |
} |
|
292 |
|
|
293 |
public String getCacheName() { |
|
294 |
return m_cacheName; |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* Verifies that the vector layer's legend matches the one in the cache |
|
299 |
* folder |
|
300 |
*/ |
|
301 |
public void VerifyLegend(String planetName) { |
|
302 |
|
|
303 |
NotificationManager.addInfo("Estoy aki", null); |
|
304 |
NotificationManager.addInfo(m_cacheDir, null); |
|
305 |
if (m_layer instanceof Classifiable) { |
|
306 |
Classifiable legendLyr = (Classifiable) m_layer; |
|
307 |
String cacheFolder = m_cacheDir + "/" + planetName |
|
308 |
+ "/" + m_cacheName; |
|
309 |
File cacheFolderFile = new File(cacheFolder); |
|
310 |
if (!cacheFolderFile.exists()) |
|
311 |
cacheFolderFile.mkdir(); |
|
312 |
|
|
313 |
String legendFileName = cacheFolder + "/" + "legend.xml"; |
|
314 |
File legendFile = new File(legendFileName); |
|
315 |
|
|
316 |
if (legendFile.exists()) { // read legend |
|
317 |
NotificationManager.addInfo("el fichero existe", null); |
|
318 |
FileReader reader = null; |
|
319 |
try { |
|
320 |
reader = new FileReader(legendFile); |
|
321 |
} catch (FileNotFoundException e) { |
|
322 |
return; |
|
323 |
} |
|
324 |
try { |
|
325 |
XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
|
326 |
XMLEntity legendXml = new XMLEntity(tag); |
|
327 |
ILegend legend = LegendFactory.createFromXML(legendXml); |
|
328 |
if (m_layer instanceof FLyrVect) { |
|
329 |
((FLyrVect) m_layer) |
|
330 |
.setLegend((IVectorLegend) legend); |
|
331 |
} |
|
332 |
|
|
333 |
} catch (Exception e) { |
|
334 |
e.printStackTrace(); |
|
335 |
} |
|
336 |
|
|
337 |
} else { // write legend |
|
338 |
NotificationManager.addInfo("el fichero no existe", null); |
|
339 |
ILegend legend = legendLyr.getLegend(); |
|
340 |
if (legend == null) |
|
341 |
return; |
|
342 |
|
|
343 |
XMLEntity xmlLegend = legend.getXMLEntity(); |
|
344 |
|
|
345 |
try { |
|
346 |
FileWriter writer = new FileWriter(legendFileName); |
|
347 |
Marshaller m = new Marshaller(writer); |
|
348 |
m.setEncoding("ISO-8859-1"); |
|
349 |
m.marshal(xmlLegend.getXmlTag()); |
|
350 |
|
|
351 |
} catch (Exception e) { |
|
352 |
e.printStackTrace(); |
|
353 |
} |
|
354 |
} |
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
// IPersistance |
|
359 |
|
|
360 |
public String getClassName() { |
|
361 |
return this.getClass().getName(); |
|
362 |
} |
|
363 |
|
|
364 |
public XMLEntity getXMLEntity() { |
|
365 |
XMLEntity xml = new XMLEntity(); |
|
366 |
|
|
367 |
xml.putProperty("type", m_type); |
|
368 |
xml.putProperty("order", m_tocOrder); |
|
369 |
xml.putProperty("opacity", m_opacity); |
|
370 |
xml.putProperty("heigth", m_heigth); |
|
371 |
xml.putProperty("cacheName", m_cacheName); |
|
372 |
|
|
373 |
return xml; |
|
374 |
} |
|
375 |
|
|
376 |
public void setXMLEntity(XMLEntity xml) { |
|
377 |
if (xml.contains("type")) { |
|
378 |
m_bChooseType = false; |
|
379 |
m_type = xml.getIntProperty("type"); |
|
380 |
} |
|
381 |
if (xml.contains("order")) |
|
382 |
m_tocOrder = xml.getIntProperty("order"); |
|
383 |
if (xml.contains("opacity")) |
|
384 |
m_opacity = Float.parseFloat(xml.getStringProperty("opacity")); |
|
385 |
if (xml.contains("heigth")) |
|
386 |
m_heigth = Float.parseFloat(xml.getStringProperty("heigth")); |
|
387 |
if (xml.contains("cacheName")) |
|
388 |
m_cacheName = xml.getStringProperty("cacheName"); |
|
389 |
} |
|
390 |
|
|
391 |
public float getOpacity() { |
|
392 |
return m_opacity; |
|
393 |
} |
|
394 |
|
|
395 |
public void setOpacity(float m_opacity) { |
|
396 |
this.m_opacity = m_opacity; |
|
397 |
} |
|
398 |
|
|
399 |
public float getVerticalEx() { |
|
400 |
return m_verticalEx; |
|
401 |
} |
|
402 |
|
|
403 |
public void setVerticalEx(float ex) { |
|
404 |
m_verticalEx = ex; |
|
405 |
} |
|
406 |
|
|
407 |
public float getHeigth() { |
|
408 |
return m_heigth; |
|
409 |
} |
|
410 |
|
|
411 |
public void setHeigth(float m_heigth) { |
|
412 |
this.m_heigth = m_heigth; |
|
413 |
} |
|
414 |
|
|
415 |
public boolean isZEnable() { |
|
416 |
return m_Zenable; |
|
417 |
} |
|
418 |
|
|
419 |
public void setZEnable(boolean zenable) { |
|
420 |
m_Zenable = zenable; |
|
421 |
} |
|
422 |
|
|
423 |
} |
Also available in: Unified diff