Example usage for java.awt Graphics2D setPaint

List of usage examples for java.awt Graphics2D setPaint

Introduction

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

Prototype

public abstract void setPaint(Paint paint);

Source Link

Document

Sets the Paint attribute for the Graphics2D context.

Usage

From source file:com.android.ddmuilib.log.event.OccurrenceRenderer.java

@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {
    TimeSeriesCollection timeDataSet = (TimeSeriesCollection) dataset;

    // get the x value for the series/item.
    double x = timeDataSet.getX(series, item).doubleValue();

    // get the min/max of the range axis
    double yMin = rangeAxis.getLowerBound();
    double yMax = rangeAxis.getUpperBound();

    RectangleEdge domainEdge = plot.getDomainAxisEdge();
    RectangleEdge rangeEdge = plot.getRangeAxisEdge();

    // convert the coordinates to java2d.
    double x2D = domainAxis.valueToJava2D(x, dataArea, domainEdge);
    double yMin2D = rangeAxis.valueToJava2D(yMin, dataArea, rangeEdge);
    double yMax2D = rangeAxis.valueToJava2D(yMax, dataArea, rangeEdge);

    // get the paint information for the series/item
    Paint p = getItemPaint(series, item);
    Stroke s = getItemStroke(series, item);

    Line2D line = null;/*from  w  w w . j  a  v a 2 s  .co m*/
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yMin2D, x2D, yMax2D, x2D);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(x2D, yMin2D, x2D, yMax2D);
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);
}

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);/*  w  w w.  java 2 s  .  com*/
    } 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);
}

From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java

public void drawPlot(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info) {
    Object originalAntialiasHint = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);

    if (plotAntialias) {
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    } else {/*from   w w w  .  j a v a  2 s . c o m*/
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }

    Composite originalComposite = g2.getComposite();
    if (alpha == true) {
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    }

    /* if automatic bounds... */
    if (!isNoData()) {
        if (this instanceof DmcRenderablePlot) {
            DmcPlotRenderer renderer;
            renderer = ((DmcRenderablePlot) this).getPlotRenderer();
            if (renderer != null) {
                renderer.initialize();
            }
        }
    }

    g2.setStroke(stroke);
    g2.setPaint(paint);
    render(g2, dataArea, info); /** This is where the computations method is called.*/
    g2.setComposite(originalComposite);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, originalAntialiasHint);
}

From source file:edu.cuny.jfree.chart.renderer.category.ValueListShapeRenderer.java

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

    final ListCategoryDataset setData = (ListCategoryDataset) dataset;

    final List list = setData.getList(row, column);
    if (list == null) {
        return;//from  w  w  w  .j a v a2  s  .  co m
    }

    final PlotOrientation orientation = plot.getOrientation();
    final double x = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    final Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        final Number value = (Number) iterator.next();
        final double y = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, column);

        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y, x);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x, y);
        }
        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                g2.setPaint(getItemPaint(row, column));
                g2.fill(shape);
            } else {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.draw(shape);
            }
        }
        g2.setPaint(getItemPaint(row, column));

        if (isItemLabelVisible(row, column)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, y, x, value.doubleValue() < 0.0D);
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, x, y, value.doubleValue() < 0.0D);
            }
        }

        if (state.getInfo() != null) {
            final EntityCollection entities = state.getEntityCollection();
            if ((entities != null) && (shape != null)) {
                String tip = null;
                final 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);
                }
                final CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset,
                        dataset.getRowKey(row), dataset.getColumnKey(column));
                entities.add(entity);
            }
        }
    }
}

From source file:org.proteosuite.FastScatterPlot.java

/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.//www .  ja va2  s . c  o m
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) {

    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible()) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            Iterator<ValueTick> 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(gridPaint);
                g2.setStroke(gridStroke);
                g2.draw(line);
            }
        }
    }

}

From source file:org.jfree.experimental.chart.renderer.xy.VectorRenderer.java

/**
 * Draws the block representing the specified item.
 * /*  www . ja va 2s .c om*/
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double dx = 0.0;
    double dy = 0.0;
    if (dataset instanceof VectorXYDataset) {
        dx = ((VectorXYDataset) dataset).getDeltaXValue(series, item);
        dy = ((VectorXYDataset) dataset).getDeltaYValue(series, item);
    }
    double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge());
    Line2D line;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        line = new Line2D.Double(yy0, xx0, yy1, xx1);
    } else {
        line = new Line2D.Double(xx0, yy0, xx1, yy1);
    }
    g2.setPaint(getItemPaint(series, item));
    g2.setStroke(getItemStroke(series, item));
    g2.draw(line);

    // calculate the arrow head and draw it...
    double dxx = (xx1 - xx0);
    double dyy = (yy1 - yy0);
    double bx = xx0 + (1.0 - this.baseLength) * dxx;
    double by = yy0 + (1.0 - this.baseLength) * dyy;

    double cx = xx0 + (1.0 - this.headLength) * dxx;
    double cy = yy0 + (1.0 - this.headLength) * dyy;

    double angle = 0.0;
    if (dxx != 0.0) {
        angle = Math.PI / 2.0 - Math.atan(dyy / dxx);
    }
    double deltaX = 2.0 * Math.cos(angle);
    double deltaY = 2.0 * Math.sin(angle);

    double leftx = cx + deltaX;
    double lefty = cy - deltaY;
    double rightx = cx - deltaX;
    double righty = cy + deltaY;

    GeneralPath p = new GeneralPath();
    p.moveTo((float) xx1, (float) yy1);
    p.lineTo((float) rightx, (float) righty);
    p.lineTo((float) bx, (float) by);
    p.lineTo((float) leftx, (float) lefty);
    p.closePath();
    g2.draw(p);

}

From source file:org.proteosuite.FastScatterPlot.java

/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device./*  w  ww.ja v a 2s .  co  m*/
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) {

    // draw the domain grid lines, if any...
    if (isDomainGridlinesVisible()) {
        Stroke gridStroke = getDomainGridlineStroke();
        Paint gridPaint = getDomainGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            Iterator<ValueTick> 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(gridPaint);
                g2.setStroke(gridStroke);
                g2.draw(line);
            }
        }
    }
}

From source file:com.rapidminer.gui.plotter.charts.ColorizedShapeItemRenderer.java

/**
 * Draws the block representing the specified item.
 * /*from   w  w  w  . ja v a2 s  . com*/
 * @param g2
 *            the graphics device.
 * @param state
 *            the state.
 * @param dataArea
 *            the data area.
 * @param info
 *            the plot rendering info.
 * @param plot
 *            the plot.
 * @param domainAxis
 *            the x-axis.
 * @param rangeAxis
 *            the y-axis.
 * @param dataset
 *            the dataset.
 * @param series
 *            the series index.
 * @param item
 *            the item index.
 * @param crosshairState
 *            the crosshair state.
 * @param pass
 *            the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    Shape hotspot = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double colorValue = ((XYZDataset) dataset).getZValue(series, item);
    double normalized = (colorValue - minColor) / (maxColor - minColor);

    if (Double.isNaN(x) || Double.isNaN(y)) {
        // can't draw anything
        return;
    }

    double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
    double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());

    PlotOrientation orientation = plot.getOrientation();

    Shape shape = getItemShape(series, item);
    if (orientation == PlotOrientation.HORIZONTAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, transY, transX);
    } else if (orientation == PlotOrientation.VERTICAL) {
        shape = ShapeUtilities.createTranslatedShape(shape, transX, transY);
    }
    hotspot = shape;
    if (shape.intersects(dataArea)) {
        g2.setPaint(colorProvider.getPointColor(normalized));
        g2.fill(shape);
        if (getDrawOutlines()) {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(series, item));
            } else {
                g2.setPaint(getItemPaint(series, item));
            }
            g2.setStroke(getItemOutlineStroke(series, item));
            g2.draw(shape);
        }
    }

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, hotspot, dataset, series, item, transX, transY);
    }
}

From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java

/**
 * All parameters are domain coordinates that have to be translated to
 * Java2D points./*from w  ww .j  a v a  2s  .co m*/
 */
private void drawFeedbackEdge(final double x0, final double y0, final double x1, final double y1,
        final XYItemRendererState state, final Graphics2D g2, final XYPlot plot, final ValueAxis domainAxis,
        final ValueAxis rangeAxis, final Rectangle2D dataArea) {
    if (Double.isNaN(y0) || Double.isNaN(x0) || Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

    final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    // only draw if we have good values
    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
        return;
    }

    final PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        state.workingLine.setLine(transY0, transX0, transY1, transX1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        state.workingLine.setLine(transX0, transY0, transX1, transY1);
    }

    if (state.workingLine.intersects(dataArea)) {
        g2.setStroke(getFeedbackStroke());
        g2.setPaint(getFeedbackEdgePaint());
        g2.draw(state.workingLine);
    }

}

From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java

/**
 * Paint the given tree layout/* w  w w . j ava  2s.  c  o  m*/
 * @param graphics
 *          the graphics to paint with
 * @param treeLayout
 *          the layout to paint
 */
private void paintPhylogenyTree(Graphics2D graphics, VisualTreeNode treeLayout) {
    int childNodeCount = treeLayout.getChildNodes().size();
    for (int i = 0; i < childNodeCount; i++) {
        VisualTreeNode visualChild = treeLayout.getChildNodes().get(i);

        Shape branchShape = new Line2D.Double(treeLayout.getPosition(), visualChild.getPosition());
        Shape branchShadowShape = SHADOW_TRANSFORM.createTransformedShape(branchShape);

        graphics.setColor(SHADOW_COLOR);
        graphics.draw(branchShadowShape);

        if (this.paintScale != null) {
            PhylogenyTreeEdge phylogenyEdge = treeLayout.getPhylogenyTreeNode().getChildEdges().get(i);
            if (phylogenyEdge instanceof PhylogenyTreeEdgeWithRealValue) {
                PhylogenyTreeEdgeWithRealValue phylogenyEdgeWithValue = (PhylogenyTreeEdgeWithRealValue) phylogenyEdge;
                Paint paint = this.paintScale.getPaint(phylogenyEdgeWithValue.getRealValue());
                graphics.setPaint(paint);
            } else {
                graphics.setColor(FOREGROUND_COLOR);
            }
        } else {
            graphics.setColor(FOREGROUND_COLOR);
        }
        graphics.draw(branchShape);

        // recurse
        this.paintPhylogenyTree(graphics, visualChild);
    }

    if (!treeLayout.getPhylogenyTreeNode().getStrains().isEmpty()) {
        Shape textShape = this.getLabelShape(treeLayout, graphics.getFontRenderContext());
        Shape borderShape = this.getLabelBorder(textShape);

        graphics.setColor(BACKGROUND_COLOR);
        graphics.fill(borderShape);

        graphics.setColor(SHADOW_COLOR);
        Area borderShadowShape = new Area(SHADOW_TRANSFORM.createTransformedShape(borderShape));
        borderShadowShape.subtract(new Area(borderShape));
        graphics.draw(borderShadowShape);

        graphics.setColor(FOREGROUND_COLOR);
        graphics.draw(borderShape);

        graphics.fill(textShape);
    }
}