Revision 306 2.0/trunk/org.gvsig.gvsig3d.app/org.gvsig.gvsig3d.app.extension/src/main/java/org/gvsig/gvsig3d/app/extension/View3DManager.java

View differences:

View3DManager.java
36 36
import org.gvsig.app.project.documents.actions.CopyDocumentAction;
37 37
import org.gvsig.app.project.documents.actions.CutDocumentAction;
38 38
import org.gvsig.app.project.documents.actions.PasteDocumentAction;
39
import org.gvsig.app.project.documents.gui.IDocumentWindow;
40 39
import org.gvsig.app.project.documents.gui.WindowLayout;
41
import org.gvsig.app.project.documents.view.DefaultViewDocument;
40
import org.gvsig.app.project.documents.view.ViewDocument;
42 41
import org.gvsig.fmap.mapcontext.MapContext;
43 42
import org.gvsig.fmap.mapcontext.ViewPort;
44 43
import org.gvsig.gvsig3d.Gvsig3DLocator;
45 44
import org.gvsig.gvsig3d.Gvsig3DManager;
46 45
import org.gvsig.gvsig3d.app.view.ViewProperties3D;
46
import org.gvsig.gvsig3d.impl.map3d.MapContext3DImpl;
47 47
import org.gvsig.gvsig3d.map3d.layers.FLayers3D;
48 48
import org.gvsig.osgvp.viewer.IViewerContainer;
49 49
import org.gvsig.osgvp.viewer.ViewerFactory;
50 50
import org.gvsig.tools.ToolsLocator;
51 51
import org.gvsig.tools.dynobject.DynStruct;
52 52
import org.gvsig.tools.persistence.PersistenceManager;
53
import org.gvsig.tools.persistence.PersistentState;
54
import org.gvsig.tools.persistence.exception.PersistenceException;
53 55

  
54 56
/**
55 57
 * @author AI2
......
80 82
	}
81 83

  
82 84
	public String getTitle() {
83
		return "3D View";
85
		return PluginServices.getText(this, "show_3Dview");
84 86
	}
85 87

  
86 88
	public String getTypeName() {
......
109 111
				.getPreferences().getDefaultProjection());
110 112
		FLayers3D layers = _manager.createDefaultFLayers3DInstance(vp);
111 113
		viewDocument.setMapContext(layers.getMapContext());
112
		viewDocument.setMapOverViewContext(new MapContext(null));
113
		viewDocument.getMapOverViewContext().setProjection(
114
				viewDocument.getMapContext().getProjection());
114
		viewDocument.setMapOverViewContext(new MapContext(new ViewPort(layers
115
				.getMapContext().getProjection())));
115 116
		viewDocument.setName(viewName);
116 117
		viewDocument.setCreationDate(DateFormat.getInstance()
117 118
				.format(new Date()));
......
192 193
				View3DManager.class.getClassLoader().getResource(
193 194
						"images/ProjectView3DSel.png"));
194 195

  
195
		// if (factory.persistenceDefinition == null) {
196
		// factory.persistenceDefinition = manager.addDefinition(
197
		// ViewDocument.class,
198
		// PERSISTENCE_VIEW3D_DOCUMENT_DEFINITION_NAME,
199
		// "Default view 3D document persistence definition", null, null);
200
		// factory.persistenceDefinition
201
		// .extend(manager
202
		// .getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
203
		//
204
		// factory.persistenceDefinition.addDynFieldBoolean("useMapOverview")
205
		// .setMandatory(true);
206
		// factory.persistenceDefinition.addDynFieldObject("mainMapContext")
207
		// .setClassOfValue(MapContext.class).setMandatory(true);
208
		// factory.persistenceDefinition
209
		// .addDynFieldObject("overviewMapContext")
210
		// .setClassOfValue(MapContext.class).setMandatory(false);
211
		//
212
		// }
196
		if (factory.persistenceDefinition == null) {
197
			factory.persistenceDefinition = manager.addDefinition(
198
					ViewDocument.class,
199
					PERSISTENCE_VIEW3D_DOCUMENT_DEFINITION_NAME,
200
					"Default view 3D document persistence definition", null,
201
					null);
202
			factory.persistenceDefinition
203
					.extend(manager
204
							.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
213 205

  
206
			factory.persistenceDefinition.addDynFieldBoolean("useMapOverview")
207
					.setMandatory(true);
208
			factory.persistenceDefinition.addDynFieldObject("mainMapContext")
209
					.setClassOfValue(MapContext3DImpl.class).setMandatory(true);
210
			factory.persistenceDefinition
211
					.addDynFieldObject("overviewMapContext")
212
					.setClassOfValue(MapContext.class).setMandatory(false);
213

  
214
		}
215

  
214 216
	}
215 217

  
216 218
	@SuppressWarnings("rawtypes")
217 219
	public DynStruct getDefinition(String className) {
218 220

  
219
		// if (this.persistenceDefinition.getName().equalsIgnoreCase(className))
220
		// {
221
		// return this.persistenceDefinition;
222
		// }
223
		// if (this.persistenceDefinition.getFullName()
224
		// .equalsIgnoreCase(className)) {
225
		// return this.persistenceDefinition;
226
		// }
227
		// if (this.getDocumentClass().getName().equals(className)) {
228
		// return this.persistenceDefinition;
229
		// }
230
		//
231
		// Class theClass;
232
		// try {
233
		// theClass = (Class) Class.forName(className);
234
		// } catch (ClassNotFoundException e) {
235
		// return null;
236
		// }
237
		// if (this.manages(theClass)) {
238
		// return this.persistenceDefinition;
239
		// }
221
		if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) {
222
			return this.persistenceDefinition;
223
		}
224
		if (this.persistenceDefinition.getFullName()
225
				.equalsIgnoreCase(className)) {
226
			return this.persistenceDefinition;
227
		}
228
		if (this.getDocumentClass().getName().equals(className)) {
229
			return this.persistenceDefinition;
230
		}
240 231

  
232
		Class theClass;
233
		try {
234
			theClass = (Class) Class.forName(className);
235
		} catch (ClassNotFoundException e) {
236
			return null;
237
		}
238
		if (this.manages(theClass)) {
239
			return this.persistenceDefinition;
240
		}
241

  
241 242
		return null;
242 243

  
243 244
	}
244 245

  
245 246
	@SuppressWarnings("rawtypes")
246 247
	protected Class getDocumentClass() {
247
		return DefaultViewDocument.class;
248
		return DefaultView3DDocument.class;
248 249
	}
249 250

  
250
	public Class<IDocumentWindow> getMainWindowClass() {
251
		// TODO Auto-generated method stub
252
		return null;
251
	public Class getMainWindowClass() {
252

  
253
		return DefaultView3DPanel.class;
253 254
	}
254 255

  
255 256
	public boolean manages(Object object) {
256
		// TODO Auto-generated method stub
257
		return false;
257
		return object instanceof ViewDocument;
258 258
	}
259 259

  
260
	public AbstractDocument createDocumentFromState(PersistentState state) {
261

  
262
		String viewName = "View3D";
263
		String aux = PluginServices.getText(this, "untitled");
264
		int numViews = ProjectManager.getInstance().getCurrentProject()
265
				.getDocuments(TYPENAME).size();
266
		viewName = aux + " - " + numViews++;
267

  
268
		// Buscamos si alguna vista ya ten?a este nombre:
269
		while (ProjectManager.getInstance().getCurrentProject()
270
				.getDocument(viewName, TYPENAME) != null) {
271
			viewName = aux + " - " + numViews++;
272
		}
273

  
274
		_manager = Gvsig3DLocator.getManager();
275

  
276
		DefaultView3DDocument viewDocument = new DefaultView3DDocument(this);
277

  
278
		ViewPort vp = _manager.createDefaultViewPort3DInstance(DefaultProject
279
				.getPreferences().getDefaultProjection());
280
		FLayers3D layers = _manager.createDefaultFLayers3DInstance(vp);
281
		viewDocument.setMapContext(layers.getMapContext());
282
		viewDocument.setMapOverViewContext(new MapContext(new ViewPort(layers
283
				.getMapContext().getProjection())));
284
		viewDocument.setName(viewName);
285
		viewDocument.setCreationDate(DateFormat.getInstance()
286
				.format(new Date()));
287

  
288
		return viewDocument;
289
	}
290

  
291
	public Object createFromState(PersistentState state)
292
			throws PersistenceException {
293

  
294
		Document doc = this.createDocumentFromState(state);
295
		return doc;
296
	}
297

  
260 298
}

Also available in: Unified diff