1 /*****************************************************/
2 /* This java file is a part of the */
4 /* - Plouf's Java IRC Client - */
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
8 /* All contacts : theplouf@yahoo.com */
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 */
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. */
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 */
28 /*****************************************************/
34 import irc.QueryListener;
35 import irc.ReplyServerListener;
36 import irc.style.StyledList;
38 import java.awt.event.MouseEvent;
43 public class AWTQuery extends BaseAWTSource implements QueryListener, ReplyServerListener {
44 private NickMenuHandler _menu;
47 * Create a new AWTQuery.
50 * the global irc configuration.
54 public AWTQuery(PixxConfiguration config, Query query) {
56 _menu = new NickMenuHandler(config, this, query);
57 query.addQueryListener(this);
58 query.getIRCServer().addReplyServerListener(this);
63 public void release() {
64 ((Query) _source).removeQueryListeners(this);
65 ((Query) _source).getIRCServer().removeReplyServerListener(this);
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);
81 private void title() {
82 String whois = ((Query) _source).getWhois();
83 if (whois.length() > 0)
84 setTitle(_source.getName() + " (" + _pixxConfiguration.getIRCConfiguration().formatASL(whois) + ")");
86 setTitle(_source.getName());
91 public void nickChanged(String newNick, Query query) {
96 public void whoisChanged(String whois, Query query) {
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();
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());
114 super.nickEvent(lis, nick, e);
119 public Boolean replyReceived(String prefix, String id, String params[], IRCServer server) {
120 if (id.equals("301")) // away
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);
130 return Boolean.FALSE;