gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / gui / styling / PictureSymbolTab.java @ 335
History | View | Annotate | Download (8.66 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.ImageIcon; |
14 |
import javax.swing.JButton; |
15 |
import javax.swing.JComboBox; |
16 |
import javax.swing.JFileChooser; |
17 |
import javax.swing.JInternalFrame; |
18 |
import javax.swing.JLabel; |
19 |
import javax.swing.JPanel; |
20 |
import javax.swing.JRadioButton; |
21 |
import javax.swing.JSpinner; |
22 |
import javax.swing.JTabbedPane; |
23 |
import javax.swing.JTextField; |
24 |
import javax.swing.border.TitledBorder; |
25 |
import javax.swing.filechooser.FileFilter; |
26 |
|
27 |
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.PictureMarker3DSymbol; |
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 java.awt.event.ActionListener; |
37 |
import java.awt.event.ActionEvent; |
38 |
import javax.swing.JSlider; |
39 |
import javax.swing.SpinnerNumberModel; |
40 |
import javax.swing.event.ChangeListener; |
41 |
import javax.swing.event.ChangeEvent; |
42 |
|
43 |
public class PictureSymbolTab extends JPanel implements ISymbolSelectorTab { |
44 |
|
45 |
private JTextField textField; |
46 |
|
47 |
private JPanel _picturePanel; |
48 |
|
49 |
private ISimpleMarker3DSymbol _symbol;
|
50 |
private String _pictureURL = ""; |
51 |
|
52 |
private JSpinner sizeSpinner; |
53 |
|
54 |
private JLabel background; |
55 |
|
56 |
private ImageIcon icon; |
57 |
|
58 |
private JPanel previewPanel; |
59 |
|
60 |
private JPanel panel; |
61 |
|
62 |
/**
|
63 |
* Create the panel.
|
64 |
*/
|
65 |
public PictureSymbolTab(Component parent) { |
66 |
setLayout(new BorderLayout(0, 0)); |
67 |
|
68 |
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); |
69 |
add(tabbedPane); |
70 |
|
71 |
panel = new JPanel(); |
72 |
tabbedPane.addTab("Properties", null, panel, null); |
73 |
GridBagLayout gbl_panel = new GridBagLayout(); |
74 |
gbl_panel.columnWidths = new int[] { 352, 84, 0 }; |
75 |
gbl_panel.rowHeights = new int[] { 100, 0 }; |
76 |
gbl_panel.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; |
77 |
gbl_panel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; |
78 |
panel.setLayout(gbl_panel); |
79 |
|
80 |
JPanel propertiesPanel = new JPanel(); |
81 |
propertiesPanel.setBorder(new TitledBorder(null, "Properties", |
82 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
83 |
GridBagConstraints gbc_propertiesPanel = new GridBagConstraints(); |
84 |
gbc_propertiesPanel.anchor = GridBagConstraints.NORTHWEST;
|
85 |
gbc_propertiesPanel.insets = new Insets(0, 0, 0, 5); |
86 |
gbc_propertiesPanel.gridx = 0;
|
87 |
gbc_propertiesPanel.gridy = 0;
|
88 |
panel.add(propertiesPanel, gbc_propertiesPanel); |
89 |
propertiesPanel.setLayout(new GridLayout(0, 3, 15, 0)); |
90 |
|
91 |
JLabel lblNewLabel_1 = new JLabel("Path:"); |
92 |
propertiesPanel.add(lblNewLabel_1); |
93 |
|
94 |
textField = new JTextField(); |
95 |
textField.setEditable(false);
|
96 |
// textField.setText(_nodeURL);
|
97 |
propertiesPanel.add(textField); |
98 |
textField.setColumns(10);
|
99 |
|
100 |
JButton btnBrowse = new JButton("Browse"); |
101 |
btnBrowse.addActionListener(new ActionListener() { |
102 |
public void actionPerformed(ActionEvent e) { |
103 |
|
104 |
JFileChooser fc = new JFileChooser(); |
105 |
FileFilter ff = new TypeFileFilter(); |
106 |
fc.setFileFilter(ff); |
107 |
|
108 |
int returnVal = fc.showDialog(PictureSymbolTab.this, "Accept"); |
109 |
|
110 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
111 |
File file = fc.getSelectedFile();
|
112 |
_pictureURL = file.getAbsolutePath(); |
113 |
// Aqui refrescar la imagen en el jpanel
|
114 |
textField.setText(_pictureURL); |
115 |
icon = new ImageIcon(_pictureURL); |
116 |
background = new JLabel(icon); |
117 |
_picturePanel.removeAll(); |
118 |
_picturePanel.add(background); |
119 |
_picturePanel.setIgnoreRepaint(false);
|
120 |
panel.repaint(); |
121 |
|
122 |
} else {
|
123 |
|
124 |
} |
125 |
|
126 |
// _symbol.setColor(newColor);
|
127 |
// _colorPanel.setBackground(newColor);
|
128 |
// _colorPanel.repaint();
|
129 |
// symbolPreviewPanel.repaint();
|
130 |
// ((SymbolSelector3D) _parent).setSymbol(_symbol);
|
131 |
|
132 |
} |
133 |
}); |
134 |
propertiesPanel.add(btnBrowse); |
135 |
|
136 |
JLabel lblSize = new JLabel("Scale Factor:"); |
137 |
propertiesPanel.add(lblSize); |
138 |
|
139 |
JPanel panel_3 = new JPanel(); |
140 |
propertiesPanel.add(panel_3); |
141 |
panel_3.setLayout(new BorderLayout(0, 0)); |
142 |
|
143 |
sizeSpinner = new JSpinner(); |
144 |
sizeSpinner.addChangeListener(new ChangeListener() { |
145 |
public void stateChanged(ChangeEvent arg0) { |
146 |
|
147 |
_symbol.setSize((Double) sizeSpinner.getValue());
|
148 |
} |
149 |
}); |
150 |
sizeSpinner.setModel(new SpinnerNumberModel(1, 1, 100, 1)); |
151 |
panel_3.add(sizeSpinner); |
152 |
|
153 |
previewPanel = new JPanel(); |
154 |
previewPanel.setBorder(new TitledBorder(null, "Preview", |
155 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
156 |
GridBagConstraints gbc_panel_2 = new GridBagConstraints(); |
157 |
gbc_panel_2.fill = GridBagConstraints.BOTH;
|
158 |
gbc_panel_2.anchor = GridBagConstraints.WEST;
|
159 |
gbc_panel_2.gridx = 1;
|
160 |
gbc_panel_2.gridy = 0;
|
161 |
panel.add(previewPanel, gbc_panel_2); |
162 |
previewPanel.setLayout(new BorderLayout(0, 0)); |
163 |
|
164 |
_picturePanel = new JPanel(); |
165 |
previewPanel.add(_picturePanel, BorderLayout.CENTER);
|
166 |
_picturePanel.setLayout(new BorderLayout(0, 0)); |
167 |
|
168 |
icon = new ImageIcon("/home/jzarzoso/capa0.png"); |
169 |
background = new JLabel(icon); |
170 |
|
171 |
_picturePanel.add(background, BorderLayout.CENTER);
|
172 |
|
173 |
JPanel panel_4 = new JPanel(); |
174 |
tabbedPane.addTab("Collection", null, panel_4, null); |
175 |
GridBagLayout gbl_panel_4 = new GridBagLayout(); |
176 |
gbl_panel_4.columnWidths = new int[] { 220, 220, 0 }; |
177 |
gbl_panel_4.rowHeights = new int[] { 33, 33, 33, 0 }; |
178 |
gbl_panel_4.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; |
179 |
gbl_panel_4.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; |
180 |
panel_4.setLayout(gbl_panel_4); |
181 |
|
182 |
JRadioButton rdbtnNewRadioButton = new JRadioButton(""); |
183 |
GridBagConstraints gbc_rdbtnNewRadioButton = new GridBagConstraints(); |
184 |
gbc_rdbtnNewRadioButton.anchor = GridBagConstraints.WEST;
|
185 |
gbc_rdbtnNewRadioButton.insets = new Insets(0, 0, 5, 5); |
186 |
gbc_rdbtnNewRadioButton.gridx = 0;
|
187 |
gbc_rdbtnNewRadioButton.gridy = 0;
|
188 |
panel_4.add(rdbtnNewRadioButton, gbc_rdbtnNewRadioButton); |
189 |
|
190 |
JPanel panel_5 = new JPanel(); |
191 |
GridBagConstraints gbc_panel_5 = new GridBagConstraints(); |
192 |
gbc_panel_5.fill = GridBagConstraints.BOTH;
|
193 |
gbc_panel_5.insets = new Insets(0, 0, 5, 0); |
194 |
gbc_panel_5.gridx = 1;
|
195 |
gbc_panel_5.gridy = 0;
|
196 |
panel_4.add(panel_5, gbc_panel_5); |
197 |
|
198 |
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton(""); |
199 |
GridBagConstraints gbc_rdbtnNewRadioButton_1 = new GridBagConstraints(); |
200 |
gbc_rdbtnNewRadioButton_1.fill = GridBagConstraints.BOTH;
|
201 |
gbc_rdbtnNewRadioButton_1.insets = new Insets(0, 0, 5, 5); |
202 |
gbc_rdbtnNewRadioButton_1.gridx = 0;
|
203 |
gbc_rdbtnNewRadioButton_1.gridy = 1;
|
204 |
panel_4.add(rdbtnNewRadioButton_1, gbc_rdbtnNewRadioButton_1); |
205 |
|
206 |
JPanel panel_6 = new JPanel(); |
207 |
GridBagConstraints gbc_panel_6 = new GridBagConstraints(); |
208 |
gbc_panel_6.fill = GridBagConstraints.BOTH;
|
209 |
gbc_panel_6.insets = new Insets(0, 0, 5, 0); |
210 |
gbc_panel_6.gridx = 1;
|
211 |
gbc_panel_6.gridy = 1;
|
212 |
panel_4.add(panel_6, gbc_panel_6); |
213 |
|
214 |
JRadioButton rdbtnNewRadioButton_2 = new JRadioButton(""); |
215 |
GridBagConstraints gbc_rdbtnNewRadioButton_2 = new GridBagConstraints(); |
216 |
gbc_rdbtnNewRadioButton_2.fill = GridBagConstraints.BOTH;
|
217 |
gbc_rdbtnNewRadioButton_2.insets = new Insets(0, 0, 0, 5); |
218 |
gbc_rdbtnNewRadioButton_2.gridx = 0;
|
219 |
gbc_rdbtnNewRadioButton_2.gridy = 2;
|
220 |
panel_4.add(rdbtnNewRadioButton_2, gbc_rdbtnNewRadioButton_2); |
221 |
|
222 |
JPanel panel_7 = new JPanel(); |
223 |
GridBagConstraints gbc_panel_7 = new GridBagConstraints(); |
224 |
gbc_panel_7.fill = GridBagConstraints.BOTH;
|
225 |
gbc_panel_7.gridx = 1;
|
226 |
gbc_panel_7.gridy = 2;
|
227 |
panel_4.add(panel_7, gbc_panel_7); |
228 |
|
229 |
} |
230 |
|
231 |
public I3DSymbol getNewSymbol() {
|
232 |
// TODO Auto-generated method stub
|
233 |
_symbol = new PictureMarker3DSymbol();
|
234 |
((PictureMarker3DSymbol) _symbol).setPictureFileURL(_pictureURL); |
235 |
((PictureMarker3DSymbol) _symbol).setSize(100);
|
236 |
return _symbol;
|
237 |
} |
238 |
|
239 |
public void updatePanel(I3DSymbol symbol) { |
240 |
// TODO Auto-generated method stub
|
241 |
_pictureURL = ((PictureMarker3DSymbol) symbol).getPictureFileURL(); |
242 |
// System.out.println("Setting text" + _pictureURL);
|
243 |
textField.setText(_pictureURL); |
244 |
// loadFile();
|
245 |
} |
246 |
|
247 |
public void saveParameters() { |
248 |
// TODO Auto-generated method stub
|
249 |
|
250 |
} |
251 |
|
252 |
public class TypeFileFilter extends FileFilter { |
253 |
private final String[] okFileExtensions = new String[] { "jpg", "png", |
254 |
"bmp", "jpeg", "tiff" }; |
255 |
|
256 |
public boolean accept(File file) { |
257 |
for (String extension : okFileExtensions) { |
258 |
if (file.getName().toLowerCase().endsWith(extension)
|
259 |
|| file.isDirectory()) { |
260 |
return true; |
261 |
} |
262 |
|
263 |
} |
264 |
return false; |
265 |
} |
266 |
|
267 |
@Override
|
268 |
public String getDescription() { |
269 |
// TODO Auto-generated method stub
|
270 |
return "OSG File Types"; |
271 |
} |
272 |
} |
273 |
|
274 |
} |