KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > core > filter > BooleanFilterCondition


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.core.filter;
21
22 import javax.swing.*;
23
24 /**
25  * Basic condition class for comparisons of boolean values.
26  *
27  * @author Tor Norbye
28  * @author tl
29  */

30 public class BooleanFilterCondition extends OneOfFilterCondition {
31     public static final int ISTRUE = 0;
32     public static final int ISFALSE = 1;
33
34     private static String JavaDoc[] NAME_KEYS = {
35         "IsTrue", // NOI18N
36
"IsFalse", // NOI18N
37
};
38
39     /**
40      * Creates an array of filter conditions for the specified property
41      *
42      * @param index index of the property
43      */

44     public static BooleanFilterCondition[] createConditions() {
45         return new BooleanFilterCondition[] {
46             new BooleanFilterCondition(BooleanFilterCondition.ISTRUE),
47             new BooleanFilterCondition(BooleanFilterCondition.ISFALSE)
48         };
49     };
50     
51     /**
52      * Creates a condition with the given name.
53      *
54      * @param prop index of the property this condition uses
55      * @param id one of the constants from this class
56      */

57     public BooleanFilterCondition(int id) {
58       super(NAME_KEYS, id);
59     }
60
61     public BooleanFilterCondition(final BooleanFilterCondition rhs) {
62         super(rhs);
63     }
64
65     public Object JavaDoc clone() {
66         return new BooleanFilterCondition(this);
67     }
68     
69     BooleanFilterCondition() { super(NAME_KEYS);};
70
71     public JComponent createConstantComponent() {
72         return null;
73     }
74
75     public boolean isTrue(Object JavaDoc obj) {
76         boolean n = ((Boolean JavaDoc) obj).booleanValue();
77         switch (getId()) {
78             case ISTRUE:
79                 return n == true;
80             case ISFALSE:
81                 return n == false;
82             default:
83                 throw new InternalError JavaDoc("wrong id"); // NOI18N
84
}
85     }
86
87
88   private static class Convertor extends OneOfFilterCondition.Convertor {
89     private static final String JavaDoc ELEM_BOOLEAN_CONDITION = "BooleanCondition";
90
91     public Convertor() { super(ELEM_BOOLEAN_CONDITION, NAME_KEYS);}
92
93     public static BooleanFilterCondition.Convertor create() {
94       return new BooleanFilterCondition.Convertor();
95     }
96     protected OneOfFilterCondition createCondition() { return new BooleanFilterCondition();}
97
98   }
99
100 }
101
Popular Tags