1 /*****************************************************/
2 /* This java file is a part of the */
4 /* - Plouf's Java IRC Client - */
6 /* Copyright (C) 2002 - 2005 Philippe Detournay */
8 /* All contacts : theplouf@yahoo.com */
10 /* PJIRC is free software; you can redistribute */
11 /* it and/or modify it under the terms of the GNU */
12 /* General Public License as published by the */
13 /* Free Software Foundation; version 2 or later of */
16 /* PJIRC is distributed in the hope that it will */
17 /* be useful, but WITHOUT ANY WARRANTY; without */
18 /* even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
20 /* General Public License for more details. */
22 /* You should have received a copy of the GNU */
23 /* General Public License along with PJIRC; if */
24 /* not, write to the Free Software Foundation, */
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
26 /* MA 02111-1307 USA */
28 /*****************************************************/
32 import irc.IRCConfiguration;
34 import irc.TextProvider;
36 import java.awt.Color;
37 import java.awt.event.InputEvent;
38 import java.util.Enumeration;
39 import java.util.Hashtable;
40 import java.util.Vector;
49 * MouseEventConfiguration.
51 class MouseEventConfiguration {
53 * Create a new MouseEventConfiguration
60 public MouseEventConfiguration(int m, int c) {
72 public int ClickCount;
78 public class PixxConfiguration {
79 private IRCConfiguration _config;
80 private PixxColorModel _colorModel = new PixxColorModel();
81 private TextProvider _textProvider;
83 private RuleList _dockingRules;
84 private Hashtable _htable;
85 private Hashtable _mouseConfig;
86 private Vector _highLightWords;
87 private Vector _nickMenuVector;
89 private NullItem NULL_ITEM = new NullItem();
92 * Create a new PixxConfiguration
95 * original global configuration.
97 public PixxConfiguration(IRCConfiguration config) {
99 _htable = new Hashtable();
100 _mouseConfig = new Hashtable();
101 _dockingRules = new RuleList();
102 _dockingRules.setDefaultValue(new Boolean(false));
103 _highLightWords = new Vector();
104 _nickMenuVector = new Vector();
108 * Get the nick menu configuration vector.
110 * @return the nick menu vector.
112 public synchronized Vector getNickMenuVector() {
113 return _nickMenuVector;
117 * Set the text provider to be used.
122 public void setTextProvider(TextProvider txt) {
127 * Configure the given mouse event name.
132 * mouse button index.
136 public synchronized void setMouseConfiguration(String eventName, int button, int count) {
140 mask = InputEvent.BUTTON1_MASK;
143 mask = InputEvent.BUTTON2_MASK;
146 mask = InputEvent.BUTTON3_MASK;
149 mask = InputEvent.BUTTON1_MASK;
152 _mouseConfig.put(eventName.toLowerCase(java.util.Locale.ENGLISH), new MouseEventConfiguration(mask, count));
156 * Check whether the given event name and the given mouse event match.
162 * @return true if events match, false otherwise.
164 public synchronized boolean matchMouseConfiguration(String eventName, java.awt.event.MouseEvent event) {
165 if (getB("ignoreallmouseevents"))
167 MouseEventConfiguration config = (MouseEventConfiguration) _mouseConfig.get(eventName
168 .toLowerCase(java.util.Locale.ENGLISH));
170 throw new Error(eventName + " : unknown mouse event name");
171 if (config.ClickCount != event.getClickCount())
173 return (event.getModifiers() & config.Mask) != 0;
177 * Set the given property to the given value. This value may be null.
184 public synchronized void set(String key, Object obj) {
187 _htable.put(key.toLowerCase(java.util.Locale.ENGLISH), obj);
191 * Set the given property to the given int value.
198 public synchronized void set(String key, int val) {
199 set(key, new Integer(val));
203 * Set the given property to the given boolean value.
210 public synchronized void set(String key, boolean val) {
211 set(key, new Boolean(val));
215 * Get the given property value.
219 * @return the property value.
220 * @throws RuntimeException
221 * if the property is unknown.
223 public synchronized Object get(String key) {
224 Object v = _htable.get(key.toLowerCase(java.util.Locale.ENGLISH));
226 throw new RuntimeException("Unknown configuration property " + key);
233 * Get the given property value as an int value.
237 * @return the property value.
238 * @throws RuntimeException
239 * if the property is unknown.
241 public synchronized int getI(String key) {
242 Integer i = (Integer) get(key);
247 * Get the given property value as a boolean value.
251 * @return the property value.
252 * @throws RuntimeException
253 * if the property is unknown.
255 public synchronized boolean getB(String key) {
256 Boolean b = (Boolean) get(key);
257 return b.booleanValue();
261 * Get the given property value as String value.
265 * @return the property value.
266 * @throws RuntimeException
267 * if the property is unknown.
269 public synchronized String getS(String key) {
270 return (String) get(key);
274 * Set highlight configuration.
279 * true if nick highlight enabled.
281 * hightlight words set.
283 public synchronized void setHighLightConfig(int color, boolean nick, Vector words) {
284 set("highlightcolor", color);
285 set("highlightnick", nick);
286 _highLightWords = new Vector();
287 for (int i = 0; i < words.size(); i++)
288 _highLightWords.insertElementAt(words.elementAt(i), _highLightWords.size());
292 * Get nick highlight flag.
294 * @return nick highlight flag.
296 public synchronized boolean highLightNick() {
297 return getB("highlightnick") && getB("highlight");
301 * Get highlight words.
303 * @return enumeration of String.
305 public synchronized Enumeration getHighLightWords() {
306 if (!getB("highlight"))
307 return new Vector().elements();
308 return _highLightWords.elements();
312 * Add a word into the highlight word list.
317 public synchronized void addHighLightWord(String word) {
318 _highLightWords.insertElementAt(word, _highLightWords.size());
322 * Remove a word from the highlight word list.
325 * the word to remove.
327 public synchronized void removeHighLightWord(String word) {
328 for (int i = 0; i < _highLightWords.size(); i++) {
329 if (((String) _highLightWords.elementAt(i)).equals(word)) {
330 _highLightWords.removeElementAt(i);
337 * Set the color model to be used.
342 public void setColorModel(PixxColorModel model) {
347 * Get the original IRC configuration.
349 * @return original IRCConfiguration.
351 public IRCConfiguration getIRCConfiguration() {
356 * Get color model in use.
358 * @return color model.
360 public PixxColorModel getColorModel() {
365 * Get the color at given index.
369 * @return the i'th color.
371 public Color getColor(int i) {
372 return _colorModel.getColor(i);
376 * Set the docking policy associated with the given source type and name.
383 * true if source should be undocked, false otherwise.
385 public synchronized void setDockingPolicy(String type, String name, boolean action) {
386 _dockingRules.addRule(new String[] { type, name }, new Boolean(action));
390 * Get the docking policy for the given source type and name.
396 * @return true if the source should be undocked, false otherwise.
398 public synchronized boolean getDockingPolicy(String type, String name) {
399 return ((Boolean) (_dockingRules.findValue(new String[] { type, name }))).booleanValue();
403 * Get formatted text associated with the given text code, with no parameter.
407 * @return formatted text.
409 public synchronized String getText(int code) {
410 if (code < TextProvider.USER_BASE)
411 return _config.getText(code);
412 return _textProvider.getString(code);
416 * Get formatted text associated with the given text code, with one parameter.
422 * @return formatted text.
424 public synchronized String getText(int code, String p1) {
425 if (code < TextProvider.USER_BASE)
426 return _config.getText(code, p1);
427 return _textProvider.getString(code, p1);
431 * Get formatted text associated with the given text code, with two
440 * @return formatted text.
442 public synchronized String getText(int code, String p1, String p2) {
443 if (code < TextProvider.USER_BASE)
444 return _config.getText(code, p1, p2);
445 return _textProvider.getString(code, p1, p2);
449 * Get formatted text associated with the given text code, with three
460 * @return formatted text.
462 public synchronized String getText(int code, String p1, String p2, String p3) {
463 if (code < TextProvider.USER_BASE)
464 return _config.getText(code, p1, p2, p3);
465 return _textProvider.getString(code, p1, p2, p3);