001: package org.drools.eclipse;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.net.MalformedURLException;
020: import java.net.URL;
021:
022: import org.eclipse.jface.resource.ImageDescriptor;
023: import org.eclipse.jface.resource.ImageRegistry;
024: import org.eclipse.swt.graphics.Image;
025:
026: /**
027: * Handles the images used in this plugin.
028: *
029: * @author <a href="mailto:kris_verlaenen@hotmail.com">kris verlaenen </a>
030: */
031: public class DroolsPluginImages {
032:
033: public static final String IMG_LOGICAL = "ImageLogical";
034: public static final String IMG_LOGICAL_DISABLED = "ImageLogicalDisabled";
035: public static final String REFRESH_LOG = "RefreshLog";
036: public static final String REFRESH_LOG_DISABLED = "RefreshLogDisabled";
037: public static final String OPEN_LOG = "OpenLog";
038: public static final String DELETE_LOG = "ClearLog";
039: public static final String DELETE_LOG_DISABLED = "ClearLogDisabled";
040: public static final String INSERT = "Insert";
041: public static final String UPDATE = "Update";
042: public static final String RETRACT = "RetractO";
043: public static final String CREATE_ACTIVATION = "CreateActivation";
044: public static final String CANCEL_ACTIVATION = "CancelActivation";
045: public static final String EXECUTE_ACTIVATION = "ExecuteActivation";
046: public static final String CLASS = "Class";
047: public static final String PACKAGE = "Package";
048: public static final String METHOD = "Method";
049: public static final String VARIABLE = "Variable";
050: public static final String DROOLS = "Drools";
051: public static final String RULE = "DroolsRule";
052: public static final String QUERY = "DroolsQuery";
053: public static final String DSL_EXPRESSION = "DslExpression";
054: public static final String IMPORT = "Import";
055: public static final String DSL = "DSL";
056: public static final String GLOBAL = "Global";
057: public static final String RULEFLOW = "RuleFlow";
058:
059: private static ImageRegistry imageRegistry;
060: private static final String PATH_SUFFIX = "/icons/";
061: private static final URL ICON_BASE_URL = DroolsEclipsePlugin
062: .getDefault().getBundle().getEntry(PATH_SUFFIX);
063:
064: private static void declareImages() {
065: declareRegistryImage(IMG_LOGICAL, "logical_structure.gif");
066: declareRegistryImage(IMG_LOGICAL_DISABLED,
067: "logical_structure_disabled.gif");
068: declareRegistryImage(REFRESH_LOG, "refresh.gif");
069: declareRegistryImage(REFRESH_LOG_DISABLED,
070: "refresh_disabled.gif");
071: declareRegistryImage(OPEN_LOG, "open.gif");
072: declareRegistryImage(DELETE_LOG, "clear.gif");
073: declareRegistryImage(DELETE_LOG_DISABLED, "clear_disabled.gif");
074: declareRegistryImage(INSERT, "greensquare.GIF");
075: declareRegistryImage(UPDATE, "yellowsquare.GIF");
076: declareRegistryImage(RETRACT, "redsquare.GIF");
077: declareRegistryImage(CREATE_ACTIVATION, "arrowright.GIF");
078: declareRegistryImage(CANCEL_ACTIVATION, "arrowleft.GIF");
079: declareRegistryImage(EXECUTE_ACTIVATION, "bluediamond.GIF");
080: declareRegistryImage(CLASS, "class_obj.gif");
081: declareRegistryImage(PACKAGE, "package_obj.gif");
082: declareRegistryImage(METHOD, "methpub_obj.gif");
083: declareRegistryImage(VARIABLE, "field_private_obj.gif");
084: declareRegistryImage(DROOLS, "drools.gif");
085: declareRegistryImage(RULE, "drools-rule.GIF");
086: declareRegistryImage(QUERY, "drools-query.GIF");
087: declareRegistryImage(DSL_EXPRESSION, "dsl_expression.gif");
088: declareRegistryImage(IMPORT, "import.gif");
089: declareRegistryImage(DSL, "dsl.GIF");
090: declareRegistryImage(GLOBAL, "field_public_obj.gif");
091: declareRegistryImage(RULEFLOW, "process.gif");
092: }
093:
094: /**
095: * Declare an Image in the registry table.
096: * @param key The key to use when registering the image
097: * @param path The path where the image can be found. This path is relative to where
098: * this plugin class is found (i.e. typically the packages directory)
099: */
100: private final static void declareRegistryImage(String key,
101: String path) {
102: ImageDescriptor desc = ImageDescriptor
103: .getMissingImageDescriptor();
104: try {
105: desc = ImageDescriptor.createFromURL(makeIconFileURL(path));
106: } catch (MalformedURLException e) {
107: DroolsEclipsePlugin.log(e);
108: }
109: imageRegistry.put(key, desc);
110: }
111:
112: /**
113: * Returns the ImageRegistry.
114: */
115: public static ImageRegistry getImageRegistry() {
116: if (imageRegistry == null) {
117: initializeImageRegistry();
118: }
119: return imageRegistry;
120: }
121:
122: public static ImageRegistry initializeImageRegistry() {
123: imageRegistry = new ImageRegistry();
124: declareImages();
125: return imageRegistry;
126: }
127:
128: /**
129: * Returns the <code>Image</code> identified by the given key,
130: * or <code>null</code> if it does not exist.
131: */
132: public static Image getImage(String key) {
133: return getImageRegistry().get(key);
134: }
135:
136: /**
137: * Returns the <code>ImageDescriptor</code> identified by the given key,
138: * or <code>null</code> if it does not exist.
139: */
140: public static ImageDescriptor getImageDescriptor(String key) {
141: return getImageRegistry().getDescriptor(key);
142: }
143:
144: private static URL makeIconFileURL(String iconPath)
145: throws MalformedURLException {
146: if (ICON_BASE_URL == null) {
147: throw new MalformedURLException();
148: }
149:
150: return new URL(ICON_BASE_URL, iconPath);
151: }
152: }
|