Пример #1
1
 /**
  * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles
  * Enumeration of StyleRanges, need to be in order. (output) LineStyleEvent.background line
  * background color (output)
  */
 public void lineGetStyle(LineStyleEvent event) {
   Vector styles = new Vector();
   int token;
   StyleRange lastStyle;
   // If the line is part of a block comment, create one style for the entire line.
   if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) {
     styles.addElement(
         new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null));
     event.styles = new StyleRange[styles.size()];
     styles.copyInto(event.styles);
     return;
   }
   Color defaultFgColor = ((Control) event.widget).getForeground();
   scanner.setRange(event.lineText);
   token = scanner.nextToken();
   while (token != EOF) {
     if (token == OTHER) {
       // do nothing for non-colored tokens
     } else if (token != WHITE) {
       Color color = getColor(token);
       // Only create a style if the token color is different than the
       // widget's default foreground color and the token's style is not
       // bold.  Keywords are bolded.
       if ((!color.equals(defaultFgColor)) || (token == KEY)) {
         StyleRange style =
             new StyleRange(
                 scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null);
         if (token == KEY) {
           style.fontStyle = SWT.BOLD;
         }
         if (styles.isEmpty()) {
           styles.addElement(style);
         } else {
           // Merge similar styles.  Doing so will improve performance.
           lastStyle = (StyleRange) styles.lastElement();
           if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) {
             lastStyle.length += style.length;
           } else {
             styles.addElement(style);
           }
         }
       }
     } else if ((!styles.isEmpty())
         && ((lastStyle = (StyleRange) styles.lastElement()).fontStyle == SWT.BOLD)) {
       int start = scanner.getStartOffset() + event.lineOffset;
       lastStyle = (StyleRange) styles.lastElement();
       // A font style of SWT.BOLD implies that the last style
       // represents a java keyword.
       if (lastStyle.start + lastStyle.length == start) {
         // Have the white space take on the style before it to
         // minimize the number of style ranges created and the
         // number of font style changes during rendering.
         lastStyle.length += scanner.getLength();
       }
     }
     token = scanner.nextToken();
   }
   event.styles = new StyleRange[styles.size()];
   styles.copyInto(event.styles);
 }
Пример #2
0
  public boolean equals(final ColorScale cs) {
    if (min == null && cs.min != null || min != null && cs.min == null) {
      return false;
    }
    if ((min != null && cs.min != null) && Double.compare(min, cs.min) != 0) {
      return false;
    }
    if (max == null && cs.max != null || max != null && cs.max == null) {
      return false;
    }
    if ((max != null && cs.max != null) && Double.compare(max, cs.max) != 0) {
      return false;
    }
    if (!scaling.equals(cs.scaling)) {
      return false;
    }
    if (interpolate != cs.interpolate) {
      return false;
    }
    if (forceValuesIntoRange != cs.forceValuesIntoRange) {
      return false;
    }
    if (reliefShading != cs.reliefShading) {
      return false;
    }
    if (nullColor.length != cs.nullColor.length) {
      return false;
    }
    for (int i = 0; i < nullColor.length; i++) {
      if (nullColor[i] != cs.nullColor[i]) {
        return false;
      }
    }
    if (size() != cs.size()) {
      return false;
    }
    final Iterator<Double> iterator1 = cs.keySet().iterator();
    for (final Double d1 : this.keySet()) {
      final Double d2 = iterator1.next();
      if (d1.compareTo(d2) != 0) {
        return false;
      }

      final Color value1 = get(d1);
      final Color value2 = get(d2);
      if (!value1.equals(value2)) {
        return false;
      }
    }
    return true;
  }