Statistics
| Revision:

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 @ 344

History | View | Annotate | Download (13.6 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.awt.event.ActionEvent;
13
import java.awt.event.ActionListener;
14
import java.awt.image.BufferedImage;
15
import java.io.File;
16
import java.io.FileNotFoundException;
17

    
18
import javax.swing.ImageIcon;
19
import javax.swing.JButton;
20
import javax.swing.JFileChooser;
21
import javax.swing.JLabel;
22
import javax.swing.JPanel;
23
import javax.swing.JRadioButton;
24
import javax.swing.JSpinner;
25
import javax.swing.JTabbedPane;
26
import javax.swing.JTextField;
27
import javax.swing.SpinnerNumberModel;
28
import javax.swing.border.TitledBorder;
29
import javax.swing.filechooser.FileFilter;
30

    
31
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.NodeMarker3DSymbol;
32
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.PictureMarker3DSymbol;
33
import org.gvsig.gvsig3d.resources.ResourcesFactory;
34
import org.gvsig.gvsig3d.symbology3d.I3DSymbol;
35
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol;
36
import org.gvsig.osgvp.core.osg.Group;
37
import org.gvsig.osgvp.core.osg.Node;
38
import org.gvsig.osgvp.core.osgdb.osgDB;
39
import org.gvsig.osgvp.exceptions.node.LoadNodeException;
40
import org.gvsig.osgvp.viewer.IViewerContainer;
41
import org.gvsig.osgvp.viewer.ViewerFactory;
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
                tabbedPane.setPreferredSize(new Dimension(180, 300));
70
                add(tabbedPane, BorderLayout.CENTER);
71

    
72
                panel = new JPanel();
73
                tabbedPane.addTab("Marker", null, panel, null);
74
                GridBagLayout gbl_panel = new GridBagLayout();
75
                gbl_panel.columnWidths = new int[] { 175 };
76
                gbl_panel.rowHeights = new int[] { 180, 70 };
77
                gbl_panel.columnWeights = new double[] { 0.0 };
78
                gbl_panel.rowWeights = new double[] { 0.0, 0.0 };
79
                panel.setLayout(gbl_panel);
80

    
81
                previewPanel = new JPanel();
82
                previewPanel.setBorder(new TitledBorder(null, "Preview",
83
                                TitledBorder.LEADING, TitledBorder.TOP, null, null));
84
                GridBagConstraints gbc_panel_2 = new GridBagConstraints();
85
                gbc_panel_2.insets = new Insets(0, 0, 5, 5);
86
                gbc_panel_2.fill = GridBagConstraints.BOTH;
87
                gbc_panel_2.gridx = 0;
88
                gbc_panel_2.gridy = 0;
89
                panel.add(previewPanel, gbc_panel_2);
90
                previewPanel.setLayout(new BorderLayout(0, 0));
91

    
92
                icon = new ImageIcon("");
93
                background = new JLabel(icon);
94
                previewPanel.add(background, BorderLayout.CENTER);
95

    
96
                _picturePanel = new JPanel();
97
                previewPanel.add(_picturePanel, BorderLayout.CENTER);
98
                _picturePanel.setLayout(new BorderLayout(0, 0));
99
                _picturePanel.add(new JLabel(scale(icon.getImage())),
100
                                BorderLayout.CENTER);
101

    
102
                JPanel propertiesPanel = new JPanel();
103
                propertiesPanel.setBorder(new TitledBorder(null, "Properties",
104
                                TitledBorder.LEADING, TitledBorder.TOP, null, null));
105
                GridBagConstraints gbc_propertiesPanel = new GridBagConstraints();
106
                gbc_propertiesPanel.fill = GridBagConstraints.HORIZONTAL;
107
                gbc_propertiesPanel.ipady = 10;
108
                gbc_propertiesPanel.ipadx = 10;
109
                gbc_propertiesPanel.insets = new Insets(0, 0, 0, 5);
110
                gbc_propertiesPanel.anchor = GridBagConstraints.NORTHWEST;
111
                gbc_propertiesPanel.gridx = 0;
112
                gbc_propertiesPanel.gridy = 1;
113
                panel.add(propertiesPanel, gbc_propertiesPanel);
114
                propertiesPanel.setLayout(new GridLayout(0, 3, 10, 10));
115

    
116
                JLabel lblNewLabel_1 = new JLabel("Path:");
117
                propertiesPanel.add(lblNewLabel_1);
118

    
119
                textField = new JTextField();
120
                textField.setEditable(false);
121
                // textField.setText(_nodeURL);
122
                propertiesPanel.add(textField);
123
                textField.setColumns(10);
124

    
125
                JButton btnBrowse = new JButton("Browse");
126
                btnBrowse.addActionListener(new ActionListener() {
127
                        public void actionPerformed(ActionEvent e) {
128

    
129
                                JFileChooser fc = new JFileChooser();
130
                                FileFilter ff = new TypeFileFilter();
131
                                fc.setFileFilter(ff);
132

    
133
                                int returnVal = fc.showDialog(PictureSymbolTab.this, "Accept");
134

    
135
                                if (returnVal == JFileChooser.APPROVE_OPTION) {
136
                                        File file = fc.getSelectedFile();
137
                                        _pictureURL = file.getAbsolutePath();
138
                                        // Aqui refrescar la imagen en el jpanel
139
                                        textField.setText(_pictureURL);
140
                                        icon = new ImageIcon(_pictureURL);
141
                                        background = new JLabel(icon);
142
                                        _picturePanel.removeAll();
143
                                        _picturePanel.add(new JLabel(scale(icon.getImage())),
144
                                                        BorderLayout.CENTER);
145
                                        PictureSymbolTab.this.repaint();
146

    
147
                                } else {
148

    
149
                                }
150

    
151
                                // _symbol.setColor(newColor);
152
                                // _colorPanel.setBackground(newColor);
153
                                // _colorPanel.repaint();
154
                                // symbolPreviewPanel.repaint();
155
                                // ((SymbolSelector3D) _parent).setSymbol(_symbol);
156

    
157
                        }
158
                });
159
                propertiesPanel.add(btnBrowse);
160

    
161
                JLabel lblSize = new JLabel("Size:");
162
                propertiesPanel.add(lblSize);
163

    
164
                JPanel panel_3 = new JPanel();
165
                propertiesPanel.add(panel_3);
166
                panel_3.setLayout(new BorderLayout(0, 0));
167

    
168
                sizeSpinner = new JSpinner();
169
                sizeSpinner.setModel(new SpinnerNumberModel(32.0, 1.0, 1000.0, 1.0));
170
                panel_3.add(sizeSpinner);
171

    
172
                propertiesPanel.setPreferredSize(new Dimension(80, 80));
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[] { 15, 60, 15, 60 };
178
                gbl_panel_4.rowHeights = new int[] { 33, 33, 33, 0 };
179
                gbl_panel_4.columnWeights = new double[] { 0.0, 0.0 };
180
                gbl_panel_4.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0 };
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, 5);
195
                gbc_panel_5.gridx = 1;
196
                gbc_panel_5.gridy = 0;
197

    
198
                panel_5.setLayout(new BorderLayout(0, 0));
199
                panel_5.add(new JLabel(new ImageIcon(PictureSymbolTab.class
200
                                .getResource("/markers/fire.png"))));
201
                panel_4.add(panel_5, gbc_panel_5);
202

    
203
                JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("");
204
                GridBagConstraints gbc_rdbtnNewRadioButton_1 = new GridBagConstraints();
205
                gbc_rdbtnNewRadioButton_1.fill = GridBagConstraints.BOTH;
206
                gbc_rdbtnNewRadioButton_1.insets = new Insets(0, 0, 5, 5);
207
                gbc_rdbtnNewRadioButton_1.gridx = 2;
208
                gbc_rdbtnNewRadioButton_1.gridy = 0;
209
                panel_4.add(rdbtnNewRadioButton_1, gbc_rdbtnNewRadioButton_1);
210

    
211
                JPanel panel_6 = new JPanel();
212
                GridBagConstraints gbc_panel_6 = new GridBagConstraints();
213
                gbc_panel_6.fill = GridBagConstraints.BOTH;
214
                gbc_panel_6.insets = new Insets(0, 0, 5, 0);
215
                gbc_panel_6.gridx = 3;
216
                gbc_panel_6.gridy = 0;
217
                panel_4.add(panel_6, gbc_panel_6);
218
                panel_6.setLayout(new BorderLayout(0, 0));
219
                panel_6.add(new JLabel(new ImageIcon(PictureSymbolTab.class
220
                                .getResource("/markers/artgallery.png"))));
221

    
222
                JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("");
223
                GridBagConstraints gbc_rdbtnNewRadioButton_2 = new GridBagConstraints();
224
                gbc_rdbtnNewRadioButton_2.fill = GridBagConstraints.BOTH;
225
                gbc_rdbtnNewRadioButton_2.insets = new Insets(0, 0, 5, 5);
226
                gbc_rdbtnNewRadioButton_2.gridx = 0;
227
                gbc_rdbtnNewRadioButton_2.gridy = 1;
228
                panel_4.add(rdbtnNewRadioButton_2, gbc_rdbtnNewRadioButton_2);
229

    
230
                JPanel panel_7 = new JPanel();
231
                GridBagConstraints gbc_panel_7 = new GridBagConstraints();
232
                gbc_panel_7.insets = new Insets(0, 0, 5, 5);
233
                gbc_panel_7.fill = GridBagConstraints.BOTH;
234
                gbc_panel_7.gridx = 1;
235
                gbc_panel_7.gridy = 1;
236
                panel_4.add(panel_7, gbc_panel_7);
237
                panel_7.setLayout(new BorderLayout(0, 0));
238
                panel_7.add(new JLabel(new ImageIcon(PictureSymbolTab.class
239
                                .getResource("/markers/taxi.png"))));
240

    
241
                JRadioButton radioButton = new JRadioButton("");
242
                GridBagConstraints gbc_radioButton = new GridBagConstraints();
243
                gbc_radioButton.insets = new Insets(0, 0, 5, 5);
244
                gbc_radioButton.gridx = 2;
245
                gbc_radioButton.gridy = 1;
246
                panel_4.add(radioButton, gbc_radioButton);
247
     
248
                JPanel panel_8 = new JPanel();
249
                GridBagConstraints gbc_panel_8 = new GridBagConstraints();
250
                gbc_panel_8.insets = new Insets(0, 0, 5, 5);
251
                gbc_panel_8.fill = GridBagConstraints.BOTH;
252
                gbc_panel_8.gridx = 3;
253
                gbc_panel_8.gridy = 1;
254
                panel_4.add(panel_8, gbc_panel_8);
255
                panel_8.setLayout(new BorderLayout(0, 0));
256
                panel_8.add(new JLabel(new ImageIcon(PictureSymbolTab.class
257
                                .getResource("/markers/airport_runway.png"))));
258

    
259
                JRadioButton radioButton2 = new JRadioButton("");
260
                GridBagConstraints gbc_radioButton2 = new GridBagConstraints();
261
                gbc_radioButton2.insets = new Insets(0, 0, 5, 5);
262
                gbc_radioButton2.gridx = 0;
263
                gbc_radioButton2.gridy = 2;
264
                panel_4.add(radioButton2, gbc_radioButton2);
265

    
266
                JPanel panel_9 = new JPanel();
267
                GridBagConstraints gbc_panel_9 = new GridBagConstraints();
268
                gbc_panel_9.insets = new Insets(0, 0, 5, 5);
269
                gbc_panel_9.fill = GridBagConstraints.BOTH;
270
                gbc_panel_9.gridx = 1;
271
                gbc_panel_9.gridy = 2;
272
                panel_4.add(panel_9, gbc_panel_9);
273
                panel_9.setLayout(new BorderLayout(0, 0));
274
                panel_9.add(new JLabel(new ImageIcon(PictureSymbolTab.class
275
                                .getResource("/markers/mall.png"))));
276

    
277
                JRadioButton radioButton3 = new JRadioButton("");
278
                GridBagConstraints gbc_radioButton3 = new GridBagConstraints();
279
                gbc_radioButton3.insets = new Insets(0, 0, 5, 5);
280
                gbc_radioButton3.gridx = 2;
281
                gbc_radioButton3.gridy = 2;
282
                panel_4.add(radioButton3, gbc_radioButton3);
283

    
284
                JPanel panel_10 = new JPanel();
285
                GridBagConstraints gbc_panel_10 = new GridBagConstraints();
286
                gbc_panel_10.insets = new Insets(0, 0, 5, 5);
287
                gbc_panel_10.fill = GridBagConstraints.BOTH;
288
                gbc_panel_10.gridx = 3;
289
                gbc_panel_10.gridy = 2;
290
                panel_4.add(panel_10, gbc_panel_10);
291
                panel_10.setLayout(new BorderLayout(0, 0));
292
                panel_10.add(new JLabel(new ImageIcon(PictureSymbolTab.class
293
                                .getResource("/markers/rodent.png"))));
294

    
295
                JRadioButton radioButton4 = new JRadioButton("");
296
                GridBagConstraints gbc_radioButton4 = new GridBagConstraints();
297
                gbc_radioButton4.insets = new Insets(0, 0, 5, 5);
298
                gbc_radioButton4.gridx = 0;
299
                gbc_radioButton4.gridy = 3;
300
                panel_4.add(radioButton4, gbc_radioButton4);
301

    
302
                JPanel panel_11 = new JPanel();
303
                GridBagConstraints gbc_panel_11 = new GridBagConstraints();
304
                gbc_panel_11.insets = new Insets(0, 0, 5, 5);
305
                gbc_panel_11.fill = GridBagConstraints.BOTH;
306
                gbc_panel_11.gridx = 1;
307
                gbc_panel_11.gridy = 3;
308
                panel_4.add(panel_11, gbc_panel_11);
309
                panel_11.setLayout(new BorderLayout(0, 0));
310
                panel_11.add(new JLabel(new ImageIcon(PictureSymbolTab.class
311
                                .getResource("/markers/wrestling-2.png"))));
312

    
313
                JRadioButton radioButton5 = new JRadioButton("");
314
                GridBagConstraints gbc_radioButton5 = new GridBagConstraints();
315
                gbc_radioButton5.insets = new Insets(0, 0, 5, 5);
316
                gbc_radioButton5.gridx = 2;
317
                gbc_radioButton5.gridy = 3;
318
                panel_4.add(radioButton5, gbc_radioButton5);
319

    
320
                JPanel panel_12 = new JPanel();
321
                GridBagConstraints gbc_panel_12 = new GridBagConstraints();
322
                gbc_panel_12.insets = new Insets(0, 0, 5, 5);
323
                gbc_panel_12.fill = GridBagConstraints.BOTH;
324
                gbc_panel_12.gridx = 3;
325
                gbc_panel_12.gridy = 3;
326
                panel_4.add(panel_12, gbc_panel_12);
327
                panel_12.setLayout(new BorderLayout(0, 0));
328
                panel_12.add(new JLabel(new ImageIcon(PictureSymbolTab.class
329
                                .getResource("/markers/zoo.png"))));
330

    
331
        }
332

    
333
        public I3DSymbol getNewSymbol() {
334
                // TODO Auto-generated method stub
335
                _symbol = new PictureMarker3DSymbol();
336

    
337
                if (panel.isVisible()) {
338
                        ((PictureMarker3DSymbol) _symbol).setPictureFileURL(_pictureURL);
339
                        ((PictureMarker3DSymbol) _symbol).setSize((Double) sizeSpinner
340
                                        .getValue());
341
                } else {
342

    
343
                        ((PictureMarker3DSymbol) _symbol).setPictureFileURL(PictureSymbolTab.class
344
                                        .getResource("/markers/taxi.png").getPath());
345
                        ((PictureMarker3DSymbol) _symbol).setSize((Double) sizeSpinner
346
                                        .getValue());
347
                        
348
                }
349
                return _symbol;
350
        }
351

    
352
        public void updatePanel(I3DSymbol symbol) {
353
                // TODO Auto-generated method stub
354
                _pictureURL = ((PictureMarker3DSymbol) symbol).getPictureFileURL();
355
                icon = new ImageIcon(_pictureURL);
356
                background = new JLabel(icon);
357
                _picturePanel.removeAll();
358
                _picturePanel.add(new JLabel(scale(icon.getImage())),
359
                                BorderLayout.CENTER);
360
                background.repaint();
361
                panel.repaint();
362
                sizeSpinner.setValue(((PictureMarker3DSymbol) symbol).getSize());
363
                // System.out.println("Setting text" + _pictureURL);
364
                textField.setText(_pictureURL);
365
                // loadFile();
366
        }
367

    
368
        public void saveParameters() {
369
                // TODO Auto-generated method stub
370

    
371
        }
372

    
373
        public class TypeFileFilter extends FileFilter {
374
                private final String[] okFileExtensions = new String[] { "jpg", "png",
375
                                "bmp", "jpeg", "tiff" };
376

    
377
                public boolean accept(File file) {
378
                        for (String extension : okFileExtensions) {
379
                                if (file.getName().toLowerCase().endsWith(extension)
380
                                                || file.isDirectory()) {
381
                                        return true;
382
                                }
383

    
384
                        }
385
                        return false;
386
                }
387

    
388
                @Override
389
                public String getDescription() {
390
                        // TODO Auto-generated method stub
391
                        return "Supported Image Types";
392
                }
393
        }
394

    
395
        private ImageIcon scale(Image src) {
396
                int w = 115;
397
                int h = 115;
398
                int type = BufferedImage.TYPE_INT_ARGB;
399
                BufferedImage dst = new BufferedImage(w, h, type);
400
                Graphics2D g2 = dst.createGraphics();
401
                g2.drawImage(src, 0, 0, w, h, this);
402
                g2.dispose();
403
                return new ImageIcon(dst);
404
        }
405

    
406
}