]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/gui/pixx/AWTStatus.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / gui / pixx / AWTStatus.java
1 /*****************************************************/
2 /*          This java file is a part of the          */
3 /*                                                   */
4 /*           -  Plouf's Java IRC Client  -           */
5 /*                                                   */
6 /*   Copyright (C)  2002 - 2004 Philippe Detournay   */
7 /*                                                   */
8 /*         All contacts : theplouf@yahoo.com         */
9 /*                                                   */
10 /*  PJIRC is free software; you can redistribute     */
11 /*  it and/or modify it under the terms of the GNU   */
12 /*  General Public License as published by the       */
13 /*  Free Software Foundation; version 2 or later of  */
14 /*  the License.                                     */
15 /*                                                   */
16 /*  PJIRC is distributed in the hope that it will    */
17 /*  be useful, but WITHOUT ANY WARRANTY; without     */
18 /*  even the implied warranty of MERCHANTABILITY or  */
19 /*  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   */
20 /*  General Public License for more details.         */
21 /*                                                   */
22 /*  You should have received a copy of the GNU       */
23 /*  General Public License along with PJIRC; if      */
24 /*  not, write to the Free Software Foundation,      */
25 /*  Inc., 59 Temple Place, Suite 330, Boston,        */
26 /*  MA  02111-1307  USA                              */
27 /*                                                   */
28 /*****************************************************/
29
30 package irc.gui.pixx;
31
32 import irc.IRCServer;
33 import irc.ReplyServerListener;
34 import irc.Status;
35 import irc.StatusListener;
36
37 /**
38  * The AWTStatus.
39  */
40 public class AWTStatus extends BaseAWTSource implements StatusListener, ReplyServerListener {
41
42         /**
43          * Create a new AWTStatus.
44          * 
45          * @param config
46          *          global irc configuration.
47          * @param s
48          *          source status.
49          */
50         public AWTStatus(PixxConfiguration config, Status s) {
51                 super(config, s);
52                 s.addStatusListener(this);
53                 s.getIRCServer().addReplyServerListener(this);
54                 title();
55         }
56
57         @Override
58         public void release() {
59                 ((Status) _source).removeStatusListener(this);
60                 ((Status) _source).getIRCServer().removeReplyServerListener(this);
61                 super.release();
62         }
63
64         private String getSourceName() {
65                 if (!_pixxConfiguration.getIRCConfiguration().getB("multiserver")) {
66                         if (_pixxConfiguration.getIRCConfiguration().getB("useinfo"))
67                                 return getText(PixxTextProvider.SOURCE_INFO);
68                         return getText(PixxTextProvider.SOURCE_STATUS);
69                 }
70
71                 return ((Status) _source).getServerName();
72         }
73
74         private void title() {
75                 setTitle(getSourceName() + ": " + ((Status) _source).getNick() + " [" + ((Status) _source).getMode() + "]");
76         }
77
78         @Override
79         public String getShortTitle() {
80                 return getSourceName();
81         }
82
83         /**
84          * A notice has been received.
85          * 
86          * @param from
87          *          source nickname.
88          * @param msg
89          *          notice string.
90          */
91         public void noticeReceived(String from, String msg) {
92                 print("-" + from + "- " + msg, 5);
93         }
94
95         @Override
96         public void nickChanged(String nick, Status status) {
97                 print("*** " + getText(PixxTextProvider.SOURCE_YOUR_NICK, nick), 3);
98                 title();
99         }
100
101         @Override
102         public void modeChanged(String mode, Status status) {
103                 if (mode.length() > 0)
104                         print("*** " + getText(PixxTextProvider.SOURCE_YOUR_MODE, mode), 3);
105                 title();
106         }
107
108         @Override
109         public void invited(String channel, String who, Status status) {
110                 if (status.getIRCServer().getDefaultSource() != null)
111                         status.getIRCServer().getDefaultSource().report(getText(PixxTextProvider.SOURCE_YOU_INVITED, who, channel));
112         }
113
114         @Override
115         public Boolean replyReceived(String prefix, String id, String params[], IRCServer server) {
116                 if (id.equals("301")) // away
117                 {
118                         String toSend = getText(PixxTextProvider.SOURCE_AWAY, params[1]) + " :";
119                         for (int i = 2; i < params.length; i++)
120                                 toSend += " " + params[i];
121                         _source.report(toSend);
122                 }
123                 return Boolean.FALSE;
124         }
125
126 }