1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2005 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.IRCTextProvider;
\r
33 import irc.NotEnoughParametersException;
\r
34 import irc.RootInterpretor;
\r
37 import java.util.Enumeration;
\r
38 import java.util.Locale;
\r
41 * The AWT interpretor for gui-relative commands.
\r
43 public class AWTInterpretor extends RootInterpretor {
\r
44 private PixxMDIInterface _mdi;
\r
45 private PixxConfiguration _config;
\r
48 * Create a new DefaultInterpretor.
\r
51 * global irc configuration.
\r
55 public AWTInterpretor(PixxConfiguration config, PixxMDIInterface mdi) {
\r
56 super(config.getIRCConfiguration());
\r
62 protected void handleCommand(Source source, String cmd, String[] parts, String[] cumul) {
\r
65 if (cmd.equals("dock")) {
\r
66 BaseAWTSource asource = _mdi.findBaseAWTSource(source);
\r
67 if (asource != null)
\r
69 } else if (cmd.equals("undock")) {
\r
70 BaseAWTSource asource = _mdi.findBaseAWTSource(source);
\r
71 if (asource != null)
\r
72 _mdi.undock(asource);
\r
73 } else if (cmd.equals("color")) {
\r
74 test(cmd, parts, 1);
\r
75 BaseAWTSource asource = _mdi.findBaseAWTSource(source);
\r
76 if (asource != null) {
\r
77 String front = parts[1];
\r
79 int pos = front.indexOf(",");
\r
81 back = front.substring(pos + 1);
\r
82 front = front.substring(0, pos);
\r
85 int c = Integer.parseInt(front);
\r
86 asource.setFrontColor(c);
\r
87 } catch (Exception ex) {
\r
90 int c = Integer.parseInt(back);
\r
91 asource.setBackColor(c);
\r
92 } catch (Exception ex) {
\r
95 } else if (cmd.equals("bold")) {
\r
96 test(cmd, parts, 1);
\r
97 BaseAWTSource asource = _mdi.findBaseAWTSource(source);
\r
98 if (asource != null) {
\r
99 if (parts[1].equals("1"))
\r
100 asource.setBold(true);
\r
101 else if (parts[1].equals("0"))
\r
102 asource.setBold(false);
\r
104 } else if (cmd.equals("underline")) {
\r
105 test(cmd, parts, 1);
\r
106 BaseAWTSource asource = _mdi.findBaseAWTSource(source);
\r
107 if (asource != null) {
\r
108 if (parts[1].equals("1"))
\r
109 asource.setUnderline(true);
\r
110 else if (parts[1].equals("0"))
\r
111 asource.setUnderline(false);
\r
113 } else if (cmd.equals("highlight")) {
\r
114 test(cmd, parts, 1);
\r
115 for (int i = 1; i < parts.length; i++)
\r
116 _config.addHighLightWord(parts[i]);
\r
117 } else if (cmd.equals("unhighlight")) {
\r
118 test(cmd, parts, 1);
\r
119 for (int i = 1; i < parts.length; i++)
\r
120 _config.removeHighLightWord(parts[i]);
\r
121 } else if (cmd.equals("focus")) {
\r
122 test(cmd, parts, 2);
\r
123 Enumeration e = source.getServer().getSources();
\r
124 while (e.hasMoreElements()) {
\r
125 Source s = (Source) e.nextElement();
\r
126 if (s.getType().equals(parts[1])
\r
127 && s.getName().toLowerCase(Locale.ENGLISH).equals(parts[2].toLowerCase(Locale.ENGLISH))) {
\r
128 BaseAWTSource asource = _mdi.findBaseAWTSource(s);
\r
129 if (asource != null)
\r
130 _mdi.setActive(asource);
\r
135 super.handleCommand(source, cmd, parts, cumul);
\r
137 } catch (NotEnoughParametersException ex) {
\r
138 source.report(getText(IRCTextProvider.INTERPRETOR_INSUFFICIENT_PARAMETERS, ex.getMessage()));
\r