Preferences Editor Extension

A walkthrough is available for the addition of a preferences dialog.

The PreferencesDialog is a centralized location for the user to change an application's settings. The PreferencesDialog is designed to be extended. If you provide a new plugin for INTViewer, you can extend the PreferencesDialog so that the user can configure the preferences (settings) relevant to your plugin. INTViewer itself extends this dialog. The extension consists of implementation of IObjectEditor and configuration entries. The IObjectEditor is simple interface with two methods:

IOBJECTEDITOR INTERFACE

public interface IObjectEditor {
    /**
     * Gets the editor panel for the object to be edited
     * @return a JPanel for the editor
     */
    JPanel getPanel();
    /**
     * Applies any editor parameters selected by user to the object.
     */
    void apply();
}

It is just a JPanel factory which is responsible for user interface. When user presses "apply" button the method apply() is called. Inside this call all preferences should be saved to persistent storage. Any storage could be used to save/restore settings, but Java Preferences API is preferable, because it is a standard. The PreferencesDialog uses layer.xml configuration file to hook up all IObjectEditors. An example of the use of the Java Preferences API is available in the form of a DemoPreferencesUtil.java file at the bottom of the Adding a new Preference Dialog Walkthrough.

Configuration node looks like:

PREFERENCE CONFIGURATION NODE

<filesystem>
 <folder name="PreferencePanels">
  <folder name="Gui Preferences"> <!- This folder is optional ->
   <folder name="Cursor">
    <attr name="editor" stringvalue = "com.interactive.intviewer.gui.preferences.CursorPreferenceEditor"/>
    <attr name ="help"  stringvalue = "preferences_tracking_cursor"/>
   </folder>
  </folder>
 </folder>
</filesystem>

All extensions are organized as a tree. The PreferencePanels node is a root. Each xml node (folder) may have two optional attributes- "editor" and "help". First one is just a full name of IObjectEditor implementation. Second one is java help id. This tree may have any number of levels. In code above folder "Gui Preferences" is used for grouping several editors together.