View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui.prefs;
21  
22  import java.awt.Component;
23  import java.awt.GridBagLayout;
24  
25  import javax.swing.*;
26  import javax.swing.JPanel;
27  
28  import org.xnap.XNap;
29  import org.xnap.gui.AbstractSettingsPanel;
30  import org.xnap.gui.action.EnableAction;
31  import org.xnap.gui.component.ValidatedTextField;
32  import org.xnap.gui.component.XNapCheckBox;
33  import org.xnap.gui.util.GUIHelper;
34  import org.xnap.gui.util.GridBagHelper;
35  
36  public class ChatPrefsPanel extends AbstractSettingsPanel {
37      
38      //--- Data field(s) ---
39  
40      private JCheckBox jcbBeepOnChatMessage;
41      private JCheckBox jcbBlinkOnChannelJoin;
42      private JCheckBox jcbShowChatMsgTime;
43      private JCheckBox jcbPrintServerNotifications;
44      private JCheckBox jcbAppendServerName;
45  
46      private JCheckBox jcbSendChatIgnoreMessage;
47      private ValidatedTextField jteChatIgnoreMessage;
48      
49      private ValidatedTextField jteChatAwayMessage;
50  
51      //--- Constructor(s) ---
52  
53      public ChatPrefsPanel()
54      {
55  		setLayout(new GridBagLayout());
56  
57  		// misc panel
58  		JPanel jpMisc = new JPanel(new GridBagLayout());
59  		jpMisc.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Miscellaneous")));
60  
61  		jcbBeepOnChatMessage = new JCheckBox
62  			(XNap.tr("Beep On Chat Message", 1), prefs.getBeepOnChatMessage());
63  		GridBagHelper.add(jpMisc, jcbBeepOnChatMessage);
64  
65  		jcbBlinkOnChannelJoin = new JCheckBox
66  			(XNap.tr("Blink On Channel Join", 1),
67  			 prefs.getBlinkOnChannelJoin());
68  		GridBagHelper.add(jpMisc, jcbBlinkOnChannelJoin);
69  
70  		jcbShowChatMsgTime = new JCheckBox
71  			(XNap.tr("Timestamp Chat Messages", 1),
72  			 prefs.getShowChatMsgTime());
73  		GridBagHelper.add(jpMisc, jcbShowChatMsgTime);
74  	
75  		jcbAppendServerName = new JCheckBox
76  			(XNap.tr("Append Server to User Names ", 1),
77  			 prefs.getAppendServerNameToChatUser());
78  		GridBagHelper.add(jpMisc, jcbAppendServerName);
79  
80  		jcbPrintServerNotifications = new JCheckBox
81  			(XNap.tr("Print Server Notifications", 1),
82  			 prefs.getPrintServerNotificationsInChatWindow());
83  		GridBagHelper.add(jpMisc, jcbPrintServerNotifications);
84  
85  		GridBagHelper.add(this, jpMisc);
86  
87  		JPanel jpChatIgnore = new JPanel(new GridBagLayout());
88  		jpChatIgnore.setBorder
89  			(GUIHelper.createDefaultBorder(XNap.tr("Notify peer of chat ban")));
90  		GridBagHelper.add(this, jpChatIgnore);
91  
92  		jteChatIgnoreMessage = 
93  			new ValidatedTextField(prefs.getChatIgnoreMessage(), 20,
94  								   ValidatedTextField.ANYTHING);
95  
96  		EnableAction acSendMsg = 
97  			new EnableAction(XNap.tr("Send Message"),
98  							 new Component[] { jteChatIgnoreMessage },
99  							 prefs.getSendChatIgnoreMessage());
100 		jcbSendChatIgnoreMessage = new XNapCheckBox(acSendMsg);
101 		GridBagHelper.addComponent(jpChatIgnore, jcbSendChatIgnoreMessage);
102 		GridBagHelper.add(jpChatIgnore, jteChatIgnoreMessage);
103 
104 		JPanel jpChatAway = new JPanel(new GridBagLayout());
105 		jpChatAway.setBorder
106 			(GUIHelper.createDefaultBorder(XNap.tr("Presence")));
107 		GridBagHelper.add(this, jpChatAway);
108 
109 		JLabel l = GridBagHelper.addLabel(jpChatAway, XNap.tr("Away Message"));
110 		jteChatAwayMessage = 
111 			new ValidatedTextField(prefs.getChatAwayMessage(), 20,
112 								   ValidatedTextField.ANYTHING);
113 		l.setLabelFor(jteChatAwayMessage);
114 		GridBagHelper.add(jpChatAway, jteChatAwayMessage);
115 
116 		GridBagHelper.addVerticalSpacer(this);
117 		GUIHelper.setMnemonics(this);
118     }
119 
120     public void apply() 
121     {
122 		prefs.setBeepOnChatMessage(jcbBeepOnChatMessage.isSelected());
123 		prefs.setBlinkOnChannelJoin(jcbBlinkOnChannelJoin.isSelected());
124 		prefs.setShowChatMsgTime(jcbShowChatMsgTime.isSelected());
125 		prefs.setAppendServerNameToChatUser(jcbAppendServerName.isSelected());
126 		prefs.setPrintServerNotificationsInChatWindow
127 			(jcbPrintServerNotifications.isSelected());
128 		prefs.setSendChatIgnoreMessage(jcbSendChatIgnoreMessage.isSelected());
129 		prefs.setChatIgnoreMessage(jteChatIgnoreMessage.getText());
130 		prefs.setChatAwayMessage(jteChatAwayMessage.getText());
131 
132     }
133 
134     public String getTitle()
135     {
136 		return XNap.tr("Chat");
137     }
138 
139 	public String getDescription()
140 	{
141 		return XNap.tr("Chat configuration.");
142 	}
143 }