@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;
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
0
  /**
   * Get the java2D Paint for the given feature.
   *
   * @param candidate : evaluate paint with the given feature
   * @param x : start X position of the fill area
   * @param y : start Y position of the fill area
   * @return Java2D Paint
   */
  public Paint getJ2DPaint(
      final Object candidate,
      final int x,
      final int y,
      final float coeff,
      final RenderingHints hints) {
    evaluate();

    if (cachedPaint == null) {
      // if paint is null it means it is dynamic
      final Expression expColor = styleElement.getColor();

      if (cachedGraphic != null) {
        // we have a graphic inside
        BufferedImage mosaique = cachedGraphic.getImage(candidate, coeff, hints);

        if (mosaique != null) {
          return new TexturePaint(
              mosaique, new Rectangle(x, y, mosaique.getWidth(), mosaique.getHeight()));
        } else {
          return Color.BLACK;
        }
      } else {
        // or it's a normal plain inside
        return GO2Utilities.evaluate(expColor, candidate, Color.class, Color.BLACK);
      }
    }

    return cachedPaint;
  }
Exemplo n.º 4
0
  /** {@inheritDoc} */
  @Override
  public boolean isVisible(final Object candidate) {
    evaluate();

    if (isStaticVisible == VisibilityState.VISIBLE) {
      // visible whatever feature we have
      return true;
    } else if (isStaticVisible == VisibilityState.UNVISIBLE) {
      // unvisible whatever feature we have
      return false;
    } else {
      // dynamic visibility

      // test dynamic composite
      if (cachedComposite == null) {
        final Expression opacity = styleElement.getOpacity();
        Float j2dOpacity = GO2Utilities.evaluate(opacity, candidate, 1f, 0f, 1f);
        if (j2dOpacity <= 0) return false;
      }

      // test dynamic paint
      if (cachedPaint == null) {
        final Expression expColor = styleElement.getColor();

        if (cachedGraphic != null) {
          boolean visible = cachedGraphic.isVisible(candidate);
          if (!visible) return false;
        } else {
          // or it's a normal plain inside
          Color color = GO2Utilities.evaluate(expColor, null, Color.class, Color.BLACK);
          if (color.getAlpha() <= 0) return false;
        }
      }

      // test dynamic width
      if (Float.isNaN(cachedWidth)) {
        final Expression expWidth = styleElement.getWidth();
        Float j2dWidth = GO2Utilities.evaluate(expWidth, candidate, Float.class, 1f);
        if (j2dWidth <= 0) return false;
      }

      return true;
    }
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
0
  public float getStrokeWidth(final Object candidate) {
    float candidateWidth = cachedWidth;
    if (Float.isNaN(candidateWidth)) {
      final Expression expWidth = styleElement.getWidth();
      candidateWidth = GO2Utilities.evaluate(expWidth, candidate, Float.class, 1f);
      if (candidateWidth < 0) {
        candidateWidth = 0f;
      }
    }

    return candidateWidth;
  }
Exemplo n.º 7
0
  /**
   * Get the java2D Composite for the given feature.
   *
   * @param candidate : evaluate paint with the given feature
   * @return Java2D Composite
   */
  public AlphaComposite getJ2DComposite(final Object candidate) {
    evaluate();

    if (cachedComposite == null) {
      // if composite is null it means it is dynamic
      final Expression opacity = styleElement.getOpacity();
      Float j2dOpacity = GO2Utilities.evaluate(opacity, candidate, 1f, 0f, 1f);
      return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, j2dOpacity.floatValue());
    }

    return cachedComposite;
  }
Exemplo n.º 8
0
  /** {@inheritDoc } */
  @Override
  public float getMargin(final Object candidate, final float coeff) {
    evaluate();

    if (Float.isNaN(cachedWidth)) {
      final Expression expWidth = styleElement.getWidth();
      if (candidate == null) {
        // can not evaluate
        return Float.NaN;
      } else {
        return GO2Utilities.evaluate(expWidth, candidate, Float.class, 1f);
      }
    }

    return cachedWidth * coeff;
  }
Exemplo n.º 9
0
  /**
   * Get the java2D Stroke for the given feature.
   *
   * @param candidate : evaluate stroke with the given feature
   * @param coeff : use to adjust stroke size, if in display unit value equals 1
   * @return Java2D Stroke
   */
  public java.awt.Stroke getJ2DStroke(final Object candidate, float coeff) {
    evaluate();

    coeff = Math.abs(coeff);

    java.awt.Stroke j2dStroke = cachedStroke;
    // if stroke is null it means something is dynamic
    if (j2dStroke == null || coeff != 1) {

      float[] candidateDashes = cachedDashes;
      float candidateOffset = cachedDashOffset;
      int candidateCap = cachedCap;
      int candidateJoin = cachedJoin;
      float candidateWidth = cachedWidth;

      if (Float.isNaN(candidateOffset)) {
        final Expression expOffset = styleElement.getDashOffset();
        candidateOffset = GO2Utilities.evaluate(expOffset, candidate, Float.class, 1f);
      }

      if (candidateCap == Integer.MAX_VALUE) {
        final Expression expCap = styleElement.getLineCap();
        final String cap =
            GO2Utilities.evaluate(expCap, 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;
      }

      if (candidateJoin == Integer.MAX_VALUE) {
        final Expression expJoin = styleElement.getLineJoin();
        final String join =
            GO2Utilities.evaluate(expJoin, 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;
      }

      if (Float.isNaN(candidateWidth)) {
        final Expression expWidth = styleElement.getWidth();
        candidateWidth = GO2Utilities.evaluate(expWidth, candidate, Float.class, 1f);
        if (candidateWidth < 0) {
          candidateWidth = 0f;
        }
      }

      if (candidateDashes != null) {
        float[] s = candidateDashes.clone();
        for (int i = 0; i < s.length; i++) {
          s[i] = s[i] * coeff;
        }
        j2dStroke =
            new BasicStroke(
                candidateWidth * coeff, candidateCap, candidateJoin, 1f, s, candidateOffset);
      } else {
        j2dStroke = new BasicStroke(candidateWidth * coeff, candidateCap, candidateJoin, 10f);
      }
    }

    return j2dStroke;
  }
Exemplo n.º 10
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;
  }
 public String getLabel(final Object candidate) {
   return GO2Utilities.evaluate(styleElement.getLabel(), candidate, String.class, null);
 }