]> git.somenet.org - irc/pjirc-ng.git/blob - src/main/java/irc/gui/pixx/PixxColorModel.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 / PixxColorModel.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.gui.pixx;\r
31 \r
32 import java.awt.Color;\r
33 \r
34 /**\r
35  * PixxInterface color model.\r
36  */\r
37 public class PixxColorModel {\r
38         /**\r
39          * Black.\r
40          */\r
41         public static final int COLOR_BLACK = 0;\r
42         /**\r
43          * White.\r
44          */\r
45         public static final int COLOR_WHITE = 1;\r
46         /**\r
47          * Dark gray.\r
48          */\r
49         public static final int COLOR_DARK_GRAY = 2;\r
50         /**\r
51          * Gray.\r
52          */\r
53         public static final int COLOR_GRAY = 3;\r
54         /**\r
55          * Light gray.\r
56          */\r
57         public static final int COLOR_LIGHT_GRAY = 4;\r
58         /**\r
59          * Front.\r
60          */\r
61         public static final int COLOR_FRONT = 5;\r
62         /**\r
63          * Back.\r
64          */\r
65         public static final int COLOR_BACK = 6;\r
66         /**\r
67          * Selected.\r
68          */\r
69         public static final int COLOR_SELECTED = 7;\r
70         /**\r
71          * Event.\r
72          */\r
73         public static final int COLOR_EVENT = 8;\r
74         /**\r
75          * Close.\r
76          */\r
77         public static final int COLOR_CLOSE = 9;\r
78         /**\r
79          * Voice.\r
80          */\r
81         public static final int COLOR_VOICE = 10;\r
82         /**\r
83          * Op.\r
84          */\r
85         public static final int COLOR_OP = 11;\r
86         /**\r
87          * Semiop.\r
88          */\r
89         public static final int COLOR_SEMIOP = 12;\r
90         /**\r
91          * ASL male.\r
92          */\r
93         public static final int COLOR_MALE = 13;\r
94         /**\r
95          * ASL femeale.\r
96          */\r
97         public static final int COLOR_FEMEALE = 14;\r
98         /**\r
99          * ASL undefined.\r
100          */\r
101         public static final int COLOR_UNDEF = 15;\r
102 \r
103         private Color[] _colors;\r
104 \r
105         /**\r
106          * Create a new PixxColorModel using default colors.\r
107          */\r
108         public PixxColorModel() {\r
109                 Color[] cols = new Color[16];\r
110                 cols[0] = Color.black;\r
111                 cols[1] = Color.white;\r
112                 cols[2] = new Color(0x868686);\r
113                 cols[3] = Color.gray;\r
114                 cols[4] = new Color(0xD0D0D0);\r
115                 cols[5] = new Color(0x336699);\r
116                 cols[6] = new Color(0x084079);\r
117                 cols[7] = new Color(0x003167);\r
118                 cols[8] = new Color(0xa40000);\r
119                 cols[9] = new Color(0x4B8ECE);\r
120                 cols[10] = new Color(0x008000);\r
121                 cols[11] = new Color(0x336699);\r
122                 cols[12] = new Color(0x336699);\r
123                 cols[13] = new Color(0x4040ff);\r
124                 cols[14] = new Color(0xff40ff);\r
125                 cols[15] = new Color(0x336699);\r
126                 init(cols);\r
127         }\r
128 \r
129         /**\r
130          * Set the i'th color.\r
131          * \r
132          * @param i\r
133          *          index.\r
134          * @param c\r
135          *          color.\r
136          */\r
137         public void setColor(int i, Color c) {\r
138                 if ((i >= 0) && (i < _colors.length))\r
139                         _colors[i] = c;\r
140         }\r
141 \r
142         /**\r
143          * Get the number of color in the mode.\r
144          * \r
145          * @return color count.\r
146          */\r
147         public int getColorCount() {\r
148                 return _colors.length;\r
149         }\r
150 \r
151         private Color computeColor(int r, int g, int b, int i) {\r
152                 r *= i;\r
153                 g *= i;\r
154                 b *= i;\r
155                 r /= 256;\r
156                 g /= 256;\r
157                 b /= 256;\r
158                 if (r > 255)\r
159                         r = 255;\r
160                 if (g > 255)\r
161                         g = 255;\r
162                 if (b > 255)\r
163                         b = 255;\r
164                 return new Color(r, g, b);\r
165         }\r
166 \r
167         /**\r
168          * Create a new PixxColorModel using given r g b basecolor.\r
169          * \r
170          * @param r\r
171          *          red base color.\r
172          * @param g\r
173          *          green base color.\r
174          * @param b\r
175          *          blue base color.\r
176          */\r
177         public PixxColorModel(int r, int g, int b) {\r
178                 Color[] cols = new Color[16];\r
179                 cols[0] = Color.black;\r
180                 cols[1] = Color.white;\r
181                 cols[2] = new Color(0x868686);\r
182                 cols[3] = Color.gray;\r
183                 cols[4] = new Color(0xD0D0D0);\r
184                 cols[8] = new Color(0xa40000);\r
185                 cols[10] = new Color(0x008000);\r
186                 cols[13] = new Color(0x4040ff);\r
187                 cols[14] = new Color(0xff40ff);\r
188 \r
189                 cols[5] = computeColor(r, g, b, 0x66);\r
190                 cols[6] = computeColor(r, g, b, 0x55);\r
191                 cols[7] = computeColor(r, g, b, 0x4B);\r
192                 cols[9] = computeColor(r, g, b, 0x80);\r
193                 cols[11] = computeColor(r, g, b, 0x66);\r
194                 cols[12] = computeColor(r, g, b, 0x66);\r
195                 cols[15] = computeColor(r, g, b, 0x66);\r
196                 init(cols);\r
197         }\r
198 \r
199         /**\r
200          * Create a new PixxColorModel using given colors.\r
201          * \r
202          * @param cols\r
203          *          colors to use.\r
204          */\r
205         public PixxColorModel(Color[] cols) {\r
206                 init(cols);\r
207         }\r
208 \r
209         private void init(Color[] cols) {\r
210                 _colors = new Color[cols.length];\r
211                 for (int i = 0; i < cols.length; i++)\r
212                         _colors[i] = cols[i];\r
213         }\r
214 \r
215         /**\r
216          * Get the color at the given index.\r
217          * \r
218          * @param i\r
219          *          index.\r
220          * @return the i'th color.\r
221          */\r
222         public Color getColor(int i) {\r
223                 return _colors[i];\r
224         }\r
225 }\r