001: /*
002: *
003: * JMoney - A Personal Finance Manager
004: * Copyright (c) 2006 Nigel Westbury <westbury@users.sourceforge.net>
005: *
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020: *
021: */
022:
023: package net.sf.jmoney.shoebox;
024:
025: import java.util.MissingResourceException;
026: import java.util.ResourceBundle;
027:
028: import org.eclipse.jface.resource.ImageDescriptor;
029: import org.eclipse.ui.plugin.AbstractUIPlugin;
030: import org.osgi.framework.BundleContext;
031:
032: /**
033: * The main plugin class to be used in the desktop.
034: */
035: public class ShoeboxPlugin extends AbstractUIPlugin {
036:
037: //The shared instance.
038: private static ShoeboxPlugin plugin;
039: //Resource bundle.
040: private ResourceBundle resourceBundle;
041:
042: /**
043: * The constructor.
044: */
045: public ShoeboxPlugin() {
046: plugin = this ;
047:
048: try {
049: resourceBundle = ResourceBundle
050: .getBundle("net.sf.jmoney.shoebox.Language");
051: } catch (MissingResourceException x) {
052: resourceBundle = null;
053: }
054: }
055:
056: /**
057: * This method is called upon plug-in activation
058: */
059: public void start(BundleContext context) throws Exception {
060: super .start(context);
061: }
062:
063: /**
064: * This method is called when the plug-in is stopped
065: */
066: public void stop(BundleContext context) throws Exception {
067: super .stop(context);
068: plugin = null;
069: }
070:
071: /**
072: * Returns the shared instance.
073: */
074: public static ShoeboxPlugin getDefault() {
075: return plugin;
076: }
077:
078: /**
079: * Returns an image descriptor for the image file at the given
080: * plug-in relative path.
081: *
082: * @param path the path
083: * @return the image descriptor
084: */
085: public static ImageDescriptor getImageDescriptor(String path) {
086: return AbstractUIPlugin.imageDescriptorFromPlugin(
087: "net.sf.jmoney.shoebox", path);
088: }
089:
090: /**
091: * Returns the string from the plugin's resource bundle,
092: * or 'key' if not found.
093: */
094: public static String getResourceString(String key) {
095: ResourceBundle bundle = ShoeboxPlugin.getDefault()
096: .getResourceBundle();
097: try {
098: return (bundle != null) ? bundle.getString(key) : key;
099: } catch (MissingResourceException e) {
100: return key;
101: }
102: }
103:
104: /**
105: * Returns the plugin's resource bundle,
106: */
107: public ResourceBundle getResourceBundle() {
108: return resourceBundle;
109: }
110: }
|