예제 #1
0
  private boolean evaluateComposite() {
    final Expression opacity = styleElement.getOpacity();

    if (GO2Utilities.isStatic(opacity)) {
      float j2dOpacity = GO2Utilities.evaluate(opacity, null, 1f, 0f, 1f);

      // we return false, opacity is 0 no need to cache or draw anything
      if (j2dOpacity == 0) {
        isStaticVisible = VisibilityState.UNVISIBLE;
        return false;
      }

      // this style is visible
      if (isStaticVisible == VisibilityState.NOT_DEFINED) isStaticVisible = VisibilityState.VISIBLE;

      // we cache the composite
      cachedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, j2dOpacity);
    } else {
      // this style visibility is dynamic
      if (isStaticVisible != VisibilityState.UNVISIBLE) isStaticVisible = VisibilityState.DYNAMIC;
      isStatic = false;
      GO2Utilities.getRequieredAttributsName(opacity, requieredAttributs);
    }

    return true;
  }
  @Override
  protected void evaluate() {
    if (!isNotEvaluated) return;

    final Expression expLabel = styleElement.getLabel();

    // we can not know so always visible
    isStaticVisible = VisibilityState.VISIBLE;

    if (GO2Utilities.isStatic(expLabel)) {
      label = GO2Utilities.evaluate(expLabel, null, String.class, "No Label");
    } else {
      GO2Utilities.getRequieredAttributsName(expLabel, requieredAttributs);
      isStatic = false;
    }

    cachedFont.getRequieredAttributsName(requieredAttributs);
    cachedFill.getRequieredAttributsName(requieredAttributs);
    cachedHalo.getRequieredAttributsName(requieredAttributs);
    cachedPlacement.getRequieredAttributsName(requieredAttributs);

    // no attributs needed replace with static empty list.
    if (requieredAttributs.isEmpty()) {
      requieredAttributs = EMPTY_ATTRIBUTS;
    }

    isNotEvaluated = false;
  }
예제 #3
0
  private boolean evaluatePaint() {

    final GraphicFill graphicFill = styleElement.getGraphicFill();

    if (graphicFill != null) {
      cachedGraphic = CachedGraphic.cache(graphicFill);

      if (cachedGraphic.isStaticVisible() == VisibilityState.UNVISIBLE) {
        // graphic is not visible even if some value are dynamic
        // this fill is not visible neither
        isStaticVisible = VisibilityState.UNVISIBLE;
        return false;
      } else if (cachedGraphic.isStaticVisible() == VisibilityState.DYNAMIC) {
        // graphic visibility is dynamic, so this fill too
        if (isStaticVisible != VisibilityState.UNVISIBLE) isStaticVisible = VisibilityState.DYNAMIC;
      } else {
        // this graphic is visible
        if (isStaticVisible == VisibilityState.NOT_DEFINED)
          isStaticVisible = VisibilityState.VISIBLE;
      }

      cachedGraphic.getRequieredAttributsName(requieredAttributs);

    } else {
      final Expression expColor = styleElement.getColor();

      if (GO2Utilities.isStatic(expColor)) {
        Color j2dColor = GO2Utilities.evaluate(expColor, null, Color.class, Color.BLACK);

        // we return false, opacity is 0 no need to cache or draw anything
        if (j2dColor.getAlpha() == 0) {
          isStaticVisible = VisibilityState.UNVISIBLE;
          return false;
        }

        // this style is visible even if something else is dynamic
        // evaluatePaint may change this value
        if (isStaticVisible == VisibilityState.NOT_DEFINED)
          isStaticVisible = VisibilityState.VISIBLE;

        // we cache the paint
        cachedPaint = j2dColor;
      } else {
        // this style visibility is dynamic
        if (isStaticVisible != VisibilityState.UNVISIBLE) isStaticVisible = VisibilityState.DYNAMIC;
        isStatic = false;
        GO2Utilities.getRequieredAttributsName(expColor, requieredAttributs);
      }
    }

    // TODO missing Graphic Stroke

    return true;
  }
예제 #4
0
  private boolean evaluateStroke() {
    final float[] dashArray = styleElement.getDashArray();
    final Expression expOffset = styleElement.getDashOffset();
    final Expression expLineCap = styleElement.getLineCap();
    final Expression expLineJoin = styleElement.getLineJoin();
    final Expression expWidth = styleElement.getWidth();
    boolean strokeStatic = true;

    float[] candidateDashes = null;
    float candidateOffset = Float.NaN;
    int candidateCap = -1;
    int candidateJoin = -1;
    float candidateWidth = Float.NaN;

    candidateDashes = GO2Utilities.validDashes(dashArray);

    // offset ----------------------------------------------
    if (GO2Utilities.isStatic(expOffset)) {
      candidateOffset = GO2Utilities.evaluate(expOffset, null, Float.class, 1f);
    } else {
      strokeStatic = false;
      GO2Utilities.getRequieredAttributsName(expOffset, requieredAttributs);
    }

    // line width ------------------------------------------
    if (GO2Utilities.isStatic(expWidth)) {
      candidateWidth = GO2Utilities.evaluate(expWidth, null, Float.class, 1f);

      // we return false, width is 0 no need to cache or draw anything
      if (candidateWidth == 0) {
        isStaticVisible = VisibilityState.UNVISIBLE;
        return false;
      }

      // this style is visible
      if (isStaticVisible == VisibilityState.NOT_DEFINED) isStaticVisible = VisibilityState.VISIBLE;

    } else {
      // this style visibility is dynamic
      if (isStaticVisible != VisibilityState.UNVISIBLE) isStaticVisible = VisibilityState.DYNAMIC;
      strokeStatic = false;
      GO2Utilities.getRequieredAttributsName(expWidth, requieredAttributs);
    }

    // line cap and join---------------------------------------------
    if (cachedWidth <= 2.5f) {
      // line cap and join are invisible under this size
      candidateCap = BasicStroke.CAP_SQUARE;
      candidateJoin = BasicStroke.JOIN_MITER;
    } else {
      if (GO2Utilities.isStatic(expLineCap)) {
        final String cap =
            GO2Utilities.evaluate(expLineCap, null, String.class, STROKE_CAP_BUTT_STRING);
        if (STROKE_CAP_BUTT_STRING.equalsIgnoreCase(cap)) candidateCap = BasicStroke.CAP_BUTT;
        else if (STROKE_CAP_SQUARE_STRING.equalsIgnoreCase(cap))
          candidateCap = BasicStroke.CAP_SQUARE;
        else if (STROKE_CAP_ROUND_STRING.equalsIgnoreCase(cap))
          candidateCap = BasicStroke.CAP_ROUND;
        else candidateCap = BasicStroke.CAP_BUTT;
      } else {
        strokeStatic = false;
        GO2Utilities.getRequieredAttributsName(expLineCap, requieredAttributs);
      }

      if (GO2Utilities.isStatic(expLineJoin)) {
        final String join =
            GO2Utilities.evaluate(expLineJoin, null, String.class, STROKE_JOIN_BEVEL_STRING);
        if (STROKE_JOIN_BEVEL_STRING.equalsIgnoreCase(join)) candidateJoin = BasicStroke.JOIN_BEVEL;
        else if (STROKE_JOIN_MITRE_STRING.equalsIgnoreCase(join))
          candidateJoin = BasicStroke.JOIN_MITER;
        else if (STROKE_JOIN_ROUND_STRING.equalsIgnoreCase(join))
          candidateJoin = BasicStroke.JOIN_ROUND;
        else candidateJoin = BasicStroke.JOIN_BEVEL;
      } else {
        strokeStatic = false;
        GO2Utilities.getRequieredAttributsName(expLineJoin, requieredAttributs);
      }
    }

    // we cache each possible expression ------------------------------
    this.cachedDashes = candidateDashes;
    if (!Float.isNaN(candidateOffset))
      cachedDashOffset = (candidateOffset > 0) ? candidateOffset : 0;
    if (candidateCap != -1) cachedCap = candidateCap;
    if (candidateJoin != -1) cachedJoin = candidateJoin;
    if (!Float.isNaN(candidateWidth)) {
      cachedWidth = candidateWidth;
      if (cachedWidth < 0) cachedWidth = 0f;
    }

    // if static we can can cache the stroke directly----------------------
    if (strokeStatic) {
      // we can never cache the java2d stroke seens it's size depend on the symbolizer unit of
      // mesure
      if (cachedDashes != null) {
        cachedStroke =
            new BasicStroke(
                candidateWidth, candidateCap, candidateJoin, 10f, cachedDashes, cachedDashOffset);
      } else {
        cachedStroke = new BasicStroke(candidateWidth, candidateCap, candidateJoin, 10f);
      }
    } else {
      this.isStatic = false;
    }

    return true;
  }