gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.util / org.gvsig.tools.util.impl / src / main / java / org / gvsig / imageviewer / DefaultImageViewer.java @ 1702
History | View | Annotate | Download (1.17 KB)
1 |
|
---|---|
2 |
package org.gvsig.imageviewer; |
3 |
|
4 |
import java.awt.BorderLayout; |
5 |
import java.awt.Dimension; |
6 |
import java.io.File; |
7 |
import java.net.URL; |
8 |
import javax.swing.ImageIcon; |
9 |
import javax.swing.JComponent; |
10 |
import javax.swing.JLabel; |
11 |
import javax.swing.JPanel; |
12 |
|
13 |
|
14 |
public class DefaultImageViewer extends JPanel implements ImageViewer { |
15 |
|
16 |
private JLabel label; |
17 |
|
18 |
public DefaultImageViewer() {
|
19 |
this.initComponents();
|
20 |
} |
21 |
|
22 |
private void initComponents() { |
23 |
this.label = new JLabel(); |
24 |
this.setLayout(new BorderLayout()); |
25 |
this.add(this.label, BorderLayout.CENTER); |
26 |
|
27 |
this.setPreferredSize( new Dimension(200,350)); |
28 |
} |
29 |
|
30 |
@Override
|
31 |
public void setImage(URL image) { |
32 |
ImageIcon img = new ImageIcon(image); |
33 |
this.label.setIcon(img);
|
34 |
this.setPreferredSize(new Dimension(img.getIconWidth(), img.getIconHeight())); |
35 |
} |
36 |
|
37 |
@Override
|
38 |
public void setImage(File image) { |
39 |
try {
|
40 |
this.setImage(image.toURI().toURL());
|
41 |
} catch(Exception ex) { |
42 |
throw new IllegalArgumentException(ex); |
43 |
} |
44 |
} |
45 |
|
46 |
@Override
|
47 |
public JComponent asJComponent() { |
48 |
return this; |
49 |
} |
50 |
|
51 |
|
52 |
} |