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