]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/gui/pixx/AWTQuery.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 / AWTQuery.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.Query;
34 import irc.QueryListener;
35 import irc.ReplyServerListener;
36 import irc.style.StyledList;
37
38 import java.awt.event.MouseEvent;
39
40 /**
41  * The AWTQuery.
42  */
43 public class AWTQuery extends BaseAWTSource implements QueryListener, ReplyServerListener {
44         private NickMenuHandler _menu;
45
46         /**
47          * Create a new AWTQuery.
48          * 
49          * @param config
50          *          the global irc configuration.
51          * @param query
52          *          the source query.
53          */
54         public AWTQuery(PixxConfiguration config, Query query) {
55                 super(config, query);
56                 _menu = new NickMenuHandler(config, this, query);
57                 query.addQueryListener(this);
58                 query.getIRCServer().addReplyServerListener(this);
59                 update();
60         }
61
62         @Override
63         public void release() {
64                 ((Query) _source).removeQueryListeners(this);
65                 ((Query) _source).getIRCServer().removeReplyServerListener(this);
66                 _menu.release();
67                 _menu = null;
68                 super.release();
69         }
70
71         private void update() {
72                 String whois = ((Query) _source).getWhois();
73                 String[] nick = new String[2];
74                 nick[0] = _source.getName() + ":" + _pixxConfiguration.getIRCConfiguration().formatASL(whois);
75                 nick[1] = _source.getServer().getNick() + ":"
76                                 + _pixxConfiguration.getIRCConfiguration().formatASL(_source.getServer().getUserName());
77                 _list.setNickList(nick);
78                 title();
79         }
80
81         private void title() {
82                 String whois = ((Query) _source).getWhois();
83                 if (whois.length() > 0)
84                         setTitle(_source.getName() + " (" + _pixxConfiguration.getIRCConfiguration().formatASL(whois) + ")");
85                 else
86                         setTitle(_source.getName());
87
88         }
89
90         @Override
91         public void nickChanged(String newNick, Query query) {
92                 update();
93         }
94
95         @Override
96         public void whoisChanged(String whois, Query query) {
97                 update();
98         }
99
100         private String whois(String nick) {
101                 nick = nick.toLowerCase(java.util.Locale.ENGLISH);
102                 if (nick.equals(_source.getName().toLowerCase(java.util.Locale.ENGLISH)))
103                         return ((Query) _source).getWhois();
104                 if (nick.equals(_source.getServer().getNick().toLowerCase(java.util.Locale.ENGLISH)))
105                         return _source.getServer().getUserName();
106                 return "";
107         }
108
109         @Override
110         public void nickEvent(StyledList lis, String nick, MouseEvent e) {
111                 if (_pixxConfiguration.matchMouseConfiguration("nickpopup", e)) {
112                         _menu.popup(nick, whois(nick), _list, e.getX(), e.getY());
113                 } else {
114                         super.nickEvent(lis, nick, e);
115                 }
116         }
117
118         @Override
119         public Boolean replyReceived(String prefix, String id, String params[], IRCServer server) {
120                 if (id.equals("301")) // away
121                 {
122                         if (params[1].toLowerCase(java.util.Locale.ENGLISH).equals(
123                                         _source.getName().toLowerCase(java.util.Locale.ENGLISH))) {
124                                 String toSend = getText(PixxTextProvider.SOURCE_AWAY, params[1]) + " :";
125                                 for (int i = 2; i < params.length; i++)
126                                         toSend += " " + params[i];
127                                 _source.report(toSend);
128                         }
129                 }
130                 return Boolean.FALSE;
131         }
132
133 }