A preferences sheet does not have to implement the AppPart
interface. A preferences sheet is simply a specialized component contained in a PreferencesEditor
.
In XMLmind XML Editor, user preferences such as displayScaling
, lastOpenedFiles
, etc[8] are stored in a Preferences
object. This object is accessed using App.getPreferences
.
Action EditPreferencesAction
(declared as "editPreferencesAction
" in DesktopApp.xxe_gui
) creates a PreferencesEditor
.
There are two kinds of preferences sheet:
“Plain” preferences sheets: PreferencesSheet
. Example: PrintOptions
.
Preferences sheets that need to access the App
that contains them: AppPreferencesSheet
. Examples: OpenOptions
, SaveOptions
.
The custom preferences sheet we are going to describe here belong to this second kind.
Excerpts from CountWordsOptions.java
:
public class CountWordsOptions extends AppPreferencesSheet { private SpinnerNumberModel countedWordMinCharsModel; private JSpinner countedWordMinChars; public CountWordsOptions() { super("countWords", "Count Words"); } protected PreferencesSheetPane createPane() { PreferencesSheetPane form = new PreferencesSheetPane(new FlowLayout(FlowLayout.LEFT, 5, 2)); JLabel label = new JLabel("Do not count words having less than"); form.add(label); countedWordMinCharsModel = new SpinnerNumberModel(1, 1, 1000, 1); countedWordMinChars = new JSpinner(countedWordMinCharsModel); form.add(countedWordMinChars); label = new JLabel("characters"); form.add(label); return form; } public void focusPane() { countedWordMinChars.requestFocus(); } public void fillPane(Preferences prefs) { int count = prefs.getInt("countedWordMinChars", 1, 1000, 1); countedWordMinCharsModel.setValue(new Integer(count)); } public boolean validatePane(Preferences prefs) { int count = countedWordMinCharsModel.getNumber().intValue(); prefs.putInt("countedWordMinChars", count); return true; } public void applyPreferences(Preferences prefs) { AppPart part = app.getPart("countWordsTool"); if (part != null) { part.applyPreferences(); } } }
A preferences sheet has a sheet ID: " | |
| |
| |
| |
| |
The instance of |
[8] More information about supported preferences keys in the Section 6, “The "Preferences" dialog box” in XMLmind XML Editor - Online Help.