1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2004 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\r
10 /* PJIRC is free software; you can redistribute */
\r
11 /* it and/or modify it under the terms of the GNU */
\r
12 /* General Public License as published by the */
\r
13 /* Free Software Foundation; version 2 or later of */
\r
16 /* PJIRC is distributed in the hope that it will */
\r
17 /* be useful, but WITHOUT ANY WARRANTY; without */
\r
18 /* even the implied warranty of MERCHANTABILITY or */
\r
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
\r
20 /* General Public License for more details. */
\r
22 /* You should have received a copy of the GNU */
\r
23 /* General Public License along with PJIRC; if */
\r
24 /* not, write to the Free Software Foundation, */
\r
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
\r
26 /* MA 02111-1307 USA */
\r
28 /*****************************************************/
\r
30 package irc.gui.pixx;
\r
32 import irc.EventDispatcher;
\r
35 import java.awt.Component;
\r
36 import java.awt.MenuItem;
\r
37 import java.awt.PopupMenu;
\r
38 import java.awt.event.ActionEvent;
\r
39 import java.awt.event.ActionListener;
\r
40 import java.util.Enumeration;
\r
43 * Popupmenu handling for nicknames.
\r
45 public class NickMenuHandler implements ActionListener {
\r
46 private String _selectedNick;
\r
47 private String _whoisNick;
\r
48 private PopupMenu _menu;
\r
49 private Source _source;
\r
50 private Component _parent;
\r
51 private PixxConfiguration _pixxConfiguration;
\r
54 * Create a new NickMenuHandler.
\r
57 * the pixx configuration.
\r
59 * a parent component for the popup menu.
\r
61 * the source associated with this popup menu.
\r
63 public NickMenuHandler(PixxConfiguration config, Component parent, Source source) {
\r
64 _pixxConfiguration = config;
\r
67 _menu = new PopupMenu();
\r
68 _menu.addActionListener(this);
\r
73 * Release this instance.
\r
75 public void release() {
\r
76 _menu.removeActionListener(this);
\r
77 _parent.remove(_menu);
\r
81 _pixxConfiguration = null;
\r
84 private String parameters(String on, String[] params) {
\r
85 for (int i = 0; i < on.length() - 1; i++) {
\r
86 if (on.charAt(i) == '%') {
\r
87 char next = on.charAt(i + 1);
\r
89 String before = on.substring(0, i);
\r
90 String after = on.substring(i + 2);
\r
91 on = before + "%" + after;
\r
92 } else if ((next >= '1') && (next <= '9')) {
\r
94 if (c < params.length) {
\r
95 String before = on.substring(0, i);
\r
96 String after = on.substring(i + 2);
\r
97 on = before + params[c] + after;
\r
106 public void actionPerformed(ActionEvent e) {
\r
107 EventDispatcher.dispatchEventAsync(this, "actionPerformedEff", new Object[] { e });
\r
115 public void actionPerformedEff(ActionEvent e) {
\r
116 String cmd = e.getActionCommand();
\r
117 String[] params = new String[] { _selectedNick, _source.getName(),
\r
118 _pixxConfiguration.getIRCConfiguration().formatASL(_whoisNick), _whoisNick };
\r
119 for (int j = 0; j < _pixxConfiguration.getNickMenuVector().size(); j++) {
\r
120 String[] cmds = (String[]) _pixxConfiguration.getNickMenuVector().elementAt(j);
\r
121 if (cmds[0].equals(cmd)) {
\r
122 for (int i = 1; i < cmds.length; i++)
\r
123 _source.sendString(parameters(cmds[i], params));
\r
129 * Open and handle a popup menu for a nickname.
\r
134 * the whois or asl nickname information.
\r
136 * the component where the menu is to be displayed. This component
\r
137 * must be a child of the parent component for this menu.
\r
139 * x-position relative to c.
\r
141 * y-position relative to c.
\r
143 public void popup(String nick, String whois, Component c, int x, int y) {
\r
144 if (_pixxConfiguration.getNickMenuVector().size() == 0)
\r
146 _selectedNick = nick;
\r
147 _whoisNick = whois;
\r
151 Enumeration keys = _pixxConfiguration.getNickMenuVector().elements();
\r
152 while (keys.hasMoreElements()) {
\r
153 String[] v = (String[]) keys.nextElement();
\r
154 if (v[0].equals("--"))
\r
155 _menu.addSeparator();
\r
157 _menu.add(new MenuItem(v[0]));
\r
160 _menu.show(c, x, y);
\r