KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > client > SuggestionPriority


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.client;
21
22 import org.openide.util.NbBundle;
23
24 import java.util.ResourceBundle JavaDoc;
25
26 /**
27  * This class represents an enumerated type for suggestion priorities.
28  *
29  * @author Tor Norbye
30  */

31 final public class SuggestionPriority implements Comparable JavaDoc {
32
33     private final int priority;
34
35     /** Keys for the Bundle.properties */
36     private static final String JavaDoc[] PRIORITIES_KEYS = {
37         "PriorityHigh", // NOI18N
38
"PriorityMediumHigh", // NOI18N
39
"PriorityMedium", // NOI18N
40
"PriorityMediumLow", // NOI18N
41
"PriorityLow" // NOI18N
42
};
43
44     /** Names for priorities */
45     private static String JavaDoc[] PRIORITIES;
46
47     static {
48         PRIORITIES = new String JavaDoc[PRIORITIES_KEYS.length];
49         ResourceBundle JavaDoc rb = NbBundle.getBundle(SuggestionPriority.class);
50         for (int i = 0; i < PRIORITIES_KEYS.length; i++) {
51             PRIORITIES[i] = rb.getString(PRIORITIES_KEYS[i]);
52         }
53     }
54
55     private SuggestionPriority(final int priority) {
56         this.priority = priority;
57     }
58
59     /** Highest priority */
60     public static final SuggestionPriority HIGH =
61         new SuggestionPriority(1); // NOI18N
62

63     /** Normal/default priority */
64     public static final SuggestionPriority MEDIUM_HIGH =
65         new SuggestionPriority(2); // NOI18N
66

67     /** Normal/default priority */
68     public static final SuggestionPriority MEDIUM =
69         new SuggestionPriority(3); // NOI18N
70

71     /** Normal/default priority */
72     public static final SuggestionPriority MEDIUM_LOW =
73         new SuggestionPriority(4); // NOI18N
74

75     /** Lowest priority */
76     public static final SuggestionPriority LOW =
77         new SuggestionPriority(5); // NOI18N
78

79     /** Return a numeric value for the priority. Lower number means
80      * higher priority. Don't depend on the actual values; they may
81      * change without notice.
82      * @return Numeric value for the priority
83      * XXX clients often use as index to getPriorityNames
84      */

85     public int intValue() {
86         return priority;
87     }
88     
89     /** Provides a useful string representation for a particular priority.
90      * Not internationalized. Don't depend on this format or content.
91      * @return A string representation of the priority
92      */

93     public String JavaDoc toString() {
94         switch (priority) {
95         case 1: return "high priority"; // NOI18N
96
case 2: return "medium-high priority"; // NOI18N
97
case 3: return "normal priority"; // NOI18N
98
case 4: return "medium-low priority"; // NOI18N
99
case 5: return "low priority"; // NOI18N
100
default: return "error"; // NOI18N
101
}
102     }
103
104     public int compareTo(final Object JavaDoc o) {
105         return ((SuggestionPriority)o).priority - priority;
106     }
107
108     /**
109      * Returns localized names for priorities
110      *
111      * @return [0] - high, [1] - medium-high, ...
112      */

113     public static String JavaDoc[] getPriorityNames() {
114         return PRIORITIES;
115     }
116
117     /**
118      * Finds a priority.
119      * @param n integer representation of a priority
120      * @return priority
121      */

122     public static SuggestionPriority getPriority(final int n) {
123         switch (n) {
124             case 1:
125                 return HIGH;
126             case 2:
127                 return MEDIUM_HIGH;
128             case 3:
129                 return MEDIUM;
130             case 4:
131                 return MEDIUM_LOW;
132             case 5:
133                 return LOW;
134             default:
135                 return MEDIUM;
136         }
137     }
138 }
139
Popular Tags