KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > SearchTermIcon


1 package net.suberic.pooka.gui;
2 import java.awt.Component JavaDoc;
3 import javax.mail.Message JavaDoc;
4
5 /**
6  * This is a definition which allows for a particular Icon to be specified
7  * for multiple SearchTerm instances. The way the class works is that
8  * each SearchTerm is tried in order. The first one for which the current
9  * message returns true is considered to be the value. The Icon for that
10  * value is then returned.
11  */

12 public class SearchTermIcon implements TableCellIcon {
13
14     SearchTermIconManager manager;
15     MessageProxy message;
16     int value = -1;
17
18     public SearchTermIcon(SearchTermIconManager newManager, MessageProxy newMessage) {
19     manager = newManager;
20     message = newMessage;
21     value = manager.getValue(message.getMessageInfo().getMessage());
22     }
23
24     /**
25      * This method should return the appropriate component depending on the
26      * values of the particular TableCellIcon.
27      */

28     public Component JavaDoc getIcon() {
29     return manager.getIcon(value);
30     }
31
32     /**
33      * Compares this SearchTermIcon to another SearchTermIcon.
34      */

35     public int compareTo(Object JavaDoc o) {
36     if (o instanceof SearchTermIcon) {
37         int otherValue= ((SearchTermIcon) o).getIntValue();
38         if ( getIntValue() < otherValue)
39         return -1;
40         else if (getIntValue() == otherValue)
41         return 0;
42         else
43         return 1;
44     }
45
46     throw new ClassCastException JavaDoc("object is not a SearchTermIcon.");
47     }
48
49     /**
50      * Compares this SearchTermIcon to another SearchTermIcon.
51      */

52     public boolean equals(Object JavaDoc o) {
53       if (o instanceof SearchTermIcon) {
54     return (this.compareTo(o) == 0);
55       }
56
57       return false;
58     }
59
60     /**
61      * Returns the integer value for this Icon.
62      */

63     public int getIntValue() {
64     return value;
65     }
66 }
67
Popular Tags