Revision 334 2.0/trunk/org.gvsig.gvsig3d.app/org.gvsig.gvsig3d.app.extension/src/main/java/org/gvsig/gvsig3d/app/gui/styling/PictureSymbolTab.java

View differences:

PictureSymbolTab.java
1 1
package org.gvsig.gvsig3d.app.gui.styling;
2 2

  
3
import java.awt.BorderLayout;
3 4
import java.awt.Component;
4
import java.awt.FlowLayout;
5
import java.awt.Dimension;
5 6
import java.awt.GridBagConstraints;
6 7
import java.awt.GridBagLayout;
7 8
import java.awt.GridLayout;
8 9
import java.awt.Insets;
10
import java.io.File;
11
import java.io.FileNotFoundException;
9 12

  
13
import javax.swing.ImageIcon;
10 14
import javax.swing.JButton;
11 15
import javax.swing.JComboBox;
16
import javax.swing.JFileChooser;
12 17
import javax.swing.JInternalFrame;
13 18
import javax.swing.JLabel;
14 19
import javax.swing.JPanel;
......
17 22
import javax.swing.JTabbedPane;
18 23
import javax.swing.JTextField;
19 24
import javax.swing.border.TitledBorder;
25
import javax.swing.filechooser.FileFilter;
20 26

  
27
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.PictureMarker3DSymbol;
21 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;
22 42

  
23
public class PictureSymbolTab extends JPanel implements ISymbolSelectorTab{
24
	/**
25
	 * 
26
	 */
27
	private static final long serialVersionUID = -967291574626881727L;
43
public class PictureSymbolTab extends JPanel implements ISymbolSelectorTab {
44

  
28 45
	private JTextField textField;
29
	
30
	private I3DSymbol _symbol;
31 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

  
32 62
	/**
33 63
	 * Create the panel.
34 64
	 */
35 65
	public PictureSymbolTab(Component parent) {
36
		FlowLayout flowLayout_1 = (FlowLayout) getLayout();
37
		
66
		setLayout(new BorderLayout(0, 0));
67

  
38 68
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
39 69
		add(tabbedPane);
40
		
41
		JPanel panel = new JPanel();
70

  
71
		panel = new JPanel();
42 72
		tabbedPane.addTab("Properties", null, panel, null);
43 73
		GridBagLayout gbl_panel = new GridBagLayout();
44
		gbl_panel.columnWidths = new int[]{352, 84, 0};
45
		gbl_panel.rowHeights = new int[]{100, 0};
46
		gbl_panel.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
47
		gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
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 };
48 78
		panel.setLayout(gbl_panel);
49
		
50
		JPanel panel_1 = new JPanel();
51
		panel_1.setBorder(new TitledBorder(null, "Properties", TitledBorder.LEADING, TitledBorder.TOP, null, null));
52
		GridBagConstraints gbc_panel_1 = new GridBagConstraints();
53
		gbc_panel_1.anchor = GridBagConstraints.NORTHWEST;
54
		gbc_panel_1.insets = new Insets(0, 0, 0, 5);
55
		gbc_panel_1.gridx = 0;
56
		gbc_panel_1.gridy = 0;
57
		panel.add(panel_1, gbc_panel_1);
58
		panel_1.setLayout(new GridLayout(0, 3, 0, 0));
59
		
60
		JLabel lblNewLabel_1 = new JLabel("Ruta:");
61
		panel_1.add(lblNewLabel_1);
62
		
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

  
63 94
		textField = new JTextField();
64 95
		textField.setEditable(false);
65
		panel_1.add(textField);
96
		// textField.setText(_nodeURL);
97
		propertiesPanel.add(textField);
66 98
		textField.setColumns(10);
67
		
99

  
68 100
		JButton btnBrowse = new JButton("Browse");
69
		panel_1.add(btnBrowse);
70
		
71
		JLabel lblSize = new JLabel("Size:");
72
		panel_1.add(lblSize);
73
		
74
		JSpinner spinner = new JSpinner();
75
		panel_1.add(spinner);
76
		
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

  
77 139
		JPanel panel_3 = new JPanel();
78
		panel_1.add(panel_3);
79
		
80
		JLabel lblUnits = new JLabel("Units");
81
		panel_1.add(lblUnits);
82
		
83
		JComboBox comboBox = new JComboBox();
84
		panel_1.add(comboBox);
85
		
86
		JComboBox comboBox_1 = new JComboBox();
87
		panel_1.add(comboBox_1);
88
		
89
		JPanel panel_2 = new JPanel();
90
		FlowLayout flowLayout = (FlowLayout) panel_2.getLayout();
91
		panel_2.setBorder(new TitledBorder(null, "Preview", TitledBorder.LEADING, TitledBorder.TOP, null, null));
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));
92 156
		GridBagConstraints gbc_panel_2 = new GridBagConstraints();
157
		gbc_panel_2.fill = GridBagConstraints.BOTH;
93 158
		gbc_panel_2.anchor = GridBagConstraints.WEST;
94 159
		gbc_panel_2.gridx = 1;
95 160
		gbc_panel_2.gridy = 0;
96
		panel.add(panel_2, gbc_panel_2);
97
		
98
		JInternalFrame internalFrame_1 = new JInternalFrame("New JInternalFrame");
99
		panel_2.add(internalFrame_1);
100
		
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
		_picturePanel.setPreferredSize(new Dimension(80,80));
168

  
169
		icon = new ImageIcon("/home/jzarzoso/capa0.png");
170
		background = new JLabel(icon);
171

  
172
		_picturePanel.add(background, BorderLayout.CENTER);
173

  
101 174
		JPanel panel_4 = new JPanel();
102 175
		tabbedPane.addTab("Collection", null, panel_4, null);
103
		panel_4.setLayout(new GridLayout(3, 4, 0, 0));
104
		
105
		JRadioButton rdbtnNewRadioButton = new JRadioButton("New radio button");
106
		panel_4.add(rdbtnNewRadioButton);
107
		
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

  
108 191
		JPanel panel_5 = new JPanel();
109
		panel_4.add(panel_5);
110
		
111
		JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("New radio button");
112
		panel_4.add(rdbtnNewRadioButton_1);
113
		
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

  
114 207
		JPanel panel_6 = new JPanel();
115
		panel_4.add(panel_6);
116
		
117
		JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("New radio button");
118
		panel_4.add(rdbtnNewRadioButton_2);
119
		
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

  
120 223
		JPanel panel_7 = new JPanel();
121
		panel_4.add(panel_7);
122
		
123
		internalFrame_1.setVisible(true);
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);
124 229

  
125 230
	}
126 231

  
127 232
	public I3DSymbol getNewSymbol() {
128 233
		// TODO Auto-generated method stub
234
		_symbol = new PictureMarker3DSymbol();
235
		((PictureMarker3DSymbol) _symbol).setPictureFileURL(_pictureURL);
236
		((PictureMarker3DSymbol) _symbol).setSize(100);
129 237
		return _symbol;
130 238
	}
239

  
240
	public void updatePanel(I3DSymbol symbol) {
241
		// TODO Auto-generated method stub
242
		_pictureURL = ((PictureMarker3DSymbol) symbol).getPictureFileURL();
243
		// System.out.println("Setting text" + _pictureURL);
244
		textField.setText(_pictureURL);
245
		// loadFile();
246
	}
247

  
248
	public void saveParameters() {
249
		// TODO Auto-generated method stub
250

  
251
	}
252

  
253
	public class TypeFileFilter extends FileFilter {
254
		private final String[] okFileExtensions = new String[] { "jpg", "png",
255
				"bmp", "jpeg", "tiff" };
256

  
257
		public boolean accept(File file) {
258
			for (String extension : okFileExtensions) {
259
				if (file.getName().toLowerCase().endsWith(extension)
260
						|| file.isDirectory()) {
261
					return true;
262
				}
263

  
264
			}
265
			return false;
266
		}
267

  
268
		@Override
269
		public String getDescription() {
270
			// TODO Auto-generated method stub
271
			return "OSG File Types";
272
		}
273
	}
274

  
131 275
}

Also available in: Unified diff