gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / gui / styling / Object3DSymbolTab.java @ 345
History | View | Annotate | Download (9.97 KB)
1 |
package org.gvsig.gvsig3d.app.gui.styling; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.GridBagConstraints; |
7 |
import java.awt.GridBagLayout; |
8 |
import java.awt.GridLayout; |
9 |
import java.awt.Insets; |
10 |
import java.awt.event.ActionEvent; |
11 |
import java.awt.event.ActionListener; |
12 |
import java.io.File; |
13 |
import java.io.FileNotFoundException; |
14 |
|
15 |
import javax.swing.JButton; |
16 |
import javax.swing.JFileChooser; |
17 |
import javax.swing.JLabel; |
18 |
import javax.swing.JPanel; |
19 |
import javax.swing.JRadioButton; |
20 |
import javax.swing.JSpinner; |
21 |
import javax.swing.JTabbedPane; |
22 |
import javax.swing.JTextField; |
23 |
import javax.swing.SpinnerNumberModel; |
24 |
import javax.swing.border.TitledBorder; |
25 |
import javax.swing.filechooser.FileFilter; |
26 |
|
27 |
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.NodeMarker3DSymbol; |
28 |
import org.gvsig.gvsig3d.symbology3d.I3DSymbol; |
29 |
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol; |
30 |
import org.gvsig.osgvp.core.osg.Group; |
31 |
import org.gvsig.osgvp.core.osg.Node; |
32 |
import org.gvsig.osgvp.core.osgdb.osgDB; |
33 |
import org.gvsig.osgvp.exceptions.node.LoadNodeException; |
34 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
35 |
import org.gvsig.osgvp.viewer.ViewerFactory; |
36 |
import javax.swing.JComboBox; |
37 |
import javax.swing.DefaultComboBoxModel; |
38 |
|
39 |
public class Object3DSymbolTab extends JPanel implements ISymbolSelectorTab { |
40 |
|
41 |
private JTextField textField; |
42 |
|
43 |
private IViewerContainer _canvas3d;
|
44 |
private IViewerContainer _alternateCanvas3d;
|
45 |
|
46 |
private ISimpleMarker3DSymbol _symbol;
|
47 |
private String _nodeURL = ""; |
48 |
|
49 |
private JSpinner sizeSpinner; |
50 |
|
51 |
private JComboBox _comboBox; |
52 |
|
53 |
/**
|
54 |
* Create the panel.
|
55 |
*/
|
56 |
public Object3DSymbolTab(Component parent) { |
57 |
setLayout(new BorderLayout(0, 0)); |
58 |
|
59 |
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); |
60 |
tabbedPane.setPreferredSize(new Dimension(180, 300)); |
61 |
add(tabbedPane, BorderLayout.CENTER);
|
62 |
|
63 |
JPanel panel = new JPanel(); |
64 |
tabbedPane.addTab("Marker", null, panel, null); |
65 |
GridBagLayout gbl_panel = new GridBagLayout(); |
66 |
gbl_panel.columnWidths = new int[] { 175 }; |
67 |
gbl_panel.rowHeights = new int[] { 180, 70 }; |
68 |
gbl_panel.columnWeights = new double[] { 0.0 }; |
69 |
gbl_panel.rowWeights = new double[] { 0.0, 0.0 }; |
70 |
panel.setLayout(gbl_panel); |
71 |
|
72 |
JPanel panel_2 = new JPanel(); |
73 |
panel_2.setBorder(new TitledBorder(null, "Preview", |
74 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
75 |
GridBagConstraints gbc_panel_2 = new GridBagConstraints(); |
76 |
gbc_panel_2.insets = new Insets(0, 0, 5, 5); |
77 |
gbc_panel_2.fill = GridBagConstraints.BOTH;
|
78 |
gbc_panel_2.gridx = 0;
|
79 |
gbc_panel_2.gridy = 0;
|
80 |
panel.add(panel_2, gbc_panel_2); |
81 |
panel_2.setLayout(new BorderLayout(0, 0)); |
82 |
|
83 |
JPanel panel_8 = getOsgPanel();
|
84 |
panel_2.add(panel_8, BorderLayout.CENTER);
|
85 |
|
86 |
JPanel propertiesPanel = new JPanel(); |
87 |
propertiesPanel.setBorder(new TitledBorder(null, "Properties", |
88 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
89 |
GridBagConstraints gbc_propertiesPanel = new GridBagConstraints(); |
90 |
gbc_propertiesPanel.fill = GridBagConstraints.HORIZONTAL;
|
91 |
gbc_propertiesPanel.ipady = 10;
|
92 |
gbc_propertiesPanel.ipadx = 10;
|
93 |
gbc_propertiesPanel.insets = new Insets(0, 0, 0, 5); |
94 |
gbc_propertiesPanel.anchor = GridBagConstraints.NORTHWEST;
|
95 |
gbc_propertiesPanel.gridx = 0;
|
96 |
gbc_propertiesPanel.gridy = 1;
|
97 |
panel.add(propertiesPanel, gbc_propertiesPanel); |
98 |
propertiesPanel.setLayout(new GridLayout(0, 3, 10, 10)); |
99 |
|
100 |
JLabel lblNewLabel_1 = new JLabel("Path:"); |
101 |
propertiesPanel.add(lblNewLabel_1); |
102 |
|
103 |
textField = new JTextField(); |
104 |
textField.setEditable(false);
|
105 |
// textField.setText(_nodeURL);
|
106 |
propertiesPanel.add(textField); |
107 |
textField.setColumns(10);
|
108 |
|
109 |
JButton btnBrowse = new JButton("Browse"); |
110 |
btnBrowse.addActionListener(new ActionListener() { |
111 |
public void actionPerformed(ActionEvent e) { |
112 |
|
113 |
JFileChooser fc = new JFileChooser(); |
114 |
FileFilter ff = new TypeFileFilter(); |
115 |
fc.setFileFilter(ff); |
116 |
|
117 |
int returnVal = fc.showDialog(Object3DSymbolTab.this, "Accept"); |
118 |
|
119 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
120 |
File file = fc.getSelectedFile();
|
121 |
_nodeURL = file.getAbsolutePath(); |
122 |
try {
|
123 |
Node node = osgDB.readNodeFile(_nodeURL); |
124 |
_canvas3d.getOSGViewer().setSceneData(node); |
125 |
} catch (LoadNodeException e1) {
|
126 |
// TODO Auto-generated catch block
|
127 |
e1.printStackTrace(); |
128 |
} catch (FileNotFoundException e1) { |
129 |
// TODO Auto-generated catch block
|
130 |
e1.printStackTrace(); |
131 |
} |
132 |
textField.setText(_nodeURL); |
133 |
|
134 |
} else {
|
135 |
|
136 |
} |
137 |
|
138 |
// _symbol.setColor(newColor);
|
139 |
// _colorPanel.setBackground(newColor);
|
140 |
// _colorPanel.repaint();
|
141 |
// symbolPreviewPanel.repaint();
|
142 |
// ((SymbolSelector3D) _parent).setSymbol(_symbol);
|
143 |
|
144 |
} |
145 |
}); |
146 |
propertiesPanel.add(btnBrowse); |
147 |
|
148 |
JLabel lblSize = new JLabel("Scale Factor:"); |
149 |
propertiesPanel.add(lblSize); |
150 |
|
151 |
JPanel panel_3 = new JPanel(); |
152 |
propertiesPanel.add(panel_3); |
153 |
panel_3.setLayout(new BorderLayout(0, 0)); |
154 |
|
155 |
sizeSpinner = new JSpinner(); |
156 |
sizeSpinner.setModel(new SpinnerNumberModel(1.0, 1.0, 1000.0, 1.0)); |
157 |
panel_3.add(sizeSpinner); |
158 |
|
159 |
propertiesPanel.setPreferredSize(new Dimension(80, 80)); |
160 |
|
161 |
JPanel panel_4 = new JPanel(); |
162 |
tabbedPane.addTab("Collection", null, panel_4, null); |
163 |
GridBagLayout gbl_panel_4 = new GridBagLayout(); |
164 |
gbl_panel_4.columnWidths = new int[] { 175 }; |
165 |
gbl_panel_4.rowHeights = new int[] { 250, 45 }; |
166 |
gbl_panel_4.columnWeights = new double[] { 1.0 }; |
167 |
gbl_panel_4.rowWeights = new double[] { 1.0, 0.0 }; |
168 |
panel_4.setLayout(gbl_panel_4); |
169 |
|
170 |
JPanel panel_1 = new JPanel(); |
171 |
panel_1.setBorder(new TitledBorder(null, "Preview", |
172 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
173 |
GridBagConstraints gbc_panel_1 = new GridBagConstraints(); |
174 |
gbc_panel_1.insets = new Insets(0, 0, 5, 0); |
175 |
gbc_panel_1.fill = GridBagConstraints.BOTH;
|
176 |
gbc_panel_1.gridx = 0;
|
177 |
gbc_panel_1.gridy = 0;
|
178 |
panel_4.add(panel_1, gbc_panel_1); |
179 |
panel_1.setLayout(new BorderLayout(0, 0)); |
180 |
|
181 |
panel_1.add(getAlternateOsgPanel()); |
182 |
|
183 |
_comboBox = new JComboBox(); |
184 |
_comboBox.addActionListener(new ActionListener() { |
185 |
public void actionPerformed(ActionEvent arg0) { |
186 |
|
187 |
if (arg0.getSource() instanceof JComboBox) { |
188 |
switch (_comboBox.getSelectedIndex()) {
|
189 |
|
190 |
case 0: |
191 |
_nodeURL = Object3DSymbolTab.class.getResource( |
192 |
"/particle/fire.osgb").getPath();
|
193 |
break;
|
194 |
case 1: |
195 |
_nodeURL = Object3DSymbolTab.class.getResource( |
196 |
"/particle/radial.osgb").getPath();
|
197 |
break;
|
198 |
case 2: |
199 |
_nodeURL = Object3DSymbolTab.class.getResource( |
200 |
"/particle/space.osgb").getPath();
|
201 |
break;
|
202 |
case 3: |
203 |
_nodeURL = Object3DSymbolTab.class.getResource( |
204 |
"/particle/trisistema.osgb").getPath();
|
205 |
break;
|
206 |
|
207 |
default:
|
208 |
break;
|
209 |
|
210 |
} |
211 |
|
212 |
try {
|
213 |
Node node = osgDB.readNodeFile(_nodeURL); |
214 |
_alternateCanvas3d.getOSGViewer().setSceneData(node); |
215 |
} catch (LoadNodeException e) {
|
216 |
// TODO Auto-generated catch block
|
217 |
e.printStackTrace(); |
218 |
} catch (FileNotFoundException e) { |
219 |
// TODO Auto-generated catch block
|
220 |
e.printStackTrace(); |
221 |
} |
222 |
|
223 |
Object3DSymbolTab.this.repaint(); |
224 |
_alternateCanvas3d.getOSGViewer().getCameraManipulator() |
225 |
.computeHomePosition(); |
226 |
|
227 |
} |
228 |
} |
229 |
}); |
230 |
_comboBox.setModel(new DefaultComboBoxModel(new String[] { "Fire", |
231 |
"Radial", "Space", "Flare" })); |
232 |
GridBagConstraints gbc_comboBox = new GridBagConstraints(); |
233 |
gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
|
234 |
gbc_comboBox.gridx = 0;
|
235 |
gbc_comboBox.gridy = 1;
|
236 |
panel_4.add(_comboBox, gbc_comboBox); |
237 |
|
238 |
} |
239 |
|
240 |
private JPanel getOsgPanel() { |
241 |
|
242 |
int size = 140; |
243 |
JPanel aux3 = new JPanel(); |
244 |
aux3.setPreferredSize(new Dimension(size, size)); |
245 |
|
246 |
if (_canvas3d == null) { |
247 |
_canvas3d = ViewerFactory.getInstance().createViewer( |
248 |
ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, null);
|
249 |
_canvas3d.setSize(size, size); |
250 |
// _canvas3d.getOSGViewer().setClearColor(1.0, 1.0, 1.0, 0.0);
|
251 |
ViewerFactory.getInstance().startAnimator(); |
252 |
} |
253 |
|
254 |
loadFile(); |
255 |
|
256 |
aux3.add((Component) _canvas3d);
|
257 |
|
258 |
return aux3;
|
259 |
} |
260 |
|
261 |
private JPanel getAlternateOsgPanel() { |
262 |
|
263 |
int size = 140; |
264 |
JPanel aux3 = new JPanel(); |
265 |
aux3.setPreferredSize(new Dimension(size, size)); |
266 |
|
267 |
if (_alternateCanvas3d == null) { |
268 |
_alternateCanvas3d = ViewerFactory.getInstance().createViewer( |
269 |
ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, null);
|
270 |
_alternateCanvas3d.setSize(size, size); |
271 |
// _canvas3d.getOSGViewer().setClearColor(1.0, 1.0, 1.0, 0.0);
|
272 |
ViewerFactory.getInstance().startAnimator(); |
273 |
} |
274 |
|
275 |
loadFile(); |
276 |
|
277 |
aux3.add((Component) _alternateCanvas3d);
|
278 |
|
279 |
return aux3;
|
280 |
} |
281 |
|
282 |
private void loadFile() { |
283 |
Node node = null;
|
284 |
if (_nodeURL == "") { |
285 |
node = new Group(); |
286 |
} else {
|
287 |
try {
|
288 |
node = osgDB.readNodeFile(_nodeURL); |
289 |
_canvas3d.getOSGViewer().setSceneData(node); |
290 |
} catch (LoadNodeException e) {
|
291 |
// TODO Auto-generated catch block
|
292 |
e.printStackTrace(); |
293 |
} catch (FileNotFoundException e) { |
294 |
// TODO Auto-generated catch block
|
295 |
e.printStackTrace(); |
296 |
} |
297 |
} |
298 |
|
299 |
_canvas3d.getOSGViewer().setSceneData(node); |
300 |
} |
301 |
|
302 |
public I3DSymbol getNewSymbol() {
|
303 |
// TODO Auto-generated method stub
|
304 |
_symbol = new NodeMarker3DSymbol();
|
305 |
((NodeMarker3DSymbol) _symbol).setNodeFileURL(_nodeURL); |
306 |
((NodeMarker3DSymbol) _symbol).setSize((Double) sizeSpinner.getValue());
|
307 |
System.out.println("Set size to: " + (Double) sizeSpinner.getValue()); |
308 |
return _symbol;
|
309 |
} |
310 |
|
311 |
public void updatePanel(I3DSymbol symbol) { |
312 |
// TODO Auto-generated method stub
|
313 |
_nodeURL = ((NodeMarker3DSymbol) symbol).getNodeFileURL(); |
314 |
textField.setText(_nodeURL); |
315 |
sizeSpinner.setValue(((NodeMarker3DSymbol) symbol).getSize()); |
316 |
loadFile(); |
317 |
} |
318 |
|
319 |
public void saveParameters() { |
320 |
// TODO Auto-generated method stub
|
321 |
|
322 |
} |
323 |
|
324 |
public class TypeFileFilter extends FileFilter { |
325 |
private final String[] okFileExtensions = new String[] { "3ds", "ive", |
326 |
"osg" };
|
327 |
|
328 |
public boolean accept(File file) { |
329 |
for (String extension : okFileExtensions) { |
330 |
if (file.getName().toLowerCase().endsWith(extension)
|
331 |
|| file.isDirectory()) { |
332 |
return true; |
333 |
} |
334 |
|
335 |
} |
336 |
return false; |
337 |
} |
338 |
|
339 |
@Override
|
340 |
public String getDescription() { |
341 |
// TODO Auto-generated method stub
|
342 |
return "OSG File Types"; |
343 |
} |
344 |
} |
345 |
|
346 |
} |