1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-16 12:45:41 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2010-12-04 21:36:21 +00:00
parent ef023fca29
commit 1d59eac559
2 changed files with 133 additions and 166 deletions

View file

@ -23,9 +23,7 @@ import org.eclipse.swt.widgets.Display;
* A registry that maps <code>ImageDescriptors</code> to <code>Image</code>. * A registry that maps <code>ImageDescriptors</code> to <code>Image</code>.
*/ */
public class CDebugImageDescriptorRegistry { public class CDebugImageDescriptorRegistry {
private HashMap<ImageDescriptor, Image> fRegistry = new HashMap<ImageDescriptor, Image>(10);
private HashMap fRegistry = new HashMap( 10 );
private Display fDisplay; private Display fDisplay;
/** /**
@ -57,7 +55,7 @@ public class CDebugImageDescriptorRegistry {
public Image get(ImageDescriptor descriptor) { public Image get(ImageDescriptor descriptor) {
if (descriptor == null) if (descriptor == null)
descriptor = ImageDescriptor.getMissingImageDescriptor(); descriptor = ImageDescriptor.getMissingImageDescriptor();
Image result = (Image)fRegistry.get( descriptor ); Image result = fRegistry.get(descriptor);
if (result != null) if (result != null)
return result; return result;
Assert.isTrue(fDisplay == CDebugUIPlugin.getStandardDisplay(), CDebugUIMessages.getString("CDebugImageDescriptorRegistry.0")); //$NON-NLS-1$ Assert.isTrue(fDisplay == CDebugUIPlugin.getStandardDisplay(), CDebugUIMessages.getString("CDebugImageDescriptorRegistry.0")); //$NON-NLS-1$
@ -71,8 +69,8 @@ public class CDebugImageDescriptorRegistry {
* Disposes all images managed by this registry. * Disposes all images managed by this registry.
*/ */
public void dispose() { public void dispose() {
for( Iterator iter = fRegistry.values().iterator(); iter.hasNext(); ) { for (Iterator<Image> iter = fRegistry.values().iterator(); iter.hasNext();) {
Image image = (Image)iter.next(); Image image = iter.next();
image.dispose(); image.dispose();
} }
fRegistry.clear(); fRegistry.clear();
@ -80,10 +78,8 @@ public class CDebugImageDescriptorRegistry {
private void hookDisplay() { private void hookDisplay() {
fDisplay.asyncExec(new Runnable() { fDisplay.asyncExec(new Runnable() {
public void run() { public void run() {
getDisplay().disposeExec(new Runnable() { getDisplay().disposeExec(new Runnable() {
public void run() { public void run() {
dispose(); dispose();
} }

View file

@ -23,7 +23,6 @@ import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
/** /**
*
* Bundle of most images used by the C/C++ debug plug-in. * Bundle of most images used by the C/C++ debug plug-in.
* *
* @since Aug 30, 2002 * @since Aug 30, 2002
@ -34,15 +33,11 @@ public class CDebugImages {
private static URL fgIconBaseURL = null; private static URL fgIconBaseURL = null;
static static {
{
String pathSuffix = "icons/"; //$NON-NLS-1$ String pathSuffix = "icons/"; //$NON-NLS-1$
try try {
{
fgIconBaseURL = new URL(CDebugUIPlugin.getDefault().getBundle().getEntry("/"), pathSuffix); //$NON-NLS-1$ fgIconBaseURL = new URL(CDebugUIPlugin.getDefault().getBundle().getEntry("/"), pathSuffix); //$NON-NLS-1$
} } catch (MalformedURLException e) {
catch( MalformedURLException e )
{
CDebugUIPlugin.log(e); CDebugUIPlugin.log(e);
} }
} }
@ -214,8 +209,7 @@ public class CDebugImages {
* @param key the image's key * @param key the image's key
* @return the image managed under the given key * @return the image managed under the given key
*/ */
public static Image get( String key ) public static Image get(String key) {
{
return getImageRegistry().get(key); return getImageRegistry().get(key);
} }
@ -223,8 +217,7 @@ public class CDebugImages {
* Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
* are retrieved from the *tool16 folders. * are retrieved from the *tool16 folders.
*/ */
public static void setToolImageDescriptors( IAction action, String iconName ) public static void setToolImageDescriptors(IAction action, String iconName) {
{
setImageDescriptors(action, "tool16", iconName); //$NON-NLS-1$ setImageDescriptors(action, "tool16", iconName); //$NON-NLS-1$
} }
@ -232,21 +225,17 @@ public class CDebugImages {
* Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
* are retrieved from the *lcl16 folders. * are retrieved from the *lcl16 folders.
*/ */
public static void setLocalImageDescriptors( IAction action, String iconName ) public static void setLocalImageDescriptors(IAction action, String iconName) {
{
setImageDescriptors(action, T_LCL, iconName); setImageDescriptors(action, T_LCL, iconName);
} }
/* /*
* Helper method to access the image registry from the JDIDebugUIPlugin class. * Helper method to access the image registry from the JDIDebugUIPlugin class.
*/ */
/* package */ static ImageRegistry getImageRegistry() /* package */ static ImageRegistry getImageRegistry() {
{ if (fgImageRegistry == null) {
if ( fgImageRegistry == null )
{
fgImageRegistry = new ImageRegistry(); fgImageRegistry = new ImageRegistry();
for ( Iterator<String> iter = fgAvoidSWTErrorMap.keySet().iterator(); iter.hasNext(); ) for (Iterator<String> iter = fgAvoidSWTErrorMap.keySet().iterator(); iter.hasNext();) {
{
String key = iter.next(); String key = iter.next();
fgImageRegistry.put(key, fgAvoidSWTErrorMap.get(key)); fgImageRegistry.put(key, fgAvoidSWTErrorMap.get(key));
} }
@ -257,72 +246,54 @@ public class CDebugImages {
//---- Helper methods to access icons on the file system -------------------------------------- //---- Helper methods to access icons on the file system --------------------------------------
private static void setImageDescriptors( IAction action, String type, String path ) private static void setImageDescriptors(IAction action, String type, String path) {
{
String relPath = path.substring(NAME_PREFIX_LENGTH); String relPath = path.substring(NAME_PREFIX_LENGTH);
try try {
{
ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath)); //$NON-NLS-1$ ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath)); //$NON-NLS-1$
if (id != null) if (id != null)
action.setDisabledImageDescriptor(id); action.setDisabledImageDescriptor(id);
} } catch (MalformedURLException e) {
catch( MalformedURLException e )
{
CDebugUIPlugin.log(e); CDebugUIPlugin.log(e);
} }
try try {
{
ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath)); //$NON-NLS-1$ ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath)); //$NON-NLS-1$
if (id != null) if (id != null)
action.setHoverImageDescriptor(id); action.setHoverImageDescriptor(id);
} } catch (MalformedURLException e) {
catch( MalformedURLException e )
{
CDebugUIPlugin.log(e); CDebugUIPlugin.log(e);
} }
action.setImageDescriptor(create("e" + type, relPath)); //$NON-NLS-1$ action.setImageDescriptor(create("e" + type, relPath)); //$NON-NLS-1$
} }
private static ImageDescriptor createManaged( String prefix, String name ) private static ImageDescriptor createManaged(String prefix, String name) {
{ try {
try
{
ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH))); ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
if ( fgAvoidSWTErrorMap == null ) if (fgAvoidSWTErrorMap == null) {
{
fgAvoidSWTErrorMap = new HashMap<String, ImageDescriptor>(); fgAvoidSWTErrorMap = new HashMap<String, ImageDescriptor>();
} }
fgAvoidSWTErrorMap.put(name, result); fgAvoidSWTErrorMap.put(name, result);
if ( fgImageRegistry != null ) if (fgImageRegistry != null) {
{
CDebugUIPlugin.logErrorMessage("Internal Error: Image registry already defined"); //$NON-NLS-1$ CDebugUIPlugin.logErrorMessage("Internal Error: Image registry already defined"); //$NON-NLS-1$
} }
return result; return result;
} } catch (MalformedURLException e) {
catch( MalformedURLException e )
{
CDebugUIPlugin.log(e); CDebugUIPlugin.log(e);
return ImageDescriptor.getMissingImageDescriptor(); return ImageDescriptor.getMissingImageDescriptor();
} }
} }
private static ImageDescriptor create( String prefix, String name ) private static ImageDescriptor create(String prefix, String name) {
{ try {
try
{
return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
} } catch (MalformedURLException e) {
catch( MalformedURLException e )
{
CDebugUIPlugin.log(e); CDebugUIPlugin.log(e);
return ImageDescriptor.getMissingImageDescriptor(); return ImageDescriptor.getMissingImageDescriptor();
} }
} }
private static URL makeIconFileURL( String prefix, String name ) throws MalformedURLException private static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
{
if (fgIconBaseURL == null) if (fgIconBaseURL == null)
throw new MalformedURLException(); throw new MalformedURLException();