Example usage for java.awt Graphics2D fillOval

List of usage examples for java.awt Graphics2D fillOval

Introduction

In this page you can find the example usage for java.awt Graphics2D fillOval.

Prototype

public abstract void fillOval(int x, int y, int width, int height);

Source Link

Document

Fills an oval bounded by the specified rectangle with the current color.

Usage

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

@Override
protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) {
    super.paintLayer(g2, layer);

    if (this.mainTraceInfo.getPoint() == null) {
        return;//  w w w  .j  a v a2  s . com
    }

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(COLOR_BLUE);
    final int BALL_RADIUS = 8;
    g2.fillOval((int) (this.mainTraceInfo.getPoint().getX() - (BALL_RADIUS >> 1) + 0.5),
            (int) (this.mainTraceInfo.getPoint().getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS);

    for (TraceInfo indicatorTraceInfo : this.indicatorTraceInfos) {
        final Point2D point = indicatorTraceInfo.getPoint();
        if (null == point) {
            continue;
        }
        g2.fillOval((int) (point.getX() - (BALL_RADIUS >> 1) + 0.5),
                (int) (point.getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS);
    }

    g2.setColor(oldColor);

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    this.drawInformationBox(g2, layer);
}

From source file:org.n52.oxf.render.sos.ProportionalCircleMapRenderer.java

private Image renderLegend(ObservationSeriesCollection obsValues, String observedProperty) {

    double lowestValue = (Double) obsValues.getMinimum(0);
    double highestValue = (Double) obsValues.getMaximum(0);

    double classDistance = (highestValue - lowestValue) / (NUMBER_OF_CLASSES - 2);
    int dotSizeDistance = (MAX_DOT_SIZE - MIN_DOT_SIZE) / (NUMBER_OF_CLASSES - 2);

    BufferedImage image = new BufferedImage(LEGEND_WIDTH, LEGEND_HEIGHT, BufferedImage.TYPE_INT_RGB);

    Graphics2D g = image.createGraphics();

    // draw white background:
    g.setColor(Color.WHITE);//  w  w  w. j  a v  a2 s  . c om
    g.fillRect(0, 0, LEGEND_WIDTH, LEGEND_HEIGHT);

    // draw information:
    observedProperty = observedProperty.split(":")[observedProperty.split(":").length - 1];
    g.setColor(Color.BLACK);
    g.drawString("Observed Property:   '" + observedProperty + "'", 25, 25);

    for (int i = 1; i <= NUMBER_OF_CLASSES; i++) {
        // draw text:
        int x_stringLocation = 100;
        int y_location = i * 60;
        g.setColor(Color.BLACK);

        DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN);
        df.applyPattern("#,###,##0.00");

        double lowerBorder = lowestValue + classDistance * (i - 1);
        double upperBorder = lowestValue + classDistance * i;

        g.drawString(i + ". class: " + df.format(lowerBorder) + " - " + df.format(upperBorder),
                x_stringLocation, y_location + 10);

        // draw symbol:
        int x_symbolLocation = 30;
        g.setColor(POINT_INNER_COLOR);
        g.fillOval(x_symbolLocation, y_location, i * dotSizeDistance, i * dotSizeDistance);
    }

    return image;
}

From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

/**
 * Render the pie chart with the given height
 * // w w w .  j  ava 2  s.c om
 * @param height
 *          The height of the resulting image
 * @return The pie chart rendered as an image
 */
public BufferedImage render(int height) {
    BufferedImage image = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.scale(zoom, zoom);
    // fill background to white
    g2.setColor(Color.WHITE);
    g2.fill(new Rectangle(totalWidth, totalHeight));
    // prepare render hints
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    // draw shadow image
    g2.drawImage(pieShadow.getImage(), 0, 0, pieShadow.getImageObserver());

    double start = 0;
    List<Arc2D> pies = new ArrayList<>();
    // pie segmente erzeugen und fuellen
    if (total == 0) {
        g2.setColor(BRIGHT_GRAY);
        g2.fillOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
        g2.setColor(Color.WHITE);
        g2.drawOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
    } else {
        for (Segment s : segments) {
            double portionDegrees = s.getPortion() / total;
            Arc2D pie = paintPieSegment(g2, start, portionDegrees, s.getColor());
            if (withSubSegments) {
                double smallRadius = radius * s.getSubSegmentRatio();
                paintPieSegment(g2, start, portionDegrees, smallRadius, s.getColor().darker());
            }
            start += portionDegrees;
            // portion degree jetzt noch als String (z.B. "17.3%" oder "20%" zusammenbauen)
            String p = String.format(Locale.ENGLISH, "%.1f", Math.rint(portionDegrees * 1000) / 10.0);
            p = removeSuffix(p, ".0"); // evtl. ".0" bei z.B. "25.0" abschneiden (-> "25")
            s.setPercent(p + "%");
            pies.add(pie);
        }
        // weissen Rahmen um die pie segmente zeichen
        g2.setColor(Color.WHITE);
        for (Arc2D pie : pies) {
            g2.draw(pie);
        }
    }
    // Legende zeichnen
    renderLegend(g2);
    // "xx%" Label direkt auf die pie segmente zeichen
    g2.setColor(Color.WHITE);
    float fontSize = 32f;
    g2.setFont(NORMALFONT.deriveFont(fontSize).deriveFont(Font.BOLD));
    start = 0;
    for (Segment s : segments) {
        if (s.getPortion() < 1E-6) {
            continue; // ignore segments with portions that are extremely small
        }
        double portionDegrees = s.getPortion() / total;
        double angle = start + portionDegrees / 2; // genau in der Mitte des Segments
        double xOffsetForCenteredTxt = 8 * s.getPercent().length(); // assume roughly 8px per char
        int x = (int) (centerX + 0.6 * radius * Math.sin(2 * Math.PI * angle) - xOffsetForCenteredTxt);
        int y = (int) (centerY - 0.6 * radius * Math.cos(2 * Math.PI * angle) + fontSize / 2);
        g2.drawString(s.getPercent(), x, y);
        start += portionDegrees;
    }
    return image;
}

From source file:org.n52.oxf.render.sos.ProportionalCircleMapRenderer.java

/**
 * renders one frame of the animation.//from w  ww  .  jav a  2 s.  c o  m
 */
private Image renderFrame(ITimePosition[] sortedTimeArray, int currentTimeIndex, int screenW, int screenH,
        IBoundingBox bbox, Set<OXFFeature> selectedFeatures, ObservationSeriesCollection obsValues) {
    ContextBoundingBox contextBBox = new ContextBoundingBox(bbox);

    BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB);

    Graphics2D g = image.createGraphics();

    ITimePosition currentTimePos = sortedTimeArray[currentTimeIndex];

    // draw white background:
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, screenW, screenH);

    // draw time-string into map:
    g.setColor(Color.BLACK);
    g.drawString(currentTimePos.toString(), 20, 20);

    for (OXFFeature dotFeature : selectedFeatures) {

        //
        // draw the points into the image at the georeferenced position of the corresponding feature:
        //
        Point pRealWorld = (Point) dotFeature.getGeometry();

        java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW,
                screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y));

        ObservedValueTuple tuple = obsValues.getTuple(dotFeature, currentTimePos);

        // if there wasn't a tuple for the current time position go backwards through the sortedTimeArray and take the most recent one:
        int j = currentTimeIndex - 1;
        while (tuple == null && j >= 0) {
            tuple = obsValues.getTuple(dotFeature, sortedTimeArray[j]);
            j--;
        }

        // if a tuple was found -> draw the dot:
        if (tuple != null) {
            int dotSize = computeDotSize((Double) tuple.getValue(0), (Double) obsValues.getMinimum(0),
                    (Double) obsValues.getMaximum(0));
            g.setColor(POINT_INNER_COLOR);
            g.fillOval(pScreen.x - (dotSize / 2), pScreen.y - (dotSize / 2), dotSize, dotSize);
        }
        // otherwise draw "no data available"
        else {
            g.setColor(Color.BLACK);

            // draw point of feature:
            g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                    pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                    FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT);

            g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT);
        }
    }

    return image;
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

@Override
protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) {
    super.paintLayer(g2, layer);

    final ChartPanel chartPanel = ((ChartPanel) layer.getView());

    final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();

    this.drawArea.setRect(_plotArea);

    if (false == this.investmentFlowChartJDialog.isFinishLookUpPrice()) {
        this.drawBusyBox(g2, layer);
    }//  w  w  w .  j a v a2 s .  co m

    if (this.investPoint != null) {
        final int RADIUS = 8;
        final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        final Color oldColor = g2.getColor();

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(COLOR_RED);
        g2.fillOval((int) (this.investPoint.getX() - (RADIUS >> 1) + 0.5),
                (int) (this.investPoint.getY() - (RADIUS >> 1) + 0.5), RADIUS, RADIUS);
        g2.setColor(oldColor);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
        this.updateInvestInformationBox(g2);
    }

    if (this.ROIPoint != null) {
        final int RADIUS = 8;
        final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        final Color oldColor = g2.getColor();

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(COLOR_BLUE);
        g2.fillOval((int) (this.ROIPoint.getX() - (RADIUS >> 1) + 0.5),
                (int) (this.ROIPoint.getY() - (RADIUS >> 1) + 0.5), RADIUS, RADIUS);
        g2.setColor(oldColor);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
        this.updateROIInformationBox(g2);
    }

    this.solveConflict();

    if (this.investPoint != null) {
        this.drawInformationBox(g2, this.investmentFlowChartJDialog.getInvestActivities(this.investPointIndex),
                investRect, investParams, investValues,
                GUIBundle.getString("InvestmentFlowLayerUI_Total_Invest"), totalInvestValue,
                COLOR_RED_BACKGROUND, COLOR_RED_BORDER);
    }

    if (this.ROIPoint != null) {
        this.drawInformationBox(g2, this.investmentFlowChartJDialog.getROIActivities(this.ROIPointIndex),
                ROIRect, ROIParams, ROIValues, GUIBundle.getString("InvestmentFlowLayerUI_Total_Return"),
                totalROIValue, COLOR_BLUE_BACKGROUND, COLOR_BLUE_BORDER);
    }

    this.drawTitle(g2);
}

From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java

/**
 * @param observationCollection//from w w w  .j  a v a2  s  .c  o  m
 * @param screenW
 * @param screenH
 * @param bbox
 * @param selectedFeatures
 *        the Features of Interest for which a chart shall be renderered.
 */
public StaticVisualization renderLayer(OXFFeatureCollection observationCollection, ParameterContainer paramCon,
        int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> selectedFeatures) {
    if (selectedFeaturesCache == null) {
        selectedFeaturesCache = selectedFeatures;
    }

    // before starting to render --> run garbageCollection
    Runtime.getRuntime().gc();
    LOGGER.info("Garbage Collection done.");
    // --

    String[] observedProperties;
    // which observedProperty has been used?:
    ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty");
    if (observedPropertyPS.hasMultipleSpecifiedValues()) {
        observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class);
    } else if (observedPropertyPS.hasSingleSpecifiedValue()) {
        observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() };
    } else {
        throw new IllegalArgumentException("no observedProperties found.");
    }

    // find tuples:
    if (obsValues4FOI == null) {
        obsValues4FOI = new ObservationSeriesCollection(observationCollection, selectedFeaturesCache,
                observedProperties, true);
    }

    ContextBoundingBox contextBBox = new ContextBoundingBox(bbox);

    BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();

    // draw white background:
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, screenW, screenH);

    g.setColor(Color.BLACK);

    for (OXFFeature chartFeature : selectedFeaturesCache) {

        //
        // CACHING: create Plot for each "chart feature" and add it to the cache:
        //
        if (!chartCache.containsKey(chartFeature)) {
            Map<ITimePosition, ObservedValueTuple> timeMap = obsValues4FOI.getAllTuples(chartFeature);

            // draw a chart if there are tuples for the chartFeature available:
            if (timeMap != null) {
                XYPlot chart = drawChart4FOI(chartFeature.getID(), timeMap);
                chartCache.put(chartFeature, chart);
            }
        }

        //
        // draw the plots (which are in the cache):
        //
        Point pRealWorld = (Point) chartFeature.getGeometry();

        java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW,
                screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y));
        XYPlot cachedPlot = (XYPlot) chartCache.get(chartFeature);

        // if there is a plot in the cache for the chartFeature -> draw it:
        if (cachedPlot != null) {
            cachedPlot.getRangeAxis().setRange((Double) obsValues4FOI.getMinimum(0),
                    (Double) obsValues4FOI.getMaximum(0));

            cachedPlot.draw(g,
                    new Rectangle2D.Float(pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT, CHART_WIDTH, CHART_HEIGHT),
                    null, null, null);
        } else {
            g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT);
        }

        // draw point of feature:
        g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT);

    }

    return new StaticVisualization(image);
}

From source file:au.org.ala.biocache.web.WMSController.java

@RequestMapping(value = { "/ogc/legendGraphic" }, method = RequestMethod.GET)
public void getLegendGraphic(@RequestParam(value = "ENV", required = false, defaultValue = "") String env,
        @RequestParam(value = "STYLE", required = false, defaultValue = "8b0000;opacity=1;size=5") String style,
        @RequestParam(value = "WIDTH", required = false, defaultValue = "30") Integer width,
        @RequestParam(value = "HEIGHT", required = false, defaultValue = "20") Integer height,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {/*from  w  w  w. j  a v a 2s  . c  o  m*/
        if (StringUtils.trimToNull(env) == null && StringUtils.trimToNull(style) == null) {
            style = "8b0000;opacity=1;size=5";
        }

        WmsEnv wmsEnv = new WmsEnv(env, style);
        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D) img.getGraphics();
        int size = width > height ? height : width;
        Paint fill = new Color(wmsEnv.colour | wmsEnv.alpha << 24);
        g.setPaint(fill);
        g.fillOval(0, 0, size, size);
        OutputStream out = response.getOutputStream();
        logger.debug("WMS - GetLegendGraphic requested : " + request.getQueryString());
        response.setContentType("image/png");
        ImageIO.write(img, "png", out);
        out.close();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:gg.msn.ui.panel.MainPanel.java

@Override
public void paint(Graphics g) {
    super.paint(g);
    try {/*w  ww  . ja v  a2 s.  co m*/
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        //render per utenti Facebook
        if (ChatClientView.protocol.equals(ChatClientView.FACEBOOK_PROTOCOL)) {
            final FacebookUser user = (FacebookUser) value;
            int textY = (getHeight() / 2) + (g2.getFont().getSize() / 2);

            //name string
            g2.setFont(list.getFont());
            g2.drawString(user.name, WHITE_SPACE + IMAGE_LATE + 3, textY);

            //status string
            //                g2.setFont(list.getFont());
            //                g2.drawString(user.status, WHITE_SPACE + IMAGE_LATE + 3, textY);

            //icon
            ImageIcon icon = user.portrait;
            //log.debug("icon [" + icon + "]");
            //ImageIcon scaledIcon = new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_AREA_AVERAGING));
            g2.drawImage(icon.getImage(), WHITE_SPACE, getHeight() / 2 - (IMAGE_LATE / 2), IMAGE_LATE,
                    IMAGE_LATE, null);
            //                 g2.setColor(Color.WHITE);
            //                g2.drawRoundRect(WHITE_SPACE, getHeight() / 2 - (IMAGE_LATE / 2), IMAGE_LATE, IMAGE_LATE, ARC_SIZE, ARC_SIZE);
            //                g2.drawRoundRect(WHITE_SPACE, getHeight() / 2 - ((IMAGE_LATE+1) / 2), IMAGE_LATE+1, IMAGE_LATE+1, ARC_SIZE, ARC_SIZE);
            //                g2.drawRoundRect(WHITE_SPACE, getHeight() / 2 - ((IMAGE_LATE+2) / 2), IMAGE_LATE+2, IMAGE_LATE+2, ARC_SIZE, ARC_SIZE);
            //render per utenti Client
            //                log.debug("user status [" + user.status + "]");
            //                log.debug("user online status [" + user.onlineStatus + "]");
            if (StringUtils.equals(user.status, FacebookUser.STATUS_ONLINE)) {
                g2.setColor(Color.GREEN);
                g2.fillOval(getWidth() - STATUS_ICON_OFFSET, (getHeight() / 2) - (STATUS_ICON_WIDTH / 2),
                        STATUS_ICON_WIDTH, STATUS_ICON_WIDTH);
            } else {
                g2.setColor(Color.GRAY);
                g2.fillOval(getWidth() - STATUS_ICON_OFFSET, (getHeight() / 2) - (STATUS_ICON_WIDTH / 2),
                        STATUS_ICON_WIDTH, STATUS_ICON_WIDTH);
            }

        } else {
            g2.setFont(list.getFont());
            int textY = (getHeight() / 2) + (g2.getFont().getSize() / 2);

            Client client = (Client) value;
            //                setText((client).getNick());
            ImageIcon icon = null;
            try {
                new ImageIcon(client.getImage());
            } catch (Exception e) {
                //                    log.debug("immgine non presente");
                icon = ThemeManager.getTheme().get(ThemeManager.USER_ICON);
            }
            g2.drawString(client.getNick(), WHITE_SPACE + IMAGE_LATE + 3, textY);
            //log.debug("icon [" + icon + "]");
            //ImageIcon scaledIcon = new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_AREA_AVERAGING));
            g2.drawImage(icon.getImage(), WHITE_SPACE, getHeight() / 2 - (IMAGE_LATE / 2), IMAGE_LATE,
                    IMAGE_LATE, null);

            //                setFont(list.getFont());
            //                setIcon(scaledIcon);
        }
    } catch (Exception e) {
        log.warn(e);
    }

}

From source file:it.unibo.alchemist.boundary.gui.effects.DrawShape.java

@SuppressFBWarnings("ES_COMPARING_STRINGS_WITH_EQ")
@Override//from   w w w . j a  v a2 s .  c o m
public void apply(final Graphics2D g, final Node<?> n, final int x, final int y) {
    if (molString != molStringCached // NOPMD: pointer comparison is wanted here
            || incarnation == null || curIncarnation != prevIncarnation) { // NOPMD: pointer comparison is wanted here
        molStringCached = molString;
        prevIncarnation = curIncarnation;
        incarnation = SupportedIncarnations.get(curIncarnation.getCurrent()).get();
        /*
         * Process in a separate thread: if it fails, does not kill EDT.
         */
        final Thread th = new Thread(() -> molecule = incarnation.createMolecule(molString));
        th.start();
        try {
            th.join();
        } catch (final InterruptedException e) {
            L.error("Bug.", e);
        }
    }
    if (!molFilter || (molecule != null && n.contains(molecule))) {
        final double ks = (scaleFactor.getVal() - MIN_SCALE) * 2 / (double) (SCALE_DIFF);
        final int sizex = size.getVal();
        final int startx = x - sizex / 2;
        final int sizey = (int) Math.ceil(sizex * ks);
        final int starty = y - sizey / 2;
        final Color toRestore = g.getColor();
        colorCache = new Color(red.getVal(), green.getVal(), blue.getVal(), alpha.getVal());
        Color newcolor = colorCache;
        if (molPropertyFilter && molecule != null) {
            final int minV = (int) (minprop.getVal() * FastMath.pow(PROPERTY_SCALE, propoom.getVal()));
            final int maxV = (int) (maxprop.getVal() * FastMath.pow(PROPERTY_SCALE, propoom.getVal()));
            if (minV < maxV) {
                @SuppressWarnings({ "rawtypes", "unchecked" })
                double propval = incarnation.getProperty((Node) n, molecule, property);
                if (isWritingPropertyValue()) {
                    g.setColor(colorCache);
                    g.drawString(Double.toString(propval), startx + sizex, starty + sizey);
                }
                propval = Math.min(Math.max(propval, minV), maxV);
                propval = (propval - minV) / (maxV - minV);
                if (reverse) {
                    propval = 1f - propval;
                }
                newcolor = c.alter(newcolor, (float) propval);
            }
        }
        g.setColor(newcolor);
        switch (mode) {
        case FillEllipse:
            g.fillOval(startx, starty, sizex, sizey);
            break;
        case DrawEllipse:
            g.drawOval(startx, starty, sizex, sizey);
            break;
        case DrawRectangle:
            g.drawRect(startx, starty, sizex, sizey);
            break;
        case FillRectangle:
            g.fillRect(startx, starty, sizex, sizey);
            break;
        default:
            g.fillOval(startx, starty, sizex, sizey);
        }
        g.setColor(toRestore);
    }
}

From source file:org.n52.oxf.render.sos.AnimatedMapBarChartRenderer.java

protected Image renderFrame(ITimePosition[] sortedTimeArray, int currentTimeIndex, int screenW, int screenH,
        IBoundingBox bbox, Set<OXFFeature> featuresWithCharts, ObservationSeriesCollection tupleFinder) {
    ContextBoundingBox contextBBox = new ContextBoundingBox(bbox);

    BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB);

    Graphics2D g = image.createGraphics();

    // draw white background:
    g.setColor(Color.WHITE);/*w ww  . jav  a 2s  .c  o  m*/
    g.fillRect(0, 0, screenW, screenH);

    g.setColor(Color.BLACK);

    ITimePosition currentTimePos = sortedTimeArray[currentTimeIndex];

    for (OXFFeature chartFeature : featuresWithCharts) {

        //
        // create Plot for each "chart feature" and add it to the cache:
        //
        if (!chartCache.contains(currentTimePos, chartFeature)) {

            // if there is a data tuple for the current time position -> create a new plot
            if (tupleFinder.getTuple(chartFeature, currentTimePos) != null) {
                CategoryPlot plot = drawChart4FOI(chartFeature.getID(), currentTimePos.toString(),
                        tupleFinder.getTuple(chartFeature, currentTimePos));
                chartCache.add(currentTimePos, chartFeature, plot);
            }
        }

        CategoryPlot plot = (CategoryPlot) chartCache.get(currentTimePos, chartFeature);

        // if there wasn't a plot for the current time position go backwards through the sortedTimeArray and take the most recent one:
        int j = currentTimeIndex - 1;
        while (plot == null && j >= 0) {
            plot = (CategoryPlot) chartCache.get(sortedTimeArray[j], chartFeature);
            j--;
        }

        //
        // draw the plots into the image at the georeferenced position of the corresponding chartFeature:
        //
        Point pRealWorld = (Point) chartFeature.getGeometry();

        java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW,
                screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y));
        // if an appropriate plot was found -> draw it
        if (plot != null) {
            for (int i = 0; i < observedProperties.length; i++) {
                plot.getRangeAxis(i).setRange((Double) tupleFinder.getMinimum(i) - 5,
                        (Double) tupleFinder.getMaximum(i));
                if (i > 0) {
                    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
                }
            }

            plot.draw(g,
                    new Rectangle2D.Float(pScreen.x + X_SHIFT + 10, pScreen.y + Y_SHIFT,
                            CHART_WIDTH + observedProperties.length * CHART_WIDTH_MULTIPLICATOR, CHART_HEIGHT),
                    null, null, null);
        }
        // otherwise draw "no data available"
        else {
            g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT);
        }

        // draw point of feature:
        g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT);
    }

    return image;
}