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:org.deegree.services.wps.provider.jrxml.contentprovider.map.MapContentProvider.java

private void prepareScaleBar(Map<String, Object> params, String scalebarKey, XMLAdapter jrxmlAdapter,
        List<OrderedDatasource<?>> datasources, String type, Envelope bbox, double mapWidth)
        throws ProcessletException {

    OMElement sbRep = jrxmlAdapter.getElement(jrxmlAdapter.getRootElement(), new XPath(
            ".//jasper:image[jasper:imageExpression/text()='$P{" + scalebarKey + "}']/jasper:reportElement",
            nsContext));// w  w w  .jav  a2  s .  c  om

    if (sbRep != null) {
        // TODO: rework this!
        LOG.debug("Found scalebar with key '" + scalebarKey + "'.");
        int w = jrxmlAdapter.getRequiredNodeAsInteger(sbRep, new XPath("@width", nsContext));
        int h = jrxmlAdapter.getRequiredNodeAsInteger(sbRep, new XPath("@height", nsContext));
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = img.createGraphics();

        String fontName = null;
        int fontSize = 8;
        int desiredWidth = w - 30;
        // calculate scale bar max scale and size
        int length = 0;
        double lx = 0;
        double scale = 0;
        for (int i = 0; i < 100; i++) {
            double k = 0;
            double dec = 30 * Math.pow(10, i);
            for (int j = 0; j < 9; j++) {
                k += dec;
                double tx = -k * (mapWidth / bbox.getSpan0());
                if (Math.abs(tx - lx) < desiredWidth) {
                    length = (int) Math.round(Math.abs(tx - lx));
                    scale = k;
                } else {
                    break;
                }
            }
        }
        // draw scale bar base line
        g.setStroke(new BasicStroke((desiredWidth + 30) / 250));
        g.setColor(Color.black);
        g.drawLine(10, 30, length + 10, 30);
        double dx = length / 3d;
        double vdx = scale / 3;
        double div = 1;
        String uom = "m";
        if (scale > 1000) {
            div = 1000;
            uom = "km";
        }
        // draw scale bar scales
        if (fontName == null) {
            fontName = "SANS SERIF";
        }
        g.setFont(new Font(fontName, Font.PLAIN, fontSize));
        DecimalFormat df = new DecimalFormat("##.# ");
        DecimalFormat dfWithUom = new DecimalFormat("##.# " + uom);
        for (int i = 0; i < 4; i++) {
            String label = i < 3 ? df.format((vdx * i) / div) : dfWithUom.format((vdx * i) / div);
            g.drawString(label, (int) Math.round(10 + i * dx) - 8, 10);
            g.drawLine((int) Math.round(10 + i * dx), 30, (int) Math.round(10 + i * dx), 20);
        }
        for (int i = 0; i < 7; i++) {
            g.drawLine((int) Math.round(10 + i * dx / 2d), 30, (int) Math.round(10 + i * dx / 2d), 25);
        }
        g.dispose();
        params.put(scalebarKey, convertImageToReportFormat(type, img));
        LOG.debug("added scalebar");
    }
}

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

@Override
protected void paintShapeZoomedIn(PPaintContext paintContext) {
    super.paintShapeZoomedIn(paintContext);

    if (getInputPort().getVisible() || getOutputPort().getVisible()) {
        Graphics2D g = paintContext.getGraphics();
        PBounds bounds = getBoundsReference();
        double x = bounds.getX();
        double y = bounds.getY();
        double centerY = bounds.getCenterY();
        double width = bounds.getWidth();

        // Paint a border for zoom ports.
        // g.setStroke(new BasicStroke(6f));

        // g.setColor(Color.RED);
        // g.draw(getBoundsReference());

        // Painting left port.
        if (getInputPort().getVisible()) {

            if (shapePortLeft == null) {
                double portScale = inputPort.getScale();
                double portWidth = inputPort.getWidth() * portScale;
                double portHeight = inputPort.getHeight() * portScale;

                shapePortLeft = new RoundRectangle2D.Double(x - portWidth + 15, centerY - portHeight / 2 - 5,
                        35, 60, 10, 10);
            }//from w ww  .  j  av  a  2  s  . c  o m

            Rectangle boundsPort = shapePortLeft.getBounds();
            g.setColor(Constants.Color.COLOR_SHAPE_BACKGROUND);
            if (isRenderPrimitiveRect())
                g.fillRect(boundsPort.x, boundsPort.y, boundsPort.width, boundsPort.height);
            else
                g.fill(shapePortLeft);

            g.setColor(Constants.Color.COLOR_SHAPE_BORDER);
            g.setStroke(StrokeUtils.getBasicStroke(3f));
            if (isRenderPrimitiveRect())
                g.drawRect(boundsPort.x, boundsPort.y, boundsPort.width, boundsPort.height);
            else
                g.draw(shapePortLeft);
        }

        // Painting right port.
        if (getOutputPort().getVisible()) {

            if (shapePortRight == null) {
                double portScale = outputPort.getScale();
                double portWidth = outputPort.getWidth() * portScale;
                double portHeight = outputPort.getHeight() * portScale;

                shapePortRight = new RoundRectangle2D.Double(x + width - portWidth - 21,
                        centerY - portHeight / 2 - 5, 35, 60, 10, 10);
            }

            Rectangle boundsPort = shapePortRight.getBounds();
            g.setColor(Constants.Color.COLOR_SHAPE_BACKGROUND);
            if (isRenderPrimitiveRect())
                g.fillRect(boundsPort.x, boundsPort.y, boundsPort.width, boundsPort.height);
            else
                g.fill(shapePortRight);

            g.setColor(Constants.Color.COLOR_SHAPE_BORDER);
            g.setStroke(StrokeUtils.getBasicStroke(3f));
            if (isRenderPrimitiveRect())
                g.drawRect(boundsPort.x, boundsPort.y, boundsPort.width, boundsPort.height);
            else
                g.draw(shapePortRight);
        }
    }
}

From source file:org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.java

private void paintHydrographInMap(final Graphics g) {
    final Graphics2D g2 = (Graphics2D) g;
    final GM_Point point = (GM_Point) m_selectedHydrograph.getLocation();
    final IMapPanel mapPanel = getMapPanel();

    if (mapPanel == null)
        return;// w  w w.j av  a2 s.c o m

    final GeoTransform projection = mapPanel.getProjection();
    if (projection == null || point == null)
        return;

    final int x = (int) projection.getDestX(point.getX());
    final int y = (int) projection.getDestY(point.getY());

    final int sizeOuter = 16;
    final Color defaultColor = g2.getColor();
    final Color color = new Color(255, 30, 30);
    g2.setColor(color);

    final Stroke defaultStroke = g2.getStroke();
    final BasicStroke stroke = new BasicStroke(3);
    g2.setStroke(stroke);

    g2.drawRect(x - sizeOuter / 2, y - sizeOuter / 2, sizeOuter, sizeOuter);

    g2.setColor(defaultColor);
    g2.setStroke(defaultStroke);
}

From source file:net.geoprism.dashboard.DashboardMap.java

/**
 * Builds an image layer of all the layers in a SavedMap.
 * /*from   w w w. j  av a 2  s.  c om*/
 * @mapWidth
 * @mapHeight
 */
private BufferedImage getLegendExportCanvas(int mapWidth, int mapHeight) {
    int padding = 2;
    BufferedImage base = null;
    Graphics mapBaseGraphic = null;
    Color innerBackgroundColor = Color.darkGray;
    Color outerBorderColor = Color.black;
    int legendTopPlacement = 0;
    int legendLeftPlacement = 0;
    int widestLegend = 0;
    int legendXPosition = 0;
    int legendYPosition = 0;

    List<? extends DashboardLayer> layers = this.getAllHasLayer().getAll();

    try {
        base = new BufferedImage(mapWidth, mapHeight, BufferedImage.TYPE_INT_ARGB);
        mapBaseGraphic = base.getGraphics();
        mapBaseGraphic.drawImage(base, 0, 0, null);

        // Generates map overlays and combines them into a single map image
        for (DashboardLayer layer : layers) {
            if (layer.getDisplayInLegend()) {
                Graphics2D titleBaseGraphic = null;
                Graphics2D iconGraphic = null;

                String requestURL = getLegendURL(layer);

                try {
                    // handle color graphics and categories
                    BufferedImage titleBase = getLegendTitleImage(layer);
                    titleBaseGraphic = titleBase.createGraphics();
                    int paddedTitleWidth = titleBase.getWidth();
                    int paddedTitleHeight = titleBase.getHeight();

                    BufferedImage icon = getImageFromGeoserver(requestURL);
                    int iconHeight = icon.getHeight();
                    int iconWidth = icon.getWidth();
                    int paddedIconWidth = iconWidth + (padding * 2);
                    int paddedIconHeight = iconHeight + (padding * 2);

                    int fullWidth = paddedIconWidth + paddedTitleWidth;
                    int fullHeight;
                    if (paddedIconHeight >= paddedTitleHeight) {
                        fullHeight = paddedIconHeight;
                    } else {
                        fullHeight = paddedTitleHeight;
                    }

                    DashboardLegend legend = layer.getDashboardLegend();
                    if (legend.getGroupedInLegend()) {
                        if (legendTopPlacement + fullHeight >= mapHeight) {
                            legendLeftPlacement = widestLegend + legendLeftPlacement + padding;
                            legendTopPlacement = 0; // reset so 2nd column legends start at the top row
                        }
                        legendXPosition = legendLeftPlacement + padding;
                        legendYPosition = legendTopPlacement + padding;
                    } else {
                        legendXPosition = (int) Math.round((double) legend.getLegendXPosition());
                        legendYPosition = (int) Math.round((double) legend.getLegendYPosition());
                    }

                    BufferedImage legendBase = new BufferedImage(fullWidth + (padding * 2),
                            fullHeight + (padding * 2), BufferedImage.TYPE_INT_ARGB);
                    Graphics2D legendBaseGraphic = legendBase.createGraphics();
                    legendBaseGraphic.setColor(innerBackgroundColor);
                    legendBaseGraphic.fillRect(0, 0, fullWidth, fullHeight);
                    legendBaseGraphic.setColor(outerBorderColor);
                    legendBaseGraphic.setStroke(new BasicStroke(5));
                    legendBaseGraphic.drawRect(0, 0, fullWidth, fullHeight);

                    legendBaseGraphic.drawImage(icon, padding, padding, paddedIconWidth, paddedIconHeight,
                            null);
                    legendBaseGraphic.drawImage(titleBase, paddedIconWidth + (padding * 2),
                            (fullHeight / 2) - (paddedTitleHeight / 2), paddedTitleWidth, paddedTitleHeight,
                            null);
                    mapBaseGraphic.drawImage(legendBase, legendXPosition, legendYPosition, fullWidth,
                            fullHeight, null);

                    if (legend.getGroupedInLegend()) {
                        legendTopPlacement = legendTopPlacement + fullHeight + padding;
                    }

                    if (fullWidth > widestLegend) {
                        widestLegend = fullWidth;
                    }
                } finally {
                    if (titleBaseGraphic != null) {
                        titleBaseGraphic.dispose();
                    }

                    if (iconGraphic != null) {
                        iconGraphic.dispose();
                    }
                }
            }
        }
    } finally {
        mapBaseGraphic.dispose();
    }

    return base;
}

From source file:org.squidy.designer.zoom.impl.DataTypeShape.java

@Override
protected void paintShapeZoomedOut(PPaintContext paintContext) {
    Graphics2D g = paintContext.getGraphics();

    if (dataTypes != null && dataTypes.size() > 0) {
        int i = 0;

        alreadyPaintedHighLevelDataTypes.clear();
        for (Class<? extends IData> type : dataTypes) {

            if (type.isAssignableFrom(IData.class)) {
                continue;
            }//from  w  w w. j a  va  2  s.c  o m

            Class<? extends IData> highLevelDataType = DataUtility.getHighLevelDataType(type);

            if (alreadyPaintedHighLevelDataTypes.contains(highLevelDataType)) {
                continue;
            }

            Color color;
            if (!COLOR_CACHE.containsKey(highLevelDataType)) {
                DataType dataType = highLevelDataType.getAnnotation(DataType.class);
                int[] colorScheme = dataType.color();
                color = new Color(colorScheme[0], colorScheme[1], colorScheme[2], colorScheme[3]);
                COLOR_CACHE.put(highLevelDataType, color);
            } else {
                color = COLOR_CACHE.get(highLevelDataType);
            }

            translationArrow.setToTranslation(i * 750, 0);
            paintContext.pushTransform(translationArrow);

            g.setColor(color);
            g.fill(arrowShape);

            g.setStroke(STROKE_ARROW_BOLD);
            g.setColor(Color.BLACK);
            g.draw(arrowShape);

            paintContext.popTransform(translationArrow);

            alreadyPaintedHighLevelDataTypes.add(highLevelDataType);

            i++;
        }
    } else {
        drawNoDataType(g);
    }

    // g.setColor(Color.BLACK);
    // g.setStroke(StrokeUtils.getBasicStroke(105f));
    // g.draw(getGlobalBoundsZoomedIn());
}

From source file:org.dwfa.ace.graph.AceGraphRenderer.java

/**
 * Paints the vertex <code>v</code> at the location <code>(x,y)</code> on
 * the graphics context <code>g_gen</code>. The vertex is painted
 * using the shape returned by this instance's
 * <code>VertexShapeFunction</code>,
 * and the foreground and background (border) colors provided by this
 * instance's <code>VertexColorFunction</code>. Delegates drawing the
 * label (if any) for this vertex to <code>labelVertex</code>.
 *///  w  w w .  ja v a  2s.  c o m
public void paintVertex(Graphics g, Vertex v, int x, int y) {
    if (!vertexIncludePredicate.evaluate(v))
        return;

    boolean vertexHit = true;
    Rectangle deviceRectangle = null;
    Graphics2D g2d = (Graphics2D) g;
    if (screenDevice != null) {
        Dimension d = screenDevice.getSize();
        if (d.width <= 0 || d.height <= 0) {
            d = screenDevice.getPreferredSize();
        }
        deviceRectangle = new Rectangle(0, 0, d.width, d.height);
    }

    Stroke old_stroke = g2d.getStroke();
    Stroke new_stroke = vertexStrokeFunction.getStroke(v);
    if (new_stroke != null) {
        g2d.setStroke(new_stroke);
    }
    // get the shape to be rendered
    Shape s = vertexShapeFunction.getShape(v);

    // create a transform that translates to the location of
    // the vertex to be rendered
    AffineTransform xform = AffineTransform.getTranslateInstance(x, y);
    // transform the vertex shape with xtransform
    s = xform.createTransformedShape(s);

    if (deviceRectangle == null) {
        vertexHit = false;
    } else {
        vertexHit = viewTransformer.transform(s).intersects(deviceRectangle);
    }

    if (vertexHit) {

        if (vertexShapeRendered) {
            if (vertexIconFunction != null) {
                paintIconForVertex(g2d, v, x, y);
            } else {
                paintShapeForVertex(g2d, v, s);
            }
        }

        if (new_stroke != null) {
            g2d.setStroke(old_stroke);
        }
        String label = vertexStringer.getLabel(v);
        if (label != null) {
            labelVertex(g, v, label, x, y);
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java

protected void processOtherNode(final RenderNode node) {
    if (node.isNodeVisible(drawArea) == false) {
        return;//from   w ww  .ja va2  s.c om
    }

    final int type = node.getNodeType();
    if (isTextLineOverflow()) {
        if (node.isVirtualNode()) {
            if (ellipseDrawn == false) {
                if (isClipOnWordBoundary() == false && type == LayoutNodeTypes.TYPE_NODE_TEXT) {
                    final RenderableText text = (RenderableText) node;
                    final long ellipseSize = extractEllipseSize(node);
                    final long x1 = text.getX();
                    final long effectiveAreaX2 = (contentAreaX2 - ellipseSize);

                    if (x1 < contentAreaX2) {
                        // The text node that is printed will overlap with the ellipse we need to print.
                        drawText(text, effectiveAreaX2);
                    }
                } else if (isClipOnWordBoundary() == false && type == LayoutNodeTypes.TYPE_NODE_COMPLEX_TEXT) {
                    final RenderableComplexText text = (RenderableComplexText) node;
                    // final long ellipseSize = extractEllipseSize(node);
                    final long x1 = text.getX();
                    // final long effectiveAreaX2 = (contentAreaX2 - ellipseSize);

                    if (x1 < contentAreaX2) {
                        // The text node that is printed will overlap with the ellipse we need to print.
                        final Graphics2D g2;
                        if (getTextSpec() == null) {
                            g2 = (Graphics2D) getGraphics().create();
                            final StyleSheet layoutContext = text.getStyleSheet();
                            configureGraphics(layoutContext, g2);
                            g2.setStroke(LogicalPageDrawable.DEFAULT_STROKE);

                            if (RenderUtility.isFontSmooth(layoutContext, metaData)) {
                                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                                        RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                            } else {
                                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                                        RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
                            }
                        } else {
                            g2 = getTextSpec().getGraphics();
                        }

                        drawComplexText(text, g2);
                    }
                }

                ellipseDrawn = true;

                final RenderBox parent = node.getParent();
                if (parent != null) {
                    final RenderBox textEllipseBox = parent.getTextEllipseBox();
                    if (textEllipseBox != null) {
                        processBoxChilds(textEllipseBox);
                    }
                }
                return;
            }
        }
    }

    if (type == LayoutNodeTypes.TYPE_NODE_TEXT) {
        final RenderableText text = (RenderableText) node;
        if (underline != null) {
            final ExtendedBaselineInfo baselineInfo = text.getBaselineInfo();
            final long underlinePos = text.getY() + baselineInfo.getUnderlinePosition();
            underline.updateVerticalPosition(StrictGeomUtility.toExternalValue(underlinePos));
            underline.updateStart(StrictGeomUtility.toExternalValue(text.getX()));
            underline.updateEnd(StrictGeomUtility.toExternalValue(text.getX() + text.getWidth()));
        }

        if (strikeThrough != null) {
            final ExtendedBaselineInfo baselineInfo = text.getBaselineInfo();
            final long strikethroughPos = text.getY() + baselineInfo.getStrikethroughPosition();
            strikeThrough.updateVerticalPosition(StrictGeomUtility.toExternalValue(strikethroughPos));
            strikeThrough.updateStart(StrictGeomUtility.toExternalValue(text.getX()));
            strikeThrough.updateEnd(StrictGeomUtility.toExternalValue(text.getX() + text.getWidth()));
        }

        if (isTextLineOverflow()) {
            final long ellipseSize = extractEllipseSize(node);
            final long x1 = text.getX();
            final long x2 = x1 + text.getWidth();
            final long effectiveAreaX2 = (contentAreaX2 - ellipseSize);
            if (x2 <= effectiveAreaX2) {
                // the text will be fully visible.
                drawText(text);
            } else {
                if (x1 < contentAreaX2) {
                    // The text node that is printed will overlap with the ellipse we need to print.
                    drawText(text, effectiveAreaX2);
                }

                final RenderBox parent = node.getParent();
                if (parent != null) {
                    final RenderBox textEllipseBox = parent.getTextEllipseBox();
                    if (textEllipseBox != null) {
                        processBoxChilds(textEllipseBox);
                    }
                }

                ellipseDrawn = true;
            }
        } else {
            drawText(text);
        }
    } else if (type == LayoutNodeTypes.TYPE_NODE_COMPLEX_TEXT) {
        final RenderableComplexText text = (RenderableComplexText) node;
        final long x1 = text.getX();

        if (x1 < contentAreaX2) {
            // The text node that is printed will overlap with the ellipse we need to print.
            final Graphics2D g2;
            if (getTextSpec() == null) {
                g2 = (Graphics2D) getGraphics().create();
                final StyleSheet layoutContext = text.getStyleSheet();
                configureGraphics(layoutContext, g2);
                g2.setStroke(LogicalPageDrawable.DEFAULT_STROKE);

                if (RenderUtility.isFontSmooth(layoutContext, metaData)) {
                    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                } else {
                    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                            RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
                }
            } else {
                g2 = getTextSpec().getGraphics();
            }

            drawComplexText(text, g2);
        }
    }
}

From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java

/**
 * {@inheritDoc}//from   w w w . j  av a2  s.c o m
 */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT);

    // Define the content rectangle
    int x0 = pointerLeft ? pad + pointerWidth : pad;
    RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth,
            height - 2 * pad, cornerRadius, cornerRadius);

    // Define the pointer triangle
    int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth;
    int yp = pad + height - pointerFromBottom;
    Polygon pointer = new Polygon();
    pointer.addPoint(xp, yp);
    pointer.addPoint(xp, yp - pointerHeight);
    pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2);

    // Combine content rectangle and pointer into one area
    Area area = new Area(content);
    area.add(new Area(pointer));

    // Fill the pop-up background
    Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter();
    g2.setColor(col);
    g2.fill(area);

    if (message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING
            || message.getSeverity() == MaritimeTextingNotificationSeverity.ALERT
            || message.getSeverity() == MaritimeTextingNotificationSeverity.SAFETY) {
        g2.setStroke(new BasicStroke(2.0f));

        switch (message.getSeverity()) {
        case WARNING:
            g2.setColor(WARN_COLOR);
        case ALERT:
            g2.setColor(ALERT_COLOR);
        case SAFETY:
            g2.setColor(SAFETY_COLOR);
        default:
            g2.setColor(WARN_COLOR);
        }

        // g2.setColor(message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING ? WARN_COLOR : ALERT_COLOR);

        g2.draw(area);
    }
}

From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileTool.java

@Override
public void draw(Graphics2D g) {
    if (isBlockUpdate()) {
        return;//from w w  w. j  ava2 s. c o  m
    }
    updateSelectionData();

    float tra = (transparance.getValue() / (float) (transparance.getMaximum()));

    float lineSize = 1f / (float) panel.getScale();
    float crossSize = (float) (pointSize / panel.getScale());

    RenderingHints oldHinds = g.getRenderingHints();
    Composite oldcomp = g.getComposite();
    Stroke oldStroke = g.getStroke();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, tra));
    g.setStroke(new BasicStroke(lineSize));
    GraphicsToolkit.setRenderingQuality(g, GraphicsToolkit.HIGH_QUALITY);
    Line2D.Double line = new Line2D.Double();

    double x1 = 0;
    double x2 = 0;
    double y1 = 0;
    double y2 = 0;
    for (int i = 0; i < selectionData.length - 1; i++) {
        if (axis == AXIS_X) {
            y1 = view.getImage().getHeight() / (double) (selectionData.length - 1) * i;
            x1 = view.getImage().getWidth() * (1 - getSelectionValue(i));

            y2 = view.getImage().getHeight() / (double) (selectionData.length - 1) * (i + 1);
            x2 = view.getImage().getWidth() * (1 - getSelectionValue(i + 1));
        } else if (axis == AXIS_Y) {
            x1 = view.getImage().getWidth() / (double) (selectionData.length - 1) * i;
            y1 = view.getImage().getHeight() * (1 - getSelectionValue(i));

            x2 = view.getImage().getWidth() / (double) (selectionData.length - 1) * (i + 1);
            y2 = view.getImage().getHeight() * (1 - getSelectionValue(i + 1));
        }

        if (getUseData(i)) {
            g.setColor(getPointColorSelected());
        } else {
            g.setColor(getPointColorNotSelected());
        }
        line.x1 = x1;
        line.x2 = x2;
        line.y1 = y1;
        line.y2 = y2;

        g.draw(line);

        if (showOffset.isSelected()) {
            if (getUseData(i)) {
                g.setColor(getOffsetColor());
                double offset = (Double) this.offset.getValue();

                if (axis == AXIS_X) {
                    line.x1 += offset;
                    line.x2 += offset;

                } else if (axis == AXIS_Y) {
                    line.y1 += offset;
                    line.y2 += offset;
                }
                g.draw(line);
            }
        }
    }

    // Draw each point
    if (drawCrosses) {
        double x = 0;
        double y = 0;
        for (int i = 0; i < value.length; i++) {

            if (axis == AXIS_X) {
                y = view.getImage().getHeight() / (double) (value.length - 1) * i;
                x = view.getImage().getWidth() * (1 - value[i]);
            } else if (axis == AXIS_Y) {
                x = view.getImage().getWidth() / (double) (value.length - 1) * i;
                y = view.getImage().getHeight() * (1 - value[i]);
            }
            DrawTools.drawCross(g, new Point2D.Double(x, y), crossSize, 0, getCrossColor(), lineSize);

        }
    }
    g.setComposite(oldcomp);
    g.setStroke(oldStroke);
    g.setRenderingHints(oldHinds);
}

From source file:peakml.util.jfreechart.FastErrorBarPlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {//from  www  . j a v  a  2  s .  c om
    // add the plot area to the info (used amongst other by the axis for zooming)
    if (info != null)
        info.setPlotArea(area);

    // add the insets (if any)
    RectangleInsets insets = getInsets();
    insets.trim(area);

    // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming)
    AxisSpace space = new AxisSpace();
    space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);

    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null)
        info.setDataArea(dataArea);

    // flood fill the whole area with the background color
    drawBackground(g2, dataArea);

    // draw the axis
    xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);

    // sanity check
    if (dataseries.size() == 0)
        return;

    // clip the draw area
    Shape originalclip = g2.getClip();
    g2.clip(dataArea);

    // create the strokes
    BasicStroke stroke_solid = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f);
    BasicStroke stroke_dashed = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f,
            new float[] { 2, 4 }, 0);

    g2.setStroke(stroke_solid);

    // count the number of labels
    int categoryCount = 0;
    if (showall) {
        for (Data data : dataseries)
            categoryCount += data.yvalues.length;
    } else
        categoryCount = dataseries.size();

    // draw all the values
    int pos = 0;
    boolean dashed = false;
    double prevx = -1, prevy = -1;
    for (Data data : dataseries) {
        if (data.yvalues.length == 0) {
            dashed = true;
            pos++;
            continue;
        }

        double mean[] = showall ? data.yvalues : new double[] { data.getMeanY() };
        double min[] = showall ? data.yvalues : new double[] { data.getMinY() };
        double max[] = showall ? data.yvalues : new double[] { data.getMaxY() };
        for (int i = 0; i < mean.length; ++i) {
            double ypos, xpos = xaxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, pos++, categoryCount,
                    dataArea, RectangleEdge.BOTTOM);

            // draw the mean value
            g2.setColor(Color.RED);
            ypos = yaxis.valueToJava2D(mean[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos, (int) xpos + 2, (int) ypos);

            // conect the dots
            if (prevx != -1 && prevy != -1) {
                g2.setColor(Color.BLACK);
                if (dashed)
                    g2.setStroke(stroke_dashed);
                g2.drawLine((int) prevx, (int) prevy, (int) xpos, (int) ypos);
                if (dashed) {
                    dashed = false;
                    g2.setStroke(stroke_solid);
                }

            }
            prevy = ypos;
            prevx = xpos;

            // draw the outer values
            g2.setColor(Color.LIGHT_GRAY);
            double ypos_min = yaxis.valueToJava2D(min[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos_min, (int) xpos + 2, (int) ypos_min);
            double ypos_max = yaxis.valueToJava2D(max[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos_max, (int) xpos + 2, (int) ypos_max);
            g2.drawLine((int) xpos, (int) ypos_min, (int) xpos, (int) ypos_max);
        }
    }

    // reset
    g2.setClip(originalclip);
}