Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

Settings



It is possible to create a unified settings menu in the application, used by the main GUI application and the Plugins, and to bridge these settings to the application configuration.

Creating the settings menu

You can create a settings in the GUI application with the following method applied on the Menu factory:
      // create the menus with the Application menu factory
      mfactory = new SimpleMenuFactory();
      mfactory.createDefaultMDISettings("Settings");
      super.preparePanels(4, true, true, mfactory);
The settings is a MDISettings, which is a sub-interface of Action.

To create the associated menu, you can do it in the Menu factory by using the MDIMenuFactory.createDefaultMDISettings(String) method, and add the result to a menu. For example: For example:
  public class SimpleMenuFactory extends AbstractMDIMenuFactory {
    private final JMenu settingsmenu = new JMenu("Settings");

    public SimpleMenuFactory() {
    }

    @Override
    protected void initMenus() {
      registerMenus();

      // create settings menu
       settingsmenu.add(createDefaultMDISettings("Settings"));

      Mbar.add(settingsmenu);
    }
  }

Settings component

The settings component is a split pane showing a tree on the left and the associated components on the right:
settings :
  • The left part of the pane present a tree with tree nodes for each setting
  • The right part of the pane present the components associated with each of the tree node at the right
The MDISettingsNode component allows to add a node in the tree on the left and its associated component.

Controlling if root node of the settings tree should be shown

By default the root node of the settings tree will be shown. For example:
settingstreeDefault
It is possible to hide the root node by calling MDISettings.hideTreeRoot(). For example:
settingstreeHide

Creating a node

A node for the settings component generally has:
  • A label to put on the tree node
  • An icon to decorate the tree node
  • An associated MDISettingsNode component which will be shown on the right of the panel, and which can be either any JComponent, or a MDISettingsNode element
For example:
   JPanel panel = new JPanel();
   JCheckBox cb = new JCheckBox("Tick Me!"):
   panel.add(cb);
   settings.addNode("General", node);

Creating a MDISettingsNode component

The MDISettingsNode element allows to present none UI element of a vertical list of UI elements allowing to set configuration properties: For example, to add one UI element to set a property:
   MDISettings settings = this.getMDISettings();
   JButton fileButton = new JButton("...");
   MDISettingsNode.Single node = new MDISettingsNode.Single(fileButton, "Directory");

settingsNodeSingle
For example, to add one UI element to set two properties:
   maxWidthSpinner = new JSpinner(maxWidthModel);
   maxWidthSpinner.setEditor(new JSpinner.NumberEditor(maxWidthSpinner, "####"));
   maxWidthSpinner.setMaximumSize(maxWidthSpinner.getPreferredSize());

   MDISettingsNode.Single nodeLimitWidth = new MDISettingsNode.Single(maxWidthSpinner, "Max Width");
   MDISettingsNode.Single nodeMaxWidth = new MDISettingsNode.Single(limitWidthCb, "Limit Width");
   MDISettingsNode.Multiple node = new MDISettingsNode.Multiple(nodeLimitWidth, nodeMaxWidth);

settingsNodeMultiple

Adding a node for the application

To add a settings node for the application, you must: For example:
   MDISettings settings = this.getMDISettings();
   JButton fileButton = new JButton("...");
   fileButton.addActionListener(new ActionListener() {
     @Override
     public void actionPerformed(ActionEvent e) {
       selectDirectory();
     }
   });
   MDISettingsNode.Single node = new MDISettingsNode.Single(fileButton, "Directory");
   settings.addNode("General", node);

Adding a node for a Plugin

To add a settings node for a Plugin, you must return the MDISettingsNode components in the MDIPlugin.getStaticMenuElements(String) method for the PluginElementTypes.SETTINGS key.

For example:
  public class OpenImagePlugin extends AbstractMDIPlugin {
    private MDISettingsNode settingsNode;
    private JSpinner maxWidthSpinner;
    private final JCheckBox limitWidthCb = new JCheckBox();

    public OpenImagePlugin() {
    }

    @Override
    public void register(MDIApplication app) throws Exception {
      super.register(app);

      maxWidthSpinner = new JSpinner(maxWidthModel);
      MDISettingsNode.Single nodeLimitWidth = new MDISettingsNode.Single(maxWidthSpinner, "Max Width");
      MDISettingsNode.Single nodeMaxWidth = new MDISettingsNode.Single(limitWidthCb, "Limit Width");
      settingsNode = new MDISettingsNode.Multiple(nodeLimitWidth, nodeMaxWidth);
    }

    @Override
    public void resetSettings() {
      maxWidthSpinner.setValue(pluginConf.maxWidth);
      limitWidthCb.setSelected(pluginConf.limitWidth);
    }

    @Override
    public Object getStaticMenuElements(String menu) {
      if (menu.equals(PluginElementTypes.SETTINGS)) {
        return settingsNode;
      } else {
        return null;
      }
    }
  }

See also


Categories: general

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences