Example usage for java.awt Graphics2D fill

List of usage examples for java.awt Graphics2D fill

Introduction

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

Prototype

public abstract void fill(Shape s);

Source Link

Document

Fills the interior of a Shape using the settings of the Graphics2D context.

Usage

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

/**<!====== drawItem ======================================================>
   Draws a 3D bar to represent one data item.
   <!      Name       Description>
   @param  g2         the graphics device.
   @param  state      the renderer state.
   @param  dataArea   the area for plotting the data.
   @param  plot       the plot./*w w w. j a  v  a 2s.  c o m*/
   @param  domainAxis the domain axis.
   @param  rangeAxis  the range axis.
   @param  dataset    the dataset.
   @param  row        the row index (zero-based).
   @param  column     the column index (zero-based).
   @param  pass       the pass index.
<!=======================================================================>*/
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    g2.setStroke(new BasicStroke(1));
    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint itemPaint = getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color endColor = getFrontDark((Color) itemPaint);
        Color startColor = (Color) itemPaint;
        Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor,
                (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor);
        g2.setPaint(paint);
    }
    g2.fill(bar);

    double x0 = bar.getMinX(); // left
    double x1 = x0 + getXOffset(); // offset left
    double x2 = bar.getMaxX(); // right
    double x3 = x2 + getXOffset(); // offset right

    double y0 = bar.getMinY() - getYOffset(); // offset top
    double y1 = bar.getMinY(); // bar top
    double y2 = bar.getMaxY() - getYOffset(); // offset bottom
    double y3 = bar.getMaxY(); // bottom

    //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight());

    Line2D.Double line = new Line2D.Double(x2, y1, x2, y3);
    g2.draw(line);

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    g2.setPaint(itemPaint);

    // Draw the right side
    if (barLength > 0.0) {
        bar3dRight = new GeneralPath();
        bar3dRight.moveTo((float) x2, (float) y3);
        bar3dRight.lineTo((float) x2, (float) y1);
        bar3dRight.lineTo((float) x3, (float) y0);
        bar3dRight.lineTo((float) x3, (float) y2);
        bar3dRight.closePath();

        if (itemPaint instanceof Color) {
            Color startColor = getSideLight((Color) itemPaint);
            Color endColor = getSideDark((Color) itemPaint);
            Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3,
                    endColor);
            g2.setPaint(paint);
        }
        g2.fill(bar3dRight);
    }

    // Draw the top
    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1); // bottom left
    bar3dTop.lineTo((float) x1, (float) y0); // top left
    bar3dTop.lineTo((float) x3, (float) y0); // top right
    bar3dTop.lineTo((float) x2, (float) y1); // bottom right
    bar3dTop.closePath();
    if (itemPaint instanceof Color) {
        Color endColor = getTopDark((Color) itemPaint);
        Color startColor = getTopLight((Color) itemPaint);
        //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor);
        Point2D.Double topRight = new Point2D.Double(x3, y0);
        Point2D.Double bottomLeft = new Point2D.Double(x0, y1);
        //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2)));
        Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2)));
        Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor,
                (float) darkEnd.getX(), (float) darkEnd.getY(), endColor);
        g2.setPaint(paint);
        //drawMarker(topRight, g2, startColor);
    }
    g2.fill(bar3dTop);
    g2.setPaint(itemPaint);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dRight != null) {
            g2.draw(bar3dRight);
        }
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        GeneralPath barOutline = new GeneralPath();
        barOutline.moveTo((float) x0, (float) y3);
        barOutline.lineTo((float) x0, (float) y1);
        barOutline.lineTo((float) x1, (float) y0);
        barOutline.lineTo((float) x3, (float) y0);
        barOutline.lineTo((float) x3, (float) y2);
        barOutline.lineTo((float) x2, (float) y3);
        barOutline.closePath();
        addItemEntity(entities, dataset, row, column, barOutline);
    }

}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Draws zoom rectangle (if present). The drawing is performed in XOR mode, therefore when this
 * method is called twice in a row, the second call will completely restore the state of the
 * canvas./*from  w  ww  .  j a v  a2 s .c o m*/
 * 
 * @param g2
 *            the graphics device.
 */
private void drawZoomRectangle(Graphics2D g2) {
    // Set XOR mode to draw the zoom rectangle
    g2.setXORMode(Color.gray);
    if (this.zoomRectangle != null) {
        if (this.fillZoomRectangle) {
            g2.fill(this.zoomRectangle);
        } else {
            g2.draw(this.zoomRectangle);
        }
    }
    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:lcmc.gui.ResourceGraph.java

/** This method draws in the host vertex. */
protected final void drawInsideVertex(final Graphics2D g2d, final Vertex v, final Color[] colors,
        final double x, final double y, final float height, final float width) {
    final int number = colors.length;
    if (number > 1) {
        for (int i = 1; i < number; i++) {
            final Paint p = new GradientPaint((float) x + width / number, (float) y,
                    getVertexFillSecondaryColor(v), (float) x + width / number, (float) y + height, colors[i],
                    false);//from w  w  w.ja  v  a  2s .c om
            g2d.setPaint(p);
            final Rectangle2D s = new Rectangle2D.Double(x + width / 2 + (width / number / 2) * i, y,
                    width / number / 2, height - 2);
            g2d.fill(s);
        }
    }
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

@Override
protected void drawToolTipFollower(Graphics2D g2, int x, int y) {
    Rectangle2D dataArea = getScreenDataArea();
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX()) && ((int) dataArea.getMinY() < y)
            && (y < (int) dataArea.getMaxY())) {
        String text = String.format("(%." + mouseFollowerXPrecision + "f, %." + mouseFollowerYPrecision
                + "f, %." + mouseFollowerZPrecision + "f)", getChartX(), getChartY(), getChartZ());
        int xLoc = x + 10;
        int yLoc = y + 20;
        double width = text.length() * 5.5;
        double height = 15;
        if (xLoc + width > dataArea.getMaxX()) {
            xLoc = (int) (x - width);
        }// ww w.j  ava 2 s  .c  o  m
        if (yLoc + height > dataArea.getMaxY()) {
            yLoc = (int) (y - height);
        }

        Rectangle2D toolTipArea = new Rectangle2D.Double(xLoc, yLoc, width, height);
        g2.setColor(Color.white);
        g2.fill(toolTipArea);
        g2.setColor(Color.black);
        g2.drawString(text, xLoc + 3, yLoc + 11);
    }
}

From source file:diet.gridr.g5k.util.ExtendedStackedBarRenderer.java

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device.//  ww w .  j  a va 2  s  . c o  m
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    PlotOrientation orientation = plot.getOrientation();
    double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())
            - state.getBarWidth() / 2.0;

    double positiveBase = 0.0;
    double negativeBase = 0.0;

    for (int i = 0; i < row; i++) {
        Number v = dataset.getValue(i, column);
        if (v != null) {
            double d = v.doubleValue();
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }

    double translatedBase;
    double translatedValue;
    RectangleEdge location = plot.getRangeAxisEdge();
    if (value > 0.0) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    double barL0 = Math.min(translatedBase, translatedValue);
    double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    if (value > 0.0) {
        if (this.showPositiveTotal) {
            if (isLastPositiveItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfPositiveValuesForCategory(dataset, column);
                TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2, (float) bar.getCenterX(),
                        (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER, 0.0, TextAnchor.BOTTOM_CENTER);
            }
        }
    } else {
        if (this.showNegativeTotal) {
            if (isLastNegativeItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfNegativeValuesForCategory(dataset, column);
                TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(),
                        (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER);
            }
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != 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(bar, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            entities.add(entity);
        }
    }

}

From source file:edu.ucla.stat.SOCR.chart.gui.ExtendedStackedBarRenderer.java

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device./*  ww  w  . jav a 2  s.  c  o m*/
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    PlotOrientation orientation = plot.getOrientation();
    double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge())
            - state.getBarWidth() / 2.0;

    double positiveBase = 0.0;
    double negativeBase = 0.0;

    for (int i = 0; i < row; i++) {
        Number v = dataset.getValue(i, column);
        if (v != null) {
            double d = v.doubleValue();
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }

    double translatedBase;
    double translatedValue;
    RectangleEdge location = plot.getRangeAxisEdge();
    if (value > 0.0) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    double barL0 = Math.min(translatedBase, translatedValue);
    double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    if (value > 0.0) {
        if (this.showPositiveTotal) {
            if (isLastPositiveItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfPositiveValuesForCategory(dataset, column);
                if (orientation == PlotOrientation.HORIZONTAL)
                    TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2,
                            (float) (bar.getMaxX() + 5.0), (float) bar.getCenterY(), TextAnchor.CENTER_LEFT,
                            0.0, TextAnchor.CENTER_LEFT);

                else
                    TextUtilities.drawRotatedString(this.totalFormatter.format(total), g2,
                            (float) bar.getCenterX(), (float) (bar.getMinY() - 4.0), TextAnchor.BOTTOM_CENTER,
                            0.0, TextAnchor.BOTTOM_CENTER);
            }
        }
    } else {
        if (this.showNegativeTotal) {
            if (isLastNegativeItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                double total = calculateSumOfNegativeValuesForCategory(dataset, column);
                if (orientation == PlotOrientation.HORIZONTAL)
                    TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) (bar.getMinX() - 5.0),
                            (float) bar.getCenterY(), TextAnchor.CENTER_RIGHT, 0.0, TextAnchor.CENTER_RIGHT);
                else
                    TextUtilities.drawRotatedString(String.valueOf(total), g2, (float) bar.getCenterX(),
                            (float) (bar.getMaxY() + 4.0), TextAnchor.TOP_CENTER, 0.0, TextAnchor.TOP_CENTER);
            }
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != 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(bar, tip, url, dataset, dataset.getRowKey(row),
                    dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

From source file:org.schreibubi.JCombinations.jfreechart.XYLineAndShapeRendererExtended.java

/**
 * Draws a horizontal line across the chart to represent a 'range marker'.
 * /*from   w w w. j a  v  a  2  s .  c  o m*/
 * @param g2
 *            the graphics device.
 * @param plot
 *            the plot.
 * @param rangeAxis
 *            the range axis.
 * @param marker
 *            the marker line.
 * @param dataArea
 *            the axis data area.
 */
@Override
public void drawRangeMarker(Graphics2D g2, XYPlot plot, ValueAxis rangeAxis, Marker marker,
        Rectangle2D dataArea) {

    if (marker instanceof ValueMarker)
        super.drawRangeMarker(g2, plot, rangeAxis, marker, dataArea);
    else if (marker instanceof IntervalMarker)
        super.drawRangeMarker(g2, plot, rangeAxis, marker, dataArea);
    else if (marker instanceof ArbitraryMarker) {

        ArbitraryMarker im = (ArbitraryMarker) marker;
        ArrayList<Double> xvals = im.getDomainVal();
        ArrayList<Double> lows = im.getRangeLowValues();
        ArrayList<Double> highs = im.getRangeHighValues();
        sort(xvals, lows, highs);

        Range range = rangeAxis.getRange();
        ValueAxis domainAxis = plot.getDomainAxis();
        Range domain = domainAxis.getRange();

        int length = xvals.size();
        int[] xpoly = new int[length * 2];
        int[] ypoly = new int[length * 2];

        for (int i = 0; i < xvals.size(); i++) {
            double x = domain.constrain(xvals.get(i));
            double low = range.constrain(lows.get(i));
            double high = range.constrain(highs.get(i));
            int low2d = (int) Math.round(rangeAxis.valueToJava2D(low, dataArea, plot.getRangeAxisEdge()));
            int high2d = (int) Math.round(rangeAxis.valueToJava2D(high, dataArea, plot.getRangeAxisEdge()));
            int x2d = (int) Math.round(domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()));
            xpoly[i] = x2d;
            xpoly[2 * length - 1 - i] = x2d;
            ypoly[i] = low2d;
            ypoly[2 * length - 1 - i] = high2d;
        }

        PlotOrientation orientation = plot.getOrientation();
        Polygon poly = null;
        if (orientation == PlotOrientation.HORIZONTAL)
            poly = new Polygon(ypoly, xpoly, length * 2);
        else if (orientation == PlotOrientation.VERTICAL)
            poly = new Polygon(xpoly, ypoly, length * 2);

        Paint p = im.getPaint();
        if (p instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) p;
            GradientPaintTransformer t = im.getGradientPaintTransformer();
            if (t != null)
                gp = t.transform(gp, poly);
            g2.setPaint(gp);
        } else
            g2.setPaint(p);
        g2.fill(poly);
        /*
         * String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if ( label != null ) {
         * Font labelFont = marker.getLabelFont(); g2.setFont( labelFont ); g2.setPaint( marker.getLabelPaint() );
         * Point2D coordinates = calculateRangeMarkerTextAnchorPoint( g2, orientation, dataArea, poly,
         * marker.getLabelOffset(), marker.getLabelOffsetType(), anchor ); TextUtilities.drawAlignedString( label,
         * g2, ( float ) coordinates.getX(), ( float ) coordinates.getY(), marker.getLabelTextAnchor() ); }
         */
    }
}

From source file:org.ietr.preesm.mapper.ui.MyGanttRenderer.java

/**
 * Draws the tasks/subtasks for one item.
 * // w w  w .  j av  a2 s  .co  m
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the data plot area.
 * @param plot
 *            the plot.
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the data.
 * @param row
 *            the row index (zero-based).
 * @param column
 *            the column index (zero-based).
 */
@Override
protected void drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row,
        int column) {

    int count = dataset.getSubIntervalCount(row, column);
    if (count == 0) {
        drawTask(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column);
    }

    for (int subinterval = 0; subinterval < count; subinterval++) {

        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

        // value 0
        Number value0 = dataset.getStartValue(row, column, subinterval);
        if (value0 == null) {
            return;
        }
        double translatedValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);

        // value 1
        Number value1 = dataset.getEndValue(row, column, subinterval);
        if (value1 == null) {
            return;
        }
        double translatedValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);

        if (translatedValue1 < translatedValue0) {
            double temp = translatedValue1;
            translatedValue1 = translatedValue0;
            translatedValue0 = temp;
        }

        double rectStart = calculateBarW0(plot, plot.getOrientation(), dataArea, domainAxis, state, row,
                column);
        double rectLength = Math.abs(translatedValue1 - translatedValue0);
        double rectBreadth = state.getBarWidth();

        // DRAW THE BARS...
        RoundRectangle2D bar = null;

        bar = new RoundRectangle2D.Double(translatedValue0, rectStart, rectLength, rectBreadth, 10.0, 10.0);

        /* Paint seriesPaint = */getItemPaint(row, column);

        if (((TaskSeriesCollection) dataset).getSeriesCount() > 0)
            if (((TaskSeriesCollection) dataset).getSeries(0).getItemCount() > column)
                if (((TaskSeriesCollection) dataset).getSeries(0).get(column).getSubtaskCount() > subinterval) {
                    g2.setPaint(getRandomBrightColor(((TaskSeriesCollection) dataset).getSeries(0).get(column)
                            .getSubtask(subinterval).getDescription()));

                }
        g2.fill(bar);

        if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
            g2.setStroke(getItemStroke(row, column));
            g2.setPaint(getItemOutlinePaint(row, column));
            g2.draw(bar);
        }

        // Displaying the tooltip inside the bar if enough space is
        // available
        if (getToolTipGenerator(row, column) != null) {
            // Getting the string to display
            String tip = getToolTipGenerator(row, column).generateToolTip(dataset, subinterval, column);

            // Truncting the string if it is too long
            String subtip = "";
            if (rectLength > 0) {
                double percent = (g2.getFontMetrics().getStringBounds(tip, g2).getWidth() + 10) / rectLength;

                if (percent > 1.0) {
                    subtip = tip.substring(0, (int) (tip.length() / percent));
                } else if (percent > 0) {
                    subtip = tip;
                }

                // Setting font and color
                Font font = new Font("Garamond", Font.BOLD, 12);
                g2.setFont(font);
                g2.setColor(Color.WHITE);

                // Testing width and displaying
                if (!subtip.isEmpty()) {
                    g2.drawString(subtip, (int) translatedValue0 + 5,
                            (int) rectStart + g2.getFontMetrics().getHeight());
                }
            }
        }

        // collect entity and tool tip information...
        if (state.getInfo() != null) {
            EntityCollection entities = state.getEntityCollection();
            if (entities != null) {
                String tip = null;
                if (getToolTipGenerator(row, column) != null) {
                    tip = getToolTipGenerator(row, column).generateToolTip(dataset, subinterval, column);
                }
                String url = null;
                if (getItemURLGenerator(row, column) != null) {
                    url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
                }
                CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset,
                        dataset.getRowKey(row), dataset.getColumnKey(column));
                entities.add(entity);
            }
        }
    }

}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

protected void paintAnnotations(Graphics2D g2d) {

    DecimalFormat mz_df = new DecimalFormat("0.0");

    // set font/*from ww w . ja v  a 2s  . co  m*/
    Font old_font = g2d.getFont();
    Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE);

    // compute bboxes
    PositionManager pman = new PositionManager();
    BBoxManager bbman = new BBoxManager();
    computeRectangles(pman, bbman);

    // compute connections
    computeConnections();

    // paint connections
    for (AnnotationObject a : theDocument.getAnnotations()) {
        boolean selected = !is_printing && selections.contains(a);

        // paint arrow        
        Polygon connection = connections.get(a);
        if (connection != null) {
            g2d.setColor(theOptions.CONNECTION_LINES_COLOR);
            g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH))
                    : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH));
            g2d.draw(connection);
            g2d.setStroke(new BasicStroke(1));
        }

        // paint control point       
        if (selected) {
            g2d.setColor(Color.black);
            Point2D cp = connections_cp.get(a);
            if (cp != null) {
                int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH);
                g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s));
            }
        }
    }

    // paint glycans
    for (AnnotationObject a : theDocument.getAnnotations()) {
        boolean highlighted = a.isHighlighted();
        boolean selected = !is_printing && selections.contains(a);

        // set scale
        theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a));

        // paint highlighted region
        if (highlighted) {
            Rectangle c_bbox = rectangles_complete.get(a);

            g2d.setColor(theOptions.HIGHLIGHTED_COLOR);
            g2d.setXORMode(Color.white);
            g2d.fill(c_bbox);
            g2d.setPaintMode();

            g2d.setColor(Color.black);
            g2d.draw(c_bbox);
        }

        // paint glycan
        for (Glycan s : a.getStructures())
            theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman);

        // paint MZ text
        g2d.setFont(new_font);
        g2d.setColor(theOptions.MASS_TEXT_COLOR);
        String mz_text = mz_df.format(a.getPeakPoint().getX());
        Rectangle mz_bbox = rectangles_text.get(a);
        g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height);

        // paint selection        
        if (selected) {
            // paint rectangle
            Rectangle c_bbox = rectangles_complete.get(a);

            g2d.setStroke(new BasicStroke(highlighted ? 2 : 1));
            g2d.setColor(Color.black);

            g2d.draw(c_bbox);

            g2d.setStroke(new BasicStroke(1));

            // paint resize points        
            Polygon p1 = new Polygon();
            int cx1 = right(c_bbox);
            int cy1 = top(c_bbox);
            p1.addPoint(cx1, cy1);
            p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1);
            p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3);
            g2d.fill(p1);

            Polygon p2 = new Polygon();
            int cx2 = left(c_bbox);
            int cy2 = top(c_bbox);
            p2.addPoint(cx2, cy2);
            p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2);
            p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3);
            g2d.fill(p2);
        }
    }

    g2d.setFont(old_font);
}

From source file:org.jfree.chart.demo.ExtendedStackedBarRenderer.java

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device./*from  w  w w  .j  a v  a 2  s  .com*/
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
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) {

    // nothing is drawn for null values...
    final Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    final double value = dataValue.doubleValue();

    final PlotOrientation orientation = plot.getOrientation();
    final double barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;

    double positiveBase = 0.0;
    double negativeBase = 0.0;

    for (int i = 0; i < row; i++) {
        final Number v = dataset.getValue(i, column);
        if (v != null) {
            final double d = v.doubleValue();
            if (d > 0) {
                positiveBase = positiveBase + d;
            } else {
                negativeBase = negativeBase + d;
            }
        }
    }

    final double translatedBase;
    final double translatedValue;
    final RectangleEdge location = plot.getRangeAxisEdge();
    if (value > 0.0) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    final double barL0 = Math.min(translatedBase, translatedValue);
    final double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    final Paint seriesPaint = getItemPaint(row, column);
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
    }

    //        final CategoryLabelGenerator generator = getLabelGenerator(row, column);
    //      if (generator != null && isItemLabelVisible(row, column)) {
    //        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    //  }       

    if (value > 0.0) {
        if (this.showPositiveTotal) {
            if (isLastPositiveItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                final double total = calculateSumOfPositiveValuesForCategory(dataset, column);
                //            RefineryUtilities.drawRotatedString(
                //              this.totalFormatter.format(total), g2,
                //            (float) bar.getCenterX(),
                //          (float) (bar.getMinY() - 4.0), 
                ///        TextAnchor.BOTTOM_CENTER, 
                //         TextAnchor.BOTTOM_CENTER, 
                //       0.0
                // );              
            }
        }
    } else {
        if (this.showNegativeTotal) {
            if (isLastNegativeItem(dataset, row, column)) {
                g2.setPaint(Color.black);
                g2.setFont(this.totalLabelFont);
                final double total = calculateSumOfNegativeValuesForCategory(dataset, column);
                /*                    RefineryUtilities.drawRotatedString(
                String.valueOf(total), g2,
                (float) bar.getCenterX(),
                (float) (bar.getMaxY() + 4.0), 
                TextAnchor.TOP_CENTER, 
                TextAnchor.TOP_CENTER, 
                0.0
                                    );              
                  */ }
        }
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        final EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
        if (entities != 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(bar, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            //            entities.addEntity(entity);
        }
    }

}