01: package org.skunk.dav.client.gui.editor;
02:
03: import java.awt.BorderLayout;
04: import javax.swing.Box;
05: import javax.swing.BoxLayout;
06: import javax.swing.ImageIcon;
07: import javax.swing.JComponent;
08: import javax.swing.JLabel;
09: import javax.swing.JPanel;
10: import javax.swing.JScrollPane;
11: import org.skunk.dav.client.DAVFile;
12: import org.skunk.dav.client.gui.ResourceManager;
13:
14: public class ImageViewer extends AbstractDAVEditor {
15: private ImagePanel ipanel;
16: private JScrollPane scroller;
17:
18: public ImageViewer(DAVFile file) {
19: super (file);
20: ipanel = new ImagePanel();
21: scroller = new JScrollPane(ipanel);
22: }
23:
24: public DAVEditorUndoManager getUndoManager() {
25: return null;
26: }
27:
28: public JComponent getComponent() {
29: return scroller;
30: }
31:
32: public boolean isWriteable() {
33: return false;
34: }
35:
36: public void setWriteable(boolean writeable) {
37: // do nothing
38: }
39:
40: public void load() {
41: ImageIcon ii = new ImageIcon(getResourceBody());
42: ii.setDescription(getName());
43: ipanel.setImageIcon(ii);
44: }
45:
46: }
47:
48: class ImagePanel extends JPanel {
49: private JLabel imageLabel;
50: private JLabel descriptionLabel;
51:
52: public ImagePanel() {
53: this (null);
54: }
55:
56: public ImagePanel(ImageIcon ii) {
57: super ();
58: imageLabel = new JLabel();
59: imageLabel.setIcon(ii);
60: descriptionLabel = new JLabel(getLabel(ii));
61: descriptionLabel.setHorizontalAlignment(JLabel.CENTER);
62: doImageLayout();
63: }
64:
65: private String getLabel(ImageIcon ii) {
66: if (ii != null)
67: return ResourceManager.getMessage(
68: ResourceManager.IMAGE_DESCRIPTION, new Object[] {
69: ii.getDescription(),
70: new Integer(ii.getIconWidth()),
71: new Integer(ii.getIconHeight()) });
72: else
73: return "";
74: }
75:
76: public void setImageIcon(ImageIcon ii) {
77: imageLabel.setIcon(ii);
78: String label = getLabel(ii);
79: imageLabel.setToolTipText(label);
80: descriptionLabel.setText(label);
81: revalidate();
82: }
83:
84: private void doImageLayout() {
85: Box daBox = Box.createVerticalBox();
86: daBox.add(Box.createVerticalGlue());
87: daBox.add(imageLabel);
88: daBox.add(Box.createVerticalStrut(5));
89: daBox.add(descriptionLabel);
90: daBox.add(Box.createVerticalGlue());
91: setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
92: add(Box.createHorizontalGlue());
93: add(daBox);
94: add(Box.createHorizontalGlue());
95: }
96: }
|