001: package net.refractions.udig.style.sld;
002:
003: import java.net.URL;
004: import java.util.MissingResourceException;
005: import java.util.ResourceBundle;
006:
007: import org.eclipse.core.runtime.IStatus;
008: import org.eclipse.core.runtime.Platform;
009: import org.eclipse.core.runtime.Status;
010: import org.eclipse.ui.plugin.AbstractUIPlugin;
011: import org.osgi.framework.BundleContext;
012:
013: /**
014: * The main plugin class to be used in the desktop.
015: */
016: public class SLDPlugin extends AbstractUIPlugin {
017:
018: /** The id of the plug-in */
019: public static final String ID = "net.refractions.udig.style.sld"; //$NON-NLS-1$
020: /** Icons path (value "icons/") */
021: public final static String ICONS_PATH = "icons/";//$NON-NLS-1$
022:
023: // The shared instance.
024: private static SLDPlugin plugin;
025: // Resource bundle.
026: private ResourceBundle resourceBundle;
027:
028: private Images images = new Images();
029:
030: /**
031: * The constructor.
032: */
033: public SLDPlugin() {
034: super ();
035: plugin = this ;
036: }
037:
038: /**
039: * This method is called upon plug-in activation
040: */
041: public void start(BundleContext context) throws Exception {
042: super .start(context);
043: final URL iconsUrl = context.getBundle().getEntry(ICONS_PATH);
044: images.initializeImages(iconsUrl, getImageRegistry());
045: }
046:
047: /**
048: * This method is called when the plug-in is stopped
049: */
050: public void stop(BundleContext context) throws Exception {
051: plugin = null;
052: resourceBundle = null;
053: super .stop(context);
054: }
055:
056: /**
057: * Returns the shared instance.
058: */
059: public static SLDPlugin getDefault() {
060: return plugin;
061: }
062:
063: /**
064: * Returns the string from the plugin's resource bundle, or 'key' if not found.
065: */
066: public static String getResourceString(String key) {
067: ResourceBundle bundle = SLDPlugin.getDefault()
068: .getResourceBundle();
069: try {
070: return (bundle != null) ? bundle.getString(key) : key;
071: } catch (MissingResourceException e) {
072: return key;
073: }
074: }
075:
076: /**
077: * Returns the plugin's resource bundle,
078: */
079: public ResourceBundle getResourceBundle() {
080: try {
081: if (resourceBundle == null)
082: resourceBundle = ResourceBundle
083: .getBundle("net.refractions.udig.style.sld.SldPluginResources"); //$NON-NLS-1$
084: } catch (MissingResourceException x) {
085: resourceBundle = null;
086: }
087: return resourceBundle;
088: }
089:
090: /**
091: * Writes an info log in the plugin's log.
092: * <p>
093: * This should be used for user level messages.
094: * </p>
095: */
096: public static void log(String message, Throwable e) {
097: if (message == null)
098: message = ""; //$NON-NLS-1$
099: getDefault().getLog().log(
100: new Status(IStatus.INFO, ID, 0, message, e));
101: }
102:
103: /**
104: * Messages that only engage if getDefault().isDebugging()
105: * <p>
106: * It is much prefered to do this:<pre><code>
107: * private static final String RENDERING = "net.refractions.udig.project/render/trace";
108: * if( ProjectUIPlugin.getDefault().isDebugging() && "true".equalsIgnoreCase( RENDERING ) ){
109: * System.out.println( "your message here" );
110: * }
111: */
112: public static void trace(String message, Throwable e) {
113: if (getDefault().isDebugging()) {
114: if (message != null)
115: System.out.println(message);
116: if (e != null)
117: e.printStackTrace();
118: }
119: }
120:
121: /**
122: * Performs the Platform.getDebugOption true check on the provided trace
123: * <p>
124: * Note: ProjectUIPlugin.getDefault().isDebugging() must also be on.
125: * <ul>
126: * <li>Trace.RENDER - trace rendering progress
127: * </ul>
128: * </p>
129: * @param trace currently only RENDER is defined
130: */
131: public static boolean isDebugging(final String trace) {
132: return getDefault().isDebugging()
133: && "true".equalsIgnoreCase(Platform.getDebugOption(trace)); //$NON-NLS-1$
134: }
135:
136: /**
137: * Images instance for use with ImageConstants.
138: *
139: * @return Images for use with ImageConstants.
140: */
141: public Images getImages() {
142: return images;
143: }
144: }
|