Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 76186 Details for
Bug 12116
[Contributions] widgets: MenuManager.setImageDescriptor() method needed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch to add two new constructors for instantiating a MenuManager with an ImageDescriptor.
org.eclipse.jface-bug12116-patch.txt (text/plain), 7.81 KB, created by
Remy Suen
on 2007-08-15 21:03:45 EDT
(
hide
)
Description:
Patch to add two new constructors for instantiating a MenuManager with an ImageDescriptor.
Filename:
MIME Type:
Creator:
Remy Suen
Created:
2007-08-15 21:03:45 EDT
Size:
7.81 KB
patch
obsolete
>Index: src/org/eclipse/jface/action/MenuManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/action/MenuManager.java,v >retrieving revision 1.47 >diff -u -r1.47 MenuManager.java >--- src/org/eclipse/jface/action/MenuManager.java 4 Jun 2007 19:59:23 -0000 1.47 >+++ src/org/eclipse/jface/action/MenuManager.java 16 Aug 2007 00:58:01 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Remy Chi Jian Suen <remy.suen@gmail.com> - Bug 12116 [Contributions] widgets: MenuManager.setImageDescriptor() method needed > *******************************************************************************/ > package org.eclipse.jface.action; > >@@ -15,6 +16,9 @@ > import java.util.List; > > import org.eclipse.core.runtime.ListenerList; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.resource.JFaceResources; >+import org.eclipse.jface.resource.LocalResourceManager; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.MenuAdapter; > import org.eclipse.swt.events.MenuEvent; >@@ -63,6 +67,16 @@ > * The text for a sub-menu. > */ > private String menuText; >+ >+ /** >+ * The image for a sub-menu. >+ */ >+ private ImageDescriptor image; >+ >+ /** >+ * A resource manager to remember all of the images that have been used by this menu. >+ */ >+ private LocalResourceManager imageManager; > > /** > * The overrides for items of this manager >@@ -92,7 +106,7 @@ > * Typically used for creating a context menu, where it doesn't need to be referred to by id. > */ > public MenuManager() { >- this(null, null); >+ this(null, null, null); > } > > /** >@@ -103,7 +117,20 @@ > * @param text the text for the menu, or <code>null</code> if none > */ > public MenuManager(String text) { >- this(text, null); >+ this(text, null, null); >+ } >+ >+ /** >+ * Creates a menu manager with the given text and image. The id of the menu >+ * is <code>null</code>. >+ * Typically used for creating a sub-menu, where it doesn't need to be referred to by id. >+ * >+ * @param text the text for the menu, or <code>null</code> if none >+ * @param image the image for the menu, or <code>null</code> if none >+ * @since 3.4 >+ */ >+ public MenuManager(String text, ImageDescriptor image) { >+ this(text, image, null); > } > > /** >@@ -114,7 +141,21 @@ > * @param id the menu id, or <code>null</code> if it is to have no id > */ > public MenuManager(String text, String id) { >+ this(text, null, id); >+ } >+ >+ /** >+ * Creates a menu manager with the given text, image, and id. >+ * Typically used for creating a sub-menu, where it needs to be referred to by id. >+ * >+ * @param text the text for the menu, or <code>null</code> if none >+ * @param image the image for the menu, or <code>null</code> if none >+ * @param id the menu id, or <code>null</code> if it is to have no id >+ * @since 3.4 >+ */ >+ public MenuManager(String text, ImageDescriptor image, String id) { > this.menuText = text; >+ this.image = image; > this.id = id; > } > >@@ -223,6 +264,13 @@ > > menuItem.setText(getMenuText()); > >+ ImageDescriptor image = getImageDescriptor(); >+ LocalResourceManager localManager = new LocalResourceManager(JFaceResources >+ .getResources()); >+ menuItem.setImage(image == null ? null : localManager.createImage(image)); >+ disposeOldImages(); >+ imageManager = localManager; >+ > if (!menuExist()) { > menu = new Menu(parent); > } >@@ -336,6 +384,16 @@ > public String getMenuText() { > return menuText; > } >+ >+ /** >+ * Returns the image for this menu as an image descriptor. >+ * >+ * @return the image, or <code>null</code> if this menu has no image >+ * @since 3.4 >+ */ >+ public ImageDescriptor getImageDescriptor() { >+ return image; >+ } > > /* (non-Javadoc) > * @see org.eclipse.jface.action.IContributionManager#getOverrides() >@@ -723,42 +781,60 @@ > for (int i = 0; i < items.length; i++) { > items[i].update(property); > } >- >- if (menu != null && !menu.isDisposed() && menu.getParentItem() != null >- && IAction.TEXT.equals(property)) { >- String text = getOverrides().getText(this); >- >- if (text == null) { >- text = getMenuText(); >- } >- >- if (text != null) { >- ExternalActionManager.ICallback callback = ExternalActionManager >- .getInstance().getCallback(); >- >- if (callback != null) { >- int index = text.indexOf('&'); >- >- if (index >= 0 && index < text.length() - 1) { >- char character = Character.toUpperCase(text >- .charAt(index + 1)); >- >- if (callback.isAcceleratorInUse(SWT.ALT | character)) { >- if (index == 0) { >- text = text.substring(1); >- } else { >- text = text.substring(0, index) >- + text.substring(index + 1); >- } >+ >+ if (menu != null && !menu.isDisposed() && menu.getParentItem() != null) { >+ if (IAction.TEXT.equals(property)) { >+ String text = getOverrides().getText(this); >+ >+ if (text == null) { >+ text = getMenuText(); >+ } >+ >+ if (text != null) { >+ ExternalActionManager.ICallback callback = ExternalActionManager >+ .getInstance().getCallback(); >+ >+ if (callback != null) { >+ int index = text.indexOf('&'); >+ >+ if (index >= 0 && index < text.length() - 1) { >+ char character = Character.toUpperCase(text >+ .charAt(index + 1)); >+ >+ if (callback.isAcceleratorInUse(SWT.ALT | character)) { >+ if (index == 0) { >+ text = text.substring(1); >+ } else { >+ text = text.substring(0, index) >+ + text.substring(index + 1); >+ } >+ } > } > } >- } > >- menu.getParentItem().setText(text); >- } >+ menu.getParentItem().setText(text); >+ } >+ } else if (IAction.IMAGE.equals(property)) { >+ ImageDescriptor image = getImageDescriptor(); >+ LocalResourceManager localManager = new LocalResourceManager(JFaceResources >+ .getResources()); >+ menu.getParentItem().setImage(image == null ? null : localManager.createImage(image)); >+ disposeOldImages(); >+ imageManager = localManager; >+ } > } > } > >+ /** >+ * Dispose any images allocated for this menu >+ */ >+ private void disposeOldImages() { >+ if (imageManager != null) { >+ imageManager.dispose(); >+ imageManager = null; >+ } >+ } >+ > /* (non-Javadoc) > * @see org.eclipse.jface.action.IMenuManager#updateAll(boolean) > */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 12116
:
76186
|
76251