Java Code Examples for java.awt.BasicStroke#CAP_ROUND
The following examples show how to use
java.awt.BasicStroke#CAP_ROUND .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SWTGraphics2D.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Returns the AWT line cap corresponding to the specified SWT line cap. * * @param swtLineCap the SWT line cap. * * @return The AWT line cap. */ private int toAwtLineCap(int swtLineCap) { if (swtLineCap == SWT.CAP_FLAT) { return BasicStroke.CAP_BUTT; } else if (swtLineCap == SWT.CAP_ROUND) { return BasicStroke.CAP_ROUND; } else if (swtLineCap == SWT.CAP_SQUARE) { return BasicStroke.CAP_SQUARE; } else { throw new IllegalArgumentException("SWT LineCap " + swtLineCap + " not recognised"); } }
Example 2
Source File: BorderFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Creates a dashed border of the specified {@code paint}, {@code thickness}, * line shape, relative {@code length}, and relative {@code spacing}. * If the specified {@code paint} is {@code null}, * the component's foreground color will be used to render the border. * * @param paint the {@link Paint} object used to generate a color * @param thickness the width of a dash line * @param length the relative length of a dash line * @param spacing the relative spacing between dash lines * @param rounded whether or not line ends should be round * @return the {@code Border} object * * @throws IllegalArgumentException if the specified {@code thickness} is less than {@code 1}, or * if the specified {@code length} is less than {@code 1}, or * if the specified {@code spacing} is less than {@code 0} * @since 1.7 */ public static Border createDashedBorder(Paint paint, float thickness, float length, float spacing, boolean rounded) { boolean shared = !rounded && (paint == null) && (thickness == 1.0f) && (length == 1.0f) && (spacing == 1.0f); if (shared && (sharedDashedBorder != null)) { return sharedDashedBorder; } if (thickness < 1.0f) { throw new IllegalArgumentException("thickness is less than 1"); } if (length < 1.0f) { throw new IllegalArgumentException("length is less than 1"); } if (spacing < 0.0f) { throw new IllegalArgumentException("spacing is less than 0"); } int cap = rounded ? BasicStroke.CAP_ROUND : BasicStroke.CAP_SQUARE; int join = rounded ? BasicStroke.JOIN_ROUND : BasicStroke.JOIN_MITER; float[] array = { thickness * (length - 1.0f), thickness * (spacing + 1.0f) }; Border border = createStrokeBorder(new BasicStroke(thickness, cap, join, thickness * 2.0f, array, 0.0f), paint); if (shared) { sharedDashedBorder = border; } return border; }
Example 3
Source File: SWTGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Returns the AWT line cap corresponding to the specified SWT line cap. * * @param swtLineCap the SWT line cap. * * @return The AWT line cap. */ private int toAwtLineCap(int swtLineCap) { if (swtLineCap == SWT.CAP_FLAT) { return BasicStroke.CAP_BUTT; } else if (swtLineCap == SWT.CAP_ROUND) { return BasicStroke.CAP_ROUND; } else if (swtLineCap == SWT.CAP_SQUARE) { return BasicStroke.CAP_SQUARE; } else { throw new IllegalArgumentException("SWT LineCap " + swtLineCap + " not recognised"); } }
Example 4
Source File: BorderFactory.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Creates a dashed border of the specified {@code paint}, {@code thickness}, * line shape, relative {@code length}, and relative {@code spacing}. * If the specified {@code paint} is {@code null}, * the component's foreground color will be used to render the border. * * @param paint the {@link Paint} object used to generate a color * @param thickness the width of a dash line * @param length the relative length of a dash line * @param spacing the relative spacing between dash lines * @param rounded whether or not line ends should be round * @return the {@code Border} object * * @throws IllegalArgumentException if the specified {@code thickness} is less than {@code 1}, or * if the specified {@code length} is less than {@code 1}, or * if the specified {@code spacing} is less than {@code 0} * @since 1.7 */ public static Border createDashedBorder(Paint paint, float thickness, float length, float spacing, boolean rounded) { boolean shared = !rounded && (paint == null) && (thickness == 1.0f) && (length == 1.0f) && (spacing == 1.0f); if (shared && (sharedDashedBorder != null)) { return sharedDashedBorder; } if (thickness < 1.0f) { throw new IllegalArgumentException("thickness is less than 1"); } if (length < 1.0f) { throw new IllegalArgumentException("length is less than 1"); } if (spacing < 0.0f) { throw new IllegalArgumentException("spacing is less than 0"); } int cap = rounded ? BasicStroke.CAP_ROUND : BasicStroke.CAP_SQUARE; int join = rounded ? BasicStroke.JOIN_ROUND : BasicStroke.JOIN_MITER; float[] array = { thickness * (length - 1.0f), thickness * (spacing + 1.0f) }; Border border = createStrokeBorder(new BasicStroke(thickness, cap, join, thickness * 2.0f, array, 0.0f), paint); if (shared) { sharedDashedBorder = border; } return border; }
Example 5
Source File: BorderFactory.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Creates a dashed border of the specified {@code paint}, {@code thickness}, * line shape, relative {@code length}, and relative {@code spacing}. * If the specified {@code paint} is {@code null}, * the component's foreground color will be used to render the border. * * @param paint the {@link Paint} object used to generate a color * @param thickness the width of a dash line * @param length the relative length of a dash line * @param spacing the relative spacing between dash lines * @param rounded whether or not line ends should be round * @return the {@code Border} object * * @throws IllegalArgumentException if the specified {@code thickness} is less than {@code 1}, or * if the specified {@code length} is less than {@code 1}, or * if the specified {@code spacing} is less than {@code 0} * @since 1.7 */ public static Border createDashedBorder(Paint paint, float thickness, float length, float spacing, boolean rounded) { boolean shared = !rounded && (paint == null) && (thickness == 1.0f) && (length == 1.0f) && (spacing == 1.0f); if (shared && (sharedDashedBorder != null)) { return sharedDashedBorder; } if (thickness < 1.0f) { throw new IllegalArgumentException("thickness is less than 1"); } if (length < 1.0f) { throw new IllegalArgumentException("length is less than 1"); } if (spacing < 0.0f) { throw new IllegalArgumentException("spacing is less than 0"); } int cap = rounded ? BasicStroke.CAP_ROUND : BasicStroke.CAP_SQUARE; int join = rounded ? BasicStroke.JOIN_ROUND : BasicStroke.JOIN_MITER; float[] array = { thickness * (length - 1.0f), thickness * (spacing + 1.0f) }; Border border = createStrokeBorder(new BasicStroke(thickness, cap, join, thickness * 2.0f, array, 0.0f), paint); if (shared) { sharedDashedBorder = border; } return border; }
Example 6
Source File: FXGraphics2D.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Maps a line cap code from AWT to the corresponding JavaFX StrokeLineCap * enum value. * * @param c the line cap code. * * @return A JavaFX line cap value. */ private StrokeLineCap awtToJavaFXLineCap(int c) { if (c == BasicStroke.CAP_BUTT) { return StrokeLineCap.BUTT; } else if (c == BasicStroke.CAP_ROUND) { return StrokeLineCap.ROUND; } else if (c == BasicStroke.CAP_SQUARE) { return StrokeLineCap.SQUARE; } else { throw new IllegalArgumentException("Unrecognised cap code: " + c); } }
Example 7
Source File: DialPointer.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Creates a new instance. * * @param datasetIndex the dataset index. */ public Pin(int datasetIndex) { super(datasetIndex); this.paint = Color.red; this.stroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); }
Example 8
Source File: SettingsBasicStroke.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
public void resetAll() { this.w = 1.5f; this.miterlimit = 2.f; this.dashphase = 0; this.cap = BasicStroke.CAP_ROUND; this.join = BasicStroke.JOIN_MITER; this.array = new float[] {10.f}; stroke = null; }
Example 9
Source File: ProfilerXYSelectionOverlay.java From visualvm with GNU General Public License v2.0 | 5 votes |
private void initDefaultValues() { markPaint = new Color(80, 80, 80); oddPerfPaint = Color.BLACK; evenPerfPaint = Color.WHITE; markStroke = new BasicStroke(2.8f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); oddPerfStroke = new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0, new float[] { 1.0f, 3.0f }, 0); evenPerfStroke = new BasicStroke(1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0, new float[] { 1.0f, 3.0f }, 2); selectionExtent = 3; }
Example 10
Source File: StyleUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Convert a sld line cap definition to the java awt value. * * @param sldCap the sld cap string. * @return the awt value. */ public static int sld2awtCap( String sldCap ) { if (sldCap.equals("") || sldCap.equals(lineCapNames[1])) { return BasicStroke.CAP_BUTT; } else if (sldCap.equals(lineCapNames[2])) { return BasicStroke.CAP_ROUND; } else if (sldCap.equals(lineCapNames[3])) { return BasicStroke.CAP_SQUARE; } else { throw new IllegalArgumentException("unsupported line cap"); } }
Example 11
Source File: DialPointer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Creates a new instance. * * @param datasetIndex the dataset index. */ public Pin(int datasetIndex) { super(datasetIndex); this.paint = Color.red; this.stroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); }
Example 12
Source File: FXGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Maps a line cap code from AWT to the corresponding JavaFX StrokeLineCap * enum value. * * @param c the line cap code. * * @return A JavaFX line cap value. */ private StrokeLineCap awtToJavaFXLineCap(int c) { if (c == BasicStroke.CAP_BUTT) { return StrokeLineCap.BUTT; } else if (c == BasicStroke.CAP_ROUND) { return StrokeLineCap.ROUND; } else if (c == BasicStroke.CAP_SQUARE) { return StrokeLineCap.SQUARE; } else { throw new IllegalArgumentException("Unrecognised cap code: " + c); } }
Example 13
Source File: WPrinterJob.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
protected boolean selectStylePen(int cap, int join, float width, Color color) { long endCap; long lineJoin; float[] rgb = color.getRGBColorComponents(null); switch(cap) { case BasicStroke.CAP_BUTT: endCap = PS_ENDCAP_FLAT; break; case BasicStroke.CAP_ROUND: endCap = PS_ENDCAP_ROUND; break; default: case BasicStroke.CAP_SQUARE: endCap = PS_ENDCAP_SQUARE; break; } switch(join) { case BasicStroke.JOIN_BEVEL:lineJoin = PS_JOIN_BEVEL; break; default: case BasicStroke.JOIN_MITER:lineJoin = PS_JOIN_MITER; break; case BasicStroke.JOIN_ROUND:lineJoin = PS_JOIN_ROUND; break; } return (selectStylePen(getPrintDC(), endCap, lineJoin, width, (int) (rgb[0] * MAX_WCOLOR), (int) (rgb[1] * MAX_WCOLOR), (int) (rgb[2] * MAX_WCOLOR))); }
Example 14
Source File: WPathGraphics.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Draw a line using a pen created using the specified color * and current stroke properties. */ @Override protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) { Stroke stroke = getStroke(); if (stroke instanceof BasicStroke) { BasicStroke lineStroke = (BasicStroke) stroke; if (lineStroke.getDashArray() != null) { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); return; } float lineWidth = lineStroke.getLineWidth(); Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth); AffineTransform deviceTransform = getTransform(); deviceTransform.deltaTransform(penSize, penSize); float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y)); Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin); deviceTransform.transform(begin_pos, begin_pos); Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd); deviceTransform.transform(end_pos, end_pos); int endCap = lineStroke.getEndCap(); int lineJoin = lineStroke.getLineJoin(); /* check if it's a one-pixel line */ if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) { /* endCap other than Round will not print! * due to Windows GDI limitation, force it to CAP_ROUND */ endCap = BasicStroke.CAP_ROUND; } WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); /* call native function that creates pen with style */ if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) { wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } /* selectStylePen is not supported, must be Win 9X */ else { /* let's see if we can use a a default pen * if it's round end (Windows' default style) * or it's vertical/horizontal * or stroke is too thin. */ double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes()); if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) { wPrinterJob.selectPen(deviceLineWidth, color); wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } else { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); } } } }
Example 15
Source File: ContinuousXYPainter.java From visualvm with GNU General Public License v2.0 | 4 votes |
ContinuousXYPainter(float lineWidth, Color lineColor, Color fillColor, double dataFactor, PointsComputer computer) { super((int)Math.ceil(lineWidth), fillColor != null, dataFactor); if (lineColor == null && fillColor == null) throw new IllegalArgumentException("lineColor or fillColor must not be null"); // NOI18N this.lineWidth = (int)Math.ceil(lineWidth); this.lineColor = Utils.checkedColor(lineColor); this.fillColor = Utils.checkedColor(fillColor); definingColor = lineColor != null ? lineColor : fillColor; this.lineStroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); this.computer = computer; }
Example 16
Source File: SWTGraphics2D.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Sets the stroke for this graphics context. For now, this implementation * only recognises the {@link BasicStroke} class. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getStroke() */ public void setStroke(Stroke stroke) { if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke) stroke; // linewidth this.gc.setLineWidth((int) bs.getLineWidth()); // line join switch (bs.getLineJoin()) { case BasicStroke.JOIN_BEVEL : this.gc.setLineJoin(SWT.JOIN_BEVEL); break; case BasicStroke.JOIN_MITER : this.gc.setLineJoin(SWT.JOIN_MITER); break; case BasicStroke.JOIN_ROUND : this.gc.setLineJoin(SWT.JOIN_ROUND); break; } // line cap switch (bs.getEndCap()) { case BasicStroke.CAP_BUTT : this.gc.setLineCap(SWT.CAP_FLAT); break; case BasicStroke.CAP_ROUND : this.gc.setLineCap(SWT.CAP_ROUND); break; case BasicStroke.CAP_SQUARE : this.gc.setLineCap(SWT.CAP_SQUARE); break; } // set the line style to solid by default this.gc.setLineStyle(SWT.LINE_SOLID); // apply dash style if any float[] dashes = bs.getDashArray(); if (dashes != null) { int[] swtDashes = new int[dashes.length]; for (int i = 0; i < swtDashes.length; i++) { swtDashes[i] = (int) dashes[i]; } this.gc.setLineDash(swtDashes); } } else { throw new RuntimeException( "Can only handle 'Basic Stroke' at present."); } }
Example 17
Source File: java_awt_BasicStroke.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
protected BasicStroke getAnotherObject() { float[] f = {1.0f, 2.0f, 3.0f, 4.0f}; return new BasicStroke(f[1], BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, f[2], f, f[3]); }
Example 18
Source File: ROCChartPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
private JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title null, // x axis label null, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); ValueAxis valueAxis = plot.getRangeAxis(); valueAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD); valueAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD); domainAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT); DeviationRenderer renderer = new DeviationRenderer(true, false); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); if (dataset.getSeriesCount() == 1) { renderer.setSeriesStroke(0, stroke); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); } else if (dataset.getSeriesCount() == 2) { renderer.setSeriesStroke(0, stroke); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); renderer.setSeriesStroke(1, stroke); renderer.setSeriesPaint(1, Color.BLUE); renderer.setSeriesFillPaint(1, Color.BLUE); } else { for (int i = 0; i < dataset.getSeriesCount(); i++) { renderer.setSeriesStroke(i, stroke); Color color = colorProvider.getPointColor((double) i / (double) (dataset.getSeriesCount() - 1)); renderer.setSeriesPaint(i, color); renderer.setSeriesFillPaint(i, color); } } renderer.setAlpha(0.12f); plot.setRenderer(renderer); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(PlotterAdapter.LABEL_FONT); } return chart; }
Example 19
Source File: WPathGraphics.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Draw a line using a pen created using the specified color * and current stroke properties. */ @Override protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) { Stroke stroke = getStroke(); if (stroke instanceof BasicStroke) { BasicStroke lineStroke = (BasicStroke) stroke; if (lineStroke.getDashArray() != null) { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); return; } float lineWidth = lineStroke.getLineWidth(); Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth); AffineTransform deviceTransform = getTransform(); deviceTransform.deltaTransform(penSize, penSize); float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y)); Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin); deviceTransform.transform(begin_pos, begin_pos); Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd); deviceTransform.transform(end_pos, end_pos); int endCap = lineStroke.getEndCap(); int lineJoin = lineStroke.getLineJoin(); /* check if it's a one-pixel line */ if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) { /* endCap other than Round will not print! * due to Windows GDI limitation, force it to CAP_ROUND */ endCap = BasicStroke.CAP_ROUND; } WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob(); /* call native function that creates pen with style */ if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) { wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } /* selectStylePen is not supported, must be Win 9X */ else { /* let's see if we can use a a default pen * if it's round end (Windows' default style) * or it's vertical/horizontal * or stroke is too thin. */ double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes()); if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth/lowerRes < MAX_THINLINE_INCHES))) { wPrinterJob.selectPen(deviceLineWidth, color); wPrinterJob.moveTo((float)begin_pos.getX(), (float)begin_pos.getY()); wPrinterJob.lineTo((float)end_pos.getX(), (float)end_pos.getY()); } else { draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd)); } } } }
Example 20
Source File: DrawOptions.java From Pixie with MIT License | 2 votes |
/** * Get the configuration of the Stroke in such way as to have a dashed line. * * @return the basic stroke representing a dashed line */ public static BasicStroke getDashedStroke() { return new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[]{2f}, 0f); }