Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsminto2005-06-29 20:21:25 +0000
committersminto2005-06-29 20:21:25 +0000
commit97aca2db94f6ec09787455a55cc22469df7cd1c6 (patch)
tree5d67bbe4b008b0ac7eaed67d259067c60de87e87
parentddd4fb41a124dc0921fedb223fe44dcdd42294ea (diff)
downloadorg.eclipse.mylyn.tasks-97aca2db94f6ec09787455a55cc22469df7cd1c6.tar.gz
org.eclipse.mylyn.tasks-97aca2db94f6ec09787455a55cc22469df7cd1c6.tar.xz
org.eclipse.mylyn.tasks-97aca2db94f6ec09787455a55cc22469df7cd1c6.zip
fixed bugzilla images so that it wouldn't continuously create images, now they are in a map and created lazily
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/BugzillaImages.java111
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/favorites/actions/AddToFavoritesAction.java2
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java9
3 files changed, 38 insertions, 84 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/BugzillaImages.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/BugzillaImages.java
index 0a9800832..fa5c9f043 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/BugzillaImages.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/BugzillaImages.java
@@ -13,11 +13,9 @@ package org.eclipse.mylar.bugzilla;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
+import java.util.Map;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
/**
@@ -56,89 +54,44 @@ import org.eclipse.swt.graphics.Image;
* Add the declaration to this file
*/
public class BugzillaImages {
- public static final String IMG_TOOL_ADD_TO_FAVORITES = "IMG_TOOL_FAVORITE";
+
+ private static Map<ImageDescriptor, Image> imageMap = new HashMap<ImageDescriptor, Image>();
- public static final String BUG = "IMG_BUG";
- public static final String IMG_COMMENT = "IMG_COMMENT";
-
-
- private static HashMap<String, ImageDescriptor> descriptors = new HashMap<String, ImageDescriptor>();
+ private static final URL baseURL = BugzillaPlugin.getDefault().getBundle().getEntry("/icons/");
+ public static final String T_ELCL = "elcl16";
- private static ImageRegistry imageRegistry;
-
- // Subdirectory (under the package containing this class) where 16 color images are
- private static final URL URL_BASIC = BugzillaPlugin.getDefault().getBundle().getEntry("/");
-
- public final static String ICONS_PATH = "icons/";//$NON-NLS-1$
-
- private final static void declareImages() {
- // toolbar icons for the result view
- declareImage(IMG_TOOL_ADD_TO_FAVORITES, ICONS_PATH+"elcl16/bug-favorite.gif");//$NON-NLS-1$
- declareImage(BUG, ICONS_PATH+"elcl16/bug.gif");//$NON-NLS-1$
- declareImage(IMG_COMMENT, ICONS_PATH+"elcl16/bug-comment.gif");//$NON-NLS-1$
- }
-
- /**
- * Declare an ImageDescriptor in the descriptor table.
- * @param key The key to use when registering the image
- * @param path The path where the image can be found. This path is relative to where
- * this plugin class is found (i.e. typically the packages directory)
- */
- private final static void declareImage(String key,String path) {
- URL url = null;
+ public static final ImageDescriptor IMG_TOOL_ADD_TO_FAVORITES = create(T_ELCL, "bug-favorite.gif");
+ public static final ImageDescriptor BUG = create(T_ELCL, "bug.gif");
+ public static final ImageDescriptor IMG_COMMENT = create(T_ELCL, "bug-comment.gif");
+
+ private static ImageDescriptor create(String prefix, String name) {
try {
- url = new URL(URL_BASIC, path);
+ return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
} catch (MalformedURLException e) {
- BugzillaPlugin.log(new Status(IStatus.WARNING, IBugzillaConstants.PLUGIN_ID,IStatus.OK,"Unable to declare the image for: " + path, e));
- }
- ImageDescriptor desc = ImageDescriptor.createFromURL(url);
- descriptors.put(key, desc);
- }
-
- /**
- * Returns the image stored in the workbench plugin's image registry
- * under the given symbolic name. If there isn't any value associated
- * with the name then <code>null</code> is returned.
- *
- * The returned Image is managed by the workbench plugin's image registry.
- * Callers of this method must not dispose the returned image.
- *
- * This method is essentially a convenient short form of
- * HipikatImages.getImageRegistry.get(symbolicName).
- */
- public static Image getImage(String symbolicName) {
- return getImageRegistry().get(symbolicName);
- }
-
- /**
- * Returns the image descriptor stored under the given symbolic name.
- * If there isn't any value associated with the name then <code>null
- * </code> is returned.
- *
- * The class also "caches" commonly used images in the image registry.
- * If you are looking for one of these common images it is recommended you use
- * the getImage() method instead.
- */
- public static ImageDescriptor getImageDescriptor(String symbolicName) {
- if (imageRegistry == null) {
- initializeImageRegistry();
+ return ImageDescriptor.getMissingImageDescriptor();
}
- return descriptors.get(symbolicName);
}
-
+
+ private static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
+ if (baseURL == null)
+ throw new MalformedURLException();
+
+ StringBuffer buffer= new StringBuffer(prefix);
+ buffer.append('/');
+ buffer.append(name);
+ return new URL(baseURL, buffer.toString());
+ }
+
/**
- * Returns the ImageRegistry.
+ * Lazily initializes image map.
*/
- public static ImageRegistry getImageRegistry() {
- if (imageRegistry == null) {
- initializeImageRegistry();
- }
- return imageRegistry;
- }
-
- private static ImageRegistry initializeImageRegistry() {
- imageRegistry = new ImageRegistry();
- declareImages();
- return imageRegistry;
+ public static Image getImage(ImageDescriptor imageDescriptor) {
+ Image image = imageMap.get(imageDescriptor);
+ if (image == null) {
+ image = imageDescriptor.createImage();
+ imageMap.put(imageDescriptor, image);
+ }
+ return image;
}
+
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/favorites/actions/AddToFavoritesAction.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/favorites/actions/AddToFavoritesAction.java
index 65761203c..9ab0920e4 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/favorites/actions/AddToFavoritesAction.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/favorites/actions/AddToFavoritesAction.java
@@ -35,7 +35,7 @@ public class AddToFavoritesAction extends Action {
public AddToFavoritesAction(EditorPart editor) {
editorPart = editor;
setText("&Add to favorites");
- setImageDescriptor(BugzillaImages.getImageDescriptor(BugzillaImages.IMG_TOOL_ADD_TO_FAVORITES));
+ setImageDescriptor(BugzillaImages.IMG_TOOL_ADD_TO_FAVORITES);
}
@Override
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java
index 43279af88..c8ae32c23 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/bugzilla/ui/outline/BugzillaOutlineNode.java
@@ -210,8 +210,9 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
protected static BugzillaOutlineNode parseBugReport(NewBugModel bug){
int bugId = bug.getId();
String bugServer = bug.getServer();
- Image defaultImage = BugzillaImages.getImageDescriptor(BugzillaImages.IMG_COMMENT).createImage();
- BugzillaOutlineNode topNode = new BugzillaOutlineNode(bugId, bugServer, bug.getLabel(), defaultImage, bug, bug.getSummary());
+ Image bugImage = BugzillaImages.getImage(BugzillaImages.BUG);
+ Image defaultImage = BugzillaImages.getImage(BugzillaImages.IMG_COMMENT);
+ BugzillaOutlineNode topNode = new BugzillaOutlineNode(bugId, bugServer, bug.getLabel(), bugImage, bug, bug.getSummary());
topNode.addChild(new BugzillaOutlineNode(bugId, bugServer, "New Description", defaultImage, null, bug.getSummary()));
@@ -234,8 +235,8 @@ public class BugzillaOutlineNode implements IBugzillaReportSelection {
int bugId = bug.getId();
String bugServer = bug.getServer();
- Image bugImage = BugzillaImages.getImageDescriptor(BugzillaImages.BUG).createImage();
- Image defaultImage = BugzillaImages.getImageDescriptor(BugzillaImages.IMG_COMMENT).createImage();
+ Image bugImage = BugzillaImages.getImage(BugzillaImages.BUG);
+ Image defaultImage = BugzillaImages.getImage(BugzillaImages.IMG_COMMENT);
BugzillaOutlineNode topNode = new BugzillaOutlineNode(bugId, bugServer, bug.getLabel(), bugImage, bug, bug.getSummary());
BugzillaOutlineNode desc = new BugzillaOutlineNode(bugId, bugServer, "Description", defaultImage, bug.getDescription(), bug.getSummary());

Back to the top