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.cuny.jfree.chart.renderer.category.ValueListShapeRenderer.java

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

    final ListCategoryDataset setData = (ListCategoryDataset) dataset;

    final List list = setData.getList(row, column);
    if (list == null) {
        return;/*  www . j a  v a  2s. c om*/
    }

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

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

        Shape shape = getItemShape(row, column);

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

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

        if (state.getInfo() != null) {
            final EntityCollection entities = state.getEntityCollection();
            if ((entities != null) && (shape != null)) {
                String tip = null;
                final CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
                if (tipster != null) {
                    tip = tipster.generateToolTip(dataset, row, column);
                }
                String url = null;
                if (getItemURLGenerator(row, column) != null) {
                    url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
                }
                final CategoryItemEntity entity = new CategoryItemEntity(shape, tip, url, dataset,
                        dataset.getRowKey(row), dataset.getColumnKey(column));
                entities.add(entity);
            }
        }
    }
}

From source file:ClipImage.java

public void drawDemo(Graphics2D g2) {

    if (newBufferedImage) {
        x = Math.random() * w;//from  w  w w.  j  ava  2 s .  c  o m
        y = Math.random() * h;
        ew = (Math.random() * w) / 2;
        eh = (Math.random() * h) / 2;
    }
    x += ix;
    y += iy;
    ew += iw;
    eh += ih;
    if (ew > w / 2) {
        ew = w / 2;
        iw = Math.random() * -w / 16 - 1;
    }
    if (ew < w / 8) {
        ew = w / 8;
        iw = Math.random() * w / 16 + 1;
    }
    if (eh > h / 2) {
        eh = h / 2;
        ih = Math.random() * -h / 16 - 1;
    }
    if (eh < h / 8) {
        eh = h / 8;
        ih = Math.random() * h / 16 + 1;
    }
    if ((x + ew) > w) {
        x = (w - ew) - 1;
        ix = Math.random() * -w / 32 - 1;
    }
    if (x < 0) {
        x = 2;
        ix = Math.random() * w / 32 + 1;
    }
    if ((y + eh) > h) {
        y = (h - eh) - 2;
        iy = Math.random() * -h / 32 - 1;
    }
    if (y < 0) {
        y = 2;
        iy = Math.random() * h / 32 + 1;
    }

    ellipse.setFrame(x, y, ew, eh);
    g2.setClip(ellipse);

    rect.setRect(x + 5, y + 5, ew - 10, eh - 10);
    g2.clip(rect);

    g2.drawImage(img, 0, 0, w, h, this);

    p.reset();
    p.moveTo(-w / 2.0f, -h / 8.0f);
    p.lineTo(+w / 2.0f, -h / 8.0f);
    p.lineTo(-w / 4.0f, +h / 2.0f);
    p.lineTo(+0.0f, -h / 2.0f);
    p.lineTo(+w / 4.0f, +h / 2.0f);
    p.closePath();

    at.setToIdentity();
    at.translate(w * .5f, h * .5f);
    g2.transform(at);
    g2.setStroke(bs);
    g2.setPaint(redBlend);
    g2.draw(p);

    at.setToIdentity();
    g2.setTransform(at);

    g2.setPaint(greenBlend);

    for (int yy = 0; yy < h; yy += 50) {
        for (int xx = 0, i = 0; xx < w; i++, xx += 50) {
            switch (i) {
            case 0:
                arc.setArc(xx, yy, 25, 25, 45, 270, Arc2D.PIE);
                g2.fill(arc);
                break;
            case 1:
                ellipse.setFrame(xx, yy, 25, 25);
                g2.fill(ellipse);
                break;
            case 2:
                roundRect.setRoundRect(xx, yy, 25, 25, 4, 4);
                g2.fill(roundRect);
                break;
            case 3:
                rect.setRect(xx, yy, 25, 25);
                g2.fill(rect);
                i = -1;
            }

        }
    }
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java

@Override
public void paint(Graphics2D g, StateRenderer2D renderer) {
    double radius = isActive() ? 6 : 2.5;
    for (AssetTrack track : assets.values()) {
        List<AssetPosition> positions = track.getTrack();
        Point2D lastLoc = null;/* w  ww.  j a v  a2  s .  co m*/
        long lastAge = 0;
        for (AssetPosition p : positions) {
            if (hiddenPosTypes.contains(p.getType()))
                continue;

            if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection)
                continue;

            //if (p.getAge() >= maxAge * 3600 * 1000)
            //    continue;
            Point2D pt = renderer.getScreenPosition(p.getLoc());
            if (assetProperties.containsKey(track.getAssetName()))
                g.setColor(assetProperties.get(track.getAssetName()).color);
            else
                g.setColor(track.getColor());
            if (lastLoc != null && lastLoc.distance(pt) < 20000) {
                g.draw(new Line2D.Double(lastLoc, pt));
            }
            g.fill(new Ellipse2D.Double(pt.getX() - radius, pt.getY() - radius, radius * 2, radius * 2));
            lastLoc = pt;
            lastAge = p.getAge();
        }
        g.setStroke(new BasicStroke(2.0f));
        if (lastLoc != null) {
            Color c = cmap2.getColor(1 - (lastAge / (7200000.0)));
            g.setColor(c);
            g.setStroke(new BasicStroke(2.0f));
            g.draw(new Ellipse2D.Double(lastLoc.getX() - radius - 1.5, lastLoc.getY() - radius - 1.5,
                    radius * 2 + 3, radius * 2 + 3));
        }
    }

    if (paintLabels)
        paintLabels(g, renderer);

    if (paintIcons)
        paintIcons(g, renderer);
}

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

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

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

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

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

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

    PlotOrientation orientation = plot.getOrientation();

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

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

From source file:org.squidy.designer.zoom.ActionShape.java

@Override
protected void paintShapeZoomedIn(PPaintContext paintContext) {

    Graphics2D g = paintContext.getGraphics();
    RectangularShape r = (RectangularShape) getZoomedOutShape();
    if (r instanceof RoundRectangle2D) {

        // int width = (int)(r.getMaxX()-r.getMinX());
        // int height = (int)(r.getMaxY()-r.getMinY());
        // BufferedImage shadeStarted = new BufferedImage(width, height,
        // BufferedImage.TYPE_INT_RGB);
        // BufferedImage shadeStopped = new BufferedImage(width, height,
        // BufferedImage.TYPE_INT_RGB);
        // BufferedImage shadeFailure = new BufferedImage(width, height,
        // BufferedImage.TYPE_INT_RGB);
        // shadeStarted.getGraphics().setColor(COLOR_STARTED);
        // shadeStopped.getGraphics().setColor(COLOR_STOPPED);
        // shadeFailure.getGraphics().setColor(COLOR_FAILURE);
        // shadeStarted.getGraphics().fillRect(0, 0, width, height);
        // shadeStopped.getGraphics().fillRect(0, 0, width, height);
        // shadeFailure.getGraphics().fillRect(0, 0, width, height);

        // g.setStroke(STROKE_ZOOMED_IN);
        g.setStroke(StrokeUtils.getBasicStroke(7f));

        g.setColor(failure ? COLOR_FAILURE : started ? COLOR_STARTED : COLOR_STOPPED);

        if (polygonRendering) {

            if (isRenderPrimitiveRect()) {
                if (!isHierarchicalZoomInProgress()) {

                    Polygon shadeHorizontal = new Polygon();
                    Polygon shadeVertical = new Polygon();

                    double shift = 1;
                    shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                            r.getMaxY() + shift);
                    Rectangle bounds = shapeZoomedIn.getBounds();
                    shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height);
                    shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shift = 5;//from   w  w  w.  ja va  2  s  .c om
                    shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                            r.getMaxY() + shift);
                    bounds = shapeZoomedIn.getBounds();
                    shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height);
                    shadeVertical.addPoint(bounds.x + bounds.width, bounds.y);
                    g.fillPolygon(shadeHorizontal);
                    g.fillPolygon(shadeVertical);
                }

            } else {
                g.draw(shapeZoomedIn);
            }

        } else {

            for (double shift = 6.; shift >= 1.; shift -= 1.) {
                shapeZoomedIn.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift,
                        r.getMaxY() + shift);
                if (isRenderPrimitiveRect()) {
                    if (!isHierarchicalZoomInProgress()) {
                        Rectangle bounds = shapeZoomedIn.getBounds();
                        // g.drawImage(shadeStarted,null,bounds.x,
                        // bounds.y);
                        // g.fillRect(bounds.x, bounds.y, bounds.width,
                        // bounds.height);
                        g.drawLine(bounds.x + 1, bounds.y + bounds.height, bounds.x + bounds.width - 3,
                                bounds.y + bounds.height);
                        g.drawLine(bounds.x + bounds.width, bounds.y + 1, bounds.x + bounds.width,
                                bounds.y + bounds.height - 3);
                    }
                } else {
                    g.draw(shapeZoomedIn);
                }
            }

        }

    }
    super.paintShapeZoomedIn(paintContext);
}

From source file:ClipImage.java

public void drawDemo(Graphics2D g2) {
    if (newBufferedImage) {
        x = Math.random() * w;/*from  w w  w .  ja v a2s.c  o m*/
        y = Math.random() * h;
        ew = (Math.random() * w) / 2;
        eh = (Math.random() * h) / 2;
    }
    x += ix;
    y += iy;
    ew += iw;
    eh += ih;
    if (ew > w / 2) {
        ew = w / 2;
        iw = Math.random() * -w / 16 - 1;
    }
    if (ew < w / 8) {
        ew = w / 8;
        iw = Math.random() * w / 16 + 1;
    }
    if (eh > h / 2) {
        eh = h / 2;
        ih = Math.random() * -h / 16 - 1;
    }
    if (eh < h / 8) {
        eh = h / 8;
        ih = Math.random() * h / 16 + 1;
    }
    if ((x + ew) > w) {
        x = (w - ew) - 1;
        ix = Math.random() * -w / 32 - 1;
    }
    if (x < 0) {
        x = 2;
        ix = Math.random() * w / 32 + 1;
    }
    if ((y + eh) > h) {
        y = (h - eh) - 2;
        iy = Math.random() * -h / 32 - 1;
    }
    if (y < 0) {
        y = 2;
        iy = Math.random() * h / 32 + 1;
    }

    ellipse.setFrame(x, y, ew, eh);
    g2.setClip(ellipse);

    rect.setRect(x + 5, y + 5, ew - 10, eh - 10);
    g2.clip(rect);

    g2.drawImage(img, 0, 0, w, h, this);

    p.reset();
    p.moveTo(-w / 2.0f, -h / 8.0f);
    p.lineTo(+w / 2.0f, -h / 8.0f);
    p.lineTo(-w / 4.0f, +h / 2.0f);
    p.lineTo(+0.0f, -h / 2.0f);
    p.lineTo(+w / 4.0f, +h / 2.0f);
    p.closePath();

    at.setToIdentity();
    at.translate(w * .5f, h * .5f);
    g2.transform(at);
    g2.setStroke(bs);
    g2.setPaint(redBlend);
    g2.draw(p);

    at.setToIdentity();
    g2.setTransform(at);

    g2.setPaint(greenBlend);

    for (int yy = 0; yy < h; yy += 50) {
        for (int xx = 0, i = 0; xx < w; i++, xx += 50) {
            switch (i) {
            case 0:
                arc.setArc(xx, yy, 25, 25, 45, 270, Arc2D.PIE);
                g2.fill(arc);
                break;
            case 1:
                ellipse.setFrame(xx, yy, 25, 25);
                g2.fill(ellipse);
                break;
            case 2:
                roundRect.setRoundRect(xx, yy, 25, 25, 4, 4);
                g2.fill(roundRect);
                break;
            case 3:
                rect.setRect(xx, yy, 25, 25);
                g2.fill(rect);
                i = -1;
            }

        }
    }
}

From source file:org.earthtime.UPb_Redux.dateInterpretation.WeightedMeanGraphPanel.java

private void drawAxesAndTicks(Graphics2D g2d, double rangeX, double rangeY) {

    // oct 2014 new tic logic
    // reset the clip bounds to paint axis and numbers
    g2d.setClip(0, 0, getWidth(), getHeight());

    g2d.setFont(new Font("Monospaced", Font.BOLD, 14));
    g2d.setPaint(Color.BLACK);//  ww  w  . j av a2  s  .  co  m
    g2d.setStroke(new BasicStroke(2.0f));

    // determine the axis ticks
    BigDecimal[] tics = TicGeneratorForAxes.generateTics(getMinY_Display(), getMaxY_Display(), 12);
    // trap for bad plot
    if (tics.length <= 1) {
        tics = new BigDecimal[0];
    }
    double minXDisplay = 0.0;
    int yAxisTicWidth = 8;
    int yTicLabelFrequency = 2;
    int labeledTicCountYAxis = 0;

    g2d.setPaint(Color.black);
    for (int i = 0; i < tics.length; i++) {

        double y = tics[i].doubleValue();

        if ((y > getMinY_Display()) // dont print across mappedX axis
                && (y < getMaxY_Display())) // dont print across top border
        {
            try {
                Shape ticMark = new Line2D.Double( //
                        mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth),
                        mapY(y, getMaxY_Display(), rangeY, graphHeight),
                        mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) + 7,
                        mapY(y, getMaxY_Display(), rangeY, graphHeight));
                g2d.draw(ticMark);

                String intString = "00000" + tics[i].toPlainString().replace(".", "");
                int lastPlace = Integer.parseInt(intString.substring(intString.length() - 4));

                if (lastPlace % yTicLabelFrequency == 0) {
                    if (labeledTicCountYAxis % yTicLabelFrequency == 0) {

                        TextLayout mLayout = //
                                new TextLayout(tics[i].toPlainString(), g2d.getFont(),
                                        g2d.getFontRenderContext());

                        Rectangle2D bounds = mLayout.getBounds();

                        //if (isyAxisHorizontalTicLabels()) {
                        //                            g2d.drawString(tics[i].toPlainString(),//
                        //                                    (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
                        //                                    (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f);
                        //                            } else {
                        float yLabelCenterOffset = (float) mLayout.getBounds().getWidth() / 2f;

                        g2d.rotate(-Math.PI / 2.0,
                                (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
                                (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset);
                        g2d.drawString(tics[i].toPlainString(),
                                (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
                                (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset);
                        g2d.rotate(Math.PI / 2.0,
                                (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
                                (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset);
                    }

                    labeledTicCountYAxis++;
                } else {

                    if (labeledTicCountYAxis > 0) {
                        labeledTicCountYAxis++;
                    }
                }
            } catch (Exception e) {
            }
        }
    }

    ////        // reset the clip bounds to paint axis and numbers
    ////        g2d.setClip(0, 0, getWidth(), getHeight());
    ////
    ////        g2d.setFont(new Font("Monospaced", Font.BOLD, 14));
    ////        g2d.setPaint(Color.BLACK);
    ////        g2d.setStroke(new BasicStroke(2.0f));
    ////
    ////        // determine the axis ticks
    ////        double minYtick = Math.ceil(getMinY_Display() * 100) / 100;
    ////        double maxYtick = Math.floor(getMaxY_Display() * 100) / 100;
    ////
    ////        int count = 0;
    ////        double deltay = Math.rint((maxYtick - minYtick) * 10 + 0.5);
    ////        double stepYtick = deltay / 100;
    ////
    ////        for (double y = minYtick; y
    ////                < maxYtick; y
    ////                += stepYtick) {
    ////            Line2D line = new Line2D.Double(
    ////                    mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth),
    ////                    mapY(y, getMaxY_Display(), rangeY, graphHeight),
    ////                    mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) + 7,
    ////                    mapY(y, getMaxY_Display(), rangeY, graphHeight));
    ////            g2d.draw(line);
    ////
    ////            if ((count % 2) == 1) {
    ////                NumberFormat yFormat = null;
    ////                String temp = null;
    ////
    ////                yFormat
    ////                        = new DecimalFormat("0.00");
    ////                temp
    ////                        = yFormat.format(y);
    ////
    ////                g2d.setPaint(Color.black);
    ////                g2d.rotate(
    ////                        -Math.PI / 2.0,
    ////                        (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
    ////                        (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f);
    ////                g2d.drawString(
    ////                        temp,
    ////                        (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
    ////                        (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f);
    ////                g2d.rotate(
    ////                        Math.PI / 2.0,
    ////                        (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f,
    ////                        (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f);
    ////
    ////            }
    ////
    ////            count++;
    ////
    ////        }
    // draw and label axes
    g2d.setFont(new Font("Monospaced", Font.BOLD, 20));
    g2d.drawRect(getLeftMargin(), getTopMargin(), getGraphWidth() - 1, getGraphHeight() - 1);

}

From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java

private void drawDestinationElement(final Graphics2D g, final MindMapPanelConfig cfg) {
    if (this.destinationElement != null && this.draggedElement != null) {
        g.setColor(new Color((cfg.getSelectLineColor().getRGB() & 0xFFFFFF) | 0x80000000, true));
        g.setStroke(new BasicStroke(this.config.safeScaleFloatValue(3.0f, 0.1f)));

        final Rectangle2D rectToDraw = new Rectangle2D.Double();
        rectToDraw.setRect(this.destinationElement.getBounds());
        final double selectLineGap = cfg.getSelectLineGap() * 3.0d * cfg.getScale();
        rectToDraw.setRect(rectToDraw.getX() - selectLineGap, rectToDraw.getY() - selectLineGap,
                rectToDraw.getWidth() + selectLineGap * 2, rectToDraw.getHeight() + selectLineGap * 2);

        final int position = calcDropPosition(this.destinationElement, this.draggedElement.getPosition());

        boolean draw = !this.draggedElement.isPositionInside()
                && !this.destinationElement.getModel().hasAncestor(this.draggedElement.getElement().getModel());

        switch (this.draggedElement.getModifier()) {
        case NONE: {
            switch (position) {
            case DRAG_POSITION_TOP: {
                rectToDraw.setRect(rectToDraw.getX(), rectToDraw.getY(), rectToDraw.getWidth(),
                        rectToDraw.getHeight() / 2);
            }/*from w  w w .jav  a 2 s .  c  om*/
                break;
            case DRAG_POSITION_BOTTOM: {
                rectToDraw.setRect(rectToDraw.getX(), rectToDraw.getY() + rectToDraw.getHeight() / 2,
                        rectToDraw.getWidth(), rectToDraw.getHeight() / 2);
            }
                break;
            case DRAG_POSITION_LEFT: {
                rectToDraw.setRect(rectToDraw.getX(), rectToDraw.getY(), rectToDraw.getWidth() / 2,
                        rectToDraw.getHeight());
            }
                break;
            case DRAG_POSITION_RIGHT: {
                rectToDraw.setRect(rectToDraw.getX() + rectToDraw.getWidth() / 2, rectToDraw.getY(),
                        rectToDraw.getWidth() / 2, rectToDraw.getHeight());
            }
                break;
            default:
                draw = false;
                break;
            }
        }
            break;
        case MAKE_JUMP: {
        }
            break;
        default:
            throw new Error("Unexpected state " + this.draggedElement.getModifier());
        }

        if (draw) {
            g.fill(rectToDraw);
        }
    }
}

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

/**
 * Connect intervals i1 and i2 with a dashed line to show mates.
 *///from   www .j  a v  a 2s.c o  m
private void connectPiledInterval(Graphics2D g2, GraphPaneAdapter gp, Interval i1, Interval i2, int level,
        Color linecolor, IntervalRecord ir1, IntervalRecord ir2) {
    Interval mateInterval = computeMateInterval(i1, i2);

    Stroke currentStroke = g2.getStroke();
    //Stroke drawingStroke = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0);
    Stroke drawingStroke = new BasicStroke(1);
    double yPos = gp.transformYPos(0) - (level + 1) * gp.getUnitHeight() + gp.getUnitHeight() / 2.0
            - gp.getOffset();

    Line2D line = new Line2D.Double(gp.transformXPos(mateInterval.getStart()) + arrowWidth, yPos,
            gp.transformXPos(mateInterval.getEnd()) - arrowWidth, yPos);
    g2.setStroke(drawingStroke);
    g2.setColor(linecolor);
    g2.draw(line);
    g2.setStroke(currentStroke);//reset stroke

    Rectangle2D bound = new Rectangle2D.Double(
            Math.min(gp.transformXPos(mateInterval.getStart()), gp.transformXPos(mateInterval.getEnd())),
            yPos - gp.getUnitHeight() / 2.0,
            Math.abs(gp.transformXPos(mateInterval.getEnd()) - gp.transformXPos(mateInterval.getStart())),
            gp.getUnitHeight());
    if (ir1 != null) {
        artifactMap.put(ir1, bound);
    }
    if (ir2 != null) {
        artifactMap.put(ir2, bound);
    }

}

From source file:edu.cuny.jfree.chart.annotations.CategoryIntervalAnnotation.java

public void draw(final Graphics2D g2, final CategoryPlot plot, final Rectangle2D dataArea,
        final CategoryAxis domainAxis, final ValueAxis rangeAxis) {

    final AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            plot.getForegroundAlpha());//from   w  ww  . j  a  v a 2 s.c o m
    final Composite oldComposite = g2.getComposite();
    g2.setComposite(alphaComposite);

    final CategoryDataset dataset = plot.getDataset();
    final int catIndex = dataset.getColumnIndex(category);
    final int catCount = dataset.getColumnCount();
    double lineX1 = 0.0D;
    double lineY = 0.0D;
    double lineX2 = 0.0D;
    final PlotOrientation orientation = plot.getOrientation();
    final RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    final RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        lineY = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea,
                domainEdge);
        lineX1 = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge);
        lineX2 = rangeAxis.valueToJava2D(value2, dataArea, rangeEdge);
    } else if (orientation == PlotOrientation.VERTICAL) {
        lineY = rangeAxis.valueToJava2D(value1, dataArea, rangeEdge);
        lineX1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea,
                domainEdge);
        lineX2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex, catCount, dataArea,
                domainEdge);
    }
    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.drawLine((int) lineX1, (int) lineY, (int) lineX2, (int) lineY);

    g2.setComposite(oldComposite);
}