Example usage for java.awt Graphics2D draw

List of usage examples for java.awt Graphics2D draw

Introduction

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

Prototype

public abstract void draw(Shape s);

Source Link

Document

Strokes the outline of a Shape using the settings of the current Graphics2D context.

Usage

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2 the graphics device./*from  www . j av a 2 s.c  o  m*/
 * @param dataArea the data area.
 * @param ticks the ticks.
 */
@Override
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {

    // draw the range grid lines, if the flag says they're visible...
    if (isRangeGridlinesVisible()) {
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            double v = this.rangeAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.LEFT);
            Line2D line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
            g2.setPaint(getRangeGridlinePaint());
            g2.setStroke(getRangeGridlineStroke());
            g2.draw(line);
        }
    }

}

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2 the graphics device./*from   w  w w.ja va  2s. c o m*/
 * @param dataArea the data area.
 * @param ticks the ticks.
 */
@Override
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {

    // draw the domain grid lines, if the flag says they're visible...
    if (isDomainGridlinesVisible()) {
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            double v = this.domainAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.BOTTOM);
            Line2D line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
            g2.setPaint(getDomainGridlinePaint());
            g2.setStroke(getDomainGridlineStroke());
            g2.draw(line);
        }
    }
}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Handles a 'mouse released' event.  On Windows, we need to check if this 
 * is a popup trigger, but only if we haven't already been tracking a zoom
 * rectangle.//from  w ww.j ava2 s  . com
 *
 * @param e  information about the event.
 */
public void mouseReleased(MouseEvent e) {

    if (this.zoomRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        } else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }

        boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < this.zoomPoint.getX()))
                    || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
                // restoreAutoBounds();
            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                } else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() - this.zoomPoint.getY());
                } else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() - this.zoomPoint.getX());
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() - this.zoomPoint.getY());
                }
                if (activeROI != null) {
                    Rectangle2D rectangleArea = new Rectangle2D.Double(x, y, w, h);
                    g2 = (Graphics2D) getGraphics();
                    g2.setPaint(activeROI.getColor());
                    g2.draw(rectangleArea);
                    activeROI.add(rectangleArea, getRange(rectangleArea));
                    RoiFromChartProcess process = new RoiFromChartProcess();
                    process.addParam("roi", activeROI);
                    process.addParam("raster", (FLyrRasterSE) rasterSE);
                    process.setActions(this);
                    process.start();
                    if (gestorRois != null) {
                        // Cargar la nueva ROI en el destor
                        gestorRois.clearRoiGraphics();
                    }
                }

            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
            updateUI();
        } else {
            // Erase the zoom rectangle
            Graphics2D g2 = (Graphics2D) getGraphics();
            drawRectangle(g2);
            g2.dispose();
            this.zoomPoint = null;
            this.zoomRectangle = null;
        }

    }

    else if (e.isPopupTrigger()) {
        if (this.popup != null) {
            displayPopupMenu(e.getX(), e.getY());
        }
    }
}

From source file:org.pentaho.platform.uifoundation.chart.BubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 * /*  w w  w .  ja  va2s. c  o m*/
 * @param g2
 *          the graphics device.
 * @param state
 *          the renderer state.
 * @param dataArea
 *          the area within which the data is being drawn.
 * @param info
 *          collects information about the drawing.
 * @param plot
 *          the plot (can be used to obtain standard color information etc).
 * @param domainAxis
 *          the domain (horizontal) axis.
 * @param rangeAxis
 *          the range (vertical) axis.
 * @param dataset
 *          the dataset (an {@link XYZDataset} is expected).
 * @param series
 *          the series index (zero-based).
 * @param item
 *          the item index (zero-based).
 * @param crosshairState
 *          crosshair information for the plot (<code>null</code> permitted).
 * @param pass
 *          the pass index.
 */
@Override
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    PlotOrientation orientation = plot.getOrientation();

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

        double circleSize;

        circleSize = maxSize * (z / maxZ);

        circleSize = Math.abs(circleSize);

        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize,
                    circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize,
                    circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }

        // setup for collecting optional entity info...
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

        // add an entity for the item...
        if (entities != null) {
            String tip = null;
            XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);
    }

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2             the graphics device.
 * @param state          the renderer state.
 * @param dataArea       the area within which the data is being drawn.
 * @param info           collects information about the drawing.
 * @param plot           the plot (can be used to obtain standard color information etc).
 * @param domainAxis     the domain (horizontal) axis.
 * @param rangeAxis      the range (vertical) axis.
 * @param dataset        the dataset (an {@link XYZDataset} is expected).
 * @param series         the series index (zero-based).
 * @param item           the item index (zero-based).
 * @param crosshairState crosshair information for the plot (<code>null</code> permitted).
 * @param pass           the pass index.
 *//*  ww  w . j av a  2  s . c  om*/
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    final PlotOrientation orientation = plot.getOrientation();

    // get the data point...
    final double x = dataset.getXValue(series, item);
    final double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        final XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        final double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        final double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

        double circleSize;

        circleSize = maxSize * (z / maxZ);

        circleSize = Math.abs(circleSize);

        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize,
                    circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize,
                    circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }

        // setup for collecting optional entity info...
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

        // add an entity for the item...
        if (entities != null) {
            String tip = null;
            final XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            final XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }

        final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);
    }

}

From source file:longMethod.jfreechart.draw.XYPolygonAnnotation.java

/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.//from  ww w.j a  va  2  s.  c  om
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        int rendererIndex, PlotRenderingInfo info) {

    // if we don't have at least 2 (x, y) coordinates, just return
    if (this.polygon.length < 4) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);

    GeneralPath area = new GeneralPath();
    double x = domainAxis.valueToJava2D(this.polygon[0], dataArea, domainEdge);
    double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        area.moveTo((float) y, (float) x);
        for (int i = 2; i < this.polygon.length; i += 2) {
            x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge);
            y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge);
            area.lineTo((float) y, (float) x);
        }
        area.closePath();
    } else if (orientation == PlotOrientation.VERTICAL) {
        area.moveTo((float) x, (float) y);
        for (int i = 2; i < this.polygon.length; i += 2) {
            x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge);
            y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge);
            area.lineTo((float) x, (float) y);
        }
        area.closePath();
    }

    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(area);
    }

    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(area);
    }
    addEntity(info, area, rendererIndex, getToolTipText(), getURL());

}

From source file:net.sourceforge.processdash.ev.ui.chart.RangeXYItemRenderer.java

private void drawItemRangeGradient(Graphics2D g2, Line2D line, Paint paint, Stroke stroke, double x2, double y2,
        double x3, double y3) {
    Line2D edge1, edge2, mainLine;
    Polygon fillArea;//  w ww .  java  2  s. c o m
    Stroke mainLineStroke, edgeLineStroke;
    Paint mainLinePaint, edgeLinePaint, fillPaint;

    double x0 = line.getX1();
    double y0 = line.getY1();
    double x1 = line.getX2();
    double y1 = line.getY2();

    mainLine = new Line2D.Double(x0, y0, x1, y1);
    edge1 = new Line2D.Double(x0, y0, x2, y2);
    edge2 = new Line2D.Double(x0, y0, x3, y3);
    fillArea = new Polygon();
    fillArea.addPoint((int) Math.round(x0), (int) Math.round(y0));
    fillArea.addPoint((int) Math.round(x2), (int) Math.round(y2));
    fillArea.addPoint((int) Math.round(x3), (int) Math.round(y3));

    mainLinePaint = paint;
    if (mainLinePaint instanceof Color) {
        Color c = (Color) mainLinePaint;
        Color dark = transp(c, calcAlpha(c));
        Color light = transp(c, 0.01);
        edgeLinePaint = fillPaint = c;
        try {
            fillPaint = new GradientPaint(gradientStart(x0, y0, x1, y1, x2, y2, x3, y3), light,
                    new Point2D.Double(x1, y1), dark, true);
        } catch (Exception e) {
        }
    } else {
        edgeLinePaint = fillPaint = mainLinePaint;
    }

    if (stroke instanceof BasicStroke) {
        float lineWidth = ((BasicStroke) stroke).getLineWidth();
        edgeLineStroke = new BasicStroke(lineWidth / 4);
        mainLineStroke = new BasicStroke(lineWidth * 2);
    } else {
        mainLineStroke = edgeLineStroke = stroke;
    }

    g2.setPaint(fillPaint);
    g2.fill(fillArea);
    g2.fill(fillArea);

    g2.setStroke(edgeLineStroke);
    g2.setPaint(edgeLinePaint);
    g2.draw(edge1);
    g2.draw(edge2);

    g2.setStroke(mainLineStroke);
    g2.setPaint(mainLinePaint);
    g2.draw(mainLine);
}

From source file:soap.ui.stats.LineAndShapeRendererMapToBar.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {

    // nothing is drawn for null...
    Number v = dataset.getValue(row, column);
    if (v == null)
        return;/*from w w  w.  jav  a2s . c om*/

    PlotOrientation orientation = plot.getOrientation();

    // current data point which is associated to a serie...
    double x1 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    int seriesCount = mBarRenderer.getPlot().getDataset().getRowCount();
    int categoryCount = mBarRenderer.getPlot().getDataset().getColumnCount();
    if (seriesCount > 1 && mNumSerie < seriesCount) {
        double seriesGap = dataArea.getWidth() * 0.2 / (categoryCount * (seriesCount - 1));
        double seriesW = calculateSeriesWidth(dataArea.getWidth(), domainAxis, categoryCount, seriesCount);
        x1 = x1 + mNumSerie * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0);

    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }

    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    Shape shape = getItemShape(row, column);
    if (orientation == PlotOrientation.HORIZONTAL) {
        shape = createTransformedShape(shape, y1, x1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        shape = createTransformedShape(shape, x1, y1);
    }
    if (isDrawShapes()) {
        if (getItemShapeFilled(row, column)) {
            g2.setPaint(getItemPaint(row, column));
            g2.fill(shape);
        } else {
            g2.setPaint(getItemOutlinePaint(row, column));
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }

    if (isDrawLines()) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0 = domainAxis.getCategoryStart(column - 1, getColumnCount(), dataArea,
                        plot.getDomainAxisEdge());
                //  seriesCount = getRowCount();
                //  categoryCount = getColumnCount();
                if (seriesCount > 1 && mNumSerie < seriesCount) {
                    double seriesGap = dataArea.getWidth() * 0.2 / (categoryCount * (seriesCount - 1));
                    double seriesW = calculateSeriesWidth(dataArea.getWidth(), domainAxis, categoryCount,
                            seriesCount);
                    x0 = x0 + mNumSerie * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                            plot.getDomainAxisEdge());
                }

                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());

                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.draw(line);
            }
        }
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(row, column)) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0));
        } else if (orientation == PlotOrientation.VERTICAL) {
            drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0));
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
        if (entities != null && shape != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            entities.addEntity(entity);
        }
    }
}

From source file:com.quinsoft.zeidon.objectbrowser.EntitySquare.java

@Override
public void paint(Graphics g) {
    Graphics2D graphics2 = (Graphics2D) g;
    EntityDef entityDef = getEntityDef();
    EntityCursor cursor = getView().cursor(entityDef);

    Color borderColor = Color.black;
    BasicStroke stroke = new BasicStroke(1);
    EntitySquare selectedSquare = oiDisplay.getSelectedEntity();
    if (selectedSquare != null) {
        EntityDef selectedEntityDef = selectedSquare.getEntityDef();
        if (selectedEntityDef.getRecursiveChild() == entityDef
                || selectedEntityDef.getRecursiveParent() == entityDef) {
            borderColor = Color.yellow;
            stroke = new BasicStroke(5);
            oiDisplay.setForRepaint(this);
        }/*ww  w.ja va 2  s.  co m*/
    }

    if (selectedSquare == this)
        g.setColor(SELECTED_COLOR);
    else {
        switch (cursor.getStatus()) {
        case NULL:
            g.setColor(NULL_ENTITY);
            break;

        case OUT_OF_SCOPE:
            g.setColor(OUT_OF_SCOPE);
            break;

        case NOT_LOADED:
            g.setColor(NOT_LOADED);
            break;

        default:
            g.setColor(ENTITY_EXISTS);
        }
    }

    // Fill in the shape.
    graphics2.fillRoundRect(0, 0, size.width - 1, size.height - 1, 20, 20);

    // Draw the black outline.
    g.setColor(borderColor);
    RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, size.width - 1, size.height - 1, 20,
            20);
    graphics2.setStroke(stroke);
    graphics2.draw(roundedRectangle);

    // Write the entity name
    g.setColor(Color.black);
    graphics2.setFont(font);
    paintCenteredText(graphics2, env.getPainterScaleFactor(), entityDef.getName(), null);

    switch (cursor.getStatus()) {
    case NULL:
        paintCenteredText(graphics2, size.height / 2, "null", Color.WHITE);
        setToolTipText(cursor);
        break;

    case NOT_LOADED:
        paintCenteredText(graphics2, size.height / 2, "(Not yet loaded)", Color.WHITE);
        setToolTipText(entityDef.getName());
        break;

    case OUT_OF_SCOPE:
        paintCenteredText(graphics2, size.height / 2, "(Out of Scope)", Color.WHITE);
        setToolTipText(entityDef.getName());
        break;

    default:
        String s = getKeyString(cursor, entityDef, env);
        paintCenteredText(graphics2, size.height / 2, s, null);

        s = getSiblingCount(cursor);
        paintCenteredText(graphics2, size.height - env.getPainterScaleFactor(), s, null);
        setToolTipText(cursor);
    }

}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java

protected void drawOutlineBox(final Graphics2D g2, final RenderBox box) {
    final int nodeType = box.getNodeType();
    if (nodeType == LayoutNodeTypes.TYPE_BOX_PARAGRAPH) {
        g2.setPaint(Color.magenta);
    } else if (nodeType == LayoutNodeTypes.TYPE_BOX_LINEBOX) {
        g2.setPaint(Color.orange);
    } else if ((nodeType & LayoutNodeTypes.MASK_BOX_TABLE) == LayoutNodeTypes.MASK_BOX_TABLE) {
        g2.setPaint(Color.cyan);/*from   w  w w . ja v a2 s  .co m*/
    } else {
        g2.setPaint(Color.lightGray);
    }
    final double x = StrictGeomUtility.toExternalValue(box.getX());
    final double y = StrictGeomUtility.toExternalValue(box.getY());
    final double w = StrictGeomUtility.toExternalValue(box.getWidth());
    final double h = StrictGeomUtility.toExternalValue(box.getHeight());
    boxArea.setFrame(x, y, w, h);
    g2.draw(boxArea);
}