Source code: org/relayirc/swingui/ChatOptionsDlg.java
1
2 /*
3 * FILE: ChatOptionsDlg.java
4 *
5 * The contents of this file are subject to the Mozilla Public License
6 * Version 1.0 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS"
11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
12 * License for the specific language governing rights and limitations
13 * under the License.
14 *
15 * The Original Code is Relay IRC chat client.
16 *
17 * The Initial Developer of the Original Code is David M. Johnson.
18 * Portions created by David M. Johnson are Copyright (C) 1998.
19 * All Rights Reserved.
20 *
21 * Contributor(s): No contributors to this file.
22 */
23 package org.relayirc.swingui;
24 import org.relayirc.chatengine.*;
25 import org.relayirc.swingutil.*;
26 import org.relayirc.util.*;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import java.util.*;
31 import javax.swing.*;
32 import javax.swing.border.*;
33
34 ///////////////////////////////////////////////////////////////////////
35
36 /**
37 * Dialog allows user to configure the chat client with
38 * user name, nick name and to select a server; all of the
39 * information which is stored in the ChatOptions ojbect.
40 */
41 public class ChatOptionsDlg extends TabbedDialog {
42
43 //---------------------------------------------------------------
44 public ChatOptionsDlg( ChatApp app ) {
45 super(app,"Setup",true);
46
47 addTab(new _UserPanel(app.getOptions()), ChatApp.userIcon);
48 addTab(new _ServerPanel(app), ChatApp.serverIcon);
49 addTab(new _FontPanel(app.getOptions()), ChatApp.fontIcon);
50 addTab(new _ColorPanel(app.getOptions()), ChatApp.colorsIcon);
51 addTab(new _InterfacePanel(app), ChatApp.setupIcon);
52
53 pack();
54 setSize(500,250);
55 centerOnScreen();
56 setVisible(true);
57 }
58
59 //////////////////////////////////////////////////////////////////////
60
61 private class _UserPanel extends JPanel implements ITab {
62 private ChatOptions _options = null;
63 private JTextField _nick = new JTextField(15);
64 private JTextField _name = new JTextField(15);
65 private JTextField _email = new JTextField(15);
66 private JTextField _alt = new JTextField(15);
67
68 //---------------------------------------------------------------
69 public _UserPanel(ChatOptions options) {
70 _options = options;
71
72 // GridBagConstraints2 arguments:
73 //
74 //int gridx, int gridy, int gridw, int gridh, double weightx, double weighty,
75 //int anchor, int fill, Insets insets, int ipadx, int ipady
76 //
77 setLayout(new GridBagLayout());
78
79 add(new JLabel("Full Name"),
80 new GridBagConstraints2(0,0,1,1,0.0,0.0,
81 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
82 add(_name,
83 new GridBagConstraints2(1,0,1,1,0.0,0.0,
84 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
85
86 add(new JLabel("Nick Name"),
87 new GridBagConstraints2(0,1,1,1,0.0,0.0,
88 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
89 add(_nick,
90 new GridBagConstraints2(1,1,1,1,0.0,0.0,
91 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
92
93 add(new JLabel("User Name"),
94 new GridBagConstraints2(0,2,1,1,0.0,0.0,
95 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
96 add(_email,
97 new GridBagConstraints2(1,2,1,1,0.0,0.0,
98 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
99
100 add(new JLabel("Alternate Nick Name"),
101 new GridBagConstraints2(0,3,1,1,0.0,0.0,
102 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
103 add(_alt,
104 new GridBagConstraints2(1,3,1,1,0.0,0.0,
105 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
106 }
107 //---------------------------------------------------------------
108 public void loadValues() {
109 _name.setText(_options.getFullName());
110 _nick.setText(_options.getNick());
111 _email.setText(_options.getUserName());
112 _alt.setText(_options.getAltNick());
113 }
114 //---------------------------------------------------------------
115 public void saveValues() {
116 _options.setNick(_nick.getText());
117 _options.setFullName(_name.getText());
118 _options.setAltNick(_alt.getText());
119 _options.setUserName(_email.getText());
120 }
121 //---------------------------------------------------------------
122 public String getName() {
123 return "User";
124 }
125 }
126
127 //////////////////////////////////////////////////////////////////////
128
129 private class _ServerPanel extends JPanel implements ITab {
130
131 //private JComboBox _serverCombo = new JComboBox();
132 private SetServerPanel _setServerPanel = new SetServerPanel();
133 private JTextField _name = new JTextField(15);
134 private JTextField _port = new JTextField(15);
135 private ChatOptions _options;
136 private ChatApp _chatApp;
137
138 //---------------------------------------------------------------
139 public _ServerPanel(ChatApp app) {
140 _options = app.getOptions();
141 _chatApp = app;
142
143 setBorder(new EmptyBorder(10,0,0,0)); // tlbr
144
145 setLayout(new GridBagLayout());
146 JButton editBut = new JButton("Edit Server List...");
147
148 add(_setServerPanel,
149 new GridBagConstraints2(0,0,1,1,0.0,0.0,
150 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
151
152 add(editBut,
153 new GridBagConstraints2(0,1,1,1,0.0,0.0,
154 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
155
156 editBut.addActionListener( new ActionListener() {
157 public void actionPerformed( ActionEvent e ) {
158 ServerListDlg dlg = new ServerListDlg(_chatApp,_options.getServerList());
159 loadValues();
160 }
161 });
162 loadValues();
163 }
164 //---------------------------------------------------------------
165 public void loadValues() {
166 _setServerPanel.loadServerList(
167 _options.getServerList(),ChatApp.getChatApp().getOptions());
168 }
169 //---------------------------------------------------------------
170 public void saveValues() {
171 Server server = _setServerPanel.getServerObject();
172 if (server!=null) {
173 _options.setServer(server);
174 }
175 }
176 //---------------------------------------------------------------
177 public String getName() {
178 return "IRC Server";
179 }
180 }
181
182 //////////////////////////////////////////////////////////////////////
183
184 private class _FontPanel extends JPanel implements ITab {
185 private FontChooser _fontChooser = null;
186 private ChatOptions _options;
187
188 //---------------------------------------------------------------
189 public _FontPanel(ChatOptions options) {
190 _options = options;
191 setLayout(new BorderLayout());
192 add(_fontChooser = new FontChooser());
193 }
194 //---------------------------------------------------------------
195 public void loadValues() {
196 RCTest.println("Font size="+_options.getFontSize());
197 _fontChooser.setSelectedFont(new Font(
198 _options.getFontName(),
199 _options.getFontStyle(),
200 _options.getFontSize()));
201 }
202 //---------------------------------------------------------------
203 public void saveValues() {
204 Font selFont = _fontChooser.getSelectedFont();
205 _options.setFontName(selFont.getName());
206 _options.setFontStyle(selFont.getStyle());
207 _options.setFontSize(selFont.getSize());
208 ChatApp.setChatFont(selFont);
209 }
210 public String getName() {
211 return "Font";
212 }
213 }
214
215 //////////////////////////////////////////////////////////////////////
216
217 private class _ColorPanel extends JPanel implements ITab {
218
219 private ColorCombo _messages = new ColorCombo();
220 private ColorCombo _actions = new ColorCombo();
221 private ColorCombo _joins = new ColorCombo();
222 private ColorCombo _parts = new ColorCombo();
223 private ColorCombo _ops = new ColorCombo();
224 private ColorCombo _kicks = new ColorCombo();
225 private ColorCombo _bans = new ColorCombo();
226 private ColorCombo _nicks = new ColorCombo();
227 private ChatOptions _options;
228
229 //---------------------------------------------------------------
230 public _ColorPanel(ChatOptions options) {
231 _options = options;
232
233 setBorder(new EmptyBorder(10,10,10,10)); // tlbr
234 setLayout(new GridBagLayout());
235
236 // GridBagConstraints2 arguments:
237 //
238 //int gridx, int gridy, int gridw, int gridh, double weightx, double weighty,
239 //int anchor, int fill, Insets insets, int ipadx, int ipady
240 //
241
242 add(_messages,
243 new GridBagConstraints2(1,0,1,1,0.0,0.0,
244 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
245 add(new JLabel("Messages"),
246 new GridBagConstraints2(0,0,1,1,0.0,0.0,
247 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
248
249 add(_actions,
250 new GridBagConstraints2(1,1,1,1,0.0,0.0,
251 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
252 add(new JLabel("Actions"),
253 new GridBagConstraints2(0,1,1,1,0.0,0.0,
254 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
255
256 add(_joins,
257 new GridBagConstraints2(1,2,1,1,0.0,0.0,
258 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
259 add(new JLabel("Joins"),
260 new GridBagConstraints2(0,2,1,1,0.0,0.0,
261 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
262
263 add(_parts,
264 new GridBagConstraints2(1,3,1,1,0.0,0.0,
265 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
266 add(new JLabel("Parts"),
267 new GridBagConstraints2(0,3,1,1,0.0,0.0,
268 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
269
270 add(_ops,
271 new GridBagConstraints2(3,0,1,1,0.0,0.0,
272 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
273 add(new JLabel("Ops"),
274 new GridBagConstraints2(2,0,1,1,0.0,0.0,
275 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
276
277 add(_kicks,
278 new GridBagConstraints2(3,1,1,1,0.0,0.0,
279 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
280 add(new JLabel("Kicks"),
281 new GridBagConstraints2(2,1,1,1,0.0,0.0,
282 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
283
284 add(_bans,
285 new GridBagConstraints2(3,2,1,1,0.0,0.0,
286 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
287 add(new JLabel("Bans"),
288 new GridBagConstraints2(2,2,1,1,0.0,0.0,
289 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
290
291 add(_nicks,
292 new GridBagConstraints2(3,3,1,1,0.0,0.0,
293 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
294 add(new JLabel("Nicks"),
295 new GridBagConstraints2(2,3,1,1,0.0,0.0,
296 GridBagConstraints.EAST,GridBagConstraints.NONE, new Insets(3,3,3,3),0,0));
297 }
298 //---------------------------------------------------------------
299 public void loadValues() {
300 _messages.setSelectedColorName( _options.getDisplayColor("Messages"));
301 _actions.setSelectedColorName( _options.getDisplayColor("Actions"));
302 _joins.setSelectedColorName( _options.getDisplayColor("Joins"));
303 _parts.setSelectedColorName( _options.getDisplayColor("Parts"));
304 _ops.setSelectedColorName( _options.getDisplayColor("Ops"));
305 _kicks.setSelectedColorName( _options.getDisplayColor("Kicks"));
306 _bans.setSelectedColorName( _options.getDisplayColor("Bans"));
307 _nicks.setSelectedColorName( _options.getDisplayColor("Nicks"));
308 }
309 //---------------------------------------------------------------
310 public void saveValues() {
311 _options.setDisplayColor("Messages",_messages.getSelectedColorName());
312 _options.setDisplayColor("Actions", _actions.getSelectedColorName());
313 _options.setDisplayColor("Joins", _joins.getSelectedColorName());
314 _options.setDisplayColor("Parts", _parts.getSelectedColorName());
315 _options.setDisplayColor("Ops", _ops.getSelectedColorName());
316 _options.setDisplayColor("Kicks", _kicks.getSelectedColorName());
317 _options.setDisplayColor("Bans", _bans.getSelectedColorName());
318 _options.setDisplayColor("Nicks", _nicks.getSelectedColorName());
319 }
320 //---------------------------------------------------------------
321 public String getName() {
322 return "Colors";
323 }
324 }
325
326 //////////////////////////////////////////////////////////////////////
327
328 private class _InterfacePanel extends JPanel implements ITab {
329 private ChatOptions _options;
330 private ChatApp _app;
331 private EmptyBorder _emptyBorder = new EmptyBorder(20,50,20,50); // tlbr
332 private JCheckBox _barCheck = new JCheckBox("Show Status Bar");
333 private JComboBox _lafCombo = new JComboBox();
334
335 //---------------------------------------------------------------
336 public _InterfacePanel(ChatApp app) {
337 _app = app;
338 _options = _app.getOptions();
339 setLayout(new GridBagLayout());
340
341 // GridBagConstraints2 arguments:
342 //
343 //int gridx, int gridy, int gridw, int gridh, double weightx, double weighty,
344 //int anchor, int fill, Insets insets, int ipadx, int ipady
345 //
346
347 add(_barCheck,
348 new GridBagConstraints2(0,0,1,1,0.0,0.0,
349 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
350
351 JCheckBox toolCheck = new JCheckBox("Show Tool Bar");
352 toolCheck.setEnabled(false);
353 add(toolCheck,
354 new GridBagConstraints2(0,1,1,1,0.0,0.0,
355 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
356
357 JCheckBox maxCheck = new JCheckBox("Maximize Window on Join");
358 maxCheck.setEnabled(false);
359 add(maxCheck,
360 new GridBagConstraints2(0,2,1,1,0.0,0.0,
361 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
362
363 JCheckBox chanCheck = new JCheckBox("Confirm Channel Exits");
364 chanCheck.setEnabled(false);
365 add(chanCheck,
366 new GridBagConstraints2(1,0,1,1,0.0,0.0,
367 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
368
369 JCheckBox exitCheck = new JCheckBox("Confirm Exit");
370 exitCheck.setEnabled(false);
371 add(exitCheck,
372 new GridBagConstraints2(1,1,1,1,0.0,0.0,
373 GridBagConstraints.WEST,GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
374
375
376 // Look and feel combo
377 UIManager.LookAndFeelInfo[] lafArray = UIManager.getInstalledLookAndFeels();
378 for (int i=0; i < lafArray.length; i++) {
379 _lafCombo.addItem(lafArray[i].getName());
380 }
381 add(_lafCombo,new GridBagConstraints2(1,3,1,1,0.0,0.0,
382 GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(15,5,0,15),0,0));
383
384 JLabel lafLabel = new JLabel("Look and Feel");
385 add(lafLabel,new GridBagConstraints2(0,3,1,1,0.0,0.0,
386 GridBagConstraints.EAST,GridBagConstraints.NONE,new Insets(15,0,5,15),0,0));
387
388 doLayout();
389 }
390 //---------------------------------------------------------------
391 public String getName() {
392 return "Interface";
393 }
394 //---------------------------------------------------------------
395 public void saveValues() {
396
397 _options.setStatusBarEnabled(_barCheck.isSelected());
398 _app.setStatusBarEnabled(_barCheck.isSelected());
399
400 if (_lafCombo.getSelectedItem()!=null) {
401 _options.setCustomOption("LookAndFeel",_lafCombo.getSelectedItem().toString());
402 _app.loadLookAndFeel(_lafCombo.getSelectedItem().toString());
403 }
404 }
405 //---------------------------------------------------------------
406 public void loadValues() {
407 _barCheck.setSelected(_options.isStatusBarEnabled());
408 _lafCombo.setSelectedItem(_options.getCustomOption("LookAndFeel"));
409 }
410 }
411 }
412