Example usage for java.awt Graphics2D setStroke

List of usage examples for java.awt Graphics2D setStroke

Introduction

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

Prototype

public abstract void setStroke(Stroke s);

Source Link

Document

Sets the Stroke for the Graphics2D context.

Usage

From source file:edu.dlnu.liuwenpeng.render.LineAndShapeRenderer.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    ls.add(dataset.getValue(0, column).doubleValue());

    if (!getItemVisible(row, column)) {
        return;/*w ww  . j  av  a  2 s .com*/
    }

    if (!getItemLineVisible(row, column) && !getItemShapeVisible(row, column)) {
        return;
    }

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

    PlotOrientation orientation = plot.getOrientation();

    // current data point...    
    double x1;
    if (this.useSeriesOffset) {
        x1 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(column), dataset.getRowKey(row), dataset,
                this.itemMargin, dataArea, plot.getDomainAxisEdge());
    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...    
                double previous = previousValue.doubleValue();
                double x0;
                if (this.useSeriesOffset) {
                    x0 = domainAxis.getCategorySeriesMiddle(dataset.getColumnKey(column - 1),
                            dataset.getRowKey(row), dataset, this.itemMargin, dataArea,
                            plot.getDomainAxisEdge());
                } 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);
            }
        }
    }

    if (pass == 1) {
        Shape shape = getItemShape(row, column);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }

        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (this.useOutlinePaint) {
                    g2.setPaint(getItemOutlinePaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.draw(shape);

            }
        }

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

        // add an item entity, if this information is being collected    
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, shape);
        }
    }
    if (i == dataset.getColumnCount() - 1) {
        average = GetAverage.getAverage(ls);

        double averangeline = rangeAxis.valueToJava2D(average, dataArea, plot.getRangeAxisEdge());
        double x = rangeAxis.valueToJava2D(dataset.getColumnCount() - 1, dataArea, plot.getDomainAxisEdge());
        Line2D line2d = new Line2D.Double(0, averangeline, x, averangeline);
        g2.setPaint(Color.white);
        g2.draw(line2d);
        i = 0;
        ls.clear();
    }
    i++;
}

From source file:savant.view.tracks.BAMTrackRenderer.java

private void renderArcPairedMode(Graphics2D g2, GraphPaneAdapter gp) {

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    LOG.debug("YMAX for ARC mode: " + ((AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE)).getYMax());
    AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE);
    ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME);
    int discordantMin = (Integer) instructions.get(DrawingInstruction.DISCORDANT_MIN);
    int discordantMax = (Integer) instructions.get(DrawingInstruction.DISCORDANT_MAX);
    //LOG.info("discordantMin=" + discordantMin + " discordantMax=" + discordantMax);

    // set up colors
    Color normalArcColor = makeTransparent(cs.getColor(ColourKey.CONCORDANT_LENGTH));
    Color invertedReadColor = makeTransparent(cs.getColor(ColourKey.ONE_READ_INVERTED));
    Color evertedPairColor = makeTransparent(cs.getColor(ColourKey.EVERTED_PAIR));
    Color discordantLengthColor = makeTransparent(cs.getColor(ColourKey.DISCORDANT_LENGTH));
    Color unmappedMateColor = makeTransparent(cs.getColor(ColourKey.UNMAPPED_MATE));

    // set graph pane's range parameters
    gp.setXRange(axisRange.getXRange());
    gp.setYRange(axisRange.getYRange());

    // iterate through the data and draw
    LOG.debug("BAMTrackRenderer.renderArcMatePairMode: " + data.size() + " records.");
    for (Record record : data) {
        BAMIntervalRecord bamRecord = (BAMIntervalRecord) record;
        SAMRecord samRecord = bamRecord.getSAMRecord();
        SAMReadUtils.PairedSequencingProtocol prot = (SAMReadUtils.PairedSequencingProtocol) instructions
                .get(DrawingInstruction.PAIRED_PROTOCOL);
        SAMReadUtils.PairMappingType type = SAMReadUtils.getPairType(samRecord, prot);

        if (samRecord.getReadPairedFlag() && type != null) {
            if (samRecord.getMateUnmappedFlag()) {
                // Read with unmapped mate.
                int alignmentStart = samRecord.getAlignmentStart();
                double x = gp.transformXPos(alignmentStart);
                double radius = 4.0;
                double top = gp.transformYPos(axisRange.getYRange().getTo() * 0.25) + radius;
                g2.setColor(unmappedMateColor);
                g2.setStroke(ONE_STROKE);
                Path2D flower = new Path2D.Double();
                flower.moveTo(x, gp.transformYPos(0.0));
                flower.lineTo(x, top);/*from   w  ww . jav  a2  s.c  om*/
                flower.moveTo(x - radius, top - radius);
                flower.lineTo(x + radius, top + radius);
                flower.moveTo(x - radius, top + radius);
                flower.lineTo(x + radius, top - radius);
                //flower.append(new Ellipse2D.Double(x - radius, top - radius, radius * 2.0, radius * 2.0), false);
                g2.draw(flower);
                recordToShapeMap.put(record, flower);

                // mates map to different chrs
            } else if (!samRecord.getMateReferenceName().equals(samRecord.getReferenceName())) {

                int alignmentStart = samRecord.getAlignmentStart();
                double x = gp.transformXPos(alignmentStart);
                double arrowWidth = 10;
                double arrowHeight = 15;
                double top = gp.transformYPos(axisRange.getYRange().getTo() * 0.9);
                g2.setColor(invertedReadColor);
                g2.setStroke(TWO_STROKE);

                Path2D stem = new Path2D.Double();
                stem.moveTo(x, gp.transformYPos(0.0));
                stem.lineTo(x, top + arrowHeight);

                g2.draw(stem);

                Path2D pointer = new Path2D.Double();
                pointer.moveTo(x, top);
                pointer.lineTo(x - arrowWidth / 2, top + arrowHeight);
                pointer.lineTo(x + arrowWidth / 2, top + arrowHeight);
                pointer.lineTo(x, top);
                g2.fill(pointer);

                pointer.append(stem, false);

                //flower.append(new Ellipse2D.Double(x - radius, top - radius, radius * 2.0, radius * 2.0), false);
                //g2.draw(pointer);

                recordToShapeMap.put(record, pointer);

                // mates map to the same chr
            } else {
                // Paired read with normal mate.

                int arcLength = Math.abs(samRecord.getInferredInsertSize());

                // skip reads with a zero insert length--probably mapping errors
                if (arcLength == 0) {
                    continue;
                }

                int alignmentStart;
                int mateAlignmentStart = samRecord.getMateAlignmentStart();
                if (samRecord.getAlignmentStart() > mateAlignmentStart) {
                    if (!(mateAlignmentStart < LocationController.getInstance().getRangeStart())) {
                        // this is the second in the pair, and it doesn't span the beginning of the range, so don't draw anything
                        continue;
                    } else {
                        // switch the mate start/end for the read start/end to deal with reversed position
                        alignmentStart = mateAlignmentStart;
                    }
                } else {
                    alignmentStart = samRecord.getAlignmentStart();
                }
                // at this point alignmentStart/End refers the the start end of the first occurrence in the pair

                int intervalStart;
                switch (type) {
                case INVERTED_READ:
                case INVERTED_MATE:
                    intervalStart = alignmentStart;
                    g2.setColor(invertedReadColor);
                    g2.setStroke(TWO_STROKE);
                    break;
                case EVERTED:
                    intervalStart = alignmentStart;
                    g2.setColor(evertedPairColor);
                    g2.setStroke(TWO_STROKE);
                    break;
                default:
                    // make sure arclength is over our threshold
                    /*if (threshold != 0.0d && threshold < 1.0d && arcLength < axisRange.getXRange().getLength()*threshold) {
                     continue;
                     }
                     else if (threshold > 1.0d && arcLength < threshold) {
                     continue;
                     }*/

                    intervalStart = alignmentStart;

                    if (arcLength > discordantMax || arcLength < discordantMin) {
                        g2.setColor(discordantLengthColor);
                        g2.setStroke(TWO_STROKE);
                    } else {
                        g2.setColor(normalArcColor);
                        g2.setStroke(ONE_STROKE);
                    }
                    break;
                }
                int arcHeight = arcLength;

                double rectWidth = arcLength * gp.getUnitWidth();
                double rectHeight = arcHeight * 2 * gp.getUnitHeight();

                double xOrigin = gp.transformXPos(intervalStart);
                double yOrigin = gp.transformYPos(arcHeight);

                Arc2D arc = new Arc2D.Double(xOrigin, yOrigin, rectWidth, rectHeight, -180, -180, Arc2D.OPEN);
                g2.draw(arc);
                recordToShapeMap.put(record, arc);
            }
        }
    }
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Draws a radar plot polygon./*from   w ww.  ja  v  a2  s .c  o  m*/
 *
 * @param g2 the graphics device.
 * @param plotArea the area we are plotting in (already adjusted).
 * @param centre the centre point of the radar axes
 * @param info chart rendering info.
 * @param series the series within the dataset we are plotting
 * @param catCount the number of categories per radar plot
 * @param headH the data point height
 * @param headW the data point width
 */
protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info,
        int series, int catCount, double headH, double headW) {

    Polygon polygon = new Polygon();

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

    // plot the data...
    for (int cat = 0; cat < catCount; cat++) {

        Number dataValue = getPlotValue(series, cat);

        if (dataValue != null) {
            double value = dataValue.doubleValue();

            if (value >= 0) { // draw the polygon series...

                // Finds our starting angle from the centre for this axis

                double angle = getStartAngle()
                        + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3));

                // The following angle calc will ensure there isn't a top
                // vertical axis - this may be useful if you don't want any
                // given criteria to 'appear' move important than the
                // others..
                //  + (getDirection().getFactor()
                //        * (cat + 0.5) * 360 / catCount);

                // find the point at the appropriate distance end point
                // along the axis/angle identified above and add it to the
                // polygon

                Point2D point = getWebPoint(plotArea, angle, value / this.maxValue);
                polygon.addPoint((int) point.getX(), (int) point.getY());

                // put an elipse at the point being plotted..

                Paint paint = getSeriesPaint(series);
                Paint outlinePaint = getSeriesOutlinePaint(series);
                Stroke outlineStroke = getSeriesOutlineStroke(series);

                Ellipse2D head = new Ellipse2D.Double(point.getX() - headW / 2, point.getY() - headH / 2, headW,
                        headH);
                g2.setPaint(paint);
                g2.fill(head);
                g2.setStroke(outlineStroke);
                g2.setPaint(outlinePaint);
                g2.draw(head);

                if (entities != null) {
                    int row = 0;
                    int col = 0;
                    if (this.dataExtractOrder == TableOrder.BY_ROW) {
                        row = series;
                        col = cat;
                    } else {
                        row = cat;
                        col = series;
                    }
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col);
                    }

                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, row, col);
                    }

                    Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH),
                            (int) (headW * 2), (int) (headH * 2));
                    CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset,
                            this.dataset.getRowKey(row), this.dataset.getColumnKey(col));
                    entities.add(entity);
                }

            }
        }
    }
    // Plot the polygon

    Paint paint = getSeriesPaint(series);
    g2.setPaint(paint);
    g2.setStroke(getSeriesOutlineStroke(series));
    g2.draw(polygon);

    // Lastly, fill the web polygon if this is required

    if (this.webFilled) {
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2.fill(polygon);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    }
}

From source file:org.executequery.gui.erd.ErdTable.java

protected void drawTable(Graphics2D g, int offsetX, int offsetY) {

    if (parent == null) {

        return;/* w  w w .  java2  s .  c om*/
    }

    Font tableNameFont = parent.getTableNameFont();
    Font columnNameFont = parent.getColumnNameFont();

    // set the table value background
    g.setColor(TITLE_BAR_BG_COLOR);
    g.fillRect(offsetX, offsetY, FINAL_WIDTH - 1, TITLE_BAR_HEIGHT);

    // set the table value
    FontMetrics fm = g.getFontMetrics(tableNameFont);
    int lineHeight = fm.getHeight();
    int titleXPosn = (FINAL_WIDTH / 2) - (fm.stringWidth(tableName) / 2) + offsetX;

    g.setColor(Color.BLACK);
    g.setFont(tableNameFont);
    g.drawString(tableName, titleXPosn, lineHeight + offsetY);

    // draw the line separator
    lineHeight = TITLE_BAR_HEIGHT + offsetY - 1;
    g.drawLine(offsetX, lineHeight, offsetX + FINAL_WIDTH - 1, lineHeight);

    // fill the white background
    g.setColor(tableBackground);
    g.fillRect(offsetX, TITLE_BAR_HEIGHT + offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - TITLE_BAR_HEIGHT - 1);

    // add the column names
    fm = g.getFontMetrics(columnNameFont);
    int heightPlusSep = 1 + TITLE_BAR_HEIGHT + offsetY;
    int leftMargin = 5 + offsetX;

    lineHeight = fm.getHeight();
    g.setColor(Color.BLACK);
    g.setFont(columnNameFont);

    int drawCount = 0;
    String value = null;
    if (ArrayUtils.isNotEmpty(columns)) {

        for (int i = 0; i < columns.length; i++) {
            ColumnData column = columns[i];
            if (displayReferencedKeysOnly && !column.isKey()) {
                continue;
            }

            int y = (((drawCount++) + 1) * lineHeight) + heightPlusSep;
            int x = leftMargin;

            // draw the column value string
            value = column.getColumnName();
            g.drawString(value, x, y);

            // draw the data type and size string
            x = leftMargin + dataTypeOffset;
            value = column.getFormattedDataType();
            g.drawString(value, x, y);

            // draw the key label
            if (column.isKey()) {

                if (column.isPrimaryKey() && column.isForeignKey()) {

                    value = PRIMARY + FOREIGN;

                } else if (column.isPrimaryKey()) {

                    value = PRIMARY;

                } else if (column.isForeignKey()) {

                    value = FOREIGN;
                }

                x = leftMargin + dataTypeOffset + keyLabelOffset;
                g.drawString(value, x, y);
            }

        }

    }

    // draw the rectangle border
    double scale = g.getTransform().getScaleX();

    if (selected && scale != ErdPrintable.PRINT_SCALE) {
        g.setStroke(focusBorderStroke);
        g.setColor(Color.BLUE);
    } else {
        g.setColor(Color.BLACK);
    }

    g.drawRect(offsetX, offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - 1);
    //    g.setColor(Color.DARK_GRAY);
    //    g.draw3DRect(offsetX, offsetY, FINAL_WIDTH - 2, FINAL_HEIGHT - 2, true);
}

From source file:edu.jhuapl.graphs.jfreechart.CategoryLineGraphRenderer.java

/**
 * Draw a single data item.//from   ww  w .  ja  v a  2 s .c  o m
 *
 * @param g2         the graphics device.
 * @param state      the renderer state.
 * @param dataArea   the area in which the data is drawn.
 * @param plot       the plot.
 * @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) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }

    // do nothing if both the line and shape are not visible
    if (!getItemLineVisible(row, column) && !getItemShapeVisible(row, column)) {
        return;
    }

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

    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    // current data point...
    double x1;
    if (getUseSeriesOffset()) {
        x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount,
                getItemMargin(), dataArea, plot.getDomainAxisEdge());
    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double value = v.doubleValue();
    double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());

    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = dataset.getValue(row, column - 1);

            // Added by Wayne Loschen 5/25/2010
            // Modified this method to draw a line between the last non-null value
            // instead of only drawing a line if the column - 1 value was non-null
            int prevColumnIndex = column - 1;
            if (previousValue == null) {
                while (prevColumnIndex > 0 && previousValue == null) {
                    prevColumnIndex--;
                    previousValue = dataset.getValue(row, prevColumnIndex);
                }
            }

            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0;
                if (getUseSeriesOffset()) {
                    // WAL - Replaced column - 1 with prevColumnIndex
                    x0 = domainAxis.getCategorySeriesMiddle(prevColumnIndex, dataset.getColumnCount(),
                            visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
                } else {
                    // WAL - Replaced column - 1 with prevColumnIndex
                    x0 = domainAxis.getCategoryMiddle(prevColumnIndex, 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);
            }
        }
    }

    if (pass == 1) {
        Shape shape = getItemShape(row, column);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }

        if (getItemShapeVisible(row, column)) {
            if (getItemShapeFilled(row, column)) {
                if (getUseFillPaint()) {
                    g2.setPaint(getItemFillPaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.fill(shape);
            }
            if (getDrawOutlines()) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(row, column));
                } else {
                    g2.setPaint(getItemPaint(row, column));
                }
                g2.setStroke(getItemOutlineStroke(row, column));
                g2.draw(shape);
            }
        }

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

        // submit the current data point as a crosshair candidate
        int datasetIndex = plot.indexOf(dataset);
        updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column),
                value, datasetIndex, x1, y1, orientation);

        // add an item entity, if this information is being collected
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, shape);
        }
    }

}

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

/**
 * Draws a single interval./*from ww w  .j  a  v  a 2 s .c om*/
 * 
 * @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).
 */
protected void drawInterval(final Graphics2D g2, final CategoryItemRendererState state,
        final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
        final ValueAxis rangeAxis, final DefaultIntervalListCategoryDataset dataset, final int row,
        final int column) {

    final int seriesCount = getRowCount();
    final int categoryCount = getColumnCount();

    final PlotOrientation orientation = plot.getOrientation();

    double rectX = 0.0;
    double rectY = 0.0;

    final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

    final List list = dataset.getList(row, column);

    if (list == null) {
        return;
    }

    Interval interval = null;
    for (int i = 0; i < list.size(); i++) {

        interval = (Interval) list.get(i);

        if (!interval.isMeaningful()) {
            continue;
        }

        // Y0
        double java2dValue0 = rangeAxis.valueToJava2D(interval.low, dataArea, rangeAxisLocation);

        // Y1
        double java2dValue1 = rangeAxis.valueToJava2D(interval.high, dataArea, rangeAxisLocation);

        if (java2dValue1 < java2dValue0) {
            final double temp = java2dValue1;
            java2dValue1 = java2dValue0;
            java2dValue0 = temp;
        }

        // BAR WIDTH
        double rectWidth = state.getBarWidth();

        // BAR HEIGHT
        double rectHeight = Math.abs(java2dValue1 - java2dValue0);

        if (orientation == PlotOrientation.HORIZONTAL) {
            // BAR Y
            rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation);
            if (seriesCount > 1) {
                final double seriesGap = dataArea.getHeight() * getItemMargin()
                        / (categoryCount * (seriesCount - 1));
                rectY = rectY + row * (state.getBarWidth() + seriesGap);
            } else {
                rectY = rectY + row * state.getBarWidth();
            }

            rectX = java2dValue0;

            rectHeight = state.getBarWidth();
            rectWidth = Math.abs(java2dValue1 - java2dValue0);

        } else if (orientation == PlotOrientation.VERTICAL) {
            // BAR X
            rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation);

            if (seriesCount > 1) {
                final double seriesGap = dataArea.getWidth() * getItemMargin()
                        / (categoryCount * (seriesCount - 1));
                rectX = rectX + row * (state.getBarWidth() + seriesGap);
            } else {
                rectX = rectX + row * state.getBarWidth();
            }

            rectY = java2dValue0;

        }
        final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
        final Paint seriesPaint = getItemPaint(row, column);
        g2.setPaint(seriesPaint);
        g2.fill(bar);

        // draw the outline...
        if (state.getBarWidth() > BarRenderer.BAR_OUTLINE_WIDTH_THRESHOLD) {
            final Stroke stroke = getItemOutlineStroke(row, column);
            final Paint paint = getItemOutlinePaint(row, column);
            if ((stroke != null) && (paint != null)) {
                g2.setStroke(stroke);
                g2.setPaint(paint);
                g2.draw(bar);
            }
        }

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

        // 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,
                        dataset.getRowKey(row), dataset.getColumnKey(column));
                entities.add(entity);
            }
        }
    }
}

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

protected void drawTasks(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate,
        Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis,
        GanttCategoryDataset ganttcategorydataset, int i, int j) {
    int k = ganttcategorydataset.getSubIntervalCount(i, j);
    if (k == 0)//from   ww w .ja  va 2s. c o  m
        drawTask(graphics2d, categoryitemrendererstate, rectangle2d, categoryplot, categoryaxis, valueaxis,
                ganttcategorydataset, i, j);
    for (int l = 0; l < k; l++) {
        org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge();
        Number number = ganttcategorydataset.getStartValue(i, j, l);
        if (number == null)
            return;
        double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge);
        Number number1 = ganttcategorydataset.getEndValue(i, j, l);
        if (number1 == null)
            return;
        double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge);
        if (d1 < d) {
            double d2 = d1;
            d1 = d;
            d = d2;
        }
        double d3 = calculateBarW0(categoryplot, categoryplot.getOrientation(), rectangle2d, categoryaxis,
                categoryitemrendererstate, i, j);
        double d4 = Math.abs(d1 - d);
        double d5 = categoryitemrendererstate.getBarWidth();
        java.awt.geom.Rectangle2D.Double double1 = null;
        if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL)
            double1 = new java.awt.geom.Rectangle2D.Double(d, d3, d4, d5);
        else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL)
            double1 = new java.awt.geom.Rectangle2D.Double(d3, d, d5, d4);
        java.awt.geom.Rectangle2D.Double double2 = null;
        java.awt.geom.Rectangle2D.Double double3 = null;
        Number number2 = ganttcategorydataset.getPercentComplete(i, j, l);
        double d6 = getStartPercent();
        double d7 = getEndPercent();
        if (number2 != null) {
            double d8 = number2.doubleValue();
            if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) {
                double2 = new java.awt.geom.Rectangle2D.Double(d, d3 + d6 * d5, d4 * d8, d5 * (d7 - d6));
                double3 = new java.awt.geom.Rectangle2D.Double(d + d4 * d8, d3 + d6 * d5, d4 * (1.0D - d8),
                        d5 * (d7 - d6));
            } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) {
                double2 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d + d4 * (1.0D - d8),
                        d5 * (d7 - d6), d4 * d8);
                double3 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d, d5 * (d7 - d6),
                        d4 * (1.0D - d8));
            }
        }
        Paint paint = getItemPaint(i, j);
        graphics2d.setPaint(paint);
        graphics2d.fill(double1);
        if (double2 != null) {
            graphics2d.setPaint(getCompletePaint());
            graphics2d.fill(double2);
        }
        if (double3 != null) {
            graphics2d.setPaint(getIncompletePaint());
            graphics2d.fill(double3);
        }
        if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) {
            graphics2d.setStroke(getItemStroke(i, j));
            graphics2d.setPaint(getItemOutlinePaint(i, j));
            graphics2d.draw(double1);
        }
        if (categoryitemrendererstate.getInfo() == null)
            continue;
        EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection();
        if (entitycollection == null)
            continue;
        String s = null;
        if (getToolTipGenerator(i, j) != null)
            s = getToolTipGenerator(i, j).generateToolTip(ganttcategorydataset, i, j);
        String s1 = null;
        if (getItemURLGenerator(i, j) != null)
            s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j);
        CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset,
                ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j));
        entitycollection.add(categoryitementity);
    }

}

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

/**
 * Draws the visual representation of a series as shapes.
 *
 * @param g2  the graphics device.//from   w  w w . ja va 2 s . co  m
 * @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 axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 * @param drawShapes  a flag indicating whether shapes should be drawn
 * @param createEntities  a flag indicating whether entities should be
 * generated.
 */
protected void drawSeriesShapes(Graphics2D g2, State state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series,
        CrosshairState crosshairState, int pass, boolean drawShapes, boolean createEntities) {
    if (!drawShapes && !createEntities) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    double x = 0.0;
    double y = 0.0;
    double transX = 0.0;
    double transY = 0.0;
    boolean itemShapeFilled = getItemShapeFilled(series, 0);
    boolean drawOutlines = getDrawOutlines();
    Paint itemFillPaint = getUseFillPaint() ? getItemFillPaint(series, 0) : getItemPaint(series, 0);
    Paint itemOutlinePaint = getUseOutlinePaint() ? getItemOutlinePaint(series, 0) : getItemPaint(series, 0);
    Stroke itemOutlineStroke = getItemOutlineStroke(series, 0);
    Shape centeredShape = getItemShape(series, 0);
    /*
      if(centeredShape instanceof LinedShape){
    itemOutlinePaint = itemFillPaint;
    drawOutlines = true;
    itemShapeFilled = false;
      }
    */
    //draw items
    //and create entities
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);

    for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) {
        if (state.itemVisible(series, itemIndex)) {
            x = dataset.getXValue(series, itemIndex);
            y = dataset.getYValue(series, itemIndex);
            transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
            if (orientation == PlotOrientation.HORIZONTAL) {
                double temp = transX;
                transX = transY;
                transY = temp;
            }
            updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                    orientation);

            Shape shape = ShapeUtilities.createTranslatedShape(centeredShape, transX, transY);

            if (drawShapes) {
                if (itemShapeFilled) {
                    g2.setPaint(itemFillPaint);
                    g2.fill(shape);
                }
                if (drawOutlines) {
                    g2.setPaint(itemOutlinePaint);
                    g2.setStroke(itemOutlineStroke);
                    g2.draw(shape);
                }
            }
            if (createEntities && entities != null) {
                addEntity(entities, shape, dataset, series, itemIndex, transX, transY);
            }
        }
    }
}

From source file:com.bdaum.zoom.report.internal.jfree.custom.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 *
 * @param g2  the graphics device.//from  w ww.java 2 s.  com
 * @param state  the renderer state.
 * @param dataArea  the area for plotting the data.
 * @param plot  the plot.
 * @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.
 */
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;
    }

    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();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    Shape top = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo((float) (barL0 + getXOffset() / 2), (float) barW0);
        bar.lineTo((float) (barL0 + barLength + getXOffset() / 2), (float) barW0);
        Arc2D arc = new Arc2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth(), 90, 180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barL0 + getXOffset() / 2), (float) (barW0 + state.getBarWidth()));
        arc = new Arc2D.Double(barL0, barW0, getXOffset(), state.getBarWidth(), 270, -180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
        top = new Ellipse2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth());

    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();

        top = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    } else {
        g2.setPaint(PaintAlpha.darker(itemPaint)); // bd
    }
    if (top != null) {
        g2.fill(top);
    }

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

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

    // 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.getBounds2D(), tip, url, dataset,
                    dataset.getRowKey(row), dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}

From source file:org.operamasks.faces.render.graph.CurveAndShapeRenderer.java

private void drawSeriesCurve(Graphics2D g2, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int series) {
    // do nothing if item is not visible
    if (!(getItemVisible(series, 0) && (getItemLineVisible(series, 0) || drawArea))) {
        return;/*from w w w . j ava 2 s  .  c  o  m*/
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    PlotOrientation orientation = plot.getOrientation();

    int itemCount = dataset.getColumnCount();
    double[][] points = new double[itemCount][2];
    int count = 0;

    // get data points
    for (int i = 0; i < itemCount; i++) {
        Number value = dataset.getValue(series, i);
        if (value != null) {
            points[count][0] = domainAxis.getCategoryMiddle(i, itemCount, dataArea, xAxisLocation);
            points[count][1] = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, yAxisLocation);
            count++;
        }
    }

    if (count < 2) {
        return;
    }

    // draw curve
    CubicSplineFunction2D f = new CubicSplineFunction2D(points, count);
    GeneralPath path = new GeneralPath();

    double startX = points[0][0];
    double startY = points[0][1];
    double endX = points[count - 1][0];
    double endY = points[count - 1][1];
    double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation);

    if (orientation == PlotOrientation.HORIZONTAL) {
        if (drawArea) {
            path.moveTo((float) yz, (float) startX);
            path.lineTo((float) startY, (float) startX);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) f.getValue(x), (float) x);
            }
            path.lineTo((float) endY, (float) endX);
            path.lineTo((float) yz, (float) endX);
            path.closePath();
        } else {
            path.moveTo((float) startY, (float) startX);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) f.getValue(x), (float) x);
            }
            path.lineTo((float) endY, (float) endX);
        }
    } else {
        if (drawArea) {
            path.moveTo((float) startX, (float) yz);
            path.lineTo((float) startX, (float) startY);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) x, (float) f.getValue(x));
            }
            path.lineTo((float) endX, (float) endY);
            path.lineTo((float) endX, (float) yz);
            path.closePath();
        } else {
            path.moveTo((float) startX, (float) startY);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) x, (float) f.getValue(x));
            }
            path.lineTo((float) endX, (float) endY);
        }
    }

    Paint paint = getSeriesPaint(series);
    Stroke stroke = getSeriesStroke(series);

    if (drawArea) {
        g2.setPaint(paint);
        g2.fill(path);

        // create paint for outline
        if (paint instanceof Color) {
            paint = ((Color) paint).darker();
        } else if (paint instanceof GradientPaint) {
            paint = ((GradientPaint) paint).getColor1().darker();
        }
    }

    if (getItemLineVisible(series, 0)) {
        g2.setPaint(paint);
        g2.setStroke(stroke);
        g2.draw(path);
    }
}