svn-gvsig-desktop / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / ProjectView3DFactory.java @ 26236
History | View | Annotate | Download (8.36 KB)
1 |
package org.gvsig.gvsig3dgui; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.text.DateFormat; |
5 |
import java.util.Date; |
6 |
import java.util.Enumeration; |
7 |
import java.util.Hashtable; |
8 |
|
9 |
import javax.swing.ImageIcon; |
10 |
import javax.swing.JOptionPane; |
11 |
|
12 |
import org.gvsig.gvsig3d.map3d.ViewPort3D; |
13 |
import org.gvsig.gvsig3d.map3d.layers.FLayers3D; |
14 |
import org.gvsig.gvsig3dgui.view.ViewProperties3D; |
15 |
|
16 |
import com.iver.andami.PluginServices; |
17 |
import com.iver.cit.gvsig.fmap.MapContext; |
18 |
import com.iver.cit.gvsig.fmap.ViewPort; |
19 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
20 |
import com.iver.cit.gvsig.project.Project; |
21 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
22 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
23 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
24 |
import com.iver.utiles.XMLEntity; |
25 |
|
26 |
/**
|
27 |
* Factory of View3D.
|
28 |
*
|
29 |
* @author Vicente Caballero Navarro
|
30 |
*/
|
31 |
public class ProjectView3DFactory extends ProjectDocumentFactory { |
32 |
public static String registerName = "ProjectView3D"; |
33 |
|
34 |
private boolean createFromGUI = false; |
35 |
|
36 |
/**
|
37 |
* Returns image of button.
|
38 |
*
|
39 |
* @return Image button.
|
40 |
*/
|
41 |
public ImageIcon getButtonIcon() { |
42 |
return new ImageIcon(this.getClass().getClassLoader().getResource( |
43 |
"images/ProjectView3D.png"));
|
44 |
} |
45 |
|
46 |
/**
|
47 |
* Returns image of selected button.
|
48 |
*
|
49 |
* @return Image button.
|
50 |
*/
|
51 |
public ImageIcon getSelectedButtonIcon() { |
52 |
return new ImageIcon(this.getClass().getClassLoader().getResource( |
53 |
"images/ProjectView3DSel.png"));
|
54 |
} |
55 |
|
56 |
public ProjectDocument createFromGUI(Project project) {
|
57 |
createFromGUI = true;
|
58 |
ProjectDocument doc = create(project); |
59 |
createFromGUI = false;
|
60 |
return doc;
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* Create a new ProjectDocument.
|
65 |
*
|
66 |
* @param project
|
67 |
* Opened project.
|
68 |
*
|
69 |
* @return ProjectDocument.
|
70 |
*/
|
71 |
public ProjectDocument create(Project project) {
|
72 |
String viewName = ""; |
73 |
String aux = PluginServices.getText(this, "untitled"); |
74 |
int numViews=((Integer)ProjectDocument.NUMS.get(registerName)).intValue(); |
75 |
|
76 |
viewName = aux + " - " + numViews++;
|
77 |
|
78 |
if (project != null) { |
79 |
// Buscamos si alguna vista ya ten?a este nombre:
|
80 |
while (existName(project, viewName)) {
|
81 |
viewName = aux + " - " + numViews++;
|
82 |
} |
83 |
} |
84 |
|
85 |
ProjectDocument.NUMS.put(registerName,new Integer(numViews)); |
86 |
ProjectView3D vista = createView(viewName); |
87 |
|
88 |
if (vista != null) |
89 |
vista.setProject(project, 0);
|
90 |
|
91 |
|
92 |
return vista;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Create a new ProjectView.
|
97 |
*
|
98 |
* @param baseName
|
99 |
* name
|
100 |
*
|
101 |
* @return ProjectView.
|
102 |
*/
|
103 |
private ProjectView3D createView(String viewName) { |
104 |
ProjectView3D v = new ProjectView3D();
|
105 |
|
106 |
// in the case of 3D layers, the map context is created by the FLayers'
|
107 |
// constructor
|
108 |
ViewPort vp = new ViewPort3D(Project.getDefaultProjection());
|
109 |
FLayers layers = new FLayers3D(null, null, vp); |
110 |
v.setMapContext(layers.getMapContext()); |
111 |
v.setMapOverViewContext(new MapContext(null)); |
112 |
v.getMapOverViewContext().setProjection( |
113 |
v.getMapContext().getProjection()); |
114 |
v.setName(viewName); |
115 |
v.setCreationDate(DateFormat.getInstance().format(new Date())); |
116 |
|
117 |
if (createFromGUI)
|
118 |
setView3DProperties(v); |
119 |
|
120 |
return v;
|
121 |
} |
122 |
|
123 |
private void setView3DProperties(ProjectView3D prView) { |
124 |
|
125 |
ViewProperties3D viewProperties = new ViewProperties3D(prView, true); |
126 |
PluginServices.getMDIManager().addWindow(viewProperties); |
127 |
|
128 |
// // choose spherical or flat view
|
129 |
// int option = JOptionPane.showConfirmDialog(
|
130 |
// (Component)PluginServices.getMainFrame(),
|
131 |
// /*"<html>"+
|
132 |
// PluginServices.getText(this,"desea_una_vista_esf?rica_(Si)") + "<br>"
|
133 |
// +
|
134 |
// PluginServices.getText(this,"o_plana_(No)") + "<br>" +
|
135 |
// "</html>",
|
136 |
// PluginServices.getText(this,"tipo_de_vista"),*/
|
137 |
// "?Desea una vista esf?rica (Si) o plana (No)?",
|
138 |
// "Tipo de vista 3D",
|
139 |
// JOptionPane.YES_NO_OPTION
|
140 |
// );
|
141 |
// int planetType;
|
142 |
// if (option == JOptionPane.YES_OPTION)
|
143 |
// planetType = PlanetType.SPHERICAL_MODE;
|
144 |
// else
|
145 |
// planetType = PlanetType.PLANE_MODE;
|
146 |
// prView.setPlanetType(planetType);
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Returns the name of registration in the point of extension.
|
151 |
*
|
152 |
* @return Name of registration
|
153 |
*/
|
154 |
public String getRegisterName() { |
155 |
return registerName;
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* Returns the name of ProjectDocument.
|
160 |
*
|
161 |
* @return Name of ProjectDocument.
|
162 |
*/
|
163 |
public String getNameType() { |
164 |
return PluginServices.getText(this, "Vista3D"); |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Registers in the points of extension the Factory with alias.
|
169 |
*
|
170 |
*/
|
171 |
public static void register() { |
172 |
register(registerName, new ProjectView3DFactory());
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Returns the priority of de ProjectDocument.
|
177 |
*
|
178 |
* @return Priority.
|
179 |
*/
|
180 |
public int getPriority() { |
181 |
return 10; |
182 |
} |
183 |
|
184 |
/**
|
185 |
* Returns the priority of the Document in the ProjectWindow list.
|
186 |
*
|
187 |
* @return Priority.
|
188 |
*/
|
189 |
public int getListPriority() { |
190 |
return 10; // so the 3D View appears before other document types |
191 |
} |
192 |
|
193 |
public boolean resolveImportXMLConflicts(XMLEntity root, Project project, |
194 |
Hashtable conflicts) {
|
195 |
Hashtable viewsConflits = (Hashtable) conflicts.get(this |
196 |
.getRegisterName()); |
197 |
Hashtable tablesConflits = (Hashtable) conflicts |
198 |
.get(ProjectTableFactory.registerName); |
199 |
XMLEntity xmlTables = root.firstChild("type",
|
200 |
ProjectTableFactory.registerName); |
201 |
|
202 |
if (viewsConflits != null && viewsConflits.size() > 0) { |
203 |
int option = JOptionPane |
204 |
.showConfirmDialog( |
205 |
(Component) PluginServices.getMainFrame(),
|
206 |
"<html>"
|
207 |
+ PluginServices |
208 |
.getText(this,
|
209 |
"conflicto_de_nombres_de_vistas_al_pegar")
|
210 |
+ "<br>"
|
211 |
+ PluginServices |
212 |
.getText(this,
|
213 |
"debera_introducir_nombres_para_las_vistas_a_pegar")
|
214 |
+ "<br>"
|
215 |
+ PluginServices.getText(this,
|
216 |
"no_se_pegaran_las_tablas")
|
217 |
+ "<br>"
|
218 |
+ PluginServices.getText(this,
|
219 |
"desea_continuar") + "</html>", |
220 |
PluginServices.getText(this, "pegar_vistas"), |
221 |
JOptionPane.YES_NO_OPTION);
|
222 |
if (option != JOptionPane.YES_OPTION) { |
223 |
return false; |
224 |
} |
225 |
Enumeration en = viewsConflits.elements();
|
226 |
while (en.hasMoreElements()) {
|
227 |
XMLEntity view = (XMLEntity) en.nextElement(); |
228 |
String newName = JOptionPane |
229 |
.showInputDialog( |
230 |
(Component) PluginServices.getMainFrame(),
|
231 |
"<html>"
|
232 |
+ PluginServices |
233 |
.getText(this,
|
234 |
"introduzca_nuevo_nombre_para_la_vista")
|
235 |
+ " " + view.getStringProperty("name") |
236 |
+ ":" + "</html>", // Mensaje |
237 |
view.getStringProperty("name") // Valor por |
238 |
// defecto
|
239 |
); |
240 |
if (newName == null) { |
241 |
JOptionPane.showMessageDialog((Component) PluginServices |
242 |
.getMainFrame(), "<html>"
|
243 |
+ PluginServices.getText(this,
|
244 |
"operacion_cancelada") + "</html>",// Mensaje |
245 |
PluginServices.getText(this, "pegar_vistas"),// titulo |
246 |
JOptionPane.ERROR_MESSAGE);
|
247 |
} else if (newName.equalsIgnoreCase(view |
248 |
.getStringProperty("name"))) {
|
249 |
JOptionPane.showMessageDialog((Component) PluginServices |
250 |
.getMainFrame(), "<html>"
|
251 |
+ PluginServices.getText(this,
|
252 |
"operacion_cancelada") + ":<br>" |
253 |
+ PluginServices.getText(this, "nombre_no_valido") |
254 |
+ "</html>",// Mensaje |
255 |
PluginServices.getText(this, "pegar_vistas"),// FIXME: |
256 |
// getText
|
257 |
JOptionPane.ERROR_MESSAGE);
|
258 |
return false; |
259 |
} |
260 |
view.setName(newName); |
261 |
} |
262 |
if (xmlTables != null) |
263 |
xmlTables.removeAllChildren(); |
264 |
tablesConflits = null;
|
265 |
} |
266 |
|
267 |
if (tablesConflits != null && tablesConflits.size() > 0) { |
268 |
int option = JOptionPane.showConfirmDialog( |
269 |
(Component) PluginServices.getMainFrame(), "<html>" |
270 |
+ PluginServices.getText(this,
|
271 |
"conflicto_de_nombres_de_tablas_al_pegar")
|
272 |
+ "<br>"
|
273 |
+ PluginServices.getText(this,
|
274 |
"no_se_pegaran_las_tablas") + "<br>" |
275 |
+ PluginServices.getText(this, "desea_continuar") |
276 |
+ "</html>", // Mensaje |
277 |
PluginServices.getText(this, "pegar_vistas"),// FIXME: |
278 |
// getText
|
279 |
JOptionPane.YES_NO_OPTION);
|
280 |
if (option != JOptionPane.YES_OPTION) { |
281 |
return false; |
282 |
} |
283 |
xmlTables.removeAllChildren(); |
284 |
} |
285 |
|
286 |
return true; |
287 |
} |
288 |
} |