1 19 20 package org.netbeans.modules.editor.errorstripe.privatespi; 21 22 import java.awt.Color ; 23 import java.text.MessageFormat ; 24 import org.openide.ErrorManager; 25 import org.openide.filesystems.FileObject; 26 import org.openide.util.NbBundle; 27 28 32 public final class Status implements Comparable { 33 34 36 private static final int STATUS_OK_NUMBER = 0; 37 38 40 private static final int STATUS_WARNING_NUMBER = 1; 41 42 44 private static final int STATUS_ERROR_NUMBER = 2; 45 46 48 public static final Status STATUS_OK = new Status(STATUS_OK_NUMBER); 49 50 52 public static final Status STATUS_WARNING = new Status(STATUS_WARNING_NUMBER); 53 54 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 [] DEFAULT_STATUS_COLORS = new Color [] {Color.GREEN, new Color (0xE1AA00), new Color (0xFF2A1C)}; 61 62 private int status; 63 64 75 private Status(int status) throws IllegalArgumentException { 76 if (status != STATUS_ERROR_NUMBER && status != STATUS_WARNING_NUMBER && status != STATUS_OK_NUMBER) 77 throw new IllegalArgumentException ("Invalid status provided: " + status); this.status = status; 79 } 80 81 85 private int getStatus() { 86 return status; 87 } 88 89 90 public int compareTo(Object 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 105 public boolean equals(Object 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 116 public int hashCode() { 117 return 43 ^ status; 118 } 119 120 private static String [] STATUS_NAMES = new String [] { 121 "OK", "WARNING", "ERROR" }; 123 124 130 public String toString() { 131 return "[Status: " + STATUS_NAMES[getStatus()] + "]"; } 133 134 146 public static Status getCompoundStatus(Status first, Status second) throws IllegalArgumentException { 147 if (first != STATUS_ERROR && first != STATUS_WARNING && first != STATUS_OK) 148 throw new IllegalArgumentException ("Invalid status provided: " + first); 150 if (second != STATUS_ERROR && second != STATUS_WARNING && second != STATUS_OK) 151 throw new IllegalArgumentException ("Invalid status provided: " + second); 153 return VALUES[Math.max(first.getStatus(), second.getStatus())]; 154 } 155 156 161 public static Color getDefaultColor(Status s) { 162 return DEFAULT_STATUS_COLORS[s.getStatus()]; 163 } 164 } 165 | Popular Tags |