KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > directory > jxplorer > viewer > BasicPluggableEditor


1 package com.ca.directory.jxplorer.viewer;
2
3 import java.awt.*;
4 import javax.swing.*;
5
6 import com.ca.directory.jxplorer.DataSource;
7 import com.ca.directory.jxplorer.DataSink;
8 import com.ca.commons.naming.DXEntry;
9 import com.ca.commons.cbutil.CBIntText;
10 import com.ca.commons.cbutil.CBHelpSystem;
11
12 import javax.swing.ImageIcon JavaDoc;
13
14
15
16 /**
17  * This is a Basic 'PluggableEditor' that it may be useful to inherit from.
18  * It is no more than a read-only text display of an entry, with no-op methods for
19  * for most of the PluggableEditor and DataSink interface methods.
20  * @author Chris Betts
21  *
22  */

23  
24
25 public class BasicPluggableEditor extends JPanel
26     implements DataSink, PluggableEditor
27 {
28     
29     JEditorPane basicDisplay = null;
30
31     /**
32      * A Simple constructor that creates the JEditorPane.
33      */

34     public BasicPluggableEditor()
35     {
36         setVisible(true);
37     }
38     
39     protected void initDefaultEditor(String JavaDoc bloop)
40     {
41         basicDisplay = new JEditorPane("text/plain",bloop);
42         basicDisplay.setEditable(false);
43         basicDisplay.setFont(new Font("Monospaced",Font.PLAIN,12));
44         this.removeAll();
45         this.setLayout(new BorderLayout());
46         this.add(basicDisplay, BorderLayout.CENTER);
47         this.repaint();
48         this.invalidate();
49         
50     }
51     
52     /**
53      * Displays the data in an entry as a plain text list.
54      */

55      
56     public void displayEntry(DXEntry entry, DataSource ds)
57     {
58         String JavaDoc bloop = entry.toString();
59         initDefaultEditor(bloop);
60     }
61
62     /**
63      * This returns the swing component being used to display
64      * the data, so that another component can set its visibility.<p>
65      * In many cases this may be the editor itself.
66      * @return the java.swing component being used to display the node data.
67      */

68      
69     public JComponent getDisplayComponent()
70     {
71         return this;
72     }
73     
74     /**
75      * This returns the component that should be used to print
76      * the data (e.g. a full table of data that spans several pages).<p>
77      * The default implementation simply returns getDisplayComponent().
78      * @return the component being used to print the node data.
79      */

80     public Component getPrintComponent()
81     {
82         return getDisplayComponent();
83     }
84     
85      /**
86       * Returns the data sink that will be used to slurp data.<p>
87       * In many cases this may be the editor itself.
88       * @return a data sink to display or process data.
89       */

90       
91      public DataSink getDataSink()
92      {
93      
94          return this;
95      }
96
97     
98     /**
99      * This sets whether the component expects to be the <i>only</i>
100      * editor used for its object class, or whether it will co-exist
101      * with any other applicable editors, and the default (html/table)
102      * editor.
103      */

104      
105     public boolean isUnique()
106     {
107         return false;
108     }
109     
110     /**
111      * Returns the title of the editor. (This might be displayed on a
112      * tab or similar). If null, the object class name will be used
113      * instead.
114      */

115      
116     public String JavaDoc getName()
117     {
118         return CBIntText.get("Basic Editor");
119     }
120      
121     /**
122      * Returns the icon of the editor. (This might be displayed on a tab or similar).
123      * (not set yet).
124      *
125      */

126            
127     public ImageIcon JavaDoc getIcon()
128     {
129         return new ImageIcon JavaDoc("");
130     }
131     
132     /**
133      * Returns the Tool Tip of the editor. (This might be displayed on a tab or similar).
134      * (not set yet).
135      * .
136      */

137          
138     public String JavaDoc getToolTip()
139     {
140         return "";
141     }
142     
143     /**
144      * Registers Swing components that the pluggable editor may manipulate.
145      * Any or all of these may be null if the editor is not permitted to
146      * manipulate the objects. <p>
147      *
148      * Any changes made by the editor should be removed when the editor is
149      * unloaded.
150      */

151      
152     public void registerComponents(JMenuBar menu, JToolBar buttons, JTree tree, JPopupMenu treeMenu, JFrame jxplorer)
153     {
154         // do nothing
155
}
156      
157      
158      /**
159       * This method is called when the editor is being unloaded by the browser,
160       * and allows for any required clean up activity.
161       */

162           
163     public void unload()
164     {
165         // do nothing
166
}
167
168     /**
169      * Whether this editor can handle a partially created new entry.
170      */

171          
172     public boolean canCreateEntry()
173     {
174         return false;
175     }
176     
177     /**
178      * Use the default tree icon system based on naming value
179      * or object class.
180      */

181      
182     public ImageIcon JavaDoc getTreeIcon(String JavaDoc rdn) { return null; }
183     
184     /**
185      * Use the default popupmenu.
186      */

187      
188     public JPopupMenu getPopupMenu(String JavaDoc rdn) { return null; }
189     
190     /**
191      * Don't hide sub entries.
192      */

193      
194     public boolean hideSubEntries(String JavaDoc rdn) { return false; }
195      
196      
197     /**
198      * <p>If you want to include language translation files in
199      * your plugin, simply zip 'em up, and use this method
200      * to register the base name of the translation files.</p>
201      * <p>For example, if your translation files are 'myPlugin.properties',
202      * 'myPlugin_ja.properties', and 'myPlugin_fr_CA.properties',
203      * you can just zip them up in the same zip file as the
204      * rest of the plugins, and call this method with the
205      * string 'myPlugin' to have these language files
206      * appended to the base JX language file set.)</p>
207      * @param name the base name of all the different language
208      * files.
209      */

210     public void addLanguageBundle(String JavaDoc name)
211     {
212         CBIntText.addBundle(name, getClass().getClassLoader());
213     }
214     
215     /**
216     * <p>Optionally adds the name of a custom help set to
217     * JXplorer's default help set. The help set will
218     * be loaded from the plugin's zip file (or equivalently
219     * the top level of the /plugins directory.</p>
220     *
221     * <p>This method should return null if no help set needs
222     * to be registered.</p>
223     *
224     * @param name the base name (without any localisation
225     * extensions) of the help set to append.
226     */

227     
228     public void addHelpSet(String JavaDoc name)
229     {
230         CBHelpSystem.addToDefaultHelpSystem(name, getClass().getClassLoader());
231     }
232
233 }
Popular Tags