KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > errorstripe > privatespi > Status


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.editor.errorstripe.privatespi;
21
22 import java.awt.Color JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import org.openide.ErrorManager;
25 import org.openide.filesystems.FileObject;
26 import org.openide.util.NbBundle;
27
28 /**Represents a status of a {@link Mark}.
29  *
30  * @author Jan Lahoda
31  */

32 public final class Status implements Comparable JavaDoc {
33
34     /**Status OK.
35      */

36     private static final int STATUS_OK_NUMBER = 0;
37
38     /**Status warning.
39      */

40     private static final int STATUS_WARNING_NUMBER = 1;
41
42     /**Status error.
43      */

44     private static final int STATUS_ERROR_NUMBER = 2;
45     
46     /**Status OK.
47      */

48     public static final Status STATUS_OK = new Status(STATUS_OK_NUMBER);
49     
50     /**Status warning.
51      */

52     public static final Status STATUS_WARNING = new Status(STATUS_WARNING_NUMBER);
53     
54     /**Status error.
55      */

56     public static final Status STATUS_ERROR = new Status(STATUS_ERROR_NUMBER);
57     
58     private static final Status[] VALUES = new Status[] {STATUS_OK, STATUS_WARNING, STATUS_ERROR};
59     
60     private static final Color JavaDoc[] DEFAULT_STATUS_COLORS = new Color JavaDoc[] {Color.GREEN, new Color JavaDoc(0xE1AA00), new Color JavaDoc(0xFF2A1C)};
61     
62     private int status;
63     
64     /**Creates a Status with a given status value.
65      *
66      * @param status status value to use
67      * @see #STATUS_ERROR
68      * @see #STATUS_WARNING
69      * @see #STATUS_OK
70      * @throws IllegalArgumentException if one of the provided statuses is something
71      * else then {@link #STATUS_ERROR},
72      * {@link #STATUS_WARNING} and
73      * {@link #STATUS_OK}
74      */

75     private Status(int status) throws IllegalArgumentException JavaDoc {
76         if (status != STATUS_ERROR_NUMBER && status != STATUS_WARNING_NUMBER && status != STATUS_OK_NUMBER)
77             throw new IllegalArgumentException JavaDoc("Invalid status provided: " + status); // NOI18N
78
this.status = status;
79     }
80     
81     /**Returns the numerical status assigned to this {@link Status}.
82      *
83      * @return numerical status
84      */

85     private int getStatus() {
86         return status;
87     }
88
89     /**{@inheritDoc}*/
90     public int compareTo(Object JavaDoc o) {
91         Status remote = (Status) o;
92         
93         if (status > remote.status) {
94             return 1;
95         }
96         
97         if (status < remote.status) {
98             return -1;
99         }
100         
101         return 0;
102     }
103     
104     /**{@inheritDoc}*/
105     public boolean equals(Object JavaDoc o) {
106         if (!(o instanceof Status)) {
107             return false;
108         }
109         
110         Status remote = (Status) o;
111         
112         return status == remote.status;
113     }
114     
115     /**{@inheritDoc}*/
116     public int hashCode() {
117         return 43 ^ status;
118     }
119     
120     private static String JavaDoc[] STATUS_NAMES = new String JavaDoc[] {
121         "OK", "WARNING", "ERROR" // NOI18N
122
};
123     
124     /**Returns a {@link String} representation of the {@link Status}.
125      * The format of the {@link String} is not specified.
126      * This method should only be used for debugging purposes.
127      *
128      * @return {@link String} representation of this object
129      */

130     public String JavaDoc toString() {
131         return "[Status: " + STATUS_NAMES[getStatus()] + "]"; // NOI18N
132
}
133     
134     /**Return the more important status out of the two given statuses.
135      * The statuses are ordered as follows:
136      * {@link #STATUS_ERROR}&gt;{@link #STATUS_WARNING}&gt;{@link #STATUS_OK}.
137      *
138      * @param first one provided status
139      * @param second another provided status
140      * @return the more important status out of the two provided statuses
141      * @throws IllegalArgumentException if one of the provided statuses is something
142      * else then {@link #STATUS_ERROR},
143      * {@link #STATUS_WARNING} and
144      * {@link #STATUS_OK}
145      */

146     public static Status getCompoundStatus(Status first, Status second) throws IllegalArgumentException JavaDoc {
147         if (first != STATUS_ERROR && first != STATUS_WARNING && first != STATUS_OK)
148             throw new IllegalArgumentException JavaDoc("Invalid status provided: " + first); // NOI18N
149

150         if (second != STATUS_ERROR && second != STATUS_WARNING && second != STATUS_OK)
151             throw new IllegalArgumentException JavaDoc("Invalid status provided: " + second); // NOI18N
152

153         return VALUES[Math.max(first.getStatus(), second.getStatus())];
154     }
155
156     /**Returns default {@link Color} for a given {@link Status}.
157      *
158      * @param s {@link Status} for which default color should be found
159      * @return default {@link Color} for a given {@link Status}
160      */

161     public static Color JavaDoc getDefaultColor(Status s) {
162         return DEFAULT_STATUS_COLORS[s.getStatus()];
163     }
164 }
165
Popular Tags