19 |
19 |
|
20 |
20 |
package org.gvsig.gvsig3dgui.import3D;
|
21 |
21 |
|
|
22 |
import java.awt.BorderLayout;
|
22 |
23 |
import java.awt.Component;
|
|
24 |
import java.awt.FlowLayout;
|
23 |
25 |
import java.awt.GridBagConstraints;
|
|
26 |
import java.awt.GridLayout;
|
24 |
27 |
import java.awt.event.ActionEvent;
|
25 |
28 |
import java.awt.event.ActionListener;
|
26 |
29 |
import java.awt.event.KeyEvent;
|
... | ... | |
34 |
37 |
import javax.swing.JOptionPane;
|
35 |
38 |
import javax.swing.JPanel;
|
36 |
39 |
import javax.swing.JTextField;
|
37 |
|
import javax.swing.SwingConstants;
|
|
40 |
import javax.swing.border.TitledBorder;
|
38 |
41 |
import javax.swing.filechooser.FileFilter;
|
39 |
42 |
|
|
43 |
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
|
40 |
44 |
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG;
|
|
45 |
import org.gvsig.gvsig3d.map3d.MapContext3D;
|
|
46 |
import org.gvsig.gvsig3dgui.view.View3D;
|
41 |
47 |
import org.gvsig.osgvp.core.osg.Group;
|
42 |
48 |
import org.gvsig.osgvp.core.osgdb.osgDB;
|
43 |
49 |
import org.gvsig.osgvp.exceptions.node.SaveNodeException;
|
... | ... | |
46 |
52 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
|
47 |
53 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
|
48 |
54 |
import com.iver.andami.PluginServices;
|
49 |
|
import com.iver.andami.plugins.IExtension;
|
50 |
55 |
import com.iver.andami.ui.mdiManager.IWindow;
|
51 |
56 |
import com.iver.andami.ui.mdiManager.WindowInfo;
|
|
57 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException;
|
52 |
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;
|
53 |
63 |
|
54 |
|
public class CreateNewLayerOSGPanel extends JPanel implements IWindow,
|
55 |
|
ActionListener {
|
|
64 |
public class CreateNewLayerOSGPanel extends JPanel implements IWindow{
|
56 |
65 |
|
57 |
66 |
private WindowInfo windowInfo = null;
|
58 |
67 |
private JLabel jLabelLayerPath = null;
|
... | ... | |
62 |
71 |
private JButton closeButton = null;
|
63 |
72 |
private JPanel buttonsPanel = null;
|
64 |
73 |
private File file = null;
|
|
74 |
|
|
75 |
private MapContext3D mapa = null;
|
65 |
76 |
|
66 |
77 |
private static final long serialVersionUID = 1L;
|
67 |
78 |
|
68 |
|
public CreateNewLayerOSGPanel() {
|
|
79 |
public CreateNewLayerOSGPanel(MapContext3D m) {
|
69 |
80 |
super();
|
|
81 |
mapa = m;
|
70 |
82 |
initialize();
|
71 |
83 |
}
|
72 |
84 |
|
73 |
85 |
public void initialize() {
|
74 |
|
this.setLayout(null);
|
|
86 |
setLayout(new BorderLayout(5,5));
|
|
87 |
|
|
88 |
JPanel contentPanel = new JPanel();
|
|
89 |
contentPanel.setLayout(new GridLayout(4, 1));
|
|
90 |
|
75 |
91 |
// Label
|
76 |
92 |
jLabelLayerPath = new JLabel();
|
77 |
|
jLabelLayerPath.setBounds(new java.awt.Rectangle(14, 9, 370, 22));
|
78 |
93 |
jLabelLayerPath.setText(PluginServices
|
79 |
94 |
.getText(this, "enter_layer_path"));
|
80 |
95 |
this.add(jLabelLayerPath, null);
|
81 |
|
// File path
|
82 |
|
this.add(getJTextFieldPath(), null);
|
83 |
|
this.add(getJButtonSelectPath(), 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 |
|
84 |
108 |
// Label
|
85 |
109 |
jLabelLayerPath = new JLabel();
|
86 |
|
jLabelLayerPath.setBounds(new java.awt.Rectangle(14, 66, 370, 22));
|
87 |
110 |
jLabelLayerPath.setText(PluginServices.getText(this,
|
88 |
111 |
"remember_save_layer"));
|
89 |
|
this.add(jLabelLayerPath, null);
|
|
112 |
contentPanel.add(jLabelLayerPath);
|
|
113 |
|
90 |
114 |
// Accpet buttons
|
91 |
|
this.add(getButtonsPanel());
|
|
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);
|
92 |
123 |
|
93 |
124 |
}
|
94 |
125 |
|
... | ... | |
100 |
131 |
private JTextField getJTextFieldPath() {
|
101 |
132 |
if (jTextFieldPath == null) {
|
102 |
133 |
jTextFieldPath = new JTextField();
|
103 |
|
jTextFieldPath.setPreferredSize(new java.awt.Dimension(210, 20));
|
104 |
|
jTextFieldPath.setBounds(new java.awt.Rectangle(12, 38, 338, 23));
|
|
134 |
jTextFieldPath.setBounds(new java.awt.Rectangle(12, 10, 338, 23));
|
105 |
135 |
jTextFieldPath.addKeyListener(new java.awt.event.KeyAdapter() {
|
106 |
136 |
public void keyReleased(KeyEvent arg0) {
|
107 |
137 |
if (!jTextFieldPath.getText().equals(""))
|
... | ... | |
125 |
155 |
jButtonSelectPath = new JButton();
|
126 |
156 |
jButtonSelectPath.setText("...");
|
127 |
157 |
jButtonSelectPath
|
128 |
|
.setBounds(new java.awt.Rectangle(355, 38, 32, 22));
|
|
158 |
.setBounds(new java.awt.Rectangle(355, 10, 32, 22));
|
129 |
159 |
jButtonSelectPath
|
130 |
160 |
.addActionListener(new java.awt.event.ActionListener() {
|
131 |
161 |
public void actionPerformed(java.awt.event.ActionEvent e) {
|
... | ... | |
209 |
239 |
acceptButton = new JButton();
|
210 |
240 |
acceptButton.setEnabled(false);
|
211 |
241 |
acceptButton.setText(PluginServices.getText(this, "accept"));
|
212 |
|
acceptButton.addActionListener(this);
|
213 |
|
acceptButton.setActionCommand("a");
|
|
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();
|
214 |
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 |
mapa.getLayers().addLayer(layerOSG);
|
|
289 |
|
|
290 |
Group node = new Group();
|
|
291 |
try {
|
|
292 |
osgDB.writeNodeFile(node, file.getAbsolutePath());
|
|
293 |
} catch (SaveNodeException sne) {
|
|
294 |
// TODO Auto-generated catch block
|
|
295 |
sne.printStackTrace();
|
|
296 |
}
|
|
297 |
|
|
298 |
PluginServices.getMDIManager().closeWindow(CreateNewLayerOSGPanel.this);
|
|
299 |
|
|
300 |
file = null;
|
|
301 |
}
|
|
302 |
});
|
|
303 |
|
215 |
304 |
closeButton = new JButton();
|
216 |
305 |
closeButton.setText(PluginServices.getText(this, "close"));
|
217 |
|
closeButton.addActionListener(this);
|
218 |
|
closeButton.setActionCommand("c");
|
|
306 |
closeButton.setBounds(new java.awt.Rectangle(10, 10, 50, 22));
|
|
307 |
closeButton.addActionListener(new ActionListener() {
|
|
308 |
public void actionPerformed(ActionEvent e) {
|
|
309 |
PluginServices.getMDIManager().closeWindow(CreateNewLayerOSGPanel.this);
|
|
310 |
}
|
|
311 |
});
|
|
312 |
|
|
313 |
JPanel panelButtonsAux = new JPanel();
|
|
314 |
panelButtonsAux.setLayout(new GridLayout(1, 2, 5, 5));
|
219 |
315 |
|
|
316 |
panelButtonsAux.add(acceptButton);
|
|
317 |
panelButtonsAux.add(closeButton);
|
|
318 |
|
220 |
319 |
buttonsPanel = new JPanel();
|
221 |
|
|
222 |
|
buttonsPanel.setBounds(new java.awt.Rectangle(12, 90, 370, 23));
|
223 |
|
buttonsPanel.setLayout(new java.awt.GridBagLayout());
|
224 |
|
|
225 |
|
GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
|
226 |
|
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2);
|
227 |
|
buttonsPanel.add(acceptButton, gridBagConstraints);
|
228 |
|
|
229 |
|
gridBagConstraints = new java.awt.GridBagConstraints();
|
230 |
|
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2);
|
231 |
|
buttonsPanel.add(closeButton, gridBagConstraints);
|
|
320 |
buttonsPanel.setLayout(new BorderLayout());
|
|
321 |
|
|
322 |
buttonsPanel.add(panelButtonsAux, BorderLayout.EAST);
|
232 |
323 |
}
|
233 |
324 |
|
234 |
325 |
return buttonsPanel;
|
... | ... | |
236 |
327 |
|
237 |
328 |
public WindowInfo getWindowInfo() {
|
238 |
329 |
if (windowInfo == null) {
|
239 |
|
windowInfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
240 |
|
windowInfo.setWidth(400);
|
241 |
|
windowInfo.setHeight(82);
|
|
330 |
windowInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
|
331 |
windowInfo.setWidth(410);
|
|
332 |
windowInfo.setHeight(120);
|
242 |
333 |
windowInfo.setTitle(PluginServices.getText(this, "Crear_capa_osg"));
|
243 |
334 |
}
|
244 |
335 |
return windowInfo;
|
... | ... | |
247 |
338 |
public Object getWindowProfile() {
|
248 |
339 |
return WindowInfo.DIALOG_PROFILE;
|
249 |
340 |
}
|
250 |
|
|
251 |
|
public void actionPerformed(ActionEvent e) {
|
252 |
|
if (e.getActionCommand().equals("a")) {
|
253 |
|
acceptButtonActionPerformed();
|
254 |
|
} else if (e.getActionCommand().equals("c")) {
|
255 |
|
closeButtonActionPerformed();
|
256 |
|
}
|
257 |
|
}
|
258 |
|
|
259 |
|
public void acceptButtonActionPerformed() {
|
260 |
|
CreateNewLayerOSG createNewLayerOSGExtension = (CreateNewLayerOSG) PluginServices
|
261 |
|
.getExtension(CreateNewLayerOSG.class);
|
262 |
|
closeButtonActionPerformed();
|
263 |
|
if (createNewLayerOSGExtension != null) {
|
264 |
|
createNewLayerOSGExtension.setFile(file);
|
265 |
|
createNewLayerOSGExtension.execute("GUARDARCAPA");
|
266 |
|
|
267 |
|
}
|
268 |
|
|
269 |
|
Group node = new Group();
|
270 |
|
try {
|
271 |
|
osgDB.writeNodeFile(node, file.getAbsolutePath());
|
272 |
|
} catch (SaveNodeException e) {
|
273 |
|
// TODO Auto-generated catch block
|
274 |
|
e.printStackTrace();
|
275 |
|
}
|
276 |
|
|
277 |
|
file = null;
|
278 |
|
|
279 |
|
}
|
280 |
|
|
281 |
|
public void closeButtonActionPerformed() {
|
282 |
|
PluginServices.getMDIManager().closeWindow(this);
|
283 |
|
}
|
284 |
341 |
}
|