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; }
/** * 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 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; } }