KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > filter > UTPriorityCondition


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.usertasks.filter;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import javax.swing.*;
25 import org.netbeans.modules.tasklist.core.checklist.CheckList;
26 import org.netbeans.modules.tasklist.core.checklist.DefaultCheckListModel;
27 import org.netbeans.modules.tasklist.core.filter.FilterCondition;
28 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
29 import org.openide.util.NbBundle;
30
31 /**
32  * "Priority is" - condition
33  *
34  * @author tl
35  */

36 public class UTPriorityCondition extends FilterCondition {
37     /**
38      * Creates an array of filter conditions for the specified property
39      *
40      * @param index index of the property
41      */

42     public static UTPriorityCondition[] createConditions() {
43         return new UTPriorityCondition[] {
44             new UTPriorityCondition()
45         };
46     };
47     
48     
49     private static int NPRIORITIES = 5;
50     
51     // 5 = Number of different priorities
52
protected boolean[] priorities = new boolean[NPRIORITIES];
53     
54     /**
55      * Creates a new instance
56      *
57      * @param prop index of a property
58      */

59     public UTPriorityCondition() {
60         Arrays.fill(priorities, true);
61     }
62     
63     
64     public UTPriorityCondition(final UTPriorityCondition rhs) {
65         super(rhs);
66         // copy priorities
67
for (int i = 0; i < NPRIORITIES; i++)
68             this.priorities[i] = rhs.priorities[i];
69     }
70     
71     public Object JavaDoc clone() {
72         return new UTPriorityCondition(this);
73     }
74     
75     public boolean isTrue(Object JavaDoc o1) {
76         Integer JavaDoc k = (Integer JavaDoc) o1;
77         return priorities[k - 1];
78     }
79     
80     public JComponent createConstantComponent() {
81         CheckList list = new CheckList(
82                 new DefaultCheckListModel(
83                 priorities, UserTask.getPriorityNames()));
84         JPanel panel = new JPanel(new BorderLayout JavaDoc());
85         panel.setOpaque(false);
86         panel.setBorder(BorderFactory.createCompoundBorder(
87                 UIManager.getBorder("TextField.border"), // NOI18N
88
BorderFactory.createEmptyBorder(2, 2, 2, 2)
89                 ));
90         panel.add(list, BorderLayout.CENTER);
91         panel.setToolTipText(NbBundle.getMessage(UTPriorityCondition.class,
92                 "prio_desc"));
93         
94         list.getAccessibleContext().setAccessibleName(
95                 NbBundle.getMessage(UTPriorityCondition.class,
96                 "LBL_PriorityCheckList"));
97         list.getAccessibleContext().setAccessibleDescription(
98                 NbBundle.getMessage(UTPriorityCondition.class,
99                 "LBL_PriorityCheckList"));
100         
101         return panel;
102     }
103     
104     public void getConstantFrom(JComponent cmp) {
105         // Nothing to do. The array of booleans will not be cloned in
106
// DefaultCheckListModel
107
}
108     
109     protected String JavaDoc getDisplayName() {
110         return NbBundle.getMessage(UTPriorityCondition.class, "IsOneOf");
111     }
112     
113     
114     private static class Convertor extends FilterCondition.Convertor {
115         private static final String JavaDoc ATTR_PRIORITIES = "priorities";
116         
117         public Convertor() {
118             super("PriorityCondition");
119         }
120         
121         public static UTPriorityCondition.Convertor create() {
122             return new UTPriorityCondition.Convertor();
123         }
124         
125         protected Object JavaDoc readElement(org.w3c.dom.Element JavaDoc element)
126                 throws java.io.IOException JavaDoc, java.lang.ClassNotFoundException JavaDoc {
127             UTPriorityCondition cond = new UTPriorityCondition();
128             super.readCondition(element, cond);
129             
130             String JavaDoc spriorities = element.getAttribute(ATTR_PRIORITIES);
131             boolean bpriorities [] = new boolean[NPRIORITIES];
132             for (int i = 0; i < NPRIORITIES; i++)
133                 bpriorities[i] = (spriorities.charAt(i) == '+');
134             cond.priorities = bpriorities;
135             
136             return cond;
137         }
138         
139         // write methods for supported condition types
140
protected void writeElement(org.w3c.dom.Document JavaDoc document,
141                 org.w3c.dom.Element JavaDoc element, Object JavaDoc obj)
142                 throws java.io.IOException JavaDoc, org.w3c.dom.DOMException JavaDoc {
143             UTPriorityCondition cond = (UTPriorityCondition)obj;
144             super.writeCondition(document, element, cond);
145             
146             StringBuffer JavaDoc str = new StringBuffer JavaDoc(NPRIORITIES);
147             for (int i = 0; i < NPRIORITIES; i++)
148                 str.append(cond.priorities[i] ? '+' : '-');
149             element.setAttribute(ATTR_PRIORITIES, str.toString());
150         }
151     }
152     
153     
154 }
155
Popular Tags