The Global Options Dialog Box

The Global Options dialog box is a common location for changing editor-wide settings, including plugin settings. Plugins can add panes, as well as groups of panes to this dialog box. If your plugin has lots of options that can be set, it might be a good idea to create multiple option panes and group them.

Each pane in an implementation of the org.gjt.sp.jedit.OptionPane interface - though most plugins will subclass the org.gjt.sp.jedit.AbstractOptionPane class which provides a default layout implementation. Groups of option panes are implemented using the org.gjt.sp.jedit.OptionGroup class. Option groups are containers to which other option panes and groups can be added.

AbstractOptionPane class

public abstract class AbstractOptionPane extends JPanel
implements OptionPane
{
        public OptionPane(String name);
        public void _init();
        public void _save();
        public void addComponent(String label, Component comp);
        public void addComponent(Component comp);
}

Most plugins will want to use the AbstractOptionPane class, instead of the OptionPane interface; only the former will be covered here. Each AbstractOptionPane instance, like many other jEdit objects, has a unique "name" which is used to query properties. The only option pane property currently used is options.name.label, which stores the label for the option pane in the options dialog box.

The _init() method should create the option pane's user interface. _save() should save any settings to the properties.

The two addComponent() methods can be used to add components to the option pane using the default layout manager. Nothing prevents you from calling setLayout() and add() to implement your own appearance, though.

OptionsDialog.addOptionPane() method

import org.gjt.sp.jedit.OptionPane;

public void addOptionPane(OptionPane pane);

The addOptionPane() method adds the specified option pane to an options dialog instance. This method should only be called from your plugin's createOptionPanes() method, which is invoked every time the Global Options dialog box is displayed.

OptionGroup class

public class OptionGroup
{
        public OptionGroup(String name);
        public void addOptionPane(OptionPane pane);
        public void addOptionGroup(OptionGroup group);
}

Like option panes, each option group has a label which is obtained from the options.name.label property. Option panes and other groups can be added using the addOptionPane() and addOptionGroup() methods.

OptionsDialog.addOptionGroup() method

import org.gjt.sp.jedit.OptionGroup;

public void addOptionGroup(OptionGroup group);

The addOptionGroup() method adds the specified option group to an options dialog instance. This method should only be called from your plugin's createOptionPanes() method, which is invoked every time the Global Options dialog box is displayed.

EditPlugin.createOptionPanes() method

import org.gjt.sp.jedit.OptionsDialog;

public void createOptionPanes(OptionsDialog dialog);

The Plugin Options dialog box invokes the createOptionPanes() method of each plugin when it is being displayed. The canonical implementation would add OptionPane or OptionGroup instances to the options dialog using the addOptionPane() or addOptionGroup() methods.