public class SimpleMenuFactory extends AbstractMDIMenuFactory { private final JMenu filemenu = new JMenu("File"); private final JMenu openmenu = new JMenu("Open"); private final JMenu helpmenu = new JMenu("Help"); public SimpleMenuFactory() { } @Override protected void initMenus() { JMenuItem exitItem = new JMenuItem(getDefaultExitAction("Exit")); staticMenuKeyMap.put(PluginElementTypes.OPEN_ACTIONS, openmenu); registerMenus(); progress.setProgress(progress.getProgress() + 20, "Register Plugins Menus"); JMenuItem aboutItem = new JMenuItem(createDefaultMDIAbout(null, false)); helpmenu.add(aboutItem); filemenu.add(openmenu); filemenu.add(exitItem); Mbar.add(filemenu); Mbar.add(helpmenu); } }We will have this menu if we click on the "About" menu item:
public class AboutTutorialMDI extends AbstractMDIApplication { private Preferences pref = null; public AboutTutorialMDI() { super("MDI About Example"); conf = AppliConfiguration.getInstance(); ApplicationDesc desc = getApplicationDesc(); desc.setBuildDate("08/10/2023"); desc.setVersion("0.1"); desc.setApplicationName("About Tutorial"); desc.setAlternateText("This is a Tutorial about the About menu"); ImageIcon splash = new ImageIcon(this.getClass().getResource("splash.png")); SplashScreen splashdialog = new SplashScreen(splash, getApplicationDesc(), true); ... } }We now will have the following dialog:
public class AboutTutorialMDI extends AbstractMDIApplication { private Preferences pref = null; public AboutTutorialMDI() { super("MDI About Example"); conf = AppliConfiguration.getInstance(); conf.setupApplicationDesc(getApplicationDesc()); ImageIcon splash = new ImageIcon(this.getClass().getResource("splash.png")); SplashScreen splashdialog = new SplashScreen(splash, getApplicationDesc(), true); ... }The Configuration.setupApplicationDesc(ApplicationDesc) method in the configuration allows the configuration to set the content of the application description. Let's create anapp.properties file with the description we will use in the same package as our Configuration class:
version=0.1 date=08/10/2023 name=About Tutorial desc=This is a Tutorial about the About menuAnd get the content of these properties in the
setupApplicationDesc
method[1]
public class AppliConfiguration implements Configuration { private static AppliConfiguration conf = null; public File lastDir = new File(System.getProperty("user.dir")); private AppliConfiguration() { } public static AppliConfiguration getInstance() { if (conf == null) { conf = new AppliConfiguration(); } return conf; } @Override public void setupApplicationDesc(ApplicationDesc appDesc) { MDIConfigUtils.setupApplicationDesc(this, "app.properties", appDesc); } }With this code, the ApplicationDesc of our application wil be set with the content of the properties file. We have the same result when we click on the "About" item:
public class OpenImagePlugin extends AbstractMDIPlugin { private AbstractAction importImageAction; public OpenImagePlugin() { } @Override public void register(MDIApplication app) throws Exception { super.register(app); importImageAction = new ImportImageAction("Image"); } @Override public Object getStaticMenuElements(String menu) { if (menu.equals(PluginElementTypes.OPEN_ACTIONS)) { return importImageAction; } else { return null; } } }Now we have the default description for the Plugin when we click on the "About" item:
version=0.1 date=08/10/2023 desc=Open Images PluginNow we will create a configuration for the Plugin, and get the content of these properties in the
setupApplicationDesc
method, exactly as we did for the application[1]
public class OpenImagePluginConfiguration implements Configuration { private static OpenImagePluginConfiguration conf = null; private OpenImagePluginConfiguration() { } public static OpenImagePluginConfiguration getInstance() { if (conf == null) { conf = new OpenImagePluginConfiguration(); } return conf; } @Override public void setupApplicationDesc(ApplicationDesc pluginDesc) { MDIConfigUtils.setupApplicationDesc(this, "openImagePlugin.properties", pluginDesc); } @Override public void putConfiguration(Preferences p, File file) { } @Override public void getConfiguration(Preferences p, File file) { } }Now all we have to do is to get these in the main Plugin class:
public class OpenImagePlugin extends AbstractMDIPlugin { private AbstractAction importImageAction; private final OpenImagePluginConfiguration pluginConf = OpenImagePluginConfiguration.getInstance(); public OpenImagePlugin() { setupPluginDesc(pluginConf); } @Override public void register(MDIApplication app) throws Exception { super.register(app); importImageAction = new ImportImageAction("Image"); } @Override public Object getStaticMenuElements(String menu) { if (menu.equals(PluginElementTypes.OPEN_ACTIONS)) { return importImageAction; } else { return null; } } @Override public Configuration getPluginConfiguration() { return pluginConf; } }
Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences