package org.eclipse.jdt.internal.debug.ui; | |
/* | |
* (c) Copyright IBM Corp. 2000, 2001. | |
* All Rights Reserved. | |
*/ | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import org.eclipse.jface.action.IAction; | |
import org.eclipse.jface.resource.ImageDescriptor; | |
import org.eclipse.jface.resource.ImageRegistry; | |
import org.eclipse.swt.graphics.Image; | |
import org.eclipse.swt.widgets.Display; | |
/** | |
* Bundle of most images used by the Java debug plug-in. | |
*/ | |
public class JavaDebugImages { | |
private static final String NAME_PREFIX= "org.eclipse.jdt.debug.ui."; //$NON-NLS-1$ | |
private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length(); | |
private static URL fgIconBaseURL= null; | |
// Determine display depth. If depth > 4 then we use high color images. Otherwise low color | |
// images are used | |
static { | |
String pathSuffix= "icons/basic/"; //$NON-NLS-1$ | |
// Don't consider the default display since accessing it throws an SWTException anyway. | |
Display display= Display.getCurrent(); | |
if (display != null && display.getIconDepth() > 4) | |
pathSuffix = "icons/full/"; //$NON-NLS-1$ | |
try { | |
fgIconBaseURL= new URL(JDIDebugUIPlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix); | |
} catch (MalformedURLException e) { | |
// do nothing | |
} | |
} | |
// The plugin registry | |
private final static ImageRegistry IMAGE_REGISTRY= new ImageRegistry(); | |
/* | |
* Available cached Images in the Java debug plug-in image registry. | |
*/ | |
public static final String IMG_OBJS_EXCEPTION= NAME_PREFIX + "jexception_obj.gif"; //$NON-NLS-1$ | |
public static final String IMG_OBJS_ERROR= NAME_PREFIX + "jrtexception_obj.gif"; //$NON-NLS-1$ | |
public static final String IMG_OBJS_BREAKPOINT_INSTALLED= NAME_PREFIX + "brkpi_obj.gif"; //$NON-NLS-1$ | |
public static final String IMG_OBJS_SNIPPET_EVALUATING= NAME_PREFIX + "jsbook_run_obj.gif"; //$NON-NLS-1$ | |
/* | |
* Set of predefined Image Descriptors. | |
*/ | |
private static final String T_OBJ= "obj16"; //$NON-NLS-1$ | |
private static final String T_OVR= "ovr16"; //$NON-NLS-1$ | |
private static final String T_WIZBAN= "wizban"; //$NON-NLS-1$ | |
private static final String T_LCL= "clcl16"; //$NON-NLS-1$ | |
private static final String T_CTOOL= "ctool16"; //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_OBJS_EXCEPTION= createManaged(T_OBJ, IMG_OBJS_EXCEPTION); | |
public static final ImageDescriptor DESC_OBJS_BREAKPOINT_INSTALLED= createManaged(T_OBJ, IMG_OBJS_BREAKPOINT_INSTALLED); | |
public static final ImageDescriptor DESC_OBJS_ERROR= createManaged(T_OBJ, IMG_OBJS_ERROR); | |
public static final ImageDescriptor DESC_OBJS_SNIPPET_EVALUATING= createManaged(T_OBJ, IMG_OBJS_SNIPPET_EVALUATING); | |
public static final ImageDescriptor DESC_OVR_IS_OUT_OF_SYNCH= create(T_OVR, "error_co.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_OVR_MAY_BE_OUT_OF_SYNCH= create(T_OVR, "warning_co.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_WIZBAN_NEWSCRAPPAGE= create(T_WIZBAN, "newsbook_wiz.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_WIZBAN_JAVA_LAUNCH= create(T_WIZBAN, "java_app_wiz.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_WIZBAN_JAVA_ATTACH= create(T_WIZBAN, "java_attach_wiz.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_TOOL_DISPLAYSNIPPET= create(T_CTOOL, "disp_sbook.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_TOOL_RUNSNIPPET= create(T_CTOOL, "run_sbook.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_TOOL_INSPSNIPPET= create(T_CTOOL, "insp_sbook.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_TOOL_PACKSNIPPET= create(T_CTOOL, "pack_sbook.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_TOOL_TERMSNIPPET= create(T_CTOOL, "term_sbook.gif"); //$NON-NLS-1$ | |
public static final ImageDescriptor DESC_TOOL_NEWSNIPPET= create(T_CTOOL, "newsbook_wiz.gif"); //$NON-NLS-1$ | |
/** | |
* Returns the image managed under the given key in this registry. | |
* | |
* @param key the image's key | |
* @return the image managed under the given key | |
*/ | |
public static Image get(String key) { | |
return IMAGE_REGISTRY.get(key); | |
} | |
/** | |
* Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions | |
* are retrieved from the *tool16 folders. | |
*/ | |
public static void setToolImageDescriptors(IAction action, String iconName) { | |
setImageDescriptors(action, "tool16", iconName); //$NON-NLS-1$ | |
} | |
/** | |
* Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions | |
* are retrieved from the *lcl16 folders. | |
*/ | |
public static void setLocalImageDescriptors(IAction action, String iconName) { | |
setImageDescriptors(action, "lcl16", iconName); //$NON-NLS-1$ | |
} | |
/* | |
* Helper method to access the image registry from the JDIDebugUIPlugin class. | |
*/ | |
/* package */ static ImageRegistry getImageRegistry() { | |
return IMAGE_REGISTRY; | |
} | |
//---- Helper methods to access icons on the file system -------------------------------------- | |
private static void setImageDescriptors(IAction action, String type, String relPath) { | |
try { | |
ImageDescriptor id= ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath)); //$NON-NLS-1$ | |
if (id != null) | |
action.setDisabledImageDescriptor(id); | |
} catch (MalformedURLException e) { | |
} | |
try { | |
ImageDescriptor id= ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath)); //$NON-NLS-1$ | |
if (id != null) | |
action.setHoverImageDescriptor(id); | |
} catch (MalformedURLException e) { | |
} | |
action.setImageDescriptor(create("e" + type, relPath)); //$NON-NLS-1$ | |
} | |
private static ImageDescriptor createManaged(String prefix, String name) { | |
try { | |
ImageDescriptor result= ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH))); | |
IMAGE_REGISTRY.put(name, result); | |
return result; | |
} catch (MalformedURLException e) { | |
return ImageDescriptor.getMissingImageDescriptor(); | |
} | |
} | |
private static ImageDescriptor create(String prefix, String name) { | |
try { | |
return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); | |
} catch (MalformedURLException e) { | |
return ImageDescriptor.getMissingImageDescriptor(); | |
} | |
} | |
private static URL makeIconFileURL(String prefix, String name) throws MalformedURLException { | |
if (fgIconBaseURL == null) | |
throw new MalformedURLException(); | |
StringBuffer buffer= new StringBuffer(prefix); | |
buffer.append('/'); | |
buffer.append(name); | |
return new URL(fgIconBaseURL, buffer.toString()); | |
} | |
} |