1 22 23 27 28 package org.netbeans.lib.terminalemulator; 29 30 class Attr { 31 private final static int BGCOLORf = 0; 35 private final static int BGCOLORw = 5; 36 private final static int BGCOLORm = 0xf; 37 public final static int BGCOLOR = BGCOLORm << BGCOLORf; 38 39 private final static int FGCOLORf = BGCOLORf + BGCOLORw; 40 private final static int FGCOLORw = 5; 41 private final static int FGCOLORm = 0xf; 42 public final static int FGCOLOR = FGCOLORm << FGCOLORf; 43 44 private final static int HIDDENf = FGCOLORf + FGCOLORw; 45 private final static int HIDDENw = 1; 46 public final static int HIDDEN = 0x1 << HIDDENf; 47 48 private final static int REVERSEf = HIDDENf + HIDDENw; 49 private final static int REVERSEw = 1; 50 public final static int REVERSE = 0x1 << REVERSEf; 51 52 private final static int BLINKf = REVERSEf + REVERSEw; 53 private final static int BLINKw = 1; 54 public final static int BLINK = 0x1 << BLINKf; 55 56 private final static int UNDERSCOREf = BLINKf + BLINKw; 57 private final static int UNDERSCOREw = 1; 58 public final static int UNDERSCORE = 0x1 << UNDERSCOREf; 59 60 private final static int BRIGHTf = UNDERSCOREf + UNDERSCOREw; 61 private final static int BRIGHTw = 1; 62 public final static int BRIGHT = 0x1 << BRIGHTf; 63 64 private final static int DIMf = BRIGHTf + BRIGHTw; 65 private final static int DIMw = 1; 66 public final static int DIM = 0x1 << DIMf; 67 68 private final static int ACTIVEf = DIMf + DIMw; 69 public final static int ACTIVE = 0x1 << ACTIVEf; 70 71 public final static int UNSET = 0x40000000; 76 77 78 79 82 83 public static int setBackgroundColor(int attr, int code) { 84 code &= BGCOLORm; attr &= ~ BGCOLOR; attr |= code << BGCOLORf; 87 return attr; 88 } 89 90 91 94 95 public static int setForegroundColor(int attr, int code) { 96 code &= FGCOLORm; attr &= ~ FGCOLOR; attr |= code << FGCOLORf; 99 return attr; 100 } 101 102 105 public static int foregroundColor(int attr) { 106 return (attr >> FGCOLORf) & FGCOLORm; 107 } 108 109 112 public static int backgroundColor(int attr) { 113 return (attr >> BGCOLORf) & BGCOLORm; 114 } 115 116 119 public static int setAttribute(int attr, int value) { 120 switch (value) { 121 case 0: 122 attr = 0; 124 break; 125 case 5: 126 case 1: 129 attr &= ~ Attr.DIM; 130 attr |= Attr.BRIGHT; 131 break; 132 case 2: 133 attr &= ~ Attr.BRIGHT; 134 attr |= Attr.DIM; 135 break; 136 case 4: 137 attr |= Attr.UNDERSCORE; 138 break; 139 case 7: 140 attr |= Attr.REVERSE; 141 break; 142 case 8: 143 attr |= Attr.HIDDEN; 144 break; 145 146 case 9: 147 attr |= Attr.ACTIVE; 149 break; 150 151 case 25: 153 case 22: 156 attr &= ~ Attr.DIM; 157 attr &= ~ Attr.BRIGHT; 158 break; 159 case 24: 160 attr &= ~ Attr.UNDERSCORE; 161 break; 162 case 27: 163 attr &= ~ Attr.REVERSE; 164 break; 165 case 28: 166 attr &= ~ Attr.HIDDEN; 167 break; 168 169 case 30: 170 case 31: 171 case 32: 172 case 33: 173 case 34: 174 case 35: 175 case 36: 176 case 37: 177 attr = Attr.setForegroundColor(attr, value-30+1); 178 break; 179 180 case 39: 181 attr = Attr.setForegroundColor(attr, 0); 183 break; 184 185 case 40: 186 case 41: 187 case 42: 188 case 43: 189 case 44: 190 case 45: 191 case 46: 192 case 47: 193 attr = Attr.setBackgroundColor(attr, value-40+1); 194 break; 195 196 case 49: 197 attr = Attr.setBackgroundColor(attr, 0); 199 break; 200 201 case 50: 202 case 51: 203 case 52: 204 case 53: 205 case 54: 206 case 55: 207 case 56: 208 case 57: 209 attr = Attr.setForegroundColor(attr, value-50+9); 211 break; 212 213 case 60: 214 case 61: 215 case 62: 216 case 63: 217 case 64: 218 case 65: 219 case 66: 220 case 67: 221 attr = Attr.setBackgroundColor(attr, value-60+9); 223 break; 224 225 default: 226 break; 228 } 229 return attr; 230 } 231 232 237 public static int unsetAttribute(int attr, int value) { 238 switch (value) { 239 case 0: 240 attr = 0; 242 break; 243 case 5: 244 case 1: 247 attr &= ~ Attr.BRIGHT; 248 break; 249 case 2: 250 attr &= ~ Attr.DIM; 251 break; 252 case 4: 253 attr &= ~ Attr.UNDERSCORE; 254 break; 255 case 7: 256 attr &= ~ Attr.REVERSE; 257 break; 258 case 8: 259 attr &= ~ Attr.HIDDEN; 260 break; 261 case 9: 262 attr &= ~ Attr.ACTIVE; 263 break; 264 265 case 30: 266 case 31: 267 case 32: 268 case 33: 269 case 34: 270 case 35: 271 case 36: 272 case 37: 273 attr = Attr.setForegroundColor(attr, 0); 274 break; 275 276 case 40: 277 case 41: 278 case 42: 279 case 43: 280 case 44: 281 case 45: 282 case 46: 283 case 47: 284 attr = Attr.setBackgroundColor(attr, 0); 285 break; 286 287 case 50: 288 case 51: 289 case 52: 290 case 53: 291 case 54: 292 case 55: 293 case 56: 294 case 57: 295 attr = Attr.setForegroundColor(attr, 0); 297 break; 298 299 case 60: 300 case 61: 301 case 62: 302 case 63: 303 case 64: 304 case 65: 305 case 66: 306 case 67: 307 attr = Attr.setBackgroundColor(attr, 0); 309 break; 310 311 default: 312 break; 314 } 315 return attr; 316 } 317 } 318 | Popular Tags |