File Source: ServerSettingsDialog.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.ui_swing.dialogs.serversetting;
24
25 import com.dmdirc.Server;
26 import com.dmdirc.config.Identity;
27 import com.dmdirc.addons.ui_swing.UIUtilities;
28 import com.dmdirc.addons.ui_swing.components.StandardDialog;
29 import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel;
30 import com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel.OptionType;
31
32 import java.awt.Window;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35
36 import javax.swing.JButton;
37 import javax.swing.JScrollPane;
38 import javax.swing.JTabbedPane;
39
40 import net.miginfocom.swing.MigLayout;
41
42 /**
43 * Allows the user to modify server settings and the ignore list.
44 */
45 public final class ServerSettingsDialog extends StandardDialog implements ActionListener {
46
47 /**
48 * A version number for this class. It should be changed whenever the class
49 * structure is changed (or anything else that would prevent serialized
50 * objects being unserialized with the new class).
51 */
52 private static final long serialVersionUID = 2;
53 /** Server settings dialogs, semi singleton use. */
54 private static volatile ServerSettingsDialog me;
55 /** Parent server. */
56 private final Server server;
57 /** User modes panel. */
58 private UserModesPane modesPanel;
59 /** Ignore list panel. */
60 private IgnoreListPanel ignoreList;
61 /** Perform panel. */
62 private PerformPanel performPanel;
63 /** Settings panel. */
64 private SettingsPanel settingsPanel;
65 /** The tabbed pane. */
66 private JTabbedPane tabbedPane;
67 /** Parent window. */
68 private Window parentWindow;
69
70 /**
71 * Creates a new instance of ServerSettingsDialog.
72 *
73 * @param server The server object that we're editing settings for
74 * @param parentWindow Parent window
75 */
76 private ServerSettingsDialog(final Server server, final Window parentWindow) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog(Server, Window)
*
* Presumptions:
* init'ed(java.awt.Dialog$ModalityType.MODELESS)
*
* Postconditions:
* this.parentWindow == parentWindow
* init'ed(this.parentWindow)
* this.server == server
* init'ed(this.server)
*/
77 super(parentWindow, ModalityType.MODELESS);
78
79 this.server = server;
80 this.parentWindow = parentWindow;
81
82 setTitle("Server settings");
83 setResizable(false);
84
85 initComponents();
86 initListeners();
87 }
88
89 /**
90 * Creates the dialog if one doesn't exist, and displays it.
91 *
92 * @param server The server object that we're editing settings for
93 * @param parentWindow Parent window
94 */
95 public static void showServerSettingsDialog(final Server server,
96 final Window parentWindow) {
/*
P/P * Method: void showServerSettingsDialog(Server, Window)
*
* Preconditions:
* init'ed(me)
*
* Postconditions:
* me == One-of{old me, &new ServerSettingsDialog(getServerSettingsDialog#1)}
* me != null
* new ServerSettingsDialog(getServerSettingsDialog#1) num objects <= 1
* new ServerSettingsDialog(getServerSettingsDialog#1).parentWindow == parentWindow
* init'ed(new ServerSettingsDialog(getServerSettingsDialog#1).parentWindow)
* new ServerSettingsDialog(getServerSettingsDialog#1).server == server
* init'ed(new ServerSettingsDialog(getServerSettingsDialog#1).server)
*/
97 me = getServerSettingsDialog(server, parentWindow);
98
99 me.pack();
100 me.setLocationRelativeTo(parentWindow);
101 me.setVisible(true);
102 me.requestFocusInWindow();
103 }
104
105 /**
106 * Returns the current instance of the ServerSettingsDialog.
107 *
108 * @param server The server object that we're editing settings for
109 * @param parentWindow Parent window
110 *
111 * @return The current ServerSettingsDialog instance
112 */
113 public static ServerSettingsDialog getServerSettingsDialog(
114 final Server server, final Window parentWindow) {
/*
P/P * Method: ServerSettingsDialog getServerSettingsDialog(Server, Window)
*
* Preconditions:
* init'ed(me)
*
* Postconditions:
* me == One-of{old me, &new ServerSettingsDialog(getServerSettingsDialog#1)}
* me != null
* return_value == One-of{old me, &new ServerSettingsDialog(getServerSettingsDialog#1)}
* return_value != null
* new ServerSettingsDialog(getServerSettingsDialog#1) num objects <= 1
* new ServerSettingsDialog(getServerSettingsDialog#1).parentWindow == parentWindow
* init'ed(new ServerSettingsDialog(getServerSettingsDialog#1).parentWindow)
* new ServerSettingsDialog(getServerSettingsDialog#1).server == server
* init'ed(new ServerSettingsDialog(getServerSettingsDialog#1).server)
*/
115 synchronized (ServerSettingsDialog.class) {
116 if (me == null) {
117 me = new ServerSettingsDialog(server, parentWindow);
118 }
119 }
120
121 return me;
122 }
123
124 /** Initialises the main UI components. */
125 private void initComponents() {
/*
P/P * Method: void initComponents()
*
* Preconditions:
* init'ed(this.parentWindow)
* this.server != null
*
* Presumptions:
* com.dmdirc.Server:getConfigManager(...)@167 != null
* javax.swing.JScrollPane:getViewport(...)@151 != null
*
* Postconditions:
* this.ignoreList == &new IgnoreListPanel(initComponents#5)
* this.modesPanel == &new UserModesPane(initComponents#4)
* this.performPanel == &new PerformPanel(initComponents#6)
* this.settingsPanel == &new SettingsPanel(initComponents#7)
* this.tabbedPane == &new JTabbedPane(initComponents#3)
* new Hashtable(initModesPanel#1) num objects == 1
* new IgnoreList(initComponents#1) num objects == 1
* new IgnoreListModel(initComponents#2) num objects == 1
* new IgnoreListPanel(initComponents#5) num objects == 1
* new JButton(initComponents#5) num objects == 1
* ...
*/
126 orderButtons(new JButton(), new JButton());
127
128 tabbedPane = new JTabbedPane();
129
130 modesPanel = new UserModesPane(server);
131
132 ignoreList =
133 new IgnoreListPanel(server, parentWindow);
134
135 performPanel =
136 new PerformPanel(server);
137
138 settingsPanel =
139 new SettingsPanel(server.getNetworkIdentity(),
140 "These settings are specific to this " +
141 "network, any settings specified here will overwrite global " +
142 "settings");
143
144 if (settingsPanel != null) {
145 addSettings();
146 }
147
148 final JScrollPane userModesSP = new JScrollPane(modesPanel);
149 userModesSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
150 userModesSP.setOpaque(UIUtilities.getTabbedPaneOpaque());
151 userModesSP.getViewport().setOpaque(UIUtilities.getTabbedPaneOpaque());
152 userModesSP.setBorder(null);
153
154 tabbedPane.add("User modes", userModesSP);
155 tabbedPane.add("Ignore list", ignoreList);
156 tabbedPane.add("Perform", performPanel);
157 if (settingsPanel != null) {
158 tabbedPane.add("Settings", settingsPanel);
159 }
160
161 setLayout(new MigLayout("fill, wrap 1, hmax 80sp"));
162
163 add(tabbedPane, "grow");
164 add(getLeftButton(), "split 2, right");
165 add(getRightButton(), "right");
166
167 tabbedPane.setSelectedIndex(server.getConfigManager().
168 getOptionInt("dialogstate", "serversettingsdialog"));
169 }
170
171 /** Adds the settings to the panel. */
172 private void addSettings() {
/*
P/P * Method: void addSettings()
*
* Preconditions:
* this.settingsPanel != null
*
* Presumptions:
* init'ed(com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel$OptionType.CHECKBOX)
* init'ed(com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel$OptionType.COLOUR)
* init'ed(com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel$OptionType.SPINNER)
* init'ed(com.dmdirc.addons.ui_swing.components.expandingsettings.SettingsPanel$OptionType.TEXTFIELD)
*/
173 settingsPanel.addOption("channel.splitusermodes", "Split user modes",
174 OptionType.CHECKBOX);
175 settingsPanel.addOption("channel.sendwho", "Send WHO",
176 OptionType.CHECKBOX);
177 settingsPanel.addOption("channel.showmodeprefix", "Show mode prefix",
178 OptionType.CHECKBOX);
179
180 settingsPanel.addOption("general.cyclemessage", "Cycle message",
181 OptionType.TEXTFIELD);
182 settingsPanel.addOption("general.kickmessage", "Kick message",
183 OptionType.TEXTFIELD);
184 settingsPanel.addOption("general.partmessage", "Part message",
185 OptionType.TEXTFIELD);
186
187 settingsPanel.addOption("ui.backgroundcolour", "Background colour",
188 OptionType.COLOUR);
189 settingsPanel.addOption("ui.foregroundcolour", "Foreground colour",
190 OptionType.COLOUR);
191 settingsPanel.addOption("ui.frameBufferSize", "Textpane buffer limit",
192 OptionType.SPINNER);
193
194 settingsPanel.addOption("ui.inputBufferSize", "Input buffer size",
195 OptionType.SPINNER);
196 settingsPanel.addOption("ui.textPaneFontName", "Textpane font name",
197 OptionType.TEXTFIELD);
198 //TODO issue 2251
199 //settingsPanel.addOption("ui.textPaneFontSize", "Textpane font size",
200 // OptionType.SPINNER);
201
202 settingsPanel.addOption("ui.inputbackgroundcolour",
203 "Input field background colour",
204 OptionType.COLOUR);
205 settingsPanel.addOption("ui.inputforegroundcolour",
206 "Input field foreground colour",
207 OptionType.COLOUR);
208 settingsPanel.addOption("ui.nicklistbackgroundcolour",
209 "Nicklist background colour",
210 OptionType.COLOUR);
211 settingsPanel.addOption("ui.nicklistforegroundcolour",
212 "Nicklist foreground colour",
213 OptionType.COLOUR);
214 settingsPanel.addOption("ui.shownickcoloursinnicklist",
215 "Show coloured nicks in nicklist",
216 OptionType.CHECKBOX);
217 settingsPanel.addOption("ui.shownickcoloursintext",
218 "Show coloured nicks in textpane",
219 OptionType.CHECKBOX);
220
221 settingsPanel.addOption("general.closechannelsonquit",
222 "Close channels on quit",
223 OptionType.CHECKBOX);
224 settingsPanel.addOption("general.closechannelsondisconnect",
225 "Close channels on disconnect",
226 OptionType.CHECKBOX);
227 settingsPanel.addOption("general.closequeriesonquit",
228 "Close queries on quit",
229 OptionType.CHECKBOX);
230 settingsPanel.addOption("general.closequeriesondisconnect",
231 "Close queries on disconnect",
232 OptionType.CHECKBOX);
233 settingsPanel.addOption("general.quitmessage", "Quit message",
234 OptionType.TEXTFIELD);
235 settingsPanel.addOption("general.reconnectmessage", "Reconnect message",
236 OptionType.TEXTFIELD);
237 settingsPanel.addOption("general.rejoinchannels",
238 "Rejoin channels on reconnect",
239 OptionType.CHECKBOX);
240
241 settingsPanel.addOption("general.friendlymodes", "Show friendly modes",
242 OptionType.CHECKBOX);
243 settingsPanel.addOption("general.pingtimeout", "Ping timeout",
244 OptionType.SPINNER);
245 }
246
247 /** Initialises listeners for this dialog. */
248 private void initListeners() {
/*
P/P * Method: void initListeners()
*
* Presumptions:
* com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog:getCancelButton(...)@250 != null
* com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog:getOkButton(...)@249 != null
*/
249 getOkButton().addActionListener(this);
250 getCancelButton().addActionListener(this);
251 }
252
253 /** Saves the settings from this dialog. */
254 public void saveSettings() {
/*
P/P * Method: void saveSettings()
*
* Preconditions:
* init'ed(this.performPanel.networkAction)
* init'ed(this.performPanel.networkPerform)
* init'ed(this.performPanel.serverAction)
* init'ed(this.performPanel.serverPerform)
* this.ignoreList != null
* this.ignoreList.cachedIgnoreList != null
* this.ignoreList.server != null
* this.modesPanel != null
* this.performPanel != null
* init'ed(this.performPanel.isNetworkPerform)
* ...
*
* Presumptions:
* com.dmdirc.Server:getNetworkIdentity(...)@260 != null
*
* Postconditions:
* init'ed(this.performPanel.networkAction)
* this.performPanel.networkPerform != null
* init'ed(this.performPanel.serverAction)
* this.performPanel.serverPerform != null
*/
255 modesPanel.save();
256 settingsPanel.save();
257 performPanel.savePerforms();
258 ignoreList.saveList();
259
260 final Identity identity = server.getNetworkIdentity();
261 identity.setOption("dialogstate", "serversettingsdialog",
262 String.valueOf(tabbedPane.getSelectedIndex()));
263 }
264
265 /**
266 * {@inheritDoc}
267 *
268 * @param e Action event
269 */
270 @Override
271 public void actionPerformed(final ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* e != null
* (soft) init'ed(me)
* (soft) init'ed(this.performPanel.networkAction)
* (soft) init'ed(this.performPanel.networkPerform)
* (soft) init'ed(this.performPanel.serverAction)
* (soft) init'ed(this.performPanel.serverPerform)
* (soft) this.ignoreList != null
* (soft) this.ignoreList.cachedIgnoreList != null
* (soft) this.ignoreList.server != null
* (soft) this.modesPanel != null
* ...
*
* Postconditions:
* me == One-of{old me, null}
* init'ed(me)
* init'ed(this.performPanel.networkAction)
* init'ed(this.performPanel.networkPerform)
* init'ed(this.performPanel.serverAction)
* init'ed(this.performPanel.serverPerform)
*/
272 if (e.getSource() == getOkButton()) {
273 saveSettings();
274 dispose();
275 } else if (e.getSource() == getCancelButton()) {
276 dispose();
277 }
278 }
279
280 /** {@inheritDoc} */
281 @Override
282 public void dispose() {
/*
P/P * Method: void dispose()
*
* Preconditions:
* init'ed(me)
*
* Postconditions:
* me == null
*
* Test Vectors:
* me: Inverse{null}, Addr_Set{null}
*/
283 if (me == null) {
284 return;
285 }
286 synchronized (me) {
287 super.dispose();
288 me = null;
289 }
290 }
291 }
SofCheck Inspector Build Version : 2.17854
| ServerSettingsDialog.java |
2009-Jun-25 01:54:24 |
| ServerSettingsDialog.class |
2009-Sep-02 17:04:16 |