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 @ 334
History | View | Annotate | Download (9.24 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.io.File; |
11 |
import java.io.FileNotFoundException; |
12 |
|
13 |
import javax.swing.JButton; |
14 |
import javax.swing.JComboBox; |
15 |
import javax.swing.JFileChooser; |
16 |
import javax.swing.JInternalFrame; |
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.border.TitledBorder; |
24 |
import javax.swing.filechooser.FileFilter; |
25 |
|
26 |
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.NodeMarker3DSymbol; |
27 |
import org.gvsig.gvsig3d.symbology3d.I3DSymbol; |
28 |
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol; |
29 |
import org.gvsig.osgvp.core.osg.Group; |
30 |
import org.gvsig.osgvp.core.osg.Node; |
31 |
import org.gvsig.osgvp.core.osgdb.osgDB; |
32 |
import org.gvsig.osgvp.exceptions.node.LoadNodeException; |
33 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
34 |
import org.gvsig.osgvp.viewer.ViewerFactory; |
35 |
import java.awt.event.ActionListener; |
36 |
import java.awt.event.ActionEvent; |
37 |
import javax.swing.JSlider; |
38 |
import javax.swing.SpinnerNumberModel; |
39 |
import javax.swing.event.ChangeListener; |
40 |
import javax.swing.event.ChangeEvent; |
41 |
|
42 |
public class Object3DSymbolTab extends JPanel implements ISymbolSelectorTab { |
43 |
|
44 |
private JTextField textField; |
45 |
|
46 |
private IViewerContainer _canvas3d;
|
47 |
|
48 |
private ISimpleMarker3DSymbol _symbol;
|
49 |
private String _nodeURL = ""; |
50 |
|
51 |
private JSpinner sizeSpinner; |
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 |
add(tabbedPane); |
61 |
|
62 |
JPanel panel = new JPanel(); |
63 |
tabbedPane.addTab("Properties", null, panel, null); |
64 |
GridBagLayout gbl_panel = new GridBagLayout(); |
65 |
gbl_panel.columnWidths = new int[] { 352, 84, 0 }; |
66 |
gbl_panel.rowHeights = new int[] { 100, 0 }; |
67 |
gbl_panel.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; |
68 |
gbl_panel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; |
69 |
panel.setLayout(gbl_panel); |
70 |
|
71 |
JPanel propertiesPanel = new JPanel(); |
72 |
propertiesPanel.setBorder(new TitledBorder(null, "Properties", |
73 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
74 |
GridBagConstraints gbc_propertiesPanel = new GridBagConstraints(); |
75 |
gbc_propertiesPanel.anchor = GridBagConstraints.NORTHWEST;
|
76 |
gbc_propertiesPanel.insets = new Insets(0, 0, 0, 5); |
77 |
gbc_propertiesPanel.gridx = 0;
|
78 |
gbc_propertiesPanel.gridy = 0;
|
79 |
panel.add(propertiesPanel, gbc_propertiesPanel); |
80 |
propertiesPanel.setLayout(new GridLayout(0, 3, 15, 0)); |
81 |
|
82 |
JLabel lblNewLabel_1 = new JLabel("Path:"); |
83 |
propertiesPanel.add(lblNewLabel_1); |
84 |
|
85 |
textField = new JTextField(); |
86 |
textField.setEditable(false);
|
87 |
// textField.setText(_nodeURL);
|
88 |
propertiesPanel.add(textField); |
89 |
textField.setColumns(10);
|
90 |
|
91 |
JButton btnBrowse = new JButton("Browse"); |
92 |
btnBrowse.addActionListener(new ActionListener() { |
93 |
public void actionPerformed(ActionEvent e) { |
94 |
|
95 |
JFileChooser fc = new JFileChooser(); |
96 |
FileFilter ff = new TypeFileFilter(); |
97 |
fc.setFileFilter(ff); |
98 |
|
99 |
int returnVal = fc.showDialog(Object3DSymbolTab.this, "Accept"); |
100 |
|
101 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
102 |
File file = fc.getSelectedFile();
|
103 |
_nodeURL = file.getAbsolutePath(); |
104 |
try {
|
105 |
Node node = osgDB.readNodeFile(_nodeURL); |
106 |
_canvas3d.getOSGViewer().setSceneData(node); |
107 |
} catch (LoadNodeException e1) {
|
108 |
// TODO Auto-generated catch block
|
109 |
e1.printStackTrace(); |
110 |
} catch (FileNotFoundException e1) { |
111 |
// TODO Auto-generated catch block
|
112 |
e1.printStackTrace(); |
113 |
} |
114 |
textField.setText(_nodeURL); |
115 |
|
116 |
} else {
|
117 |
|
118 |
} |
119 |
|
120 |
// _symbol.setColor(newColor);
|
121 |
// _colorPanel.setBackground(newColor);
|
122 |
// _colorPanel.repaint();
|
123 |
// symbolPreviewPanel.repaint();
|
124 |
// ((SymbolSelector3D) _parent).setSymbol(_symbol);
|
125 |
|
126 |
} |
127 |
}); |
128 |
propertiesPanel.add(btnBrowse); |
129 |
|
130 |
JLabel lblSize = new JLabel("Scale Factor:"); |
131 |
propertiesPanel.add(lblSize); |
132 |
|
133 |
JPanel panel_3 = new JPanel(); |
134 |
propertiesPanel.add(panel_3); |
135 |
panel_3.setLayout(new BorderLayout(0, 0)); |
136 |
|
137 |
sizeSpinner = new JSpinner(); |
138 |
sizeSpinner.addChangeListener(new ChangeListener() { |
139 |
public void stateChanged(ChangeEvent arg0) { |
140 |
|
141 |
_symbol.setSize((Double) sizeSpinner.getValue()); }
|
142 |
}); |
143 |
sizeSpinner.setModel(new SpinnerNumberModel(1, 1, 100, 1)); |
144 |
panel_3.add(sizeSpinner); |
145 |
|
146 |
|
147 |
|
148 |
JPanel panel_2 = new JPanel(); |
149 |
panel_2.setBorder(new TitledBorder(null, "Preview", |
150 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
151 |
GridBagConstraints gbc_panel_2 = new GridBagConstraints(); |
152 |
gbc_panel_2.fill = GridBagConstraints.BOTH;
|
153 |
gbc_panel_2.anchor = GridBagConstraints.WEST;
|
154 |
gbc_panel_2.gridx = 1;
|
155 |
gbc_panel_2.gridy = 0;
|
156 |
panel.add(panel_2, gbc_panel_2); |
157 |
panel_2.setLayout(new BorderLayout(0, 0)); |
158 |
|
159 |
JPanel panel_8 = getOsgPanel();
|
160 |
panel_2.add(panel_8, BorderLayout.CENTER);
|
161 |
|
162 |
JPanel panel_4 = new JPanel(); |
163 |
tabbedPane.addTab("Collection", null, panel_4, null); |
164 |
GridBagLayout gbl_panel_4 = new GridBagLayout(); |
165 |
gbl_panel_4.columnWidths = new int[] { 220, 220, 0 }; |
166 |
gbl_panel_4.rowHeights = new int[] { 33, 33, 33, 0 }; |
167 |
gbl_panel_4.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; |
168 |
gbl_panel_4.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; |
169 |
panel_4.setLayout(gbl_panel_4); |
170 |
|
171 |
JRadioButton rdbtnNewRadioButton = new JRadioButton(""); |
172 |
GridBagConstraints gbc_rdbtnNewRadioButton = new GridBagConstraints(); |
173 |
gbc_rdbtnNewRadioButton.anchor = GridBagConstraints.WEST;
|
174 |
gbc_rdbtnNewRadioButton.insets = new Insets(0, 0, 5, 5); |
175 |
gbc_rdbtnNewRadioButton.gridx = 0;
|
176 |
gbc_rdbtnNewRadioButton.gridy = 0;
|
177 |
panel_4.add(rdbtnNewRadioButton, gbc_rdbtnNewRadioButton); |
178 |
|
179 |
JPanel panel_5 = new JPanel(); |
180 |
GridBagConstraints gbc_panel_5 = new GridBagConstraints(); |
181 |
gbc_panel_5.fill = GridBagConstraints.BOTH;
|
182 |
gbc_panel_5.insets = new Insets(0, 0, 5, 0); |
183 |
gbc_panel_5.gridx = 1;
|
184 |
gbc_panel_5.gridy = 0;
|
185 |
panel_4.add(panel_5, gbc_panel_5); |
186 |
|
187 |
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton(""); |
188 |
GridBagConstraints gbc_rdbtnNewRadioButton_1 = new GridBagConstraints(); |
189 |
gbc_rdbtnNewRadioButton_1.fill = GridBagConstraints.BOTH;
|
190 |
gbc_rdbtnNewRadioButton_1.insets = new Insets(0, 0, 5, 5); |
191 |
gbc_rdbtnNewRadioButton_1.gridx = 0;
|
192 |
gbc_rdbtnNewRadioButton_1.gridy = 1;
|
193 |
panel_4.add(rdbtnNewRadioButton_1, gbc_rdbtnNewRadioButton_1); |
194 |
|
195 |
JPanel panel_6 = new JPanel(); |
196 |
GridBagConstraints gbc_panel_6 = new GridBagConstraints(); |
197 |
gbc_panel_6.fill = GridBagConstraints.BOTH;
|
198 |
gbc_panel_6.insets = new Insets(0, 0, 5, 0); |
199 |
gbc_panel_6.gridx = 1;
|
200 |
gbc_panel_6.gridy = 1;
|
201 |
panel_4.add(panel_6, gbc_panel_6); |
202 |
|
203 |
JRadioButton rdbtnNewRadioButton_2 = new JRadioButton(""); |
204 |
GridBagConstraints gbc_rdbtnNewRadioButton_2 = new GridBagConstraints(); |
205 |
gbc_rdbtnNewRadioButton_2.fill = GridBagConstraints.BOTH;
|
206 |
gbc_rdbtnNewRadioButton_2.insets = new Insets(0, 0, 0, 5); |
207 |
gbc_rdbtnNewRadioButton_2.gridx = 0;
|
208 |
gbc_rdbtnNewRadioButton_2.gridy = 2;
|
209 |
panel_4.add(rdbtnNewRadioButton_2, gbc_rdbtnNewRadioButton_2); |
210 |
|
211 |
JPanel panel_7 = new JPanel(); |
212 |
GridBagConstraints gbc_panel_7 = new GridBagConstraints(); |
213 |
gbc_panel_7.fill = GridBagConstraints.BOTH;
|
214 |
gbc_panel_7.gridx = 1;
|
215 |
gbc_panel_7.gridy = 2;
|
216 |
panel_4.add(panel_7, gbc_panel_7); |
217 |
|
218 |
} |
219 |
|
220 |
private JPanel getOsgPanel() { |
221 |
|
222 |
int size = 150; |
223 |
JPanel aux3 = new JPanel(); |
224 |
aux3.setPreferredSize(new Dimension(size, size)); |
225 |
if (_canvas3d == null) { |
226 |
_canvas3d = ViewerFactory.getInstance().createViewer( |
227 |
ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, null);
|
228 |
_canvas3d.setSize(size, size); |
229 |
// _canvas3d.getOSGViewer().setClearColor(1.0, 1.0, 1.0, 0.0);
|
230 |
ViewerFactory.getInstance().startAnimator(); |
231 |
} |
232 |
|
233 |
loadFile(); |
234 |
|
235 |
aux3.add((Component) _canvas3d);
|
236 |
|
237 |
return aux3;
|
238 |
} |
239 |
|
240 |
private void loadFile() { |
241 |
Node node = null;
|
242 |
if (_nodeURL == "") { |
243 |
node = new Group(); |
244 |
} else {
|
245 |
try {
|
246 |
node = osgDB.readNodeFile(_nodeURL); |
247 |
_canvas3d.getOSGViewer().setSceneData(node); |
248 |
} catch (LoadNodeException e) {
|
249 |
// TODO Auto-generated catch block
|
250 |
e.printStackTrace(); |
251 |
} catch (FileNotFoundException e) { |
252 |
// TODO Auto-generated catch block
|
253 |
e.printStackTrace(); |
254 |
} |
255 |
} |
256 |
|
257 |
_canvas3d.getOSGViewer().setSceneData(node); |
258 |
} |
259 |
|
260 |
public I3DSymbol getNewSymbol() {
|
261 |
// TODO Auto-generated method stub
|
262 |
_symbol = new NodeMarker3DSymbol();
|
263 |
((NodeMarker3DSymbol) _symbol).setNodeFileURL(_nodeURL); |
264 |
return _symbol;
|
265 |
} |
266 |
|
267 |
public void updatePanel(I3DSymbol symbol) { |
268 |
// TODO Auto-generated method stub
|
269 |
_nodeURL = ((NodeMarker3DSymbol) symbol).getNodeFileURL(); |
270 |
System.out.println("Setting text" + _nodeURL); |
271 |
textField.setText(_nodeURL); |
272 |
loadFile(); |
273 |
} |
274 |
|
275 |
public void saveParameters() { |
276 |
// TODO Auto-generated method stub
|
277 |
|
278 |
} |
279 |
|
280 |
public class TypeFileFilter extends FileFilter { |
281 |
private final String[] okFileExtensions = new String[] { "3ds", "ive", |
282 |
"osg" };
|
283 |
|
284 |
public boolean accept(File file) { |
285 |
for (String extension : okFileExtensions) { |
286 |
if (file.getName().toLowerCase().endsWith(extension)
|
287 |
|| file.isDirectory()) { |
288 |
return true; |
289 |
} |
290 |
|
291 |
} |
292 |
return false; |
293 |
} |
294 |
|
295 |
@Override
|
296 |
public String getDescription() { |
297 |
// TODO Auto-generated method stub
|
298 |
return "OSG File Types"; |
299 |
} |
300 |
} |
301 |
|
302 |
} |