gvsig-3d / 1.10 / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / import3D / CreateNewLayerOSGPanel.java @ 112
History | View | Annotate | Download (10.5 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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 |
|
20 |
package org.gvsig.gvsig3dgui.import3D; |
21 |
|
22 |
import java.awt.BorderLayout; |
23 |
import java.awt.Component; |
24 |
import java.awt.FlowLayout; |
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.GridLayout; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import java.awt.event.KeyEvent; |
30 |
import java.io.File; |
31 |
import java.util.Hashtable; |
32 |
import java.util.Iterator; |
33 |
|
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JFileChooser; |
36 |
import javax.swing.JLabel; |
37 |
import javax.swing.JOptionPane; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JTextField; |
40 |
import javax.swing.border.TitledBorder; |
41 |
import javax.swing.filechooser.FileFilter; |
42 |
|
43 |
import org.gvsig.gvsig3d.cacheservices.OSGCacheService; |
44 |
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG; |
45 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
46 |
import org.gvsig.gvsig3dgui.view.View3D; |
47 |
import org.gvsig.osgvp.core.osg.Group; |
48 |
import org.gvsig.osgvp.core.osgdb.osgDB; |
49 |
import org.gvsig.osgvp.exceptions.node.SaveNodeException; |
50 |
|
51 |
import com.hardcode.gdbms.driver.exceptions.OpenDriverException; |
52 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
53 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.andami.ui.mdiManager.IWindow; |
56 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
57 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
59 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
60 |
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
61 |
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
62 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
63 |
|
64 |
public class CreateNewLayerOSGPanel extends JPanel implements IWindow{ |
65 |
|
66 |
private WindowInfo windowInfo = null; |
67 |
private JLabel jLabelLayerPath = null; |
68 |
private JTextField jTextFieldPath = null; |
69 |
private JButton jButtonSelectPath = null; |
70 |
private JButton acceptButton = null; |
71 |
private JButton closeButton = null; |
72 |
private JPanel buttonsPanel = null; |
73 |
private File file = null; |
74 |
|
75 |
private MapContext3D mapa = null; |
76 |
|
77 |
private static final long serialVersionUID = 1L; |
78 |
|
79 |
public CreateNewLayerOSGPanel(MapContext3D m) {
|
80 |
super();
|
81 |
mapa = m; |
82 |
initialize(); |
83 |
} |
84 |
|
85 |
public void initialize() { |
86 |
setLayout(new BorderLayout(5,5)); |
87 |
|
88 |
JPanel contentPanel = new JPanel(); |
89 |
contentPanel.setLayout(new GridLayout(4, 1)); |
90 |
|
91 |
// Label
|
92 |
jLabelLayerPath = new JLabel(); |
93 |
jLabelLayerPath.setText(PluginServices |
94 |
.getText(this, "enter_layer_path")); |
95 |
this.add(jLabelLayerPath, null); |
96 |
|
97 |
contentPanel.add(jLabelLayerPath); |
98 |
|
99 |
// File panel
|
100 |
JPanel filePanel = new JPanel(); |
101 |
filePanel.setLayout(new BorderLayout(5,5)); |
102 |
|
103 |
filePanel.add(getJTextFieldPath(), BorderLayout.CENTER);
|
104 |
filePanel.add(getJButtonSelectPath(), BorderLayout.EAST);
|
105 |
|
106 |
contentPanel.add(filePanel); |
107 |
|
108 |
// Label
|
109 |
jLabelLayerPath = new JLabel(); |
110 |
jLabelLayerPath.setText(PluginServices.getText(this,
|
111 |
"remember_save_layer"));
|
112 |
contentPanel.add(jLabelLayerPath); |
113 |
|
114 |
// Accpet buttons
|
115 |
contentPanel.add(getButtonsPanel()); |
116 |
|
117 |
//Void panel
|
118 |
JPanel voidPanel = new JPanel(); |
119 |
voidPanel.setLayout(null);
|
120 |
|
121 |
add(contentPanel, BorderLayout.NORTH);
|
122 |
add(voidPanel, BorderLayout.CENTER);
|
123 |
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* This method initializes jTextFieldPath
|
128 |
*
|
129 |
* @return javax.swing.JTextField
|
130 |
*/
|
131 |
private JTextField getJTextFieldPath() { |
132 |
if (jTextFieldPath == null) { |
133 |
jTextFieldPath = new JTextField(); |
134 |
jTextFieldPath.setBounds(new java.awt.Rectangle(12, 10, 338, 23)); |
135 |
jTextFieldPath.addKeyListener(new java.awt.event.KeyAdapter() {
|
136 |
public void keyReleased(KeyEvent arg0) { |
137 |
if (!jTextFieldPath.getText().equals("")) |
138 |
acceptButton.setEnabled(true);
|
139 |
else
|
140 |
acceptButton.setEnabled(false);
|
141 |
} |
142 |
|
143 |
}); |
144 |
} |
145 |
return jTextFieldPath;
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* This method initializes jButtonSelectPath
|
150 |
*
|
151 |
* @return javax.swing.JButton
|
152 |
*/
|
153 |
private JButton getJButtonSelectPath() { |
154 |
if (jButtonSelectPath == null) { |
155 |
jButtonSelectPath = new JButton(); |
156 |
jButtonSelectPath.setText("...");
|
157 |
jButtonSelectPath |
158 |
.setBounds(new java.awt.Rectangle(355, 10, 32, 22)); |
159 |
jButtonSelectPath |
160 |
.addActionListener(new java.awt.event.ActionListener() {
|
161 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
162 |
JFileChooser jfc = new JFileChooser(); |
163 |
jfc.removeChoosableFileFilter(jfc |
164 |
.getAcceptAllFileFilter()); |
165 |
|
166 |
// Add supported extensions
|
167 |
Hashtable _iveExtensionsSupported = new Hashtable(); |
168 |
Hashtable _osgExtensionsSupported = new Hashtable(); |
169 |
_iveExtensionsSupported.put("ive",
|
170 |
new MyFileFilter("ive", PluginServices |
171 |
.getText(this, "Ficheros *.ive"), |
172 |
"ive"));
|
173 |
_osgExtensionsSupported.put("osg",
|
174 |
new MyFileFilter("osg", PluginServices |
175 |
.getText(this, "Ficheros *.osg"), |
176 |
"osg"));
|
177 |
|
178 |
Iterator iter = _osgExtensionsSupported.values()
|
179 |
.iterator(); |
180 |
while (iter.hasNext()) {
|
181 |
jfc.addChoosableFileFilter((FileFilter) iter
|
182 |
.next()); |
183 |
} |
184 |
|
185 |
iter = _iveExtensionsSupported.values().iterator(); |
186 |
while (iter.hasNext()) {
|
187 |
jfc.addChoosableFileFilter((FileFilter) iter
|
188 |
.next()); |
189 |
} |
190 |
|
191 |
if (jfc.showSaveDialog((Component) PluginServices |
192 |
.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
193 |
file = jfc.getSelectedFile(); |
194 |
if (file.exists()) {// file exists in the |
195 |
// directory.
|
196 |
int resp = JOptionPane |
197 |
.showConfirmDialog( |
198 |
(Component) PluginServices
|
199 |
.getMainFrame(), |
200 |
PluginServices |
201 |
.getText(this,
|
202 |
"fichero_ya_existe_seguro_desea_guardarlo")
|
203 |
+ "\n"
|
204 |
+ file |
205 |
.getAbsolutePath(), |
206 |
PluginServices.getText( |
207 |
this, "guardar"), |
208 |
JOptionPane.YES_NO_OPTION);
|
209 |
if (resp != JOptionPane.YES_OPTION) {// cancel |
210 |
// pressed.
|
211 |
return;
|
212 |
} |
213 |
}// if exits.
|
214 |
MyFileFilter filter = (MyFileFilter) jfc |
215 |
.getFileFilter();// ive,
|
216 |
// osg
|
217 |
file = filter.normalizeExtension(file); |
218 |
jTextFieldPath.setText(file.getAbsolutePath()); |
219 |
acceptButton.setEnabled(true);
|
220 |
} else {
|
221 |
acceptButton.setEnabled(false);
|
222 |
} |
223 |
|
224 |
} |
225 |
}); |
226 |
} |
227 |
return jButtonSelectPath;
|
228 |
} |
229 |
|
230 |
/**
|
231 |
* Initialize buttons panel
|
232 |
*
|
233 |
* @return
|
234 |
*/
|
235 |
public JPanel getButtonsPanel() { |
236 |
|
237 |
if (buttonsPanel == null) { |
238 |
|
239 |
acceptButton = new JButton(); |
240 |
acceptButton.setEnabled(false);
|
241 |
acceptButton.setText(PluginServices.getText(this, "accept")); |
242 |
acceptButton.setBounds(new java.awt.Rectangle(10, 10, 50, 22)); |
243 |
acceptButton.addActionListener(new ActionListener() { |
244 |
public void actionPerformed(ActionEvent e) { |
245 |
|
246 |
if(file == null) return; |
247 |
|
248 |
GvsigDriverOSG d = new GvsigDriverOSG();
|
249 |
try {
|
250 |
d.open(file); |
251 |
} catch (OpenDriverException e2) {
|
252 |
// TODO Auto-generated catch block
|
253 |
e2.printStackTrace(); |
254 |
} |
255 |
try {
|
256 |
d.initialize(); |
257 |
} catch (ReadDriverException e1) {
|
258 |
// TODO Auto-generated catch block
|
259 |
e1.printStackTrace(); |
260 |
} |
261 |
|
262 |
if (mapa == null) return; |
263 |
|
264 |
VectorialAdapter adapter = new VectorialFileAdapter(file);
|
265 |
adapter.setDriver(d); |
266 |
|
267 |
FLyrVect layerOSG = new FLyrVect();
|
268 |
|
269 |
layerOSG.setName(file.getName()); |
270 |
layerOSG.setSource(adapter); |
271 |
try {
|
272 |
layerOSG.setLegend((IVectorLegend) d.getDefaultLegend()); |
273 |
layerOSG.setLabelingStrategy(d |
274 |
.getDefaultLabelingStrategy()); |
275 |
} catch (LegendLayerException ex) {
|
276 |
// TODO Auto-generated catch block
|
277 |
ex.printStackTrace(); |
278 |
} |
279 |
|
280 |
// add 3D properties, mainly to keep track of hooked state
|
281 |
Layer3DProps props3D = new Layer3DProps();
|
282 |
props3D.setType(Layer3DProps.layer3DOSG); |
283 |
props3D.setChooseType(false);
|
284 |
props3D.setLayer(layerOSG); |
285 |
props3D.setNewLayerOSG(true);
|
286 |
layerOSG.setProperty("3DLayerExtension", props3D);
|
287 |
layerOSG.setProjection(mapa.getProjection()); |
288 |
|
289 |
Group node = new Group(); |
290 |
try {
|
291 |
osgDB.writeNodeFile(node, file.getAbsolutePath()); |
292 |
} catch (SaveNodeException sne) {
|
293 |
// TODO Auto-generated catch block
|
294 |
sne.printStackTrace(); |
295 |
} |
296 |
|
297 |
mapa.getLayers().addLayer(layerOSG); |
298 |
|
299 |
PluginServices.getMDIManager().closeWindow(CreateNewLayerOSGPanel.this); |
300 |
|
301 |
file = null;
|
302 |
} |
303 |
}); |
304 |
|
305 |
closeButton = new JButton(); |
306 |
closeButton.setText(PluginServices.getText(this, "close")); |
307 |
closeButton.setBounds(new java.awt.Rectangle(10, 10, 50, 22)); |
308 |
closeButton.addActionListener(new ActionListener() { |
309 |
public void actionPerformed(ActionEvent e) { |
310 |
PluginServices.getMDIManager().closeWindow(CreateNewLayerOSGPanel.this); |
311 |
} |
312 |
}); |
313 |
|
314 |
JPanel panelButtonsAux = new JPanel(); |
315 |
panelButtonsAux.setLayout(new GridLayout(1, 2, 5, 5)); |
316 |
|
317 |
panelButtonsAux.add(acceptButton); |
318 |
panelButtonsAux.add(closeButton); |
319 |
|
320 |
buttonsPanel = new JPanel(); |
321 |
buttonsPanel.setLayout(new BorderLayout()); |
322 |
|
323 |
buttonsPanel.add(panelButtonsAux, BorderLayout.EAST);
|
324 |
} |
325 |
|
326 |
return buttonsPanel;
|
327 |
} |
328 |
|
329 |
public WindowInfo getWindowInfo() {
|
330 |
if (windowInfo == null) { |
331 |
windowInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
332 |
windowInfo.setWidth(410);
|
333 |
windowInfo.setHeight(120);
|
334 |
windowInfo.setTitle(PluginServices.getText(this, "Crear_capa_osg")); |
335 |
} |
336 |
return windowInfo;
|
337 |
} |
338 |
|
339 |
public Object getWindowProfile() { |
340 |
return WindowInfo.DIALOG_PROFILE;
|
341 |
} |
342 |
} |