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 @ 328
History | View | Annotate | Download (7.89 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 |
|
25 |
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.NodeMarker3DSymbol; |
26 |
import org.gvsig.gvsig3d.symbology3d.I3DSymbol; |
27 |
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol; |
28 |
import org.gvsig.osgvp.core.osg.Group; |
29 |
import org.gvsig.osgvp.core.osg.Node; |
30 |
import org.gvsig.osgvp.core.osgdb.osgDB; |
31 |
import org.gvsig.osgvp.exceptions.node.LoadNodeException; |
32 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
33 |
import org.gvsig.osgvp.viewer.ViewerFactory; |
34 |
import java.awt.event.ActionListener; |
35 |
import java.awt.event.ActionEvent; |
36 |
|
37 |
public class Object3DSymbolTab extends JPanel implements ISymbolSelectorTab{ |
38 |
|
39 |
private JTextField textField; |
40 |
|
41 |
private IViewerContainer _canvas3d;
|
42 |
|
43 |
private ISimpleMarker3DSymbol _symbol;
|
44 |
private String _nodeURL; |
45 |
|
46 |
/**
|
47 |
* Create the panel.
|
48 |
*/
|
49 |
public Object3DSymbolTab(Component parent) { |
50 |
setLayout(new BorderLayout(0, 0)); |
51 |
|
52 |
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); |
53 |
add(tabbedPane); |
54 |
|
55 |
JPanel panel = new JPanel(); |
56 |
tabbedPane.addTab("Properties", null, panel, null); |
57 |
GridBagLayout gbl_panel = new GridBagLayout(); |
58 |
gbl_panel.columnWidths = new int[] { 352, 84, 0 }; |
59 |
gbl_panel.rowHeights = new int[] { 100, 0 }; |
60 |
gbl_panel.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; |
61 |
gbl_panel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; |
62 |
panel.setLayout(gbl_panel); |
63 |
|
64 |
JPanel propertiesPanel = new JPanel(); |
65 |
propertiesPanel.setBorder(new TitledBorder(null, "Properties", |
66 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
67 |
GridBagConstraints gbc_propertiesPanel = new GridBagConstraints(); |
68 |
gbc_propertiesPanel.anchor = GridBagConstraints.NORTHWEST;
|
69 |
gbc_propertiesPanel.insets = new Insets(0, 0, 0, 5); |
70 |
gbc_propertiesPanel.gridx = 0;
|
71 |
gbc_propertiesPanel.gridy = 0;
|
72 |
panel.add(propertiesPanel, gbc_propertiesPanel); |
73 |
propertiesPanel.setLayout(new GridLayout(0, 3, 15, 0)); |
74 |
|
75 |
JLabel lblNewLabel_1 = new JLabel("Ruta:"); |
76 |
propertiesPanel.add(lblNewLabel_1); |
77 |
|
78 |
textField = new JTextField(); |
79 |
textField.setEditable(false);
|
80 |
propertiesPanel.add(textField); |
81 |
textField.setColumns(10);
|
82 |
|
83 |
JButton btnBrowse = new JButton("Browse"); |
84 |
btnBrowse.addActionListener(new ActionListener() { |
85 |
public void actionPerformed(ActionEvent e) { |
86 |
|
87 |
JFileChooser fc = new JFileChooser(); |
88 |
|
89 |
int returnVal = fc.showDialog(Object3DSymbolTab.this,
|
90 |
"Select Color");
|
91 |
|
92 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
93 |
File file = fc.getSelectedFile();
|
94 |
_nodeURL = file.getAbsolutePath(); |
95 |
try {
|
96 |
Node node = osgDB.readNodeFile(_nodeURL); |
97 |
_canvas3d.getOSGViewer().setSceneData(node); |
98 |
} catch (LoadNodeException e1) {
|
99 |
// TODO Auto-generated catch block
|
100 |
e1.printStackTrace(); |
101 |
} catch (FileNotFoundException e1) { |
102 |
// TODO Auto-generated catch block
|
103 |
e1.printStackTrace(); |
104 |
} |
105 |
// this is where a real application would open the file.
|
106 |
|
107 |
} else {
|
108 |
|
109 |
} |
110 |
|
111 |
// _symbol.setColor(newColor);
|
112 |
// _colorPanel.setBackground(newColor);
|
113 |
// _colorPanel.repaint();
|
114 |
// symbolPreviewPanel.repaint();
|
115 |
// ((SymbolSelector3D) _parent).setSymbol(_symbol);
|
116 |
|
117 |
} |
118 |
}); |
119 |
propertiesPanel.add(btnBrowse); |
120 |
|
121 |
JLabel lblSize = new JLabel("Scale Factor:"); |
122 |
propertiesPanel.add(lblSize); |
123 |
|
124 |
JSpinner spinner = new JSpinner(); |
125 |
propertiesPanel.add(spinner); |
126 |
|
127 |
JPanel panel_3 = new JPanel(); |
128 |
propertiesPanel.add(panel_3); |
129 |
|
130 |
JLabel lblUnits = new JLabel("Units"); |
131 |
propertiesPanel.add(lblUnits); |
132 |
|
133 |
JComboBox comboBox = new JComboBox(); |
134 |
propertiesPanel.add(comboBox); |
135 |
|
136 |
JComboBox comboBox_1 = new JComboBox(); |
137 |
propertiesPanel.add(comboBox_1); |
138 |
|
139 |
JPanel panel_2 = new JPanel(); |
140 |
panel_2.setBorder(new TitledBorder(null, "Preview", |
141 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
142 |
GridBagConstraints gbc_panel_2 = new GridBagConstraints(); |
143 |
gbc_panel_2.fill = GridBagConstraints.BOTH;
|
144 |
gbc_panel_2.anchor = GridBagConstraints.WEST;
|
145 |
gbc_panel_2.gridx = 1;
|
146 |
gbc_panel_2.gridy = 0;
|
147 |
panel.add(panel_2, gbc_panel_2); |
148 |
panel_2.setLayout(new BorderLayout(0, 0)); |
149 |
|
150 |
JPanel panel_8 = getOsgPanel();
|
151 |
panel_2.add(panel_8, BorderLayout.CENTER);
|
152 |
|
153 |
JPanel panel_4 = new JPanel(); |
154 |
tabbedPane.addTab("Collection", null, panel_4, null); |
155 |
GridBagLayout gbl_panel_4 = new GridBagLayout(); |
156 |
gbl_panel_4.columnWidths = new int[] { 220, 220, 0 }; |
157 |
gbl_panel_4.rowHeights = new int[] { 33, 33, 33, 0 }; |
158 |
gbl_panel_4.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; |
159 |
gbl_panel_4.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; |
160 |
panel_4.setLayout(gbl_panel_4); |
161 |
|
162 |
JRadioButton rdbtnNewRadioButton = new JRadioButton(""); |
163 |
GridBagConstraints gbc_rdbtnNewRadioButton = new GridBagConstraints(); |
164 |
gbc_rdbtnNewRadioButton.anchor = GridBagConstraints.WEST;
|
165 |
gbc_rdbtnNewRadioButton.insets = new Insets(0, 0, 5, 5); |
166 |
gbc_rdbtnNewRadioButton.gridx = 0;
|
167 |
gbc_rdbtnNewRadioButton.gridy = 0;
|
168 |
panel_4.add(rdbtnNewRadioButton, gbc_rdbtnNewRadioButton); |
169 |
|
170 |
JPanel panel_5 = new JPanel(); |
171 |
GridBagConstraints gbc_panel_5 = new GridBagConstraints(); |
172 |
gbc_panel_5.fill = GridBagConstraints.BOTH;
|
173 |
gbc_panel_5.insets = new Insets(0, 0, 5, 0); |
174 |
gbc_panel_5.gridx = 1;
|
175 |
gbc_panel_5.gridy = 0;
|
176 |
panel_4.add(panel_5, gbc_panel_5); |
177 |
|
178 |
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton(""); |
179 |
GridBagConstraints gbc_rdbtnNewRadioButton_1 = new GridBagConstraints(); |
180 |
gbc_rdbtnNewRadioButton_1.fill = GridBagConstraints.BOTH;
|
181 |
gbc_rdbtnNewRadioButton_1.insets = new Insets(0, 0, 5, 5); |
182 |
gbc_rdbtnNewRadioButton_1.gridx = 0;
|
183 |
gbc_rdbtnNewRadioButton_1.gridy = 1;
|
184 |
panel_4.add(rdbtnNewRadioButton_1, gbc_rdbtnNewRadioButton_1); |
185 |
|
186 |
JPanel panel_6 = new JPanel(); |
187 |
GridBagConstraints gbc_panel_6 = new GridBagConstraints(); |
188 |
gbc_panel_6.fill = GridBagConstraints.BOTH;
|
189 |
gbc_panel_6.insets = new Insets(0, 0, 5, 0); |
190 |
gbc_panel_6.gridx = 1;
|
191 |
gbc_panel_6.gridy = 1;
|
192 |
panel_4.add(panel_6, gbc_panel_6); |
193 |
|
194 |
JRadioButton rdbtnNewRadioButton_2 = new JRadioButton(""); |
195 |
GridBagConstraints gbc_rdbtnNewRadioButton_2 = new GridBagConstraints(); |
196 |
gbc_rdbtnNewRadioButton_2.fill = GridBagConstraints.BOTH;
|
197 |
gbc_rdbtnNewRadioButton_2.insets = new Insets(0, 0, 0, 5); |
198 |
gbc_rdbtnNewRadioButton_2.gridx = 0;
|
199 |
gbc_rdbtnNewRadioButton_2.gridy = 2;
|
200 |
panel_4.add(rdbtnNewRadioButton_2, gbc_rdbtnNewRadioButton_2); |
201 |
|
202 |
JPanel panel_7 = new JPanel(); |
203 |
GridBagConstraints gbc_panel_7 = new GridBagConstraints(); |
204 |
gbc_panel_7.fill = GridBagConstraints.BOTH;
|
205 |
gbc_panel_7.gridx = 1;
|
206 |
gbc_panel_7.gridy = 2;
|
207 |
panel_4.add(panel_7, gbc_panel_7); |
208 |
|
209 |
} |
210 |
|
211 |
private JPanel getOsgPanel() { |
212 |
|
213 |
int size = 150; |
214 |
JPanel aux3 = new JPanel(); |
215 |
aux3.setPreferredSize(new Dimension(size, size)); |
216 |
if (_canvas3d == null) { |
217 |
_canvas3d = ViewerFactory.getInstance().createViewer( |
218 |
ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, null);
|
219 |
_canvas3d.setSize(size, size); |
220 |
//_canvas3d.getOSGViewer().setClearColor(1.0, 1.0, 1.0, 0.0);
|
221 |
ViewerFactory.getInstance().startAnimator(); |
222 |
} |
223 |
|
224 |
loadFile(); |
225 |
|
226 |
aux3.add((Component) _canvas3d);
|
227 |
|
228 |
return aux3;
|
229 |
} |
230 |
|
231 |
private void loadFile() { |
232 |
Node node = null;
|
233 |
// if (this.getFilePath() == "") {
|
234 |
node = new Group(); |
235 |
// } else {
|
236 |
// node = osgDB.readNodeFile(filePath);
|
237 |
// }
|
238 |
|
239 |
_canvas3d.getOSGViewer().setSceneData(node); |
240 |
} |
241 |
|
242 |
public I3DSymbol getNewSymbol() {
|
243 |
// TODO Auto-generated method stub
|
244 |
_symbol = new NodeMarker3DSymbol();
|
245 |
((NodeMarker3DSymbol) _symbol).setNodeFileURL(_nodeURL); |
246 |
|
247 |
return _symbol;
|
248 |
} |
249 |
|
250 |
} |