/machinelearning/4.0.x/drools-eclipse3.3/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsPluginImages.java

https://github.com/etirelli/droolsjbpm-contributed-experiments · Java · 146 lines · 96 code · 13 blank · 37 comment · 4 complexity · b7372280fce41c8b954123f4f393f6a4 MD5 · raw file

  1. package org.drools.eclipse;
  2. /*
  3. * Copyright 2005 JBoss Inc
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import java.net.MalformedURLException;
  18. import java.net.URL;
  19. import org.eclipse.jface.resource.ImageDescriptor;
  20. import org.eclipse.jface.resource.ImageRegistry;
  21. import org.eclipse.swt.graphics.Image;
  22. /**
  23. * Handles the images used in this plugin.
  24. *
  25. * @author <a href="mailto:kris_verlaenen@hotmail.com">kris verlaenen </a>
  26. */
  27. public class DroolsPluginImages {
  28. public static final String IMG_LOGICAL = "ImageLogical";
  29. public static final String IMG_LOGICAL_DISABLED = "ImageLogicalDisabled";
  30. public static final String REFRESH_LOG = "RefreshLog";
  31. public static final String REFRESH_LOG_DISABLED = "RefreshLogDisabled";
  32. public static final String OPEN_LOG = "OpenLog";
  33. public static final String DELETE_LOG = "ClearLog";
  34. public static final String DELETE_LOG_DISABLED = "ClearLogDisabled";
  35. public static final String INSERT = "Insert";
  36. public static final String UPDATE = "Update";
  37. public static final String RETRACT = "RetractO";
  38. public static final String CREATE_ACTIVATION = "CreateActivation";
  39. public static final String CANCEL_ACTIVATION = "CancelActivation";
  40. public static final String EXECUTE_ACTIVATION = "ExecuteActivation";
  41. public static final String CLASS = "Class";
  42. public static final String PACKAGE = "Package";
  43. public static final String METHOD = "Method";
  44. public static final String VARIABLE = "Variable";
  45. public static final String DROOLS = "Drools";
  46. public static final String RULE = "DroolsRule";
  47. public static final String QUERY = "DroolsQuery";
  48. public static final String DSL_EXPRESSION = "DslExpression";
  49. public static final String IMPORT = "Import";
  50. public static final String DSL = "DSL";
  51. public static final String GLOBAL = "Global";
  52. public static final String RULEFLOW = "RuleFlow";
  53. private static ImageRegistry imageRegistry;
  54. private static final String PATH_SUFFIX = "/icons/";
  55. private static final URL ICON_BASE_URL =
  56. DroolsEclipsePlugin.getDefault().getBundle().getEntry(PATH_SUFFIX);
  57. private static void declareImages() {
  58. declareRegistryImage(IMG_LOGICAL, "logical_structure.gif");
  59. declareRegistryImage(IMG_LOGICAL_DISABLED, "logical_structure_disabled.gif");
  60. declareRegistryImage(REFRESH_LOG, "refresh.gif");
  61. declareRegistryImage(REFRESH_LOG_DISABLED, "refresh_disabled.gif");
  62. declareRegistryImage(OPEN_LOG, "open.gif");
  63. declareRegistryImage(DELETE_LOG, "clear.gif");
  64. declareRegistryImage(DELETE_LOG_DISABLED, "clear_disabled.gif");
  65. declareRegistryImage(INSERT, "greensquare.GIF");
  66. declareRegistryImage(UPDATE, "yellowsquare.GIF");
  67. declareRegistryImage(RETRACT, "redsquare.GIF");
  68. declareRegistryImage(CREATE_ACTIVATION, "arrowright.GIF");
  69. declareRegistryImage(CANCEL_ACTIVATION, "arrowleft.GIF");
  70. declareRegistryImage(EXECUTE_ACTIVATION, "bluediamond.GIF");
  71. declareRegistryImage(CLASS, "class_obj.gif");
  72. declareRegistryImage(PACKAGE, "package_obj.gif");
  73. declareRegistryImage(METHOD, "methpub_obj.gif");
  74. declareRegistryImage(VARIABLE, "field_private_obj.gif");
  75. declareRegistryImage(DROOLS, "drools.gif");
  76. declareRegistryImage(RULE, "drools-rule.GIF");
  77. declareRegistryImage(QUERY, "drools-query.GIF");
  78. declareRegistryImage(DSL_EXPRESSION, "dsl_expression.gif");
  79. declareRegistryImage(IMPORT, "import.gif");
  80. declareRegistryImage(DSL, "dsl.GIF");
  81. declareRegistryImage(GLOBAL, "field_public_obj.gif");
  82. declareRegistryImage(RULEFLOW, "process.gif");
  83. }
  84. /**
  85. * Declare an Image in the registry table.
  86. * @param key The key to use when registering the image
  87. * @param path The path where the image can be found. This path is relative to where
  88. * this plugin class is found (i.e. typically the packages directory)
  89. */
  90. private final static void declareRegistryImage(String key, String path) {
  91. ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor();
  92. try {
  93. desc= ImageDescriptor.createFromURL(makeIconFileURL(path));
  94. } catch (MalformedURLException e) {
  95. DroolsEclipsePlugin.log(e);
  96. }
  97. imageRegistry.put(key, desc);
  98. }
  99. /**
  100. * Returns the ImageRegistry.
  101. */
  102. public static ImageRegistry getImageRegistry() {
  103. if (imageRegistry == null) {
  104. initializeImageRegistry();
  105. }
  106. return imageRegistry;
  107. }
  108. public static ImageRegistry initializeImageRegistry() {
  109. imageRegistry = new ImageRegistry();
  110. declareImages();
  111. return imageRegistry;
  112. }
  113. /**
  114. * Returns the <code>Image</code> identified by the given key,
  115. * or <code>null</code> if it does not exist.
  116. */
  117. public static Image getImage(String key) {
  118. return getImageRegistry().get(key);
  119. }
  120. /**
  121. * Returns the <code>ImageDescriptor</code> identified by the given key,
  122. * or <code>null</code> if it does not exist.
  123. */
  124. public static ImageDescriptor getImageDescriptor(String key) {
  125. return getImageRegistry().getDescriptor(key);
  126. }
  127. private static URL makeIconFileURL(String iconPath) throws MalformedURLException {
  128. if (ICON_BASE_URL == null) {
  129. throw new MalformedURLException();
  130. }
  131. return new URL(ICON_BASE_URL, iconPath);
  132. }
  133. }