Revision 32462 branches/gvSIG_19_ext3D_osgVP_2_2_0/extensions/ext3Dgui/src/org/gvsig/gvsig3dgui/import3D/CreateNewLayerOSG.java

View differences:

CreateNewLayerOSG.java
1 1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 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
*/
2
 *
3
 * Copyright (C) 2005 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 19

  
20 20
package org.gvsig.gvsig3dgui.import3D;
21 21

  
22
import java.awt.Component;
23
import java.io.File;
24
import java.util.Hashtable;
25
import java.util.Iterator;
26

  
27
import javax.swing.JFileChooser;
28
import javax.swing.JOptionPane;
29
import javax.swing.filechooser.FileFilter;
30

  
31
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
22 32
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
23 33
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG;
24 34
import org.gvsig.gvsig3d.map3d.MapContext3D;
25 35
import org.gvsig.gvsig3dgui.view.View3D;
26 36

  
37
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
38
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
27 39
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
28 40
import com.iver.andami.PluginServices;
29 41
import com.iver.andami.plugins.Extension;
30 42
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException;
31 43
import com.iver.cit.gvsig.fmap.core.FShape;
44

  
32 45
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
46
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
47
import com.iver.cit.gvsig.fmap.layers.LayerListener;
33 48
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
34 49
import com.iver.cit.gvsig.fmap.layers.VectorialDefaultAdapter;
50
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter;
51
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend;
35 52
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
36 53
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
54
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy;
37 55
import com.iver.cit.gvsig.project.documents.view.IProjectView;
38 56

  
39 57
/**
40
 * @author �ngel Fraile Gri��n  e-mail: angel.fraile@iver.es
58
 * @author �ngel Fraile Gri��n e-mail: angel.fraile@iver.es
41 59
 * @since 1.1
42 60
 * 
43 61
 */
44 62
public class CreateNewLayerOSG extends Extension {
45
	private FLyrVect _layerOSG;
63
	protected FLyrVect _layerOSG;
64
	private Hashtable _iveExtensionsSupported = null;
65
	private Hashtable _osgExtensionsSupported = null;
46 66

  
47
	
48 67
	/**
49 68
	 * Creating a new layer OSG editable, ready to insert OSG objects
50 69
	 */
......
55 74
					.getMDIManager().getActiveWindow();
56 75

  
57 76
			if (activeWindow instanceof View3D) {
77
				// Create a file chooser
78

  
79
				JFileChooser jfc = new JFileChooser();
80
				jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
81
				_iveExtensionsSupported = new Hashtable();
82
				_osgExtensionsSupported = new Hashtable();
83
				_iveExtensionsSupported.put("ive", new MyFileFilter("ive",
84
						PluginServices.getText(this, "Ficheros *.ive"), "ive"));
85
				_osgExtensionsSupported.put("osg", new MyFileFilter("osg",
86
						PluginServices.getText(this, "Ficheros *.osg"), "osg"));
87

  
88
				Iterator iter = _osgExtensionsSupported.values().iterator();
89
				while (iter.hasNext()) {
90
					jfc.addChoosableFileFilter((FileFilter) iter.next());
91
				}
92

  
93
				iter = _iveExtensionsSupported.values().iterator();
94
				while (iter.hasNext()) {
95
					jfc.addChoosableFileFilter((FileFilter) iter.next());
96
				}
97
				File f = null;
98
				if (jfc.showSaveDialog((Component) PluginServices
99
						.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
100
					f = jfc.getSelectedFile();
101
					if (f.exists()) {// file exists in the directory.
102
						int resp = JOptionPane
103
								.showConfirmDialog(
104
										(Component) PluginServices
105
												.getMainFrame(),
106
										PluginServices
107
												.getText(this,
108
														"fichero_ya_existe_seguro_desea_guardarlo")
109
												+ "\n" + f.getAbsolutePath(),
110
										PluginServices.getText(this, "guardar"),
111
										JOptionPane.YES_NO_OPTION);
112
						if (resp != JOptionPane.YES_OPTION) {// cancel pressed.
113
							return;
114
						}
115
					}// if exits.
116
					MyFileFilter filter = (MyFileFilter) jfc.getFileFilter();// ive,
117
																				// osg
118
					f = filter.normalizeExtension(f);
119
				}
58 120
				GvsigDriverOSG d = new GvsigDriverOSG();
59
				VectorialAdapter adapter = new VectorialDefaultAdapter();
121
				try {
122
					d.open(f);
123
				} catch (OpenDriverException e2) {
124
					// TODO Auto-generated catch block
125
					e2.printStackTrace();
126
				}
127
				try {
128
					d.initialize();
129
				} catch (ReadDriverException e1) {
130
					// TODO Auto-generated catch block
131
					e1.printStackTrace();
132
				}
133
				VectorialAdapter adapter = new VectorialFileAdapter(f);
60 134
				adapter.setDriver(d);
61

  
62
				_layerOSG = new FLyrVect() {
63
					@Override
64
					public boolean isPropertiesMenuVisible() {
65
						// TODO Auto-generated method stub
66
						return false;
67
					}
68
				};
135
				// LayerFactory.registerLayerClassForName("com.iver.ai2.gvsig3d.map3d.layers.OSGFLyrVect",
136
				// OSGFLyrVect.class);
137
				_layerOSG = new FLyrVect(); // {
138
				// @Override
139
				// public boolean isPropertiesMenuVisible() {
140
				// // TODO Auto-generated method stub
141
				// return false;
142
				// }
143
				// };
69 144
				View3D vista = (View3D) PluginServices.getMDIManager()
70 145
						.getActiveWindow();
71 146
				IProjectView model = vista.getModel();
72 147

  
73 148
				MapContext3D mapa = (MapContext3D) model.getMapContext();
74
				_layerOSG.setName("defaultLayerOSG");
149
				_layerOSG.setName(f.getName());
75 150
				_layerOSG.setSource(adapter);
76

  
151
				try {
152
					_layerOSG.setLegend((IVectorLegend) d.getDefaultLegend());
153
					_layerOSG.setLabelingStrategy(d
154
							.getDefaultLabelingStrategy());
155
				} catch (LegendLayerException e) {
156
					// TODO Auto-generated catch block
157
					e.printStackTrace();
158
				}
77 159
				// add 3D properties, mainly to keep track of hooked state
78 160
				Layer3DProps props3D = new Layer3DProps();
79 161
				props3D.setType(Layer3DProps.layer3DOSG);
......
83 165
				_layerOSG.setProperty("3DLayerExtension", props3D);
84 166
				_layerOSG.setProjection(mapa.getProjection());
85 167
				mapa.getLayers().addLayer(_layerOSG);
86

  
87 168
				OSGCacheService osgCacheService = (OSGCacheService) props3D
88 169
						.getCacheService();
89 170
				osgCacheService.startEditing();
......
129 210
		return false;
130 211

  
131 212
	}
132
	
133
	
134 213

  
135 214
}

Also available in: Unified diff