예제 #1
0
  /** Retrieves the FSTDirectives from the changed document. */
  private LinkedList<FSTDirective> getNewDirectives() {
    Vector<String> lines = new Vector<String>();

    for (int i = 0; i < document.getNumberOfLines(); i++) {
      try {
        lines.add(document.get(document.getLineOffset(i), document.getLineLength(i)));
      } catch (BadLocationException e) {
        LogService.getInstance().log(LogLevel.DEBUG, e.getMessage());
      }
    }

    return composer.buildModelDirectivesForFile(lines);
  }
예제 #2
0
  /** Creates the color annotations from the FSTDirectives. */
  private void createAnnotations() {
    AnnotationModelEvent event = new AnnotationModelEvent(this);

    for (FSTDirective directive : validDirectiveList) {
      if (directive == null) {
        continue;
      }
      try {
        int startline = directive.getStartLine();
        int endline = getLastChildLine(directive, directive.getEndLine());
        final int color = directive.getColor();
        int overViewStartOffset = document.getLineOffset(startline);
        int overViewLength = 0;
        for (int line = startline; line <= endline; line++) {
          int length = document.getLineLength(line);
          if (line < endline || directive.getEndLength() > 0) {
            int lineOffset = document.getLineOffset(line);

            if (line == directive.getEndLine()) {
              length = directive.getEndLength();
            }
            if (line == startline) {
              lineOffset += directive.getStartOffset();
              length -= directive.getStartOffset();
            }

            if (hasChildAtLine(directive, line)) {
              length = 1;
            }

            if (overViewStartOffset != -1 && hasChildAtLineWithColor(directive, line)) {
              Position overViewPos = new Position(overViewStartOffset, overViewLength);
              createOverViewRuler(event, directive, color, overViewPos);
              overViewStartOffset = -1;
              overViewLength = 0;
            } else if (!hasChildAtLineWithColor(directive, line)) {
              if (overViewStartOffset == -1) {
                overViewStartOffset = document.getLineOffset(line);
              }
              overViewLength += document.getLineLength(line);
            }

            FSTDirective parent = directive.getParent();
            while (parent != null) {
              lineOffset++;
              if (length > 1) {
                length--;
              }
              parent = parent.getParent();
            }
            Position newPos = new Position(lineOffset, length);

            if (!hasChildAtLine(directive, line)) {
              // bar at the left of the editor
              ColorAnnotation ca = new ColorAnnotation(color, newPos, ColorAnnotation.TYPE_IMAGE);
              ca.setText(directive.toString());
              annotations.add(ca);
              event.annotationAdded(ca);
            }
            if (!hasChildAtLine(directive, line)) {
              // bar at the right of the editor

            }
            if (highlighting) {
              // background colors
              ColorAnnotation ca =
                  new ColorAnnotation(color, newPos, ColorAnnotation.TYPE_HIGHLIGHT);
              ca.setText(directive.toDependencyString());
              annotations.add(ca);
              event.annotationAdded(ca);
            }
          }
        }
        if (overViewStartOffset != -1) {
          Position overViewPos = new Position(overViewStartOffset, overViewLength);
          createOverViewRuler(event, directive, color, overViewPos);
          overViewStartOffset = -1;
          overViewLength = 0;
        }
      } catch (BadLocationException e) {
        LogService.getInstance().log(LogLevel.DEBUG, e.getMessage());
      }
    }

    fireModelChanged(event);
  }