KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > viewer > ViewerPlugin


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * *
5  * This library is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or (at your option) any later version. *
9  * *
10  * This library is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13  * Lesser General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Lesser General Public *
16  * License along with this library; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, *
19  * Boston, MA 02110-1301 USA *
20  * *
21  * Or get it online : *
22  * http://www.gnu.org/copyleft/lesser.html *
23  * *
24  * *
25  ******************************************************************************/

26
27 package org.nightlabs.editor2d.viewer;
28
29 import java.util.MissingResourceException JavaDoc;
30 import java.util.ResourceBundle JavaDoc;
31
32 import org.eclipse.core.runtime.Platform;
33 import org.eclipse.jface.resource.ImageDescriptor;
34 import org.eclipse.ui.plugin.AbstractUIPlugin;
35 import org.osgi.framework.BundleContext;
36
37 /**
38  * The main plugin class to be used in the desktop.
39  */

40 public class ViewerPlugin
41 extends AbstractUIPlugin {
42
43     //The shared instance.
44
private static ViewerPlugin plugin;
45     
46     /**
47      * The constructor.
48      */

49     public ViewerPlugin() {
50         plugin = this;
51     }
52
53     /**
54      * This method is called upon plug-in activation
55      */

56     public void start(BundleContext context) throws Exception JavaDoc {
57         super.start(context);
58         resourceBundle = Platform.getResourceBundle(getBundle());
59     }
60
61     /**
62      * This method is called when the plug-in is stopped
63      */

64     public void stop(BundleContext context) throws Exception JavaDoc {
65         super.stop(context);
66         plugin = null;
67         resourceBundle = null;
68     }
69
70     /**
71      * Returns the shared instance.
72      */

73     public static ViewerPlugin getDefault() {
74         return plugin;
75     }
76
77     /**
78      * Returns an image descriptor for the image file at the given
79      * plug-in relative path.
80      *
81      * @param path the path
82      * @return the image descriptor
83      */

84     public static ImageDescriptor getImageDescriptor(String JavaDoc path) {
85         return AbstractUIPlugin.imageDescriptorFromPlugin("org.nightlabs.editor2d.viewer", path);
86     }
87     
88     private static ResourceBundle JavaDoc resourceBundle;
89     
90     /**
91      * Returns a string from the resource bundle, knowing its key. Note: the generated
92      * code is not strong enough because a NullPointerException is raised if there is no
93      * resource bundle, instead of 'key' to be returned for consistency.
94      *
95      * @return The string from the plugin's resource bundle, or 'key' if not found.
96      */

97     public static String JavaDoc getResourceString(String JavaDoc key) {
98         try {
99             return resourceBundle.getString(key);
100         } catch (Exception JavaDoc e) {
101             return key;
102         }
103     }
104
105     /**
106      * Returns the plugin's resource bundle. Note that for this plugin, the resource
107      * bundle is the same as the plugin descriptor resource bundle.
108      *
109      * @return The plugin's resource bundle
110      */

111     public ResourceBundle JavaDoc getResourceBundle() {
112         return resourceBundle;
113     }
114     
115 // /**
116
// * Returns the string from the plugin's resource bundle,
117
// * or 'key' if not found.
118
// */
119
// public static String getResourceString(String key) {
120
// ResourceBundle bundle = ViewerPlugin.getDefault().getResourceBundle();
121
// try {
122
// return (bundle != null) ? bundle.getString(key) : key;
123
// } catch (MissingResourceException e) {
124
// return key;
125
// }
126
// }
127
//
128
// /**
129
// * Returns the plugin's resource bundle,
130
// */
131
// public ResourceBundle getResourceBundle()
132
// {
133
// if (resourceBundle == null)
134
// {
135
// try {
136
// resourceBundle = ResourceBundle.getBundle("org.nightlabs.editor2d.viewer.plugin");
137
// } catch (MissingResourceException x) {
138
// resourceBundle = null;
139
// }
140
// }
141
// return resourceBundle;
142
// }
143
}
144
Popular Tags