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 @ 2543
History | View | Annotate | Download (1.67 KB)
1 |
|
---|---|
2 |
package org.gvsig.imageviewer; |
3 |
|
4 |
import java.awt.BorderLayout; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.Image; |
7 |
import java.io.File; |
8 |
import java.net.URL; |
9 |
import javax.swing.Action; |
10 |
import javax.swing.ImageIcon; |
11 |
import javax.swing.JComponent; |
12 |
import javax.swing.JLabel; |
13 |
import javax.swing.JPanel; |
14 |
|
15 |
|
16 |
@SuppressWarnings("UseSpecificCatch") |
17 |
public class DefaultImageViewer extends JPanel implements ImageViewer { |
18 |
|
19 |
private JLabel label; |
20 |
|
21 |
public DefaultImageViewer() {
|
22 |
this.initComponents();
|
23 |
} |
24 |
|
25 |
private void initComponents() { |
26 |
this.label = new JLabel(); |
27 |
this.setLayout(new BorderLayout()); |
28 |
this.add(this.label, BorderLayout.CENTER); |
29 |
|
30 |
this.setPreferredSize( new Dimension(200,350)); |
31 |
} |
32 |
|
33 |
private void setImage(ImageIcon image) { |
34 |
this.label.setIcon(image);
|
35 |
this.setPreferredSize(new Dimension(image.getIconWidth(), image.getIconHeight())); |
36 |
} |
37 |
|
38 |
@Override
|
39 |
public void setImage(URL image) { |
40 |
ImageIcon img = new ImageIcon(image); |
41 |
this.setImage(img);
|
42 |
} |
43 |
|
44 |
@Override
|
45 |
public void setImage(File image) { |
46 |
try {
|
47 |
this.setImage(image.toURI().toURL());
|
48 |
} catch(Exception ex) { |
49 |
throw new IllegalArgumentException(ex); |
50 |
} |
51 |
} |
52 |
|
53 |
@Override
|
54 |
public void setImage(Image image) { |
55 |
ImageIcon img = new ImageIcon(image); |
56 |
this.setImage(img);
|
57 |
} |
58 |
|
59 |
@Override
|
60 |
public JComponent asJComponent() { |
61 |
return this; |
62 |
} |
63 |
|
64 |
@Override
|
65 |
public void clean() { |
66 |
this.label.setIcon(null); |
67 |
} |
68 |
|
69 |
@Override
|
70 |
public void addAction(Action action) { |
71 |
// Do nothing, don't support adding actions.
|
72 |
} |
73 |
|
74 |
} |