Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ImageRegistry and ApplicationWindow
ImageRegistry and ApplicationWindow [message #462096] Thu, 06 October 2005 11:00 Go to next message
No real name is currently offline No real nameFriend
Messages: 92
Registered: July 2009
Member
I working on a stand alone JFace application.

To create a menu for my ApplicationWindow I can override

protected MenuManager createMenuManager()

this happens *before* the shell is created.

What if I want to use an ImageRegistry to supply icons to actions in my
MenuManager? ImageRegistry needs a display to be created but this hasn't
happened at this point. The upshot seems to be that I can't use an
ImageRegistry to supply ImageDescriptors to the menu of an
ApplicationWindow.

Is this correct? Does anyone know a way around this or what I'm doing
wrong. I want the convenience of an ImageRegistry so I know that my
images will be disposed and I also like the convenience of using image keys.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=23555

ImageRegistry was fixed to provide an ImageDescriptor directly, but this
doesn't solve the chicken egg thing, where the window makes the
menumanager before the shell but the imageregistry needs the shell (the
display) to provide images to the menumanager.

thanks,
Andy
Re: ImageRegistry and ApplicationWindow [message #462097 is a reply to message #462096] Thu, 06 October 2005 11:11 Go to previous messageGo to next message
Grzegorz Zieliñski is currently offline Grzegorz ZieliñskiFriend
Messages: 41
Registered: July 2009
Member
Hello Andy,

I had similar problem, check this thread later today and I'll post here how
to handle it. :)

Grzegorz Zieliński
g_zielinski<at>intechion.pl
Re: ImageRegistry and ApplicationWindow [message #462098 is a reply to message #462096] Thu, 06 October 2005 11:25 Go to previous messageGo to next message
Grzegorz Zieliñski is currently offline Grzegorz ZieliñskiFriend
Messages: 41
Registered: July 2009
Member
Hello Andy,

Ok, I have few more minutes, so here it is:

1. this is my main method in App

public static void main(String[] args) {
App app = new App();
app.run();
}


2. This is the run() method

public void run() {
setBlockOnOpen(true);
addMenuBar();
addToolBar(SWT.FLAT | SWT.WRAP);
addStatusLine();
create();
open();
Display.getCurrent().dispose();
}

3. All actions are created from within

protected Control createContents(Composite contents) {
....
// Create actions
createActions();
....
}

4. This is how actions are created:

protected void createActions() {
// Create actions
this.exitAction = new ExitAction(this);
this.openAction = new OpenAction(this);
this.saveAction = new SaveAction(this);
// Place actions in appropriate containers
updateMenu();
updateToolBar();
}

protected void updateMenu() {
MenuManager menuFile = new MenuManager(MENU_FILE);
menuFile.add(openAction);
menuFile.add(saveAction);
menuFile.add(new Separator());
menuFile.add(exitAction);
menuFile.fill(getMenuBarManager().getMenu(), 0);
}

5. This is how actions get images

public class ExitAction extends Action {

private ApplicationWindow window;

private static final String DESC = "Zakoń&cz";
private static final String TOOLTIP = "Zamyka aplikację";

/**
* @param window
*/
public ExitAction(ApplicationWindow window) {
this.window = window;
this.setText(DESC);
this.setToolTipText(TOOLTIP);
this.setImageDescriptor(ResourcesManager.imageRegistry.getDe scriptor(ResourcesManager.AppImage.CLOSE.toString()));
}

/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
window.close();
}
}

6. And this is part of ResourcesManager class

public class ResourcesManager {

private static final String ICON_PATH = "icons";
public static enum AppImage {
CLOSE, OPEN, SAVE, COPY, FILE, FOLDER, RUN;
public String toString() {
return super.toString().toLowerCase();
}
}

public static ImageRegistry imageRegistry = new ImageRegistry();

static {
for (AppImage i : AppImage.values()) {
String iconPath = new String(ICON_PATH + "/" + i.toString() + ".gif");
URL iconURL = ResourcesManager.class.getResource(iconPath);
imageRegistry.put(i.toString(), ImageDescriptor.createFromURL(iconURL));
}
}

public ResourcesManager() {
super();
}

}

7. That's all... May the Force be with you! :)

Grzegorz Zieliński
g_zielinski<at>intechion.pl
Re: ImageRegistry and ApplicationWindow [message #462101 is a reply to message #462096] Thu, 06 October 2005 12:45 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You should be able to create the display before you instantiate your
Application Window ... then it'll work fine.

Display display = null;
try {
display = new Display();
AppCoolbar application = null;
application = new AppCoolbar(null);
application.init();
application.setBlockOnOpen(true);
application.open();
} finally {
if (display != null) {
display.dispose();
}
}


my application.init() creates and loads up an image registry.

Later,
PW


Re: ImageRegistry and ApplicationWindow [message #462106 is a reply to message #462101] Thu, 06 October 2005 13:28 Go to previous message
No real name is currently offline No real nameFriend
Messages: 92
Registered: July 2009
Member
Paul Webster wrote:
> You should be able to create the display before you instantiate your
> Application Window ... then it'll work fine.

Thankyou both for the quick follow up. Seems it is just as easy as
creating a display before the application window...

/**
* Main: create and run.
*
* NB Runner extends ApplicationWindow
*
* @param args
*/
public static void main(String[] args)
{
Display display = new Display();
Runner r = new Runner();
r.setBlockOnOpen(true);
r.open();
display.dispose();
}

I was following the File Explorer example on the IBM site so my
ImageRegistry is created on demand inside the createMenuManager() call.
So as long as you create a display before the ApplicationWindow the
problem goes away. Seems obvious now, but I'd probably have ended up
hacking together my own image registry with an ArrayList.

so thanks!

Andy
Previous Topic:Resize Table in a (Scrolled)Composite
Next Topic:Simple threading problem
Goto Forum:
  


Current Time: Fri Apr 26 00:50:45 GMT 2024

Powered by FUDForum. Page generated in 0.03294 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top