Example usage for java.awt BasicStroke JOIN_ROUND

List of usage examples for java.awt BasicStroke JOIN_ROUND

Introduction

In this page you can find the example usage for java.awt BasicStroke JOIN_ROUND.

Prototype

int JOIN_ROUND

To view the source code for java.awt BasicStroke JOIN_ROUND.

Click Source Link

Document

Joins path segments by rounding off the corner at a radius of half the line width.

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);/*from  ww  w.  j  ava  2s.  c o  m*/
        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);
            }
        }
    }
}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Parses a string containing a sequence of line style specifications,
 * returning an array of <code>Stroke</code> objects.
 *
 * @param text  the line styles.//  w  w w . j  a  va2 s .co  m
 *
 * @return The strokes representing the line styles.
 */
private static Stroke[] parseLineStyles(String text) {
    if (text == null) {
        throw new IllegalArgumentException("Null 'text' argument (in parseStrokes(String)).");
    }
    String[] codes = breakString(text, '|');
    Stroke[] result = new BasicStroke[codes.length];
    for (int i = 0; i < codes.length; i++) {
        float width = 1.0f;
        float lineRun = 1.0f;
        float gapRun = 0.0f;
        int pos = codes[i].indexOf(',');
        if (pos == -1) {
            width = Float.parseFloat(codes[i]);
        } else {
            String widthStr = codes[i].substring(0, pos);
            width = Float.parseFloat(widthStr);
            String remaining = codes[i].substring(pos + 1);
            pos = remaining.indexOf(',');
            if (pos == -1) {
                lineRun = Float.parseFloat(remaining);
                gapRun = lineRun;
            } else {
                String s1 = remaining.substring(0, pos);
                lineRun = Float.parseFloat(s1);
                String s2 = remaining.substring(pos + 1);
                gapRun = Float.parseFloat(s2);
            }
        }
        if (gapRun <= 0.0f) {
            result[i] = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
        } else {
            result[i] = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 5.0f,
                    new float[] { lineRun, gapRun }, 0.0f);
        }
    }
    return result;
}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Process a string which specifies grid line steps and line segment sizes.
 *
 * @param spec  the grid lines specification.
 * @param chart  the chart.//w  w  w  .ja  va2  s  . c o  m
 */
private static void processGridLinesSpec(String spec, JFreeChart chart) {
    String[] parts = breakString(spec, ',');

    double xAxisStepSize = 0.0;
    double yAxisStepSize = 0.0;
    float lineSegLength = 3f;
    float blankSegLength = 6f;

    if (parts.length > 0) {
        try {
            xAxisStepSize = Double.parseDouble(parts[0]);
        } catch (NumberFormatException e) {

        }
    }
    if (parts.length > 1) {
        try {
            yAxisStepSize = Double.parseDouble(parts[1]);
        } catch (NumberFormatException e) {

        }
    }
    if (parts.length > 2) {
        try {
            lineSegLength = Float.parseFloat(parts[2]) * 0.85f;
        } catch (NumberFormatException e) {

        }
    }
    if (parts.length > 3) {
        try {
            blankSegLength = Float.parseFloat(parts[3]) * 0.85f;
        } catch (NumberFormatException e) {

        }
    }

    if (lineSegLength == 0 && blankSegLength == 0) {
        lineSegLength = 1f;
    }

    if (lineSegLength > 0) {
        Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10f,
                new float[] { lineSegLength, blankSegLength }, 0);

        Plot p = chart.getPlot();
        if (p instanceof CategoryPlot) {
            GCategoryPlot plot = (GCategoryPlot) p;
            plot.setDomainGridlinesVisible(true);
            plot.setRangeGridlinesVisible(true);
            plot.setDomainGridlineStroke(stroke);
            plot.setRangeGridlineStroke(stroke);
            plot.setXAxisStepSize(xAxisStepSize / 100.0);
            plot.setYAxisStepSize(yAxisStepSize / 100.0);
        } else if (p instanceof XYPlot) {
            GXYPlot plot = (GXYPlot) p;
            plot.setDomainGridlinesVisible(true);
            plot.setRangeGridlinesVisible(true);
            plot.setDomainGridlineStroke(stroke);
            plot.setRangeGridlineStroke(stroke);
            plot.setXAxisStepSize(xAxisStepSize / 100.0);
            plot.setYAxisStepSize(yAxisStepSize / 100.0);
        }
    }
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

public static Stroke getLineStyleStroke(final String lineStyle, float lineWidth) {

    BasicStroke stroke = null;//w w  w.  ja  v  a  2 s  .  c o m
    float[] strokeSteps = null;

    // Negative linewidths not allowed; reset to default;
    if (lineWidth < 0) {
        lineWidth = 1.0f;
    }

    if (lineStyle != null) {
        if (lineStyle.equals(ChartDefinition.LINE_STYLE_DASH_STR)) {
            strokeSteps = new float[] { 6.0f, 6.0f };
        } else if (lineStyle.equals(ChartDefinition.LINE_STYLE_DOT_STR)) {
            strokeSteps = new float[] { 2.0f, 6.0f };
        } else if (lineStyle.equals(ChartDefinition.LINE_STYLE_DASHDOT_STR)) {
            strokeSteps = new float[] { 10.0f, 6.0f, 2.0f, 6.0f };
        } else if (lineStyle.equals(ChartDefinition.LINE_STYLE_DASHDOTDOT_STR)) {
            strokeSteps = new float[] { 10.0f, 6.0f, 2.0f, 6.0f, 2.0f, 6.0f };
        }
    }

    if (strokeSteps != null) {
        stroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, strokeSteps,
                0.0f);
    } else {
        stroke = new BasicStroke(lineWidth);
    }
    return stroke;
}

From source file:net.sqs2.omr.session.logic.PageImageRenderer.java

private static void drawFormAreas(int pageIndex, float densityThreshold, FormMaster master,
        PageTaskResult pageTaskResult, Graphics2D g, MarkRecognitionConfig markRecognizationConfig,
        DeskewedImageSource pageSource, int focusedColumnIndex, Rectangle scope) {
    int formAreaIndexInPage = 0;

    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int maxY = Integer.MIN_VALUE;

    for (FormArea formArea : master.getFormAreaListByPageIndex(pageIndex)) {
        FormAreaResult result = (FormAreaResult) pageTaskResult.getPageAreaResultList()
                .get(formAreaIndexInPage);
        if (formArea.isMarkArea()) {
            if (focusedColumnIndex == formArea.getQuestionIndex()) {

                Rectangle rect = formArea.getRect();

                Point2D p1 = pageSource.getPoint((int) rect.getX(), (int) rect.getY());
                Point2D p2 = pageSource.getPoint((int) (rect.getX() + rect.getWidth()),
                        (int) (rect.getY() + rect.getHeight()));

                minX = Math.min(minX, (int) p1.getX());
                minY = Math.min(minY, (int) p1.getY());
                maxX = Math.max(maxX, (int) p2.getX());
                maxY = Math.max(maxY, (int) p2.getY());

                if (result.getDensity() < densityThreshold) {
                    g.setColor(FOCUSED_MARKED_COLOR);
                } else {
                    g.setColor(FOCUSED_NO_MARKED_COLOR);
                }//from w  ww  .  j a va2 s .  co m

            } else {
                if (result.getDensity() < densityThreshold) {
                    g.setColor(MARKED_COLOR);
                } else {
                    g.setColor(NO_MARKED_COLOR);
                }
            }

            g.fillPolygon(pageSource.createRectPolygon(
                    getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin(),
                            markRecognizationConfig.getVerticalMargin())));
            g.drawPolygon(pageSource.createRectPolygon(
                    getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin() + 3,
                            markRecognizationConfig.getVerticalMargin() + 3)));

        } else {
            g.setColor(TEXTAREA_COLOR);
            g.fillPolygon(pageSource.createRectPolygon(formArea.getRect()));
        }
        formAreaIndexInPage++;
    }

    if (scope != null) {
        int borderMarginX = 20;
        int borderMarginY = 3;
        int margin = 40;

        int x = minX - borderMarginX;
        int y = minY - borderMarginY;
        int width = maxX - minX + borderMarginX * 2;
        int height = maxY - minY + borderMarginY * 2;

        scope.x = minX - margin;
        scope.y = minY - margin;
        scope.width = maxX - minX + margin * 2;
        scope.height = maxY - minY + margin * 2;

        Stroke stroke = new BasicStroke(4.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 2.0f,
                new float[] { 4.0f, 8.0f }, 0.0f);
        g.setStroke(stroke);
        g.setColor(FOCUSED_SCOPE_COLOR);
        g.drawRoundRect(x, y, width, height, 20, 20);
    }

}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

/**
 * Reusable 'strokes' for rendering lines may be obtained from here
 * /*from   ww  w  .j  ava  2 s.  co  m*/
 * @param ls
 * @return stroke
 */
public final Stroke getCachedStroke(LineAttributes lia) {
    if (lia == null)
        return null;

    Stroke s = _htLineStyles.get(lia);
    if (s == null) {
        BasicStroke bs = null;
        int thickness = lia.getThickness();
        if (thickness == 0) {
            // Thickness can be zero, but dashed pattern can not be.
            thickness = 1;
        }
        if (lia.getStyle().getValue() == LineStyle.DASHED) {
            float[] faStyle = new float[] { 6 * thickness, 4 * thickness };
            bs = new BasicStroke(lia.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, faStyle,
                    0);
        } else if (lia.getStyle().getValue() == LineStyle.DOTTED) {
            float[] faStyle = new float[] { thickness, 4 * thickness };
            bs = new BasicStroke(lia.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, faStyle,
                    0);
        } else if (lia.getStyle().getValue() == LineStyle.DASH_DOTTED) {
            float[] faStyle = new float[] { 6 * thickness, 4 * thickness, thickness, 4 * thickness };
            bs = new BasicStroke(lia.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, faStyle,
                    0);
        } else if (lia.getStyle().getValue() == LineStyle.SOLID) {
            bs = new BasicStroke(lia.getThickness(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND);
        }
        if (bs != null) {
            _htLineStyles.put(lia, bs);
        }
        return bs;
    }
    return s;
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

/**
 * Adds stroke color and style information to the element passed in.
 * //from   w w w  .  j  av  a  2  s  .c  o m
 * @param currentElement
 *            the element to add style information to.
 * @param isClipped
 *            boolean that determines whether to defer the clipping of the
 *            element
 */
protected void setStrokeStyle(Element currentElement, boolean deferClipped)

{
    Element element = currentElement;
    if (deferStrokColor != null) {
        // Need to get the parent element.
        element = deferStrokColor;
    }

    String style = element.getAttribute("style"); //$NON-NLS-1$
    if (style == null)
        style = ""; //$NON-NLS-1$
    if (color != null) {
        style += "stroke:" + serializeToString(color) + ";"; //$NON-NLS-1$ //$NON-NLS-2$
    }
    if ((stroke != null) && (stroke instanceof BasicStroke)) {
        BasicStroke bs = (BasicStroke) stroke;
        if (bs.getLineWidth() > 0)
            style += "stroke-width:" + bs.getLineWidth() + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        if (bs.getDashArray() != null) {
            StringBuffer dashArrayStr = new StringBuffer();
            for (int x = 0; x < bs.getDashArray().length; x++) {
                dashArrayStr.append(" ").append(bs.getDashArray()[x]); //$NON-NLS-1$
            }
            if (!(dashArrayStr.toString().equals(""))) //$NON-NLS-1$
                style += "stroke-dasharray:" + dashArrayStr + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        }
        style += "stroke-miterlimit:" + bs.getMiterLimit() + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        switch (bs.getLineJoin()) {
        case BasicStroke.JOIN_BEVEL:
            style += "stroke-linejoin:bevel;"; //$NON-NLS-1$
            break;
        case BasicStroke.JOIN_ROUND:
            style += "stroke-linejoin:round;"; //$NON-NLS-1$
            break;
        }
        switch (bs.getEndCap()) {
        case BasicStroke.CAP_ROUND:
            style += "stroke-linecap:round;"; //$NON-NLS-1$
            break;
        case BasicStroke.CAP_SQUARE:
            style += "stroke-linecap:square;"; //$NON-NLS-1$
            break;
        }

    }
    element.setAttribute("style", style); //$NON-NLS-1$
    if (styleClass != null)
        element.setAttribute("class", styleClass); //$NON-NLS-1$
    if (id != null)
        element.setAttribute("id", id); //$NON-NLS-1$
    if ((clip != null) && (!deferClipped))
        element.setAttribute("clip-path", "url(#clip" + clip.hashCode() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

}

From source file:org.jcurl.demo.tactics.CurveShapeDemo.java

public static void main(String[] args) {
    log.info("Version: " + Version.find());
    final R1RNFunction c;
    {//from w ww  . j  a  v  a2s  . c om
        final R1R1Function[] f = new R1R1Function[2];
        final double[] fx = { 200, 150 };
        final double[] fy = { 4, 4, 4, 4, 4 };
        f[0] = new Polynome(fx);
        f[1] = new Polynome(fy);
        c = new CurveFkt(f);
    }
    final CurveShapeDemo frame = new CurveShapeDemo(c);
    frame.setSize(500, 400);
    frame.setVisible(true);
    frame.setContentPane(new JPanel() {

        private static final long serialVersionUID = -3582299332757831635L;

        private final double[] sections = new double[10];

        final Stroke st = new BasicStroke(20, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0);

        public void paintComponent(Graphics g) {
            setBackground(new Color(255, 255, 255));
            super.paintComponent(g);
            setBackground(new Color(255, 255, 255));
            final Graphics2D g2 = (Graphics2D) g;
            g2.scale(0.75, 0.75);
            g2.setPaint(new Color(0, 0, 255));
            g2.setStroke(st);
            g2.drawLine(0, 0, 650, 500);
            g2.setPaint(new Color(255, 170, 0, 128));
            // FIXME g2.draw(CurveShape.approximate(frame.curve, CurveShape.sections(-1, 3, sections)));
        }
    });
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.RefineFEGeometryWidget.java

private void drawRefinement(final Graphics g, final GeoTransform projection)
        throws CoreException, GM_Exception {
    /* Paint a rect. */
    final LineSymbolizer symb = new LineSymbolizer_Impl();
    final Stroke stroke = new Stroke_Impl(new HashMap<String, CssParameter>(), null, null);
    final Color color = new Color(255, 0, 0);
    for (final GM_Object object : m_objects) {
        if (object instanceof GM_Polygon) {
            final GM_Polygon surface = (GM_Polygon) object;
            final String crs = surface.getCoordinateSystem();

            for (final GM_AbstractSurfacePatch surfacePatch : surface) {
                final GM_Position[] exteriorRing = surfacePatch.getExteriorRing();
                final GM_Curve curve = org.kalypsodeegree_impl.model.geometry.GeometryFactory
                        .createGM_Curve(exteriorRing, crs);

                stroke.setWidth(3);/*from  w w w  . j  a v  a  2 s. c  o m*/
                stroke.setLineCap(BasicStroke.CAP_ROUND);
                stroke.setLineJoin(BasicStroke.JOIN_ROUND);
                stroke.setStroke(color);
                symb.setStroke(stroke);

                final DisplayElement de = DisplayElementFactory.buildLineStringDisplayElement(null, curve,
                        symb);
                de.paint(g, projection, new NullProgressMonitor());
            }
        }
    }
}

From source file:org.n52.v3d.terrainserver.povraywts.WebTerrainServlet.java

private void addAnnotations(BufferedImage pImage, int pHeight, int pWidth, double pPitch, double pYaw,
        boolean pDrawNorthArrow) {
    if (mCopyrightTextContent.length() > 0) {
        Graphics2D g = pImage.createGraphics();
        g.drawImage(pImage, 0, 0, null);
        g.setColor(new java.awt.Color(mCopyrightTextColor.getRed(), mCopyrightTextColor.getGreen(),
                mCopyrightTextColor.getBlue()));

        // 1. Copyright-Vermerk
        // Etwas unschn: Durch JPEG-Komprimierung wird Text (insb. bei kleiner Font-Gre) wird unscharf...
        // TODO: Abhilfe evtl. durch Hintergrund?
        Font font = new Font(mCopyrightTextFont, Font.BOLD /* Style als int, siehe ggf. API-Dok.*/,
                mCopyrightTextSize);//from   w w w.  j a  va2  s.  co  m
        g.setFont(font);
        // mehrzeilige Copyright-Texte erlauben:
        StringTokenizer str = new StringTokenizer(mCopyrightTextContent, "\n");
        int spacePerRow = mCopyrightTextSize;
        int rows = str.countTokens();
        int startPos = spacePerRow * rows;
        int currRow = 0;
        while (str.hasMoreTokens()) {
            int yPos = pHeight - (startPos - (currRow * spacePerRow)) + spacePerRow / 2;
            g.drawString(str.nextToken().trim(), 5, yPos);
            currRow++;
        }

        // 2. Nordpfeil
        if (pDrawNorthArrow) {
            // Zeichenparameter:
            double radius = 35.;
            double phi = 15.;
            // Symbolkonstruktion:
            int rx = (int) radius;
            int ry = (int) Math.round(radius * Math.sin(-pPitch * Math.PI / 180.));
            int mx = pWidth - rx - 5;
            int my = pHeight - ry - 5;
            int dx = (int) (radius * Math.sin(pYaw * Math.PI / 180.));
            int dy = (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos(pYaw * Math.PI / 180.));
            int px = mx - dx, py = my - dy; // Pfeilspitze
            int qlx = mx + (int) (radius * Math.sin((pYaw + phi) * Math.PI / 180.));
            int qly = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.)
                    * Math.cos((pYaw + phi) * Math.PI / 180.));
            int qrx = mx + (int) (radius * Math.sin((pYaw - phi) * Math.PI / 180.));
            int qry = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.)
                    * Math.cos((pYaw - phi) * Math.PI / 180.));
            // Ellipse zeichnen:
            g.setStroke(new BasicStroke(2.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
            g.drawOval(mx - rx, my - ry, 2 * rx, 2 * ry);
            // Striche fr Pfeil zeichnen:

            g.setStroke(new BasicStroke(1.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));

            boolean fillArrow = true;
            if (fillArrow)
                g.fill(new Polygon(new int[] { px, qlx, qrx }, new int[] { py, qly, qry }, 3));
            else {
                g.drawLine(px, py, qlx, qly);
                g.drawLine(px, py, qrx, qry);
                g.drawLine(qlx, qly, qrx, qry);
            }
        }

        g.dispose();
    }
}