|
|
Re: ImageRegistry and ApplicationWindow [message #462098 is a reply to message #462096] |
Thu, 06 October 2005 11:25 |
Grzegorz Zieliñski 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03294 seconds