コード例 #1
0
  /**
   * Builds the FSTModel of the feature project and creates a list of all directives with valid
   * colors
   *
   * @return the directive list
   */
  private void createDirectiveList() {
    directiveMap.clear();
    validDirectiveList.clear();
    FSTModel model = project.getFSTModel();
    if (model == null) {
      composer.buildFSTModel();
      model = project.getFSTModel();
    }
    if (model == null) {
      return;
    }

    int index = 0;
    for (FSTFeature fstFeature : model.getFeatures()) {
      for (FSTRole role : fstFeature.getRoles()) {
        if (file.equals(role.getFile())) {
          for (FSTDirective dir : role.getDirectives()) {
            directiveMap.put(dir.getId(), dir);
            index++;
          }
        }
      }
    }

    for (int i = 0; i < index; i++) {
      FSTDirective dir = directiveMap.get(i);
      if (dir != null && ColorList.isValidColor(dir.getColor())) {
        validDirectiveList.add(dir);
      }
    }
  }
コード例 #2
0
  /** Creates the color annotations from the FSTDirectives. */
  private void createAnnotations() {
    AnnotationModelEvent event = new AnnotationModelEvent(this);

    Iterator<FSTDirective> it = validDirectiveList.descendingIterator();
    while (it.hasNext()) {
      FSTDirective dir = it.next();
      try {
        int startline = dir.getStartLine();
        int endline = dir.getEndLine();
        for (int i = startline; i <= endline; i++) {
          if (i < endline || dir.getEndLength() > 0) {
            int lineLength = document.getLineLength(i);
            int lineOffset = document.getLineOffset(i);

            if (i == endline) {
              lineLength = dir.getEndLength();
            }
            if (i == startline) {
              lineOffset += dir.getStartOffset();
              lineLength -= dir.getStartOffset();
            }

            Position newPos = new Position(lineOffset, lineLength);

            if (!annotatedPositions.containsKey(i)) {
              if (!ColorList.isValidColor(dir.getColor())) break;
              ColorAnnotation ca =
                  new ColorAnnotation(
                      dir.getColor(),
                      new Position(lineOffset, lineLength),
                      ColorAnnotation.TYPE_IMAGE);
              annotations.add(ca);
              event.annotationAdded(ca);

              if (highlighting) {
                ca =
                    new ColorAnnotation(
                        dir.getColor(),
                        newPos,
                        i == startline
                            ? ColorAnnotation.TYPE_HIGHLIGHT_OVERVIEW
                            : ColorAnnotation.TYPE_HIGHLIGHT);
                annotations.add(ca);
                event.annotationAdded(ca);
              } else if (i == startline) {
                ca = new ColorAnnotation(dir.getColor(), newPos, ColorAnnotation.TYPE_OVERVIEW);
                annotations.add(ca);
                event.annotationAdded(ca);
              }

              annotatedPositions.put(i, newPos);
            } else if (highlighting) {
              Position oldPos = annotatedPositions.get(i);
              int oldOffset = oldPos.getOffset();
              int oldLength = oldPos.getLength();
              int wholeOffset = oldOffset;
              int wholeLength = oldLength;

              if (oldOffset > lineOffset) {
                ColorAnnotation ca =
                    new ColorAnnotation(
                        dir.getColor(),
                        new Position(lineOffset, oldOffset - lineOffset),
                        ColorAnnotation.TYPE_HIGHLIGHT);
                annotations.add(ca);
                event.annotationAdded(ca);
                wholeOffset = lineOffset;
                wholeLength += oldOffset - lineOffset;
              }
              int newOffset = oldOffset + oldLength;
              int newLength = lineLength - (newOffset - lineOffset);
              if (newLength > 0) {
                newPos.setOffset(newOffset);
                newPos.setLength(newLength);

                ColorAnnotation ca =
                    new ColorAnnotation(dir.getColor(), newPos, ColorAnnotation.TYPE_HIGHLIGHT);
                annotations.add(ca);
                event.annotationAdded(ca);

                wholeLength += newLength;
              }
              annotatedPositions.put(i, new Position(wholeOffset, wholeLength));
            }
          }
        }
      } catch (BadLocationException e) {
        UIPlugin.getDefault().logError(e);
      }
    }

    fireModelChanged(event);
  }