User Tools

Site Tools


05_developer_tutorials:02_extending_groimp:create-windows

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
05_developer_tutorials:02_extending_groimp:create-windows [2025/01/31 14:05] – removed - external edit (Unknown date) 127.0.0.105_developer_tutorials:02_extending_groimp:create-windows [2025/11/21 16:50] (current) gaetan
Line 1: Line 1:
 +===== Create windows =====
  
 +There are many level of windows that can be created in GroIMP, depending on the needs. 
 +
 +==== Basic windows ====
 +
 +The most common way of creating a new window is by invoking the "createPanel" of the currently used uitoolkit (Swingtoolkit in "normal" groimp mode). The method will create a Panel, register it to a new PanelSupport, then create a new WindowSupport to manage the PanelSupport.
 +
 +A simple example to create a windows in your plugin is:
 +
 +<code java>
 +public class CreateWindow {
 +
 +public static Panel startPanel(Context ctx, Map params) {
 + GraphManager graph = ctx.getWorkbench().getRegistry().getProjectGraph();
 + UIToolkit ui = UIToolkit.get(ctx);
 + Panel p = ui.createPanel(ctx, null, params);
 + // Do anything on to fill the panel here
 +                // ...
 +                return p;
 + }
 +}
 +</code>
 +
 +You can then register your new panel (which start a window) in the GroIMP panel menu entries with adding in your ''plugin.xml'' file:
 +
 +<code xml>
 +<ref name="ui">
 +    <ref name="panels">
 + <panel name="YOUR PANEL NAME">
 +     <exists name=".available" ref="/"/>
 +         <object expr="de.grogra.YOUR_PACKAGE_NAME.CreateWindow.startPanel">
 +             <var name="context"/>
 +     <vars/>
 +         </object>
 + </panel>          
 +    </ref>
 +</ref>
 +</code>
 +
 +Finally, you can customize the panel name and icon displayed in GroIMP by attributing some values in the ''plugin.properties''. /ui/panels/YOUR PANEL NAME.Name changes the name, and /ui/panels/YOUR PANEL NAME.Icon changes the icon.
 +
 +In this example the panel is added to the menu entries in the _Panel_ section. Indeed, after starting GroIMP add all element of _/ui/panels_ into this menu entry. (see more on [[:01_user_documentation:06_graph:03_graphs:10_registry|GroIMP registry]]).
 +
 +If you want your window to be openable from another menu than _panels_, you need to register it as a ''command''.
 +
 +Example:
 +
 +<code java>
 +public class CreateWindow {
 +
 +public static void startPanelFromCommand(Item item, Object information, Context context) {
 +                GraphManager graph = context.getWorkbench().getRegistry().getProjectGraph();
 + UIToolkit ui = UIToolkit.get(context);
 + Panel p = ui.createPanel(context, null, Map.EMPTY_MAP);
 +                // Do anything on to fill the panel here
 +                // ...
 + p.show(true, null);
 + }
 +}
 +</code>
 +
 +The window can then be added to the menu (YOUR_MENU_NAME>SUB_MENU) in the registry with:
 +
 +<code xml>
 +<directory name="YOUR_MENU_NAME">
 +    <directory name="SUB_MENU">
 + <panel name="YOUR PANEL NAME">
 +     <command name="NEW WINDOW" run="de.grogra.YOUR_PACKAGE_NAME.CreateWindow.startWindowCommand"/>
 +    </directory>
 +</directory>
 +</code>
 +
 +
 +
 +=== Dialog Window ===
 +
 +The methods ''showChoiceDialog'', ''showDialog'', ''showInputDialog'', and ''showWaitMessage'' in ''de.grogra.pf.ui.Window'' enables to open a small dialog window.
 +It can be open from a registry ''command''.
 +
 +Example: 
 +
 +<code java>
 +public static void startInputDialogWindow(Item item, Object information, Context context) {
 +    I18NBundle thisI18NBundle = context.getWorkbench().getRegistry().getPluginDescriptor("de.grogra.plugin").getI18NBundle();
 +    Workbench.current().getWindow().showInputDialog(
 + thisI18NBundle.getString ("panel.title"),
 + thisI18NBundle.getString ("panel.message"),
 + "varName");
 +}
 +</code>
 +
 +=== File explorer ===
 +
 +The method ''de.grogra.pf.ui.Window.chooseFile'' enables to open a file explorer that load the selected file.