@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;
  }
예제 #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;
  }
예제 #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
  /**
   * 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;
  }
 /** {@inheritDoc } */
 @Override
 public Shape getObjectiveShape() throws TransformException {
   if (objectiveShape == null) {
     objectiveShape = GO2Utilities.toJava2D(getObjectiveGeometryJTS());
   }
   return objectiveShape;
 }
예제 #6
0
 public void setSymbolizers(Symbolizer... symbolizers) {
   final CachedSymbolizer[] css = new CachedSymbolizer[symbolizers.length];
   for (int i = 0; i < symbolizers.length; i++) {
     css[i] = GO2Utilities.getCached(symbolizers[i], feature.getType());
   }
   setSymbolizers(css);
 }
예제 #7
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;
    }
  }
  /** {@inheritDoc } */
  @Override
  public float getUnitCoefficient(final Unit<Length> uom) {
    Float f = coeffs.get(uom);
    if (f == null) {
      f = GO2Utilities.calculateScaleCoefficient(this, uom);
      coeffs.put(uom, f);
    }

    return f;
  }
예제 #9
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;
  }
예제 #10
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;
  }
예제 #11
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;
  }
예제 #12
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;
  }
예제 #13
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 void initParameters(
      final AffineTransform2D objToDisp,
      final CanvasMonitor monitor,
      final Shape paintingDisplayShape,
      final Shape paintingObjectiveShape,
      final Shape canvasDisplayShape,
      final Shape canvasObjectiveShape,
      final double dpi) {
    this.canvasObjectiveBBox = canvas.getController().getVisibleEnvelope();
    this.objectiveCRS = canvasObjectiveBBox.getCoordinateReferenceSystem();
    this.objectiveCRS2D = canvas.getObjectiveCRS2D();
    this.displayCRS = canvas.getDisplayCRS();
    this.objectiveToDisplay = objToDisp;
    try {
      this.displayToObjective = (AffineTransform2D) objToDisp.inverse();
    } catch (NoninvertibleTransformException ex) {
      Logging.getLogger(DefaultRenderingContext2D.class).log(Level.WARNING, null, ex);
    }
    this.monitor = monitor;

    this.labelRenderer = null;

    this.coeffs.clear();
    // set the Pixel coeff = 1
    this.coeffs.put(NonSI.PIXEL, 1f);

    // calculate canvas shape/bounds values ---------------------------------
    this.canvasDisplayShape = canvasDisplayShape;
    final Rectangle2D canvasDisplayBounds = canvasDisplayShape.getBounds2D();
    this.canvasDisplaybounds = canvasDisplayBounds.getBounds();
    this.canvasObjectiveShape = canvasObjectiveShape;

    final Rectangle2D canvasObjectiveBounds = canvasObjectiveShape.getBounds2D();

    // calculate the objective bbox with there temporal and elevation parameters ----
    this.canvasObjectiveBBox2D = new Envelope2D(objectiveCRS2D, canvasObjectiveBounds);

    // calculate the resolution -----------------------------------------------
    this.dpi = dpi;
    this.resolution = new double[canvasObjectiveBBox.getDimension()];
    this.resolution[0] = canvasObjectiveBounds.getWidth() / canvasDisplayBounds.getWidth();
    this.resolution[1] = canvasObjectiveBounds.getHeight() / canvasDisplayBounds.getHeight();
    for (int i = 2; i < resolution.length; i++) {
      // other dimension are likely to be the temporal and elevation one.
      // we set a hug resolution to ensure that only one slice of data will be retrived.
      resolution[i] = Double.MAX_VALUE;
    }
    adjustResolutionWithDPI(resolution);

    // calculate painting shape/bounds values -------------------------------
    this.paintingDisplayShape = paintingDisplayShape;
    final Rectangle2D paintingDisplayBounds = paintingDisplayShape.getBounds2D();
    this.paintingDisplaybounds = paintingDisplayBounds.getBounds();
    this.paintingObjectiveShape = paintingObjectiveShape;

    final Rectangle2D paintingObjectiveBounds = paintingObjectiveShape.getBounds2D();
    this.paintingObjectiveBBox2D = new Envelope2D(objectiveCRS2D, paintingObjectiveBounds);
    this.paintingObjectiveBBox = new GeneralEnvelope(canvasObjectiveBBox);
    ((GeneralEnvelope) this.paintingObjectiveBBox)
        .setRange(0, paintingObjectiveBounds.getMinX(), paintingObjectiveBounds.getMaxX());
    ((GeneralEnvelope) this.paintingObjectiveBBox)
        .setRange(1, paintingObjectiveBounds.getMinY(), paintingObjectiveBounds.getMaxY());

    try {
      geoScale = canvas.getController().getGeographicScale();
    } catch (TransformException ex) {
      // could not calculate the geographic scale.
      geoScale = 1;
      LOGGER.log(Level.WARNING, null, ex);
    }

    // set temporal and elevation range--------------------------------------
    final Date[] temporal = canvas.getController().getTemporalRange();
    if (temporal != null) {
      temporalRange[0] = temporal[0];
      temporalRange[1] = temporal[1];
    } else {
      Arrays.fill(temporalRange, null);
    }

    final Double[] elevation = canvas.getController().getElevationRange();
    if (elevation != null) {
      elevationRange[0] = elevation[0];
      elevationRange[1] = elevation[1];
    } else {
      Arrays.fill(elevationRange, null);
    }

    // calculate the symbology encoding scale -------------------------------
    seScale = GO2Utilities.computeSEScale(this);
  }
 public String getLabel(final Object candidate) {
   return GO2Utilities.evaluate(styleElement.getLabel(), candidate, String.class, null);
 }