1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.xmlhammer.gui.actions;
22
23 import org.bounce.RunnableAction;
24 import org.xmlhammer.PreferencesHandler;
25 import org.xmlhammer.gui.XMLHammer;
26 import org.xmlhammer.gui.preferences.PreferencesDialog;
27 import org.xmlhammer.model.preferences.Preferences;
28
29 /***
30 * An action that can be used to show the preferences.
31 *
32 * @version $Revision: 1.10 $, $Date: 2007/07/04 19:42:49 $
33 * @author Edwin Dankert <edankert@gmail.com>
34 */
35 public class PreferencesAction extends RunnableAction {
36 private static final long serialVersionUID = -7972377267441487295L;
37
38 private XMLHammer parent = null;
39 private PreferencesDialog dialog = null;
40
41 /***
42 * The constructor for the action which shows the preferences.
43 *
44 * @param parent the XML Hammer parent.
45 */
46 public PreferencesAction( XMLHammer parent) {
47 super( "Preferences");
48
49 putValue( MNEMONIC_KEY, new Integer( 'P'));
50 putValue( SHORT_DESCRIPTION, "Preferences");
51
52
53 this.parent = parent;
54 }
55
56 public PreferencesDialog getDialog() {
57 if ( dialog == null) {
58 dialog = new PreferencesDialog( parent);
59 }
60
61 return dialog;
62 }
63
64 /***
65 * The implementation of the show preferences action, called after a user action.
66 */
67 public void run() {
68 PreferencesDialog dialog = getDialog();
69 Preferences preferences = PreferencesHandler.getInstance().getPreferences();
70
71 int option = dialog.open();
72 if ( option == PreferencesDialog.OK_OPTION) {
73 dialog.update( preferences);
74 parent.firePreferrencesUpdated();
75 }
76 }
77 }