]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/SmileyTable.java
Pjirc 2.2.1 as available on the net, reformatted and made it compile.
[irc/pjirc-ng.git] / src / main / java / irc / SmileyTable.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 - 2004 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;\r
31 \r
32 import java.awt.Image;\r
33 import java.util.Vector;\r
34 \r
35 /**\r
36  * SmileyItem.\r
37  */\r
38 class SmileyItem {\r
39         /**\r
40          * Matching string.\r
41          */\r
42         public String match;\r
43         /**\r
44          * Matching image.\r
45          */\r
46         public Image img;\r
47 \r
48         /**\r
49          * Create a new SmileyItem\r
50          * \r
51          * @param amatch\r
52          *          matching string.\r
53          * @param aimg\r
54          *          matching image.\r
55          */\r
56         public SmileyItem(String amatch, Image aimg) {\r
57                 match = amatch;\r
58                 img = aimg;\r
59         }\r
60 }\r
61 \r
62 /**\r
63  * Smiley table.\r
64  */\r
65 public class SmileyTable {\r
66         private Vector _table;\r
67 \r
68         /**\r
69          * Create a new, empty, smiley table.\r
70          */\r
71         public SmileyTable() {\r
72                 _table = new Vector();\r
73         }\r
74 \r
75         /**\r
76          * Add a smiley in the table.\r
77          * \r
78          * @param match\r
79          *          the macthing text.\r
80          * @param img\r
81          *          image of the smiley.\r
82          */\r
83         public void addSmiley(String match, Image img) {\r
84                 if (img != null)\r
85                         _table.insertElementAt(new SmileyItem(match, img), _table.size());\r
86         }\r
87 \r
88         /**\r
89          * Get the smileys count.\r
90          * \r
91          * @return the amount of smileys in the table.\r
92          */\r
93         public int getSize() {\r
94                 return _table.size();\r
95         }\r
96 \r
97         /**\r
98          * Get the i'th match in the smiley table.\r
99          * \r
100          * @param index\r
101          *          table index.\r
102          * @return i'th smiley match.\r
103          */\r
104         public String getMatch(int index) {\r
105                 SmileyItem item = (SmileyItem) _table.elementAt(index);\r
106                 return item.match;\r
107         }\r
108 \r
109         /**\r
110          * Get the i'th image in the smiley table.\r
111          * \r
112          * @param index\r
113          *          table index.\r
114          * @return i'th image.\r
115          */\r
116         public Image getImage(int index) {\r
117                 if (index < 0)\r
118                         return null;\r
119                 if (index >= getSize())\r
120                         return null;\r
121                 SmileyItem item = (SmileyItem) _table.elementAt(index);\r
122                 return item.img;\r
123         }\r
124 }\r