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:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java

private static void drawSelection(final Graphics2D g, final MindMapPanelConfig cfg,
        final List<Topic> selectedTopics) {
    if (selectedTopics != null && !selectedTopics.isEmpty()) {
        g.setColor(cfg.getSelectLineColor());
        final Stroke dashed = new BasicStroke(cfg.safeScaleFloatValue(cfg.getSelectLineWidth(), 0.1f),
                BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0,
                new float[] { cfg.safeScaleFloatValue(1.0f, 0.1f), cfg.safeScaleFloatValue(4.0f, 0.1f) }, 0);
        g.setStroke(dashed);
        final double selectLineGap = (double) cfg.safeScaleFloatValue(cfg.getSelectLineGap(), 0.05f);
        final double selectLineGapX2 = selectLineGap + selectLineGap;

        for (final Topic s : selectedTopics) {
            final AbstractElement e = (AbstractElement) s.getPayload();
            if (e != null) {
                final int x = (int) Math.round(e.getBounds().getX() - selectLineGap);
                final int y = (int) Math.round(e.getBounds().getY() - selectLineGap);
                final int w = (int) Math.round(e.getBounds().getWidth() + selectLineGapX2);
                final int h = (int) Math.round(e.getBounds().getHeight() + selectLineGapX2);
                g.drawRect(x, y, w, h);/*ww w .j  a  v a 2  s.co m*/
            }
        }
    }
}

From source file:hudson.util.StackedAreaRenderer2.java

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

    // plot non-null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;/*w w  w  .  j av a 2  s . c om*/
    }

    double value = dataValue.doubleValue();

    // leave the y values (y1, y0) untranslated as it is going to be be
    // stacked up later by previous series values, after this it will be
    // translated.
    double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());

    double previousHeightx1 = getPreviousHeight(dataset, row, column);
    double y1 = value + previousHeightx1;
    RectangleEdge location = plot.getRangeAxisEdge();
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location);

    g2.setPaint(getItemPaint(row, column));
    g2.setStroke(getItemStroke(row, column));

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();

    // in column zero, the only job to do is draw any visible item labels
    // and this is done in the second pass...
    if (column == 0) {
        if (pass == 1) {
            // draw item labels, if visible
            if (isItemLabelVisible(row, column)) {
                drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
            }
        }
    } else {
        Number previousValue = dataset.getValue(row, column - 1);
        if (previousValue != null) {

            double xx0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea,
                    plot.getDomainAxisEdge());
            double y0 = previousValue.doubleValue();

            // Get the previous height, but this will be different for both
            // y0 and y1 as the previous series values could differ.
            double previousHeightx0 = getPreviousHeight(dataset, row, column - 1);

            // Now stack the current y values on top of the previous values.
            y0 += previousHeightx0;

            // Now translate the previous heights
            double previousHeightxx0 = rangeAxis.valueToJava2D(previousHeightx0, dataArea, location);
            double previousHeightxx1 = rangeAxis.valueToJava2D(previousHeightx1, dataArea, location);

            // Now translate the current y values.
            double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location);

            if (pass == 0) {
                // left half
                Polygon p = new Polygon();
                p.addPoint((int) xx0, (int) yy0);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
                p.addPoint((int) xx0, (int) previousHeightxx0);

                g2.setPaint(getItemPaint(row, column - 1));
                g2.setStroke(getItemStroke(row, column - 1));
                g2.fill(p);

                if (entities != null)
                    addItemEntity(entities, dataset, row, column - 1, p);

                // right half
                p = new Polygon();
                p.addPoint((int) xx1, (int) yy1);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
                p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
                p.addPoint((int) xx1, (int) previousHeightxx1);

                g2.setPaint(getItemPaint(row, column));
                g2.setStroke(getItemStroke(row, column));
                g2.fill(p);

                if (entities != null)
                    addItemEntity(entities, dataset, row, column, p);
            } else {
                if (isItemLabelVisible(row, column)) {
                    drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
                }
            }
        }
    }
}

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

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

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

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

From source file:io.github.karols.hocr4j.PageRenderer.java

/**
 * Renders this page on the given image.
 * The image is modified, not copied.//w  w w.j  av a  2s .c o  m
 *
 * @param page page to render
 */
public void renderOnTop(@Nonnull Page page, @Nonnull BufferedImage img) {
    Graphics2D g = (Graphics2D) img.getGraphics();
    g.setColor(Color.RED);
    for (Area a : page) {
        for (Paragraph p : a) {
            for (Line l : p) {
                for (Word w : l.words) {
                    if (w.isBold()) {
                        if (w.isItalic()) {
                            g.setFont(boldItalicFont);
                        } else {
                            g.setFont(boldFont);
                        }
                    } else if (w.isItalic()) {
                        g.setFont(italicFont);
                    } else {
                        g.setFont(plainFont);
                    }
                    Bounds b = w.getBounds().scale(scale);
                    g.drawString(w.getText(), b.getLeft(), b.getBottom());
                }
            }
        }
    }
    g.setStroke(new BasicStroke(strokeWidth));
    g.setColor(defaultRectangleColor);
    for (Bounds rect : rectanglesToDraw) {
        if (rect != null) {
            Bounds b = rect.scale(scale);
            g.drawRect(b.getLeft(), b.getTop(), b.getWidth(), b.getHeight());
        }
    }
    for (Pair<Color, Bounds> rect : coloredRectanglesToDraw) {
        if (rect != null) {
            g.setColor(rect.getLeft());
            Bounds b = rect.getRight().scale(scale);
            g.drawRect(b.getLeft(), b.getTop(), b.getWidth(), b.getHeight());
        }
    }
}

From source file:msi.gama.outputs.layers.charts.FastXYItemRenderer.java

/** {@inheritDoc} */
@Override/*from  w  ww . ja v a  2 s.  c  o m*/
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    if (!getItemVisible(series, item)) {
        return;
    }
    // setup for collecting optional entity info...
    boolean bAddEntity = false;
    Shape entityArea = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    final PlotOrientation orientation = plot.getOrientation();
    final Paint paint = getItemPaint(series, item);
    final Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    final double x1 = dataset.getXValue(series, item);
    final double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        return;
    }

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

    if (getPlotLines()) {
        if (item == 0) {
            if (this.drawSeriesLineAsPath) {
                final State s = (State) state;
                s.seriesPath.reset();
                s.lastPointGood = false;
            }
            previousDrawnItem = 0;
        }

        if (this.drawSeriesLineAsPath) {
            final State s = (State) state;
            // update path to reflect latest point
            if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                // draw path
                g2.setStroke(getSeriesStroke(series));
                g2.setPaint(getSeriesPaint(series));
                g2.draw(s.seriesPath);
            }
        }

        else if (item != 0) {
            // get the previous data point...
            final double x0 = dataset.getXValue(series, item - previousDrawnItem);
            final double y0 = dataset.getYValue(series, item - previousDrawnItem);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    final int numX = dataset.getItemCount(series);
                    final double minX = dataset.getXValue(series, 0);
                    final double maxX = dataset.getXValue(series, numX - 1);
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= (maxX - minX) / numX * getGapThreshold();
                    }
                }
                if (drawLine) {
                    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

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

                    // Only draw line if it is more than a pixel away from the previous one
                    if (transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2
                            || transY1 - transY0 < -2 || 0 == previousDrawnItem) {
                        previousDrawnItem = 1;

                        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.draw(state.workingLine);
                        }
                    } else {
                        // Increase counter for the previous drawn item.
                        previousDrawnItem++;
                        bAddEntity = false;
                    }
                }
            }
        }
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            bAddEntity = true;
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        final Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            final Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        double xx = transX1;
        double yy = transY1;
        if (orientation == PlotOrientation.HORIZONTAL) {
            xx = transY1;
            yy = transX1;
        }
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y1 < 0.0);
    }

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

    // add an entity for the item...
    if (entities != null && bAddEntity) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }
}

From source file:org.uva.itast.blended.omr.scanners.SolidSquareMarkScanner.java

/**
 * @param pageImage/*from  w  w  w  . ja v  a  2 s  .c om*/
 */
public void putEmphasisMarkOnImage(PageImage pageImage, Color color) {

    Graphics2D g = pageImage.getReportingGraphics();
    // int centerColor=imagen.getRGB(maxsimX, maxsimY);
    // g.setXORMode(new Color(centerColor));
    // g.setColor(Color.RED);
    // g.fillOval(maxsimX - markWidth/2, maxsimY - markHeight/2, markWidth,
    // markHeight);
    // g.setPaintMode();
    Dimension2D markDimsPx = pageImage.sizeInPixels(new Size(markWidth, markHeight));
    int markWidth = (int) markDimsPx.getWidth();
    int markHeight = (int) markDimsPx.getHeight();
    g.setColor(color);
    AffineTransform t = g.getTransform();
    g.drawLine(maxsimX, maxsimY - markHeight / 2 - 1, maxsimX,
            maxsimY - markHeight / 2 - (int) (20 / t.getScaleY()));
    Polygon arrowHead = new Polygon();
    arrowHead.addPoint(maxsimX, (int) (maxsimY - markHeight / 2 - 1 / t.getScaleY()));
    arrowHead.addPoint((int) (maxsimX - 6 / t.getScaleX()),
            (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY()));
    arrowHead.addPoint((int) (maxsimX + 6 / t.getScaleX()),
            (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY()));
    g.fillPolygon(arrowHead);

    g.setStroke(new BasicStroke(2, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1,
            new float[] { (float) (3 / t.getScaleX()), (float) (3 / t.getScaleY()) }, 0));
    g.drawRect(maxsimX - markWidth / 2 - 1, maxsimY - markHeight / 2 - 1, markWidth + 1, markHeight + 1);

}

From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java

@Override
public void renderCellLD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY,
        int cellWidth, int cellHeight) {
    if (v == null || v.isNaN()) {
        //System.out.println(v);
        _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight);
    } else {//from   w  ww.  j a  v  a  2 s .  c o  m
        try {
            g2D.setColor(UI.colorBlack2);
            g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight);
            g2D.setColor(barColorNormal);
            g2D.setStroke(UI.stroke1_5);

            //This is the 
            //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue));
            //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight));
            if (rowNode.isSingleNode() && columnNode.isSingleNode()) {

                double value = (v - _minValue) / (_maxValue - _minValue);

                if (v >= disectBound) {
                    g2D.setColor(barColorNormal);
                } else {
                    g2D.setColor(barColorBelow);
                }

                g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * value),
                        (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * value));
            } else {

                //                    double min = percentile.evaluate(valueArray, 0);
                //                    double max = percentile.evaluate(valueArray, 100)
                double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode);
                if (fiveVal == null) {
                    g2D.setColor(UI.colorBlack1);
                    g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth),
                            Math.round(cellHeight));
                }

                double range = _maxValue - _minValue;
                double minP = (fiveVal[0] - _minValue) / range;
                double maxP = (fiveVal[4] - _minValue) / range;
                double medianP = (fiveVal[2] - _minValue) / range;
                double q1P = (fiveVal[1] - _minValue) / range;
                double q3P = (fiveVal[3] - _minValue) / range;

                try {
                    //                        if (cellWidth >= 2 && cellHeight >= 2) {
                    g2D.drawLine((int) (anchorX + cellWidth / 2),
                            (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2),
                            (int) (anchorY + cellHeight - cellHeight * minP));

                    if (fiveVal[2] >= disectBound) {
                        g2D.setColor(UI.colorLightGreen4);
                    } else {
                        g2D.setColor(UI.colorOrange2);
                    }

                    g2D.fillRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P),
                            (int) (cellWidth), (int) (cellHeight * (q3P - q1P)));

                    if (fiveVal[2] >= disectBound) {
                        g2D.setColor(barColorNormal);
                    } else {
                        g2D.setColor(barColorBelow);
                    }

                    //                        g2D.setColor(barColorNormal);
                    //g2D.drawRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth), (int) (cellHeight * (q3P - q1P)));
                    g2D.drawLine((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * medianP),
                            (int) (anchorX + cellWidth), (int) (anchorY + cellHeight - cellHeight * medianP));
                    //                        } else {
                    //
                    //                            if (fiveVal[2] >= medianP) {
                    //                                g2D.setColor(barColorNormal);
                    //                            } else {
                    //                                g2D.setColor(barColorBelow);
                    //                            }
                    //
                    ////                            System.out.println("painted rect");
                    ////                            System.out.println((int) cellWidth + " " + ((int) cellHeight));
                    //                            g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight);
                    //                        }

                } catch (Exception e) {
                    System.err.println("Boxplot render exception");
                }
            }

            //                if(cellWidth>=4 && cellHeight >=){
            //                    g2D.setColor(UI.colorBlack1);
            //                    g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight));
            //                }
        } catch (Exception e) {
        }
    }
}

From source file:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java

@SuppressWarnings("unchecked")
@Override/*  w  w  w .  jav  a  2s  .  c  om*/
public void drawTickMarks(Graphics2D g2, double cursor, Rectangle2D dataArea, RectangleEdge edge,
        AxisState state) {
    Plot p = getPlot();

    if (p == null) {
        return;
    }

    CategoryPlot plot = (CategoryPlot) p;
    double il = getTickMarkInsideLength();
    double ol = getTickMarkOutsideLength();
    Line2D line = new Line2D.Double();
    List categories = plot.getCategoriesForAxis(this);
    int tickEvery = categories.size() / (maxLabeledTicks == 0 ? 1 : maxLabeledTicks);

    if (tickEvery < 1) {
        tickEvery = 1;
    }

    if (edge.equals(RectangleEdge.TOP)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double x = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(x, cursor, x, cursor + il);
                g2.draw(line);
                line.setLine(x, cursor, x, cursor - ol);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, x);
                }
            }

            i++;
        }

        state.cursorUp(ol);
    } else if (edge.equals(RectangleEdge.BOTTOM)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double x = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(x, cursor, x, cursor - il);
                g2.draw(line);
                line.setLine(x, cursor, x, cursor + ol);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, x);
                }
            }

            i++;
        }

        state.cursorDown(ol);
    } else if (edge.equals(RectangleEdge.LEFT)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double y = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(cursor, y, cursor + il, y);
                g2.draw(line);
                line.setLine(cursor, y, cursor - ol, y);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, y);
                }
            }

            i++;
        }

        state.cursorLeft(ol);
    } else if (edge.equals(RectangleEdge.RIGHT)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double y = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(cursor, y, cursor - il, y);
                g2.draw(line);
                line.setLine(cursor, y, cursor + ol, y);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, y);
                }
            }

            i++;
        }

        state.cursorRight(ol);
    }
}

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

/**    
 * Draws the first pass shape.    /* w w  w  .  j a  v a 2  s  .c  o  m*/
 *    
 * @param g2  the graphics device.    
 * @param pass  the pass.    
 * @param series  the series index.    
 * @param item  the item index.    
 * @param shape  the shape.    
 */
protected void drawFirstPassShape(Graphics2D g2, int pass, int series, int item, Shape shape) {
    g2.setStroke(getItemStroke(series, item));
    g2.setPaint(Color.red);
    g2.draw(shape);
}

From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java

@Override
public void renderCellSD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY,
        int cellWidth, int cellHeight) {
    if (v == null || v.isNaN()) {
        //System.out.println(v);
        _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight);
    } else {//  ww  w.ja v a  2  s.co  m
        try {
            g2D.setColor(UI.colorBlack2);
            g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight);
            g2D.setColor(barColorNormal);

            //                g2D.setStroke(null);
            g2D.setStroke(UI.stroke1_5);

            //This is the 
            //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue));
            //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight));
            if (rowNode.isSingleNode() && columnNode.isSingleNode()) {

                double medianP = (v - _minValue) / (_maxValue - _minValue);
                if (v >= disectBound) {
                    g2D.setColor(barColorNormal);
                } else {
                    g2D.setColor(barColorBelow);

                }

                g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * medianP),
                        (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * medianP));
            } else {

                //                    double min = percentile.evaluate(valueArray, 0);
                //                    double max = percentile.evaluate(valueArray, 100)
                double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode);
                if (fiveVal == null) {
                    g2D.setColor(UI.colorBlack1);
                    g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth),
                            Math.round(cellHeight));
                }

                double range = _maxValue - _minValue;
                double minP = (fiveVal[0] - _minValue) / range;
                double maxP = (fiveVal[4] - _minValue) / range;
                double medianP = (fiveVal[2] - _minValue) / range;
                double q1P = (fiveVal[1] - _minValue) / range;
                double q3P = (fiveVal[3] - _minValue) / range;

                try {
                    g2D.drawLine((int) (anchorX + cellWidth / 2),
                            (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2),
                            (int) (anchorY + cellHeight - cellHeight * minP));

                    if (fiveVal[2] >= disectBound) {
                        g2D.setColor(UI.colorLightGreen4);
                    } else {
                        g2D.setColor(UI.colorOrange2);
                    }

                    g2D.fillRect((int) (anchorX + cellWidth / 4),
                            (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth / 2),
                            (int) (cellHeight * (q3P - q1P)));

                    if (fiveVal[2] >= disectBound) {
                        g2D.setColor(barColorNormal);
                    } else {
                        g2D.setColor(barColorBelow);
                    }

                    //                        g2D.setColor(barColorNormal);
                    g2D.drawRect((int) (anchorX + cellWidth / 4),
                            (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth / 2),
                            (int) (cellHeight * (q3P - q1P)));

                    g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * medianP),
                            (int) (anchorX + cellWidth - 1),
                            (int) (anchorY + cellHeight - cellHeight * medianP));
                } catch (Exception e) {
                    System.err.println("Boxplot render exception");
                }
            }

            g2D.setColor(UI.colorBlack1);
            g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth),
                    Math.round(cellHeight));
        } catch (Exception e) {
        }
    }
}