1 19 20 package org.netbeans.editor; 21 22 import java.awt.Color ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 import java.util.Iterator ; 26 import java.beans.PropertyChangeSupport ; 27 import java.awt.Image ; 28 import java.awt.Toolkit ; 29 import java.net.URL ; 30 import java.net.MalformedURLException ; 31 import org.netbeans.editor.AnnotationTypes; 32 import java.util.ResourceBundle ; 33 import org.openide.ErrorManager; 34 35 43 44 public class AnnotationType { 45 46 47 public static final String PROP_NAME = "name"; 49 50 public static final String PROP_DESCRIPTION = "description"; 52 53 public static final String PROP_VISIBLE = "visible"; 55 56 public static final String PROP_GLYPH_URL = "glyph"; 58 59 public static final String PROP_HIGHLIGHT_COLOR = "highlight"; 61 62 public static final String PROP_FOREGROUND_COLOR = "foreground"; 64 65 public static final String PROP_WAVEUNDERLINE_COLOR = "waveunderline"; 67 68 public static final String PROP_WHOLE_LINE = "wholeline"; 70 71 public static final String PROP_CONTENT_TYPE = "contenttype"; 73 74 public static final String PROP_ACTIONS = "actions"; 76 77 public static final String PROP_TOOLTIP_TEXT = "tooltipText"; 79 80 public static final String PROP_INHERIT_FOREGROUND_COLOR = "inheritForegroundColor"; 82 83 public static final String PROP_USE_HIGHLIGHT_COLOR = "useHighlightColor"; 85 86 public static final String PROP_USE_WAVEUNDERLINE_COLOR = "useWaveUnderlineColor"; 88 public static final String PROP_USE_CUSTOM_SIDEBAR_COLOR = "useCustomSidebarColor"; 90 public static final String PROP_CUSTOM_SIDEBAR_COLOR = "customSidebarColor"; 92 public static final String PROP_SEVERITY = "severity"; 94 public static final String PROP_BROWSEABLE = "browseable"; 96 public static final String PROP_PRIORITY = "priority"; 98 103 public static final String PROP_COMBINATIONS = "combinations"; 105 public static final String PROP_COMBINATION_ORDER = "combinationOrder"; 107 public static final String PROP_COMBINATION_MINIMUM_OPTIONALS = "combinationMinimumOptionals"; 109 111 public static final String PROP_FILE = "file"; 113 public static final String PROP_LOCALIZING_BUNDLE = "bundle"; 115 public static final String PROP_DESCRIPTION_KEY = "desciptionKey"; 117 public static final String PROP_ACTIONS_FOLDER = "actionsFolder"; 119 public static final String PROP_COMBINATION_TOOLTIP_TEXT_KEY = "tooltipTextKey"; 121 122 private Map properties; 123 124 125 private PropertyChangeSupport support; 126 127 128 private Image img = null; 129 130 131 private Coloring col; 132 133 public AnnotationType() { 134 properties = new HashMap (15*4/3); 135 support = new PropertyChangeSupport (this); 136 } 137 138 140 public java.net.URL getGlyph() { 141 URL u = (java.net.URL )getProp(PROP_GLYPH_URL); 142 if (u == null) 143 u = AnnotationTypes.getDefaultGlyphURL(); 144 return u; 145 } 146 147 149 public void setGlyph(java.net.URL glyph) { 150 putProp(PROP_GLYPH_URL, glyph); 151 } 152 153 156 public Image getGlyphImage() { 157 if (img == null) { 158 img = Toolkit.getDefaultToolkit().getImage(getGlyph()); 159 } 160 return img; 161 } 162 163 164 public boolean isDefaultGlyph() { 165 if (getProp(PROP_GLYPH_URL) == null) 166 return true; 167 else 168 return false; 169 } 170 171 173 public java.awt.Color getHighlight() { 174 return (java.awt.Color )getProp(PROP_HIGHLIGHT_COLOR); 175 } 176 177 179 public void setHighlight(java.awt.Color highlight) { 180 col = null; putProp(PROP_HIGHLIGHT_COLOR, highlight); 182 firePropertyChange(PROP_HIGHLIGHT_COLOR, null, null); 183 processChange(); 184 } 185 186 188 public boolean isUseHighlightColor() { 189 Boolean b = (Boolean )getProp(PROP_USE_HIGHLIGHT_COLOR); 190 if (b == null) 191 return true; 192 return b.booleanValue(); 193 } 194 195 197 public void setUseHighlightColor(boolean use) { 198 if (isUseHighlightColor() != use) { 199 col = null; putProp(PROP_USE_HIGHLIGHT_COLOR, use ? Boolean.TRUE : Boolean.FALSE); 201 firePropertyChange(PROP_USE_HIGHLIGHT_COLOR, null, null); 202 processChange(); 203 } 204 } 205 206 208 public java.awt.Color getForegroundColor() { 209 return (java.awt.Color )getProp(PROP_FOREGROUND_COLOR); 210 } 211 212 214 public void setForegroundColor(java.awt.Color foregroundColor) { 215 col = null; putProp(PROP_FOREGROUND_COLOR, foregroundColor); 217 firePropertyChange(PROP_FOREGROUND_COLOR, null, null); 218 processChange(); 219 } 220 221 223 public boolean isInheritForegroundColor() { 224 Boolean b = (Boolean )getProp(PROP_INHERIT_FOREGROUND_COLOR); 225 if (b == null) 226 return true; 227 return b.booleanValue(); 228 } 229 230 232 public void setInheritForegroundColor(boolean inherit) { 233 if (isInheritForegroundColor() != inherit) { 234 col = null; putProp(PROP_INHERIT_FOREGROUND_COLOR, inherit ? Boolean.TRUE : Boolean.FALSE); 236 firePropertyChange(PROP_INHERIT_FOREGROUND_COLOR, null, null); 237 processChange(); 238 } 239 } 240 241 243 public java.awt.Color getWaveUnderlineColor() { 244 return (java.awt.Color )getProp(PROP_WAVEUNDERLINE_COLOR); 245 } 246 247 249 public void setWaveUnderlineColor(java.awt.Color waveunderline) { 250 col = null; putProp(PROP_WAVEUNDERLINE_COLOR, waveunderline); 252 firePropertyChange(PROP_WAVEUNDERLINE_COLOR, null, null); 253 processChange(); 254 } 255 256 258 public boolean isUseWaveUnderlineColor() { 259 Boolean b = (Boolean )getProp(PROP_USE_WAVEUNDERLINE_COLOR); 260 if (b == null) 261 return true; 262 return b.booleanValue(); 263 } 264 265 267 public void setUseWaveUnderlineColor(boolean use) { 268 if (isUseWaveUnderlineColor() != use) { 269 col = null; putProp(PROP_USE_WAVEUNDERLINE_COLOR, use ? Boolean.TRUE : Boolean.FALSE); 271 firePropertyChange(PROP_USE_WAVEUNDERLINE_COLOR, null, null); 272 processChange(); 273 } 274 } 275 276 278 private void processChange() { 279 if (getProp(AnnotationType.PROP_FILE) == null) 281 return; 282 Settings.touchValue(null, null); 284 AnnotationTypes.getTypes().saveType(this); 285 } 286 287 289 public Coloring getColoring() { 290 if (col == null) 291 col = new Coloring(null, Coloring.FONT_MODE_DEFAULT, isInheritForegroundColor() ? null : getForegroundColor(), isUseHighlightColor() ? getHighlight() : null, null, null, isUseWaveUnderlineColor() ? getWaveUnderlineColor() : null); 292 return col; 293 } 294 295 297 public javax.swing.Action [] getActions() { 298 return (javax.swing.Action [])getProp(PROP_ACTIONS); 299 } 300 301 303 public void setActions(javax.swing.Action [] actions) { 304 putProp(PROP_ACTIONS, actions); 305 } 306 307 309 public CombinationMember[] getCombinations() { 310 return (CombinationMember[])getProp(PROP_COMBINATIONS); 311 } 312 313 314 public void setCombinations(CombinationMember[] combs) { 315 putProp(PROP_COMBINATIONS, combs); 316 } 317 318 320 public String getName() { 321 return (String )getProp(PROP_NAME); 322 } 323 324 326 public void setName(String name) { 327 putProp(PROP_NAME, name); 328 } 329 330 332 public String getDescription() { 333 String desc = (String )getProp(PROP_DESCRIPTION); 334 if (desc == null) { 335 String localizer = (String )getProp(PROP_LOCALIZING_BUNDLE); 336 String key = (String )getProp(PROP_DESCRIPTION_KEY); 337 try { 338 ResourceBundle bundle = ImplementationProvider.getDefault().getResourceBundle(localizer); 339 desc = bundle.getString(key); 340 }catch(java.util.MissingResourceException mre){ 341 desc = key; 342 } 343 setDescription(desc); } 345 return desc; 346 } 347 348 350 public void setDescription(String name) { 351 putProp(PROP_DESCRIPTION, name); 352 } 353 354 356 public String getTooltipText() { 357 String text = (String )getProp(PROP_TOOLTIP_TEXT); 358 if (text == null) { 359 String localizer = (String )getProp(PROP_LOCALIZING_BUNDLE); 360 String key = (String )getProp(PROP_COMBINATION_TOOLTIP_TEXT_KEY); 361 ResourceBundle bundle = ImplementationProvider.getDefault().getResourceBundle(localizer); 362 text = bundle.getString(key); 363 setTooltipText(text); } 365 return text; 366 } 367 368 370 public void setTooltipText(String text) { 371 putProp(PROP_TOOLTIP_TEXT, text); 372 } 373 374 376 public int getCombinationOrder() { 377 if (getProp(PROP_COMBINATION_ORDER) == null) 378 return 0; 379 return ((Integer )getProp(PROP_COMBINATION_ORDER)).intValue(); 380 } 381 382 384 public void setCombinationOrder(int order) { 385 putProp(PROP_COMBINATION_ORDER, new Integer (order)); 386 } 387 388 390 public void setCombinationOrder(String ord) { 391 int order; 392 try { 393 order = Integer.parseInt(ord); 394 } catch (NumberFormatException ex) { 395 Utilities.annotateLoggable(ex); 396 return; 397 } 398 putProp(PROP_COMBINATION_ORDER, new Integer (order)); 399 } 400 401 404 public int getMinimumOptionals() { 405 if (getProp(PROP_COMBINATION_MINIMUM_OPTIONALS) == null) 406 return 0; 407 return ((Integer )getProp(PROP_COMBINATION_MINIMUM_OPTIONALS)).intValue(); 408 } 409 410 public void setMinimumOptionals(int min) { 411 putProp(PROP_COMBINATION_MINIMUM_OPTIONALS, new Integer (min)); 412 } 413 414 public void setMinimumOptionals(String m) { 415 int min; 416 try { 417 min = Integer.parseInt(m); 418 } catch (NumberFormatException ex) { 419 Utilities.annotateLoggable(ex); 420 return; 421 } 422 putProp(PROP_COMBINATION_MINIMUM_OPTIONALS, new Integer (min)); 423 } 424 425 427 public boolean isVisible() { 428 Boolean b = (Boolean )getProp(PROP_VISIBLE); 429 if (b == null) 430 return false; 431 return b.booleanValue(); 432 } 433 434 436 public void setVisible(boolean vis) { 437 putProp(PROP_VISIBLE, vis ? Boolean.TRUE : Boolean.FALSE); 438 } 439 440 442 public void setVisible(String vis) { 443 putProp(PROP_VISIBLE, Boolean.valueOf(vis)); 444 } 445 446 448 public boolean isWholeLine() { 449 Boolean b = (Boolean )getProp(PROP_WHOLE_LINE); 450 if (b == null) 451 return true; 452 return b.booleanValue(); 453 } 454 455 457 public void setWholeLine(boolean wl) { 458 putProp(PROP_WHOLE_LINE, wl ? Boolean.TRUE : Boolean.FALSE); 459 } 460 461 463 public void setWholeLine(String wl) { 464 putProp(PROP_WHOLE_LINE, Boolean.valueOf(wl)); 465 } 466 467 469 public String getContentType() { 470 return (String )getProp(PROP_CONTENT_TYPE); 471 } 472 473 475 public void setContentType(String ct) { 476 putProp(PROP_CONTENT_TYPE, ct); 477 } 478 479 public boolean isUseCustomSidebarColor() { 480 return ((Boolean )getProp(PROP_USE_CUSTOM_SIDEBAR_COLOR)).booleanValue(); 481 } 482 483 public void setUseCustomSidebarColor(boolean value) { 484 putProp(PROP_USE_CUSTOM_SIDEBAR_COLOR, Boolean.valueOf(value)); 485 } 486 487 public Color getCustomSidebarColor() { 488 return (Color ) getProp(PROP_CUSTOM_SIDEBAR_COLOR); 489 } 490 491 public void setCustomSidebarColor(Color customSidebarColor) { 492 putProp(PROP_CUSTOM_SIDEBAR_COLOR, customSidebarColor); 493 } 494 495 public Severity getSeverity() { 496 return (Severity) getProp(PROP_SEVERITY); 497 } 498 499 public void setSeverity(Severity severity) { 500 putProp(PROP_SEVERITY, severity); 501 } 502 503 public int getPriority() { 504 return ((Integer ) getProp(PROP_PRIORITY)).intValue(); 505 } 506 507 public void setPriority(int priority) { 508 putProp(PROP_PRIORITY, new Integer (priority)); 509 } 510 511 public boolean isBrowseable() { 512 return ((Boolean )getProp(PROP_BROWSEABLE)).booleanValue(); 513 } 514 515 public void setBrowseable(boolean browseable) { 516 putProp(PROP_BROWSEABLE, Boolean.valueOf(browseable)); 517 } 518 519 520 public Object getProp(String prop){ 521 return properties.get(prop); 522 } 523 524 525 public void putProp(Object key, Object value){ 526 if (value == null) { 527 properties.remove(key); 528 return; 529 } 530 properties.put(key,value); 531 } 532 533 public String toString() { 534 return "AnnotationType: name='" + getName() + "', description='" + getDescription() + "', visible=" + isVisible() + ", wholeline=" + isWholeLine() + ", glyph=" + getGlyph() + ", highlight=" + getHighlight() + ", foreground=" + getForegroundColor() + "', inheritForeground=" + isInheritForegroundColor() + ", contenttype="+getContentType(); 541 } 542 543 545 final public void addPropertyChangeListener(java.beans.PropertyChangeListener l) { 546 support.addPropertyChangeListener (l); 547 } 548 549 551 final public void removePropertyChangeListener(java.beans.PropertyChangeListener l) { 552 support.removePropertyChangeListener (l); 553 } 554 555 556 final protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { 557 support.firePropertyChange(propertyName, oldValue, newValue); 558 } 559 560 561 567 public static final class CombinationMember { 568 569 570 private String type; 571 572 573 private boolean absorbAll; 574 575 576 private boolean optional; 577 578 580 private int minimumCount; 581 582 public CombinationMember(String type, boolean absorbAll, boolean optional, int minimumCount) { 583 this.type = type; 584 this.absorbAll = absorbAll; 585 this.optional = optional; 586 this.minimumCount = minimumCount; 587 } 588 589 public CombinationMember(String type, boolean absorbAll, boolean optional, String minimumCount) { 590 this.type = type; 591 this.absorbAll = absorbAll; 592 this.optional = optional; 593 if (minimumCount != null && minimumCount.length() > 0) { 594 try { 595 this.minimumCount = Integer.parseInt(minimumCount); 596 } catch (NumberFormatException ex) { 597 Utilities.annotateLoggable(ex); 598 this.minimumCount = 0; 599 } 600 } else 601 this.minimumCount = 0; 602 } 603 604 605 public String getName() { 606 return type; 607 } 608 609 610 public boolean isAbsorbAll() { 611 return absorbAll; 612 } 613 614 615 public boolean isOptional() { 616 return optional; 617 } 618 619 620 public int getMinimumCount() { 621 return minimumCount; 622 } 623 } 624 625 public static final class Severity implements Comparable { 626 627 629 private static final int STATUS_NONE_NUMBER = 0; 630 631 633 private static final int STATUS_OK_NUMBER = 1; 634 635 637 private static final int STATUS_WARNING_NUMBER = 2; 638 639 641 private static final int STATUS_ERROR_NUMBER = 3; 642 643 645 public static final Severity STATUS_NONE = new Severity(STATUS_NONE_NUMBER); 646 647 649 public static final Severity STATUS_OK = new Severity(STATUS_OK_NUMBER); 650 651 653 public static final Severity STATUS_WARNING = new Severity(STATUS_WARNING_NUMBER); 654 655 657 public static final Severity STATUS_ERROR = new Severity(STATUS_ERROR_NUMBER); 658 659 private static final Severity[] VALUES = new Severity[] {STATUS_NONE, STATUS_OK, STATUS_WARNING, STATUS_ERROR}; 660 661 private static final Color [] DEFAULT_STATUS_COLORS = new Color [] {Color.WHITE, Color.GREEN, Color.YELLOW, Color.RED}; 662 663 private int status; 664 665 676 private Severity(int status) throws IllegalArgumentException { 677 if (status != STATUS_NONE_NUMBER && status != STATUS_ERROR_NUMBER && status != STATUS_WARNING_NUMBER && status != STATUS_OK_NUMBER) 678 throw new IllegalArgumentException ("Invalid status provided: " + status); this.status = status; 680 } 681 682 686 private int getStatus() { 687 return status; 688 } 689 690 691 public int compareTo(Object o) { 692 Severity remote = (Severity) o; 693 694 if (status > remote.status) { 695 return 1; 696 } 697 698 if (status < remote.status) { 699 return -1; 700 } 701 702 return 0; 703 } 704 705 706 public boolean equals(Object o) { 707 if (!(o instanceof Severity)) { 708 return false; 709 } 710 711 Severity remote = (Severity) o; 712 713 return status == remote.status; 714 } 715 716 717 public int hashCode() { 718 return 43 ^ status; 719 } 720 721 private static String [] STATUS_NAMES = new String [] { 722 "none", "ok", "warning", "error" }; 724 725 731 public String toString() { 732 return "[Status: " + STATUS_NAMES[getStatus()] + "]"; } 734 735 747 public static Severity getCompoundStatus(Severity first, Severity second) throws IllegalArgumentException { 748 if (first != STATUS_ERROR && first != STATUS_WARNING && first != STATUS_OK) 749 throw new IllegalArgumentException ("Invalid status provided: " + first); 751 if (second != STATUS_ERROR && second != STATUS_WARNING && second != STATUS_OK) 752 throw new IllegalArgumentException ("Invalid status provided: " + second); 754 return VALUES[Math.max(first.getStatus(), second.getStatus())]; 755 } 756 757 762 public static Color getDefaultColor(Severity s) { 763 return DEFAULT_STATUS_COLORS[s.getStatus()]; 764 } 765 766 public static Severity valueOf(String severity) { 767 Severity severityValue = Severity.STATUS_NONE; 768 769 if (severity != null) { 770 if ("ok".equals(severity)) { severityValue = AnnotationType.Severity.STATUS_OK; 772 } else { 773 if ("warning".equals(severity)) { severityValue = AnnotationType.Severity.STATUS_WARNING; 775 } else { 776 if ("error".equals(severity)) { severityValue = AnnotationType.Severity.STATUS_ERROR; 778 } 779 } 780 } 781 } 782 783 return severityValue; 784 } 785 786 public String getName() { 787 return STATUS_NAMES[status]; 788 } 789 } 790 } 791 | Popular Tags |