Revision 352
2.0/trunk/org.gvsig.gvsig3d.app/org.gvsig.gvsig3d.app.extension/package.info | ||
---|---|---|
1 | 1 |
# |
2 |
#Thu Mar 22 14:22:18 CET 2012
|
|
2 |
#Fri Mar 23 14:05:05 CET 2012
|
|
3 | 3 |
owner=gvSIG Association |
4 | 4 |
code=org.gvsig.gvsig3d.app.extension |
5 | 5 |
java-version=j1_5 |
2.0/trunk/org.gvsig.gvsig3d.app/org.gvsig.gvsig3d.app.extension/src/main/java/org/gvsig/gvsig3d/app/gui/styling/PictureSymbolTab.java | ||
---|---|---|
13 | 13 |
import java.awt.event.ActionListener; |
14 | 14 |
import java.awt.image.BufferedImage; |
15 | 15 |
import java.io.File; |
16 |
import java.util.ArrayList; |
|
17 |
import java.util.Arrays; |
|
16 | 18 |
import java.util.Hashtable; |
17 | 19 |
import java.util.Iterator; |
18 | 20 |
import java.util.Map; |
... | ... | |
62 | 64 |
|
63 | 65 |
private Hashtable<JRadioButton, String> _radioMap = new Hashtable<JRadioButton, String>(); |
64 | 66 |
|
67 |
private JComboBox combo; |
|
68 |
|
|
69 |
private String path; |
|
70 |
|
|
65 | 71 |
/** |
66 | 72 |
* Create the panel. |
67 | 73 |
*/ |
... | ... | |
133 | 139 |
FileFilter ff = new TypeFileFilter(); |
134 | 140 |
fc.setFileFilter(ff); |
135 | 141 |
|
142 |
ImagePreviewPanel preview = new ImagePreviewPanel(); |
|
143 |
fc.setAccessory(preview); |
|
144 |
fc.addPropertyChangeListener(preview); |
|
145 |
|
|
136 | 146 |
int returnVal = fc.showDialog(PictureSymbolTab.this, "Accept"); |
137 | 147 |
|
138 | 148 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
... | ... | |
175 | 185 |
propertiesPanel.setPreferredSize(new Dimension(80, 80)); |
176 | 186 |
|
177 | 187 |
panel_4 = new JPanel(); |
178 |
tabbedPane.addTab("Collection", null, panel_4, null); |
|
188 |
tabbedPane.addTab("Collections", null, panel_4, null);
|
|
179 | 189 |
GridBagLayout gbl_panel_4 = new GridBagLayout(); |
180 | 190 |
gbl_panel_4.columnWidths = new int[] { 150 }; |
181 | 191 |
gbl_panel_4.rowHeights = new int[] { 30, 220 }; |
... | ... | |
183 | 193 |
gbl_panel_4.rowWeights = new double[] { 0.0, 0.0 }; |
184 | 194 |
panel_4.setLayout(gbl_panel_4); |
185 | 195 |
|
186 |
String path = PictureSymbolTab.class.getResource("/markers").getPath();
|
|
196 |
path = PictureSymbolTab.class.getResource("/markers").getPath(); |
|
187 | 197 |
|
188 |
JComboBox combo = new JComboBox(); |
|
198 |
combo = new JComboBox(); |
|
199 |
combo.addActionListener(new ActionListener() { |
|
200 |
public void actionPerformed(ActionEvent arg0) { |
|
201 |
|
|
202 |
String dir = (String) combo.getSelectedItem(); |
|
203 |
previews.removeAll(); |
|
204 |
_radioMap.clear(); |
|
205 |
fillPreviews(path + "/" + dir); |
|
206 |
PictureSymbolTab.this.repaint(); |
|
207 |
} |
|
208 |
}); |
|
189 | 209 |
File dir = new File(path); |
190 |
combo.setModel(new DefaultComboBoxModel(new String[] { dir.getName() }));
|
|
210 |
combo.setModel(new DefaultComboBoxModel(new String[] {})); |
|
191 | 211 |
GridBagConstraints gbc_combo = new GridBagConstraints(); |
192 | 212 |
// gbc_combo.fill = GridBagConstraints.HORIZONTAL; |
193 | 213 |
gbc_combo.anchor = GridBagConstraints.WEST; |
... | ... | |
200 | 220 |
GridBagLayout gbl_previews = new GridBagLayout(); |
201 | 221 |
// gbl_previews.columnWidths = new int[] { 15, 60, 15, 60 }; |
202 | 222 |
// gbl_previews.rowHeights = new int[] { 40, 40, 40, 40 }; |
203 |
gbl_previews.columnWeights = new double[] { 0.0, 0.0 };
|
|
223 |
gbl_previews.columnWeights = new double[] {}; |
|
204 | 224 |
// gbl_previews.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0 }; |
205 | 225 |
GridBagConstraints gbc_previews = new GridBagConstraints(); |
206 | 226 |
gbc_previews.fill = GridBagConstraints.BOTH; |
... | ... | |
212 | 232 |
|
213 | 233 |
JScrollPane scroll = new JScrollPane(); |
214 | 234 |
scroll.setViewportView(previews); |
235 |
scroll.getVerticalScrollBar().setUnitIncrement(16); |
|
215 | 236 |
// scroll.setPreferredSize(new Dimension(180,300)); |
216 | 237 |
panel_4.add(scroll, gbc_previews); |
217 | 238 |
|
218 |
fillPreviews(path); |
|
239 |
fillPreviews(path + "/base"); |
|
240 |
fillCombo(combo, path); |
|
219 | 241 |
|
220 | 242 |
} |
221 | 243 |
|
... | ... | |
224 | 246 |
File dir = new File(path); |
225 | 247 |
|
226 | 248 |
if (dir.isDirectory()) { |
227 |
for (File child : dir.listFiles()) { |
|
249 |
File[] files = dir.listFiles(); |
|
250 |
Arrays.sort(files); |
|
251 |
for (File child : files) { |
|
228 | 252 |
if (".".equals(child.getName()) || "..".equals(child.getName()) |
229 |
|| child.isDirectory()) { |
|
253 |
|| !child.isDirectory()) {
|
|
230 | 254 |
continue; // Ignore the self and parent aliases. |
231 | 255 |
} |
232 | 256 |
|
233 |
if (child.isDirectory()) {
|
|
257 |
combo.addItem(child.getName());
|
|
234 | 258 |
|
235 |
combo.addItem(child.getName()); |
|
236 |
|
|
237 |
} |
|
238 |
|
|
239 | 259 |
} |
240 | 260 |
} |
261 |
|
|
241 | 262 |
} |
242 | 263 |
|
243 | 264 |
private void fillPreviews(String path) { |
... | ... | |
279 | 300 |
|
280 | 301 |
radio.addActionListener(new ActionListener() { |
281 | 302 |
public void actionPerformed(ActionEvent arg0) { |
282 |
|
|
303 |
|
|
283 | 304 |
_pictureURL = _radioMap.get(arg0.getSource()); |
284 | 305 |
|
285 | 306 |
for (JRadioButton key : _radioMap.keySet()) { |
286 | 307 |
|
287 |
if (key != arg0.getSource()) |
|
308 |
if (key != arg0.getSource()) {
|
|
288 | 309 |
key.setSelected(false); |
310 |
} |
|
289 | 311 |
|
290 | 312 |
} |
291 | 313 |
|
... | ... | |
297 | 319 |
} |
298 | 320 |
} |
299 | 321 |
|
300 |
|
|
301 | 322 |
} |
302 | 323 |
|
303 | 324 |
public I3DSymbol getNewSymbol() { |
304 | 325 |
// TODO Auto-generated method stub |
305 | 326 |
_symbol = new PictureMarker3DSymbol(); |
306 | 327 |
|
328 |
if (_pictureURL == null) |
|
329 |
return null; |
|
330 |
|
|
307 | 331 |
if (panel.isVisible()) { |
308 | 332 |
((PictureMarker3DSymbol) _symbol).setPictureFileURL(_pictureURL); |
309 | 333 |
((PictureMarker3DSymbol) _symbol).setSize((Double) sizeSpinner |
310 | 334 |
.getValue()); |
311 | 335 |
} else { |
312 | 336 |
|
313 |
((PictureMarker3DSymbol) _symbol) |
|
314 |
.setPictureFileURL(_pictureURL); |
|
337 |
((PictureMarker3DSymbol) _symbol).setPictureFileURL(_pictureURL); |
|
315 | 338 |
((PictureMarker3DSymbol) _symbol).setSize((Double) sizeSpinner |
316 | 339 |
.getValue()); |
317 | 340 |
|
2.0/trunk/org.gvsig.gvsig3d.app/org.gvsig.gvsig3d.app.extension/src/main/java/org/gvsig/gvsig3d/app/gui/styling/Object3DSymbolTab.java | ||
---|---|---|
12 | 12 |
import java.io.File; |
13 | 13 |
import java.io.FileNotFoundException; |
14 | 14 |
|
15 |
import javax.swing.DefaultComboBoxModel; |
|
15 | 16 |
import javax.swing.JButton; |
17 |
import javax.swing.JComboBox; |
|
16 | 18 |
import javax.swing.JFileChooser; |
17 | 19 |
import javax.swing.JLabel; |
18 | 20 |
import javax.swing.JPanel; |
19 |
import javax.swing.JRadioButton; |
|
20 | 21 |
import javax.swing.JSpinner; |
21 | 22 |
import javax.swing.JTabbedPane; |
22 | 23 |
import javax.swing.JTextField; |
... | ... | |
29 | 30 |
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol; |
30 | 31 |
import org.gvsig.osgvp.core.osg.Group; |
31 | 32 |
import org.gvsig.osgvp.core.osg.Node; |
32 |
import org.gvsig.osgvp.core.osg.Vec3; |
|
33 | 33 |
import org.gvsig.osgvp.core.osgdb.osgDB; |
34 | 34 |
import org.gvsig.osgvp.exceptions.node.LoadNodeException; |
35 | 35 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
36 | 36 |
import org.gvsig.osgvp.viewer.ViewerFactory; |
37 |
import javax.swing.JComboBox; |
|
38 |
import javax.swing.DefaultComboBoxModel; |
|
39 | 37 |
|
40 | 38 |
public class Object3DSymbolTab extends JPanel implements ISymbolSelectorTab { |
41 | 39 |
|
... | ... | |
49 | 47 |
|
50 | 48 |
private JSpinner sizeSpinner; |
51 | 49 |
|
52 |
private JComboBox _comboBox;
|
|
50 |
private JComboBox _particleComboBox;
|
|
53 | 51 |
|
52 |
private JComboBox _instancesComboBox; |
|
53 |
|
|
54 |
private String _textureURL; |
|
55 |
|
|
54 | 56 |
/** |
55 | 57 |
* Create the panel. |
56 | 58 |
*/ |
... | ... | |
112 | 114 |
public void actionPerformed(ActionEvent e) { |
113 | 115 |
|
114 | 116 |
JFileChooser fc = new JFileChooser(); |
115 |
FileFilter ff = new TypeFileFilter(); |
|
117 |
FileFilter ff = new OSGTypeFileFilter();
|
|
116 | 118 |
fc.setFileFilter(ff); |
117 | 119 |
|
118 | 120 |
int returnVal = fc.showDialog(Object3DSymbolTab.this, "Accept"); |
... | ... | |
163 | 165 |
tabbedPane.addTab("Collection", null, panel_4, null); |
164 | 166 |
GridBagLayout gbl_panel_4 = new GridBagLayout(); |
165 | 167 |
gbl_panel_4.columnWidths = new int[] { 175 }; |
166 |
gbl_panel_4.rowHeights = new int[] { 250, 45 };
|
|
167 |
gbl_panel_4.columnWeights = new double[] { 1.0 };
|
|
168 |
gbl_panel_4.rowWeights = new double[] { 1.0, 0.0 };
|
|
168 |
gbl_panel_4.rowHeights = new int[] { 180, 18, 18, 18, 18 };
|
|
169 |
gbl_panel_4.columnWeights = new double[] { 0.0 };
|
|
170 |
gbl_panel_4.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 };
|
|
169 | 171 |
panel_4.setLayout(gbl_panel_4); |
170 | 172 |
|
171 | 173 |
JPanel panel_1 = new JPanel(); |
... | ... | |
181 | 183 |
|
182 | 184 |
panel_1.add(getAlternateOsgPanel()); |
183 | 185 |
|
184 |
_comboBox = new JComboBox();
|
|
185 |
_comboBox.addActionListener(new ActionListener() {
|
|
186 |
_particleComboBox = new JComboBox();
|
|
187 |
_particleComboBox.addActionListener(new ActionListener() {
|
|
186 | 188 |
public void actionPerformed(ActionEvent arg0) { |
187 | 189 |
|
188 | 190 |
if (arg0.getSource() instanceof JComboBox) { |
189 |
switch (_comboBox.getSelectedIndex()) {
|
|
191 |
switch (_particleComboBox.getSelectedIndex()) {
|
|
190 | 192 |
|
191 | 193 |
case 0: |
192 | 194 |
_nodeURL = Object3DSymbolTab.class.getResource( |
... | ... | |
225 | 227 |
} |
226 | 228 |
} |
227 | 229 |
}); |
228 |
_comboBox.setModel(new DefaultComboBoxModel(new String[] { "Fire", |
|
229 |
"Radial", "Space", "Flare" })); |
|
230 |
|
|
231 |
JLabel lblParticles = new JLabel("Particles:"); |
|
232 |
GridBagConstraints gbc_lblParticles = new GridBagConstraints(); |
|
233 |
gbc_lblParticles.anchor = GridBagConstraints.WEST; |
|
234 |
gbc_lblParticles.insets = new Insets(0, 0, 5, 0); |
|
235 |
gbc_lblParticles.gridx = 0; |
|
236 |
gbc_lblParticles.gridy = 1; |
|
237 |
panel_4.add(lblParticles, gbc_lblParticles); |
|
238 |
_particleComboBox.setModel(new DefaultComboBoxModel(new String[] { |
|
239 |
"Fire", "Radial", "Space", "Flare" })); |
|
230 | 240 |
GridBagConstraints gbc_comboBox = new GridBagConstraints(); |
241 |
gbc_comboBox.insets = new Insets(0, 0, 5, 0); |
|
231 | 242 |
gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; |
232 | 243 |
gbc_comboBox.gridx = 0; |
233 |
gbc_comboBox.gridy = 1;
|
|
234 |
panel_4.add(_comboBox, gbc_comboBox);
|
|
244 |
gbc_comboBox.gridy = 2;
|
|
245 |
panel_4.add(_particleComboBox, gbc_comboBox);
|
|
235 | 246 |
|
247 |
JPanel panelComboInstances = new JPanel(); |
|
248 |
|
|
249 |
GridBagConstraints gbc_panelI = new GridBagConstraints(); |
|
250 |
gbc_panelI.fill = GridBagConstraints.HORIZONTAL; |
|
251 |
gbc_panelI.gridx = 0; |
|
252 |
gbc_panelI.gridy = 4; |
|
253 |
panel_4.add(panelComboInstances, gbc_panelI); |
|
254 |
GridBagLayout gbl_panelComboInstances = new GridBagLayout(); |
|
255 |
gbl_panelComboInstances.columnWidths = new int[] { 0, 0, 0 }; |
|
256 |
gbl_panelComboInstances.rowHeights = new int[] { 0 }; |
|
257 |
gbl_panelComboInstances.columnWeights = new double[] { |
|
258 |
Double.MIN_VALUE, 0.0, Double.MIN_VALUE }; |
|
259 |
gbl_panelComboInstances.rowWeights = new double[] { Double.MIN_VALUE }; |
|
260 |
panelComboInstances.setLayout(gbl_panelComboInstances); |
|
261 |
|
|
262 |
_instancesComboBox = new JComboBox(); |
|
263 |
_instancesComboBox.addActionListener(new ActionListener() { |
|
264 |
public void actionPerformed(ActionEvent arg0) { |
|
265 |
|
|
266 |
if (arg0.getSource() instanceof JComboBox) { |
|
267 |
switch (_instancesComboBox.getSelectedIndex()) { |
|
268 |
|
|
269 |
case 0: |
|
270 |
_nodeURL = Object3DSymbolTab.class.getResource( |
|
271 |
"/particle/fire.osgb").getPath(); |
|
272 |
break; |
|
273 |
case 1: |
|
274 |
_nodeURL = Object3DSymbolTab.class.getResource( |
|
275 |
"/particle/radial.osgb").getPath(); |
|
276 |
break; |
|
277 |
case 2: |
|
278 |
_nodeURL = Object3DSymbolTab.class.getResource( |
|
279 |
"/particle/space.osgb").getPath(); |
|
280 |
break; |
|
281 |
case 3: |
|
282 |
_nodeURL = Object3DSymbolTab.class.getResource( |
|
283 |
"/particle/trisistema.osgb").getPath(); |
|
284 |
break; |
|
285 |
|
|
286 |
default: |
|
287 |
break; |
|
288 |
|
|
289 |
} |
|
290 |
|
|
291 |
try { |
|
292 |
Node node = osgDB.readNodeFile(_nodeURL); |
|
293 |
_alternateCanvas3d.getOSGViewer().setSceneData(node); |
|
294 |
|
|
295 |
} catch (LoadNodeException e) { |
|
296 |
// TODO Auto-generated catch block |
|
297 |
e.printStackTrace(); |
|
298 |
} catch (FileNotFoundException e) { |
|
299 |
// TODO Auto-generated catch block |
|
300 |
e.printStackTrace(); |
|
301 |
} |
|
302 |
|
|
303 |
} |
|
304 |
} |
|
305 |
}); |
|
306 |
|
|
307 |
JLabel lblObjects = new JLabel("Geometries:"); |
|
308 |
GridBagConstraints gbc_lblObjects = new GridBagConstraints(); |
|
309 |
gbc_lblObjects.anchor = GridBagConstraints.WEST; |
|
310 |
gbc_lblObjects.insets = new Insets(0, 0, 5, 0); |
|
311 |
gbc_lblObjects.gridx = 0; |
|
312 |
gbc_lblObjects.gridy = 3; |
|
313 |
panel_4.add(lblObjects, gbc_lblObjects); |
|
314 |
_instancesComboBox.setModel(new DefaultComboBoxModel( |
|
315 |
new String[] { "Cube" })); |
|
316 |
GridBagConstraints gbc_icomboBox = new GridBagConstraints(); |
|
317 |
gbc_icomboBox.insets = new Insets(0, 0, 0, 5); |
|
318 |
gbc_icomboBox.fill = GridBagConstraints.HORIZONTAL; |
|
319 |
gbc_icomboBox.gridx = 0; |
|
320 |
gbc_icomboBox.gridy = 0; |
|
321 |
panelComboInstances.add(_instancesComboBox, gbc_icomboBox); |
|
322 |
|
|
323 |
JButton btnTexture = new JButton("Texture"); |
|
324 |
btnTexture.addActionListener(new ActionListener() { |
|
325 |
|
|
326 |
public void actionPerformed(ActionEvent arg0) { |
|
327 |
|
|
328 |
JFileChooser fc = new JFileChooser(); |
|
329 |
fc.setCurrentDirectory(new File(Object3DSymbolTab.class |
|
330 |
.getResource("/markers").getPath())); |
|
331 |
FileFilter ff = new ImageTypeFileFilter(); |
|
332 |
fc.setFileFilter(ff); |
|
333 |
|
|
334 |
ImagePreviewPanel preview = new ImagePreviewPanel(); |
|
335 |
fc.setAccessory(preview); |
|
336 |
fc.addPropertyChangeListener(preview); |
|
337 |
|
|
338 |
int returnVal = fc.showDialog(Object3DSymbolTab.this, "Accept"); |
|
339 |
|
|
340 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
|
341 |
File file = fc.getSelectedFile(); |
|
342 |
_textureURL = file.getAbsolutePath(); |
|
343 |
|
|
344 |
} else { |
|
345 |
|
|
346 |
} |
|
347 |
|
|
348 |
// _symbol.setColor(newColor); |
|
349 |
// _colorPanel.setBackground(newColor); |
|
350 |
// _colorPanel.repaint(); |
|
351 |
// symbolPreviewPanel.repaint(); |
|
352 |
// ((SymbolSelector3D) _parent).setSymbol(_symbol); |
|
353 |
|
|
354 |
} |
|
355 |
|
|
356 |
}); |
|
357 |
GridBagConstraints gbc_btnTexture = new GridBagConstraints(); |
|
358 |
gbc_btnTexture.gridx = 1; |
|
359 |
gbc_btnTexture.gridy = 0; |
|
360 |
panelComboInstances.add(btnTexture, gbc_btnTexture); |
|
361 |
|
|
236 | 362 |
} |
237 | 363 |
|
238 | 364 |
private JPanel getOsgPanel() { |
... | ... | |
319 | 445 |
|
320 | 446 |
} |
321 | 447 |
|
322 |
public class TypeFileFilter extends FileFilter { |
|
448 |
public class OSGTypeFileFilter extends FileFilter {
|
|
323 | 449 |
private final String[] okFileExtensions = new String[] { "3ds", "ive", |
324 | 450 |
"osg" }; |
325 | 451 |
|
... | ... | |
340 | 466 |
return "OSG File Types"; |
341 | 467 |
} |
342 | 468 |
} |
469 |
|
|
470 |
public class ImageTypeFileFilter extends FileFilter { |
|
471 |
private final String[] okFileExtensions = new String[] { "bmp", "png", |
|
472 |
"jpg", "jpeg", "gif" }; |
|
343 | 473 |
|
474 |
public boolean accept(File file) { |
|
475 |
for (String extension : okFileExtensions) { |
|
476 |
if (file.getName().toLowerCase().endsWith(extension) |
|
477 |
|| file.isDirectory()) { |
|
478 |
return true; |
|
479 |
} |
|
480 |
|
|
481 |
} |
|
482 |
return false; |
|
483 |
} |
|
484 |
|
|
485 |
@Override |
|
486 |
public String getDescription() { |
|
487 |
// TODO Auto-generated method stub |
|
488 |
return "Image File Types"; |
|
489 |
} |
|
490 |
} |
|
491 |
|
|
344 | 492 |
} |
2.0/trunk/org.gvsig.gvsig3d.app/org.gvsig.gvsig3d.app.extension/src/main/java/org/gvsig/gvsig3d/app/gui/styling/ImagePreviewPanel.java | ||
---|---|---|
1 |
package org.gvsig.gvsig3d.app.gui.styling; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Dimension; |
|
5 |
import java.awt.Graphics; |
|
6 |
import java.awt.Image; |
|
7 |
import java.beans.PropertyChangeEvent; |
|
8 |
import java.beans.PropertyChangeListener; |
|
9 |
import java.io.File; |
|
10 |
|
|
11 |
import javax.swing.ImageIcon; |
|
12 |
import javax.swing.JFileChooser; |
|
13 |
import javax.swing.JPanel; |
|
14 |
|
|
15 |
public class ImagePreviewPanel extends JPanel implements PropertyChangeListener { |
|
16 |
|
|
17 |
/** |
|
18 |
* |
|
19 |
*/ |
|
20 |
private static final long serialVersionUID = 7008632116172130657L; |
|
21 |
|
|
22 |
private int width, height; |
|
23 |
private ImageIcon icon; |
|
24 |
private Image image; |
|
25 |
private static final int ACCSIZE = 155; |
|
26 |
private Color bg; |
|
27 |
|
|
28 |
public ImagePreviewPanel() { |
|
29 |
setPreferredSize(new Dimension(ACCSIZE, -1)); |
|
30 |
bg = getBackground(); |
|
31 |
} |
|
32 |
|
|
33 |
public void propertyChange(PropertyChangeEvent e) { |
|
34 |
String propertyName = e.getPropertyName(); |
|
35 |
|
|
36 |
|
|
37 |
if (propertyName.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) { |
|
38 |
File selection = (File) e.getNewValue(); |
|
39 |
String name; |
|
40 |
|
|
41 |
if (selection == null) |
|
42 |
return; |
|
43 |
else |
|
44 |
name = selection.getAbsolutePath(); |
|
45 |
|
|
46 |
if ((name != null) && name.toLowerCase().endsWith(".jpg") |
|
47 |
|| name.toLowerCase().endsWith(".jpeg") |
|
48 |
|| name.toLowerCase().endsWith(".gif") |
|
49 |
|| name.toLowerCase().endsWith(".png")) { |
|
50 |
icon = new ImageIcon(name); |
|
51 |
image = icon.getImage(); |
|
52 |
scaleImage(); |
|
53 |
repaint(); |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
private void scaleImage() { |
|
59 |
width = image.getWidth(this); |
|
60 |
height = image.getHeight(this); |
|
61 |
double ratio = 1.0; |
|
62 |
|
|
63 |
|
|
64 |
if (width >= height) { |
|
65 |
ratio = (double) (ACCSIZE - 5) / width; |
|
66 |
width = ACCSIZE - 5; |
|
67 |
height = (int) (height * ratio); |
|
68 |
} else { |
|
69 |
if (getHeight() > 150) { |
|
70 |
ratio = (double) (ACCSIZE - 5) / height; |
|
71 |
height = ACCSIZE - 5; |
|
72 |
width = (int) (width * ratio); |
|
73 |
} else { |
|
74 |
ratio = (double) getHeight() / height; |
|
75 |
height = getHeight(); |
|
76 |
width = (int) (width * ratio); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
image = image.getScaledInstance(width, height, Image.SCALE_DEFAULT); |
|
81 |
} |
|
82 |
|
|
83 |
public void paintComponent(Graphics g) { |
|
84 |
g.setColor(bg); |
|
85 |
|
|
86 |
g.fillRect(0, 0, ACCSIZE, getHeight()); |
|
87 |
g.drawImage(image, getWidth() / 2 - width / 2 + 5, getHeight() / 2 |
|
88 |
- height / 2, this); |
|
89 |
} |
|
90 |
|
|
91 |
} |
Also available in: Unified diff