]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/gui/pixx/AWTInterpretor.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 / AWTInterpretor.java
1 /*****************************************************/\r
2 /*          This java file is a part of the          */\r
3 /*                                                   */\r
4 /*           -  Plouf's Java IRC Client  -           */\r
5 /*                                                   */\r
6 /*   Copyright (C)  2002 - 2005 Philippe Detournay   */\r
7 /*                                                   */\r
8 /*         All contacts : theplouf@yahoo.com         */\r
9 /*                                                   */\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
14 /*  the License.                                     */\r
15 /*                                                   */\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
21 /*                                                   */\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
27 /*                                                   */\r
28 /*****************************************************/\r
29 \r
30 package irc.gui.pixx;\r
31 \r
32 import irc.IRCTextProvider;\r
33 import irc.NotEnoughParametersException;\r
34 import irc.RootInterpretor;\r
35 import irc.Source;\r
36 \r
37 import java.util.Enumeration;\r
38 import java.util.Locale;\r
39 \r
40 /**\r
41  * The AWT interpretor for gui-relative commands.\r
42  */\r
43 public class AWTInterpretor extends RootInterpretor {\r
44         private PixxMDIInterface _mdi;\r
45         private PixxConfiguration _config;\r
46 \r
47         /**\r
48          * Create a new DefaultInterpretor.\r
49          * \r
50          * @param config\r
51          *          global irc configuration.\r
52          * @param mdi\r
53          *          the interface.\r
54          */\r
55         public AWTInterpretor(PixxConfiguration config, PixxMDIInterface mdi) {\r
56                 super(config.getIRCConfiguration());\r
57                 _mdi = mdi;\r
58                 _config = config;\r
59         }\r
60 \r
61         @Override\r
62         protected void handleCommand(Source source, String cmd, String[] parts, String[] cumul) {\r
63                 try {\r
64 \r
65                         if (cmd.equals("dock")) {\r
66                                 BaseAWTSource asource = _mdi.findBaseAWTSource(source);\r
67                                 if (asource != null)\r
68                                         _mdi.dock(asource);\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
78                                         String back = "";\r
79                                         int pos = front.indexOf(",");\r
80                                         if (pos >= 0) {\r
81                                                 back = front.substring(pos + 1);\r
82                                                 front = front.substring(0, pos);\r
83                                         }\r
84                                         try {\r
85                                                 int c = Integer.parseInt(front);\r
86                                                 asource.setFrontColor(c);\r
87                                         } catch (Exception ex) {\r
88                                         }\r
89                                         try {\r
90                                                 int c = Integer.parseInt(back);\r
91                                                 asource.setBackColor(c);\r
92                                         } catch (Exception ex) {\r
93                                         }\r
94                                 }\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
103                                 }\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
112                                 }\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
131                                                 break;\r
132                                         }\r
133                                 }\r
134                         } else {\r
135                                 super.handleCommand(source, cmd, parts, cumul);\r
136                         }\r
137                 } catch (NotEnoughParametersException ex) {\r
138                         source.report(getText(IRCTextProvider.INTERPRETOR_INSUFFICIENT_PARAMETERS, ex.getMessage()));\r
139                 }\r
140         }\r
141 }\r