1 | package org.greenstone.gatherer.util;
|
---|
2 |
|
---|
3 | import javax.swing.JCheckBox;
|
---|
4 |
|
---|
5 | /** A CheckListEntry encapsulates a single row of the list, both its check box and the object the row represents. */
|
---|
6 | public class CheckListEntry
|
---|
7 | extends JCheckBox
|
---|
8 | implements Comparable {
|
---|
9 |
|
---|
10 | /** Is this checkboxes state fixed. */
|
---|
11 | private boolean fixed = false;
|
---|
12 | /** The original object this row is based on, and whose toString() is used to generate the check box label. */
|
---|
13 | private Object object = null;
|
---|
14 | /** A sundry string for storing original values (rather than strings retrieved from dictionary). */
|
---|
15 | private String property;
|
---|
16 | /** Constructor. */
|
---|
17 | public CheckListEntry(Object object) {
|
---|
18 | super(object.toString());
|
---|
19 | this.object = object;
|
---|
20 | }
|
---|
21 |
|
---|
22 | /** Constructor. */
|
---|
23 | public CheckListEntry(String text, boolean is_selected) {
|
---|
24 | super(text);
|
---|
25 | setSelected(is_selected);
|
---|
26 | }
|
---|
27 |
|
---|
28 | /** Test this CheckListEntry against an Object for ordering.
|
---|
29 | * @param obj the other Object.
|
---|
30 | * @return <0, 0 or >0 if this CheckListEntry is before, equal to or after the given object.
|
---|
31 | */
|
---|
32 | public int compareTo(Object obj) {
|
---|
33 | return toString().toLowerCase().compareTo(obj.toString().toLowerCase());
|
---|
34 | }
|
---|
35 | /** Test this CheckListEntry against an Object for equality.
|
---|
36 | * @param obj the other Object.
|
---|
37 | * @return true if the two are equal, false otherwise.
|
---|
38 | */
|
---|
39 | public boolean equals(Object obj) {
|
---|
40 | if (obj == null) {
|
---|
41 | return false;
|
---|
42 | }
|
---|
43 | return toString().equalsIgnoreCase(obj.toString());
|
---|
44 | }
|
---|
45 |
|
---|
46 | /** Retrieve the object associated with this entry.
|
---|
47 | * @return An <strong>Object</strong>.
|
---|
48 | */
|
---|
49 | public Object getObject() {
|
---|
50 | if(object == null) {
|
---|
51 | return getText();
|
---|
52 | }
|
---|
53 | return object;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public String getProperty() {
|
---|
57 | return property;
|
---|
58 | }
|
---|
59 |
|
---|
60 | public boolean isFixed() {
|
---|
61 | return fixed;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public void setFixed(boolean fixed) {
|
---|
65 | this.fixed = fixed;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public void setProperty(String property) {
|
---|
69 | this.property = property;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public String toString() {
|
---|
73 | if(object == null) {
|
---|
74 | return getText();
|
---|
75 | }
|
---|
76 | return object.toString();
|
---|
77 | }
|
---|
78 | }
|
---|