1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.viewer;
21
22 import javax.swing.Icon;
23 import javax.swing.JComponent;
24
25 import org.xnap.plugin.AbstractPlugin;
26
27 /***
28 * Provides the default implementation for a viewer.
29 */
30 public abstract class AbstractViewer extends AbstractPlugin implements Viewer
31 {
32
33
34
35 public String[] extensions;
36 public JComponent component;
37 private Icon icon = null;
38
39
40
41 public AbstractViewer(String[] extensions)
42 {
43 this(extensions, null);
44 }
45
46 /***
47 * Overwrite {@link #getExtensions()} if you use this constructor.
48 */
49 public AbstractViewer()
50 {
51 }
52
53 public AbstractViewer(String[] extensions, Icon icon)
54 {
55 this.extensions = extensions;
56 this.icon = icon;
57 }
58
59
60
61 /***
62 * Does nothing.
63 */
64 public void close()
65 {
66 }
67
68 public abstract JComponent createComponent();
69
70 public JComponent getComponent()
71 {
72 if (component == null) {
73 component = createComponent();
74 }
75 return component;
76 }
77
78 /***
79 * Returns a an array of extensions that this plugin can display.
80 */
81 public String[] getExtensions()
82 {
83 return extensions;
84 }
85
86 public Icon getIcon()
87 {
88 return icon;
89 }
90
91 /***
92 * Implements the Viewer interface.
93 *
94 * @return the name of the plugin
95 * @see xnap.plugin.PluginInfo#getName()
96 */
97 public String getName()
98 {
99 return getInfo().getName();
100 }
101
102 /***
103 * Does nothing.
104 *
105 * @see xnap.plugin.Plugin#start()
106 */
107 public void start()
108 {
109
110 }
111
112
113 /***
114 * Registers the extensions at the {@link ViewerManager}.
115 */
116 public void startGUI()
117 {
118 ViewerManager.getInstance().register(getExtensions(), this);
119 }
120
121 /***
122 * Does nothing.
123 *
124 * @see xnap.plugin.Plugin#stop()
125 */
126 public void stop()
127 {
128
129 }
130
131 /***
132 * Unregisters the extensions at the {@link ViewerManager}.
133 */
134 public void stopGUI()
135 {
136 ViewerManager.getInstance().unregister(getExtensions(), this);
137 component = null;
138 }
139
140 /***
141 * Returns the value get.Info().getName().
142 */
143 public String toString()
144 {
145 return getInfo().getName();
146 }
147
148 }