1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui;
21
22 import java.awt.Component;
23
24 import javax.swing.JOptionPane;
25 import javax.swing.JPanel;
26
27 import org.xnap.XNap;
28 import org.xnap.gui.action.*;
29 import org.xnap.gui.event.DialogListener;
30 import org.xnap.gui.event.DialogSupport;
31 import org.xnap.util.Preferences;
32
33 /***
34 * Provides the plugin preferences dialog.
35 */
36 public class PluginPreferencesDialog extends AbstractPreferencesDialog {
37
38
39
40 /***
41 * Used to store dialog listeners.
42 */
43 private static DialogSupport listeners = new DialogSupport();
44 private static PluginPreferencesDialog me = null;
45
46 private Preferences prefs = Preferences.getInstance();
47
48
49
50 private PluginPreferencesDialog()
51 {
52 super(XNap.tr("XNap - Plugin Settings"));
53
54 listeners.fireDialogWillBecomeVisible(this);
55
56 setSize(prefs.getPrefsWindowWidth(), prefs.getPrefsWindowHeight());
57 }
58
59
60
61 public static void addDialogListener(DialogListener listener)
62 {
63 listeners.addDialogListener(listener);
64 ActionHelper.pluginPreferencesDialogAction.setEnabled(true);
65 }
66
67 public void close()
68 {
69
70 prefs.setPrefsWindowHeight(getBounds().getSize().height);
71 prefs.setPrefsWindowWidth(getBounds().getSize().width);
72
73
74 if (isOkay() && !prefs.write()) {
75 String msg = XNap.tr("Could not write {0}.", prefs.getFilename());
76 JOptionPane.showMessageDialog
77 (this, msg, XNap.tr("Preferences"),
78 JOptionPane.ERROR_MESSAGE);
79 return;
80 }
81
82 listeners.fireDialogWillBecomeInvisible(this);
83
84 dispose();
85 me = null;
86 }
87
88 public static void removeDialogListener(DialogListener listener)
89 {
90 listeners.removeDialogListener(listener);
91 if (listeners.size() == 0) {
92 ActionHelper.pluginPreferencesDialogAction.setEnabled(false);
93 }
94 }
95
96 /***
97 * Removes <code>jp</code> from the list.
98 */
99 public static void removePanel(JPanel jp)
100 {
101 if (me != null) {
102 me.remove(jp);
103 }
104 }
105
106 /***
107 * Removes <code>tab</code> from the list of {@link SettingsPanel}
108 * objects. After this method has been invoked, <code>tab.apply()</code>
109 * is not called when the dialog is closed.
110 */
111 public static void removePanel(SettingsPanel tab)
112 {
113 if (me != null) {
114 me.remove(tab);
115 }
116 }
117
118 public static void showDialog(Component c)
119 {
120 if (me == null) {
121 me = new PluginPreferencesDialog();
122 }
123 me.show(c);
124 }
125
126 }