/** * This is the magical place where the display model is connected with the real UI. * * @param event */ @Override protected void onDisplayCreated(final DisplayCreatedEvent event) { final Display<?> display = event.getObject(); final ImageJ imageJ = display.getContext(); final PluginService pluginService = imageJ.getService(PluginService.class); final EventService eventService = imageJ.getService(EventService.class); for (@SuppressWarnings("rawtypes") final PluginInfo<DisplayViewer> info : pluginService.getPluginsOfType(DisplayViewer.class)) { try { final DisplayViewer<?> displayViewer = info.createInstance(); if (displayViewer.canView(display)) { final SwingDisplayWindow displayWindow = new SwingDisplayWindow(); displayViewer.view(displayWindow, display); displayViewers.add(displayViewer); // add a copy of the JMenuBar to the new display if (displayWindow.getJMenuBar() == null) { createMenuBar(displayWindow); } displayWindow.addEventDispatcher(new AWTWindowEventDispatcher(display, eventService)); return; } } catch (final InstantiableException e) { Log.warn("Failed to create instance of " + info.getClassName(), e); } } Log.warn("No suitable DisplayViewer found for display"); }
/** Creates a {@link ModuleInfo} to reopen data at the given path. */ private ModuleInfo createInfo(final String path) { final PluginModuleInfo<ImageJPlugin> info = new PluginModuleInfo<ImageJPlugin>("imagej.io.plugins.OpenImage", ImageJPlugin.class); // hard code path to open as a preset final HashMap<String, Object> presets = new HashMap<String, Object>(); presets.put("inputFile", path); info.setPresets(presets); // set menu path final MenuPath menuPath = new MenuPath(); menuPath.add(new MenuEntry(MenuConstants.FILE_LABEL)); menuPath.add(new MenuEntry(RECENT_MENU_NAME)); final MenuEntry leaf = new MenuEntry(shortPath(path)); menuPath.add(leaf); info.setMenuPath(menuPath); // set menu position leaf.setWeight(0); // TODO - do this properly // use the same icon as File > Open final PluginService pluginService = ImageJ.get(PluginService.class); final PluginModuleInfo<RunnablePlugin> fileOpen = pluginService.getRunnablePlugin("imagej.io.plugins.OpenImage"); final String iconPath = fileOpen.getIconPath(); info.setIconPath(iconPath); leaf.setIconPath(iconPath); // register the module with the module service moduleService.addModule(info); return info; }
@Override public void run() { pluginService.run(DuplicateImage.class); }