Revision 337 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
3 3
import java.awt.BorderLayout;
4 4
import java.awt.Component;
5 5
import java.awt.Dimension;
6
import java.awt.Graphics2D;
6 7
import java.awt.GridBagConstraints;
7 8
import java.awt.GridBagLayout;
8 9
import java.awt.GridLayout;
10
import java.awt.Image;
9 11
import java.awt.Insets;
10 12
import java.io.File;
11 13
import java.io.FileNotFoundException;
......
35 37
import org.gvsig.osgvp.viewer.ViewerFactory;
36 38
import java.awt.event.ActionListener;
37 39
import java.awt.event.ActionEvent;
40
import java.awt.image.BufferedImage;
41

  
38 42
import javax.swing.JSlider;
39 43
import javax.swing.SpinnerNumberModel;
40 44
import javax.swing.event.ChangeListener;
......
115 119
					icon = new ImageIcon(_pictureURL);
116 120
					background = new JLabel(icon);
117 121
					_picturePanel.removeAll();
118
					_picturePanel.add(background);
119
					_picturePanel.setIgnoreRepaint(false);
122
					_picturePanel.add(new JLabel(scale(icon.getImage())),BorderLayout.CENTER);
123
					background.repaint();
120 124
					panel.repaint();
121 125

  
122 126
				} else {
......
128 132
				// _colorPanel.repaint();
129 133
				// symbolPreviewPanel.repaint();
130 134
				// ((SymbolSelector3D) _parent).setSymbol(_symbol);
131

  
135
				
132 136
			}
133 137
		});
134 138
		propertiesPanel.add(btnBrowse);
......
141 145
		panel_3.setLayout(new BorderLayout(0, 0));
142 146

  
143 147
		sizeSpinner = new JSpinner();
144
		sizeSpinner.addChangeListener(new ChangeListener() {
145
			public void stateChanged(ChangeEvent arg0) {
146 148

  
147
				_symbol.setSize((Double) sizeSpinner.getValue());
148
			}
149
		});
150
		sizeSpinner.setModel(new SpinnerNumberModel(1, 1, 100, 1));
149
		sizeSpinner.setModel(new SpinnerNumberModel(1.0, 1.0, 100.0, 1.0));
151 150
		panel_3.add(sizeSpinner);
152 151

  
153 152
		previewPanel = new JPanel();
......
164 163
		_picturePanel = new JPanel();
165 164
		previewPanel.add(_picturePanel, BorderLayout.CENTER);
166 165
		_picturePanel.setLayout(new BorderLayout(0, 0));
167
		
166

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

  
171
		_picturePanel.add(background, BorderLayout.CENTER);
170
		_picturePanel.add(new JLabel(scale(icon.getImage())), BorderLayout.CENTER);
172 171

  
173 172
		JPanel panel_4 = new JPanel();
174 173
		tabbedPane.addTab("Collection", null, panel_4, null);
......
232 231
		// TODO Auto-generated method stub
233 232
		_symbol = new PictureMarker3DSymbol();
234 233
		((PictureMarker3DSymbol) _symbol).setPictureFileURL(_pictureURL);
235
		((PictureMarker3DSymbol) _symbol).setSize(100);
234
		((PictureMarker3DSymbol) _symbol).setSize((Double) sizeSpinner.getValue());
236 235
		return _symbol;
237 236
	}
238 237

  
239 238
	public void updatePanel(I3DSymbol symbol) {
240 239
		// TODO Auto-generated method stub
241 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());
242 248
		// System.out.println("Setting text" + _pictureURL);
243 249
		textField.setText(_pictureURL);
244 250
		// loadFile();
......
271 277
		}
272 278
	}
273 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

  
274 291
}

Also available in: Unified diff