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 @ 337
History | View | Annotate | Download (9.23 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 |
add(tabbedPane); |
74 |
|
75 |
panel = new JPanel(); |
76 |
tabbedPane.addTab("Properties", null, panel, null); |
77 |
GridBagLayout gbl_panel = new GridBagLayout(); |
78 |
gbl_panel.columnWidths = new int[] { 352, 84, 0 }; |
79 |
gbl_panel.rowHeights = new int[] { 100, 0 }; |
80 |
gbl_panel.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; |
81 |
gbl_panel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; |
82 |
panel.setLayout(gbl_panel); |
83 |
|
84 |
JPanel propertiesPanel = new JPanel(); |
85 |
propertiesPanel.setBorder(new TitledBorder(null, "Properties", |
86 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
87 |
GridBagConstraints gbc_propertiesPanel = new GridBagConstraints(); |
88 |
gbc_propertiesPanel.anchor = GridBagConstraints.NORTHWEST;
|
89 |
gbc_propertiesPanel.insets = new Insets(0, 0, 0, 5); |
90 |
gbc_propertiesPanel.gridx = 0;
|
91 |
gbc_propertiesPanel.gridy = 0;
|
92 |
panel.add(propertiesPanel, gbc_propertiesPanel); |
93 |
propertiesPanel.setLayout(new GridLayout(0, 3, 15, 0)); |
94 |
|
95 |
JLabel lblNewLabel_1 = new JLabel("Path:"); |
96 |
propertiesPanel.add(lblNewLabel_1); |
97 |
|
98 |
textField = new JTextField(); |
99 |
textField.setEditable(false);
|
100 |
// textField.setText(_nodeURL);
|
101 |
propertiesPanel.add(textField); |
102 |
textField.setColumns(10);
|
103 |
|
104 |
JButton btnBrowse = new JButton("Browse"); |
105 |
btnBrowse.addActionListener(new ActionListener() { |
106 |
public void actionPerformed(ActionEvent e) { |
107 |
|
108 |
JFileChooser fc = new JFileChooser(); |
109 |
FileFilter ff = new TypeFileFilter(); |
110 |
fc.setFileFilter(ff); |
111 |
|
112 |
int returnVal = fc.showDialog(PictureSymbolTab.this, "Accept"); |
113 |
|
114 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
115 |
File file = fc.getSelectedFile();
|
116 |
_pictureURL = file.getAbsolutePath(); |
117 |
// Aqui refrescar la imagen en el jpanel
|
118 |
textField.setText(_pictureURL); |
119 |
icon = new ImageIcon(_pictureURL); |
120 |
background = new JLabel(icon); |
121 |
_picturePanel.removeAll(); |
122 |
_picturePanel.add(new JLabel(scale(icon.getImage())),BorderLayout.CENTER); |
123 |
background.repaint(); |
124 |
panel.repaint(); |
125 |
|
126 |
} else {
|
127 |
|
128 |
} |
129 |
|
130 |
// _symbol.setColor(newColor);
|
131 |
// _colorPanel.setBackground(newColor);
|
132 |
// _colorPanel.repaint();
|
133 |
// symbolPreviewPanel.repaint();
|
134 |
// ((SymbolSelector3D) _parent).setSymbol(_symbol);
|
135 |
|
136 |
} |
137 |
}); |
138 |
propertiesPanel.add(btnBrowse); |
139 |
|
140 |
JLabel lblSize = new JLabel("Scale Factor:"); |
141 |
propertiesPanel.add(lblSize); |
142 |
|
143 |
JPanel panel_3 = new JPanel(); |
144 |
propertiesPanel.add(panel_3); |
145 |
panel_3.setLayout(new BorderLayout(0, 0)); |
146 |
|
147 |
sizeSpinner = new JSpinner(); |
148 |
|
149 |
sizeSpinner.setModel(new SpinnerNumberModel(1.0, 1.0, 100.0, 1.0)); |
150 |
panel_3.add(sizeSpinner); |
151 |
|
152 |
previewPanel = new JPanel(); |
153 |
previewPanel.setBorder(new TitledBorder(null, "Preview", |
154 |
TitledBorder.LEADING, TitledBorder.TOP, null, null)); |
155 |
GridBagConstraints gbc_panel_2 = new GridBagConstraints(); |
156 |
gbc_panel_2.fill = GridBagConstraints.BOTH;
|
157 |
gbc_panel_2.anchor = GridBagConstraints.WEST;
|
158 |
gbc_panel_2.gridx = 1;
|
159 |
gbc_panel_2.gridy = 0;
|
160 |
panel.add(previewPanel, gbc_panel_2); |
161 |
previewPanel.setLayout(new BorderLayout(0, 0)); |
162 |
|
163 |
_picturePanel = new JPanel(); |
164 |
previewPanel.add(_picturePanel, BorderLayout.CENTER);
|
165 |
_picturePanel.setLayout(new BorderLayout(0, 0)); |
166 |
|
167 |
icon = new ImageIcon("/home/jzarzoso/capa0.png"); |
168 |
background = new JLabel(icon); |
169 |
|
170 |
_picturePanel.add(new JLabel(scale(icon.getImage())), BorderLayout.CENTER); |
171 |
|
172 |
JPanel panel_4 = new JPanel(); |
173 |
tabbedPane.addTab("Collection", null, panel_4, null); |
174 |
GridBagLayout gbl_panel_4 = new GridBagLayout(); |
175 |
gbl_panel_4.columnWidths = new int[] { 220, 220, 0 }; |
176 |
gbl_panel_4.rowHeights = new int[] { 33, 33, 33, 0 }; |
177 |
gbl_panel_4.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; |
178 |
gbl_panel_4.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; |
179 |
panel_4.setLayout(gbl_panel_4); |
180 |
|
181 |
JRadioButton rdbtnNewRadioButton = new JRadioButton(""); |
182 |
GridBagConstraints gbc_rdbtnNewRadioButton = new GridBagConstraints(); |
183 |
gbc_rdbtnNewRadioButton.anchor = GridBagConstraints.WEST;
|
184 |
gbc_rdbtnNewRadioButton.insets = new Insets(0, 0, 5, 5); |
185 |
gbc_rdbtnNewRadioButton.gridx = 0;
|
186 |
gbc_rdbtnNewRadioButton.gridy = 0;
|
187 |
panel_4.add(rdbtnNewRadioButton, gbc_rdbtnNewRadioButton); |
188 |
|
189 |
JPanel panel_5 = new JPanel(); |
190 |
GridBagConstraints gbc_panel_5 = new GridBagConstraints(); |
191 |
gbc_panel_5.fill = GridBagConstraints.BOTH;
|
192 |
gbc_panel_5.insets = new Insets(0, 0, 5, 0); |
193 |
gbc_panel_5.gridx = 1;
|
194 |
gbc_panel_5.gridy = 0;
|
195 |
panel_4.add(panel_5, gbc_panel_5); |
196 |
|
197 |
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton(""); |
198 |
GridBagConstraints gbc_rdbtnNewRadioButton_1 = new GridBagConstraints(); |
199 |
gbc_rdbtnNewRadioButton_1.fill = GridBagConstraints.BOTH;
|
200 |
gbc_rdbtnNewRadioButton_1.insets = new Insets(0, 0, 5, 5); |
201 |
gbc_rdbtnNewRadioButton_1.gridx = 0;
|
202 |
gbc_rdbtnNewRadioButton_1.gridy = 1;
|
203 |
panel_4.add(rdbtnNewRadioButton_1, gbc_rdbtnNewRadioButton_1); |
204 |
|
205 |
JPanel panel_6 = new JPanel(); |
206 |
GridBagConstraints gbc_panel_6 = new GridBagConstraints(); |
207 |
gbc_panel_6.fill = GridBagConstraints.BOTH;
|
208 |
gbc_panel_6.insets = new Insets(0, 0, 5, 0); |
209 |
gbc_panel_6.gridx = 1;
|
210 |
gbc_panel_6.gridy = 1;
|
211 |
panel_4.add(panel_6, gbc_panel_6); |
212 |
|
213 |
JRadioButton rdbtnNewRadioButton_2 = new JRadioButton(""); |
214 |
GridBagConstraints gbc_rdbtnNewRadioButton_2 = new GridBagConstraints(); |
215 |
gbc_rdbtnNewRadioButton_2.fill = GridBagConstraints.BOTH;
|
216 |
gbc_rdbtnNewRadioButton_2.insets = new Insets(0, 0, 0, 5); |
217 |
gbc_rdbtnNewRadioButton_2.gridx = 0;
|
218 |
gbc_rdbtnNewRadioButton_2.gridy = 2;
|
219 |
panel_4.add(rdbtnNewRadioButton_2, gbc_rdbtnNewRadioButton_2); |
220 |
|
221 |
JPanel panel_7 = new JPanel(); |
222 |
GridBagConstraints gbc_panel_7 = new GridBagConstraints(); |
223 |
gbc_panel_7.fill = GridBagConstraints.BOTH;
|
224 |
gbc_panel_7.gridx = 1;
|
225 |
gbc_panel_7.gridy = 2;
|
226 |
panel_4.add(panel_7, gbc_panel_7); |
227 |
|
228 |
} |
229 |
|
230 |
public I3DSymbol getNewSymbol() {
|
231 |
// TODO Auto-generated method stub
|
232 |
_symbol = new PictureMarker3DSymbol();
|
233 |
((PictureMarker3DSymbol) _symbol).setPictureFileURL(_pictureURL); |
234 |
((PictureMarker3DSymbol) _symbol).setSize((Double) sizeSpinner.getValue());
|
235 |
return _symbol;
|
236 |
} |
237 |
|
238 |
public void updatePanel(I3DSymbol symbol) { |
239 |
// TODO Auto-generated method stub
|
240 |
_pictureURL = ((PictureMarker3DSymbol) symbol).getPictureFileURL(); |
241 |
icon = new ImageIcon(_pictureURL); |
242 |
background = new JLabel(icon); |
243 |
_picturePanel.removeAll(); |
244 |
_picturePanel.add(new JLabel(scale(icon.getImage())),BorderLayout.CENTER); |
245 |
background.repaint(); |
246 |
panel.repaint(); |
247 |
sizeSpinner.setValue( ((PictureMarker3DSymbol) symbol).getSize()); |
248 |
// System.out.println("Setting text" + _pictureURL);
|
249 |
textField.setText(_pictureURL); |
250 |
// loadFile();
|
251 |
} |
252 |
|
253 |
public void saveParameters() { |
254 |
// TODO Auto-generated method stub
|
255 |
|
256 |
} |
257 |
|
258 |
public class TypeFileFilter extends FileFilter { |
259 |
private final String[] okFileExtensions = new String[] { "jpg", "png", |
260 |
"bmp", "jpeg", "tiff" }; |
261 |
|
262 |
public boolean accept(File file) { |
263 |
for (String extension : okFileExtensions) { |
264 |
if (file.getName().toLowerCase().endsWith(extension)
|
265 |
|| file.isDirectory()) { |
266 |
return true; |
267 |
} |
268 |
|
269 |
} |
270 |
return false; |
271 |
} |
272 |
|
273 |
@Override
|
274 |
public String getDescription() { |
275 |
// TODO Auto-generated method stub
|
276 |
return "OSG File Types"; |
277 |
} |
278 |
} |
279 |
|
280 |
private ImageIcon scale(Image src) { |
281 |
int w = 80; |
282 |
int h = 80; |
283 |
int type = BufferedImage.TYPE_INT_ARGB; |
284 |
BufferedImage dst = new BufferedImage(w, h, type); |
285 |
Graphics2D g2 = dst.createGraphics();
|
286 |
g2.drawImage(src, 0, 0, w, h, this); |
287 |
g2.dispose(); |
288 |
return new ImageIcon(dst); |
289 |
} |
290 |
|
291 |
} |