List of usage examples for java.awt BasicStroke getEndCap
public int getEndCap()
From source file:Main.java
public static void main(String[] args) { BasicStroke stroke = new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.1F); System.out.println(stroke.getEndCap()); }
From source file:Main.java
/** * Serialises a <code>Stroke</code> object. This code handles the * <code>BasicStroke</code> class which is the only <code>Stroke</code> * implementation provided by the JDK (and isn't directly * <code>Serializable</code>). * * @param stroke the stroke object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. *///from w w w . java2 s .c o m public static void writeStroke(final Stroke stroke, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (stroke != null) { stream.writeBoolean(false); if (stroke instanceof BasicStroke) { final BasicStroke s = (BasicStroke) stroke; stream.writeObject(BasicStroke.class); stream.writeFloat(s.getLineWidth()); stream.writeInt(s.getEndCap()); stream.writeInt(s.getLineJoin()); stream.writeFloat(s.getMiterLimit()); stream.writeObject(s.getDashArray()); stream.writeFloat(s.getDashPhase()); } else { stream.writeObject(stroke.getClass()); stream.writeObject(stroke); } } else { stream.writeBoolean(true); } }
From source file:Main.java
public static void writeStroke(Stroke aStroke, ObjectOutputStream out) throws IOException { if (aStroke instanceof Serializable) { out.writeBoolean(true);//from w w w . j av a 2s . c o m out.writeBoolean(true); out.writeObject(aStroke); } else if (aStroke instanceof BasicStroke) { out.writeBoolean(true); out.writeBoolean(false); BasicStroke s = (BasicStroke) aStroke; float[] dash = s.getDashArray(); if (dash == null) { out.write(0); } else { out.write(dash.length); for (int i = 0; i < dash.length; i++) { out.writeFloat(dash[i]); } } out.writeFloat(s.getLineWidth()); out.writeInt(s.getEndCap()); out.writeInt(s.getLineJoin()); out.writeFloat(s.getMiterLimit()); out.writeFloat(s.getDashPhase()); } else { out.writeBoolean(false); } }
From source file:Java2DUtils.java
/** * This function provides a way to cancel the effects of the zoom on a particular Stroke. * All the stroke values (as line width, dashes, etc...) are divided by the zoom factor. * This allow to have essentially a fixed Stroke independent by the zoom. * The returned Stroke is a copy.//ww w . j a va 2 s. c o m * Remember to restore the right stroke in the graphics when done. * * It works only with instances of BasicStroke * * zoom is the zoom factor. */ public static Stroke getInvertedZoomedStroke(Stroke stroke, double zoom) { if (stroke == null || !(stroke instanceof BasicStroke)) return stroke; BasicStroke bs = (BasicStroke) stroke; float[] dashArray = bs.getDashArray(); float[] newDashArray = null; if (dashArray != null) { newDashArray = new float[dashArray.length]; for (int i = 0; i < newDashArray.length; ++i) { newDashArray[i] = (float) (dashArray[i] / zoom); } } BasicStroke newStroke = new BasicStroke((float) (bs.getLineWidth() / zoom), bs.getEndCap(), bs.getLineJoin(), bs.getMiterLimit(), //(float)(bs.getMiterLimit() / zoom), newDashArray, (float) (bs.getDashPhase() / zoom)); return newStroke; }
From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.StrokePath.java
/** * S stroke the path.//w ww. j av a2 s .c o m * @param operator The operator that is being executed. * @param arguments List * * @throws java.io.IOException If an error occurs while processing the font. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { ///dwilson 3/19/07 refactor try { GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context; float lineWidth = (float) context.getGraphicsState().getLineWidth(); Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix(); if (ctm != null && ctm.getXScale() > 0) { lineWidth = lineWidth * ctm.getXScale(); } BasicStroke stroke = (BasicStroke) drawer.getStroke(); if (stroke == null) { drawer.setStroke(new BasicStroke(lineWidth)); } else { drawer.setStroke(new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(), stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase())); } drawer.strokePath(); } catch (Exception exception) { log.warn(exception, exception); } }
From source file:net.sf.jasperreports.customizers.marker.AbstractMarkerCustomizer.java
protected BasicStroke getStroke(Float strokeWidth) { BasicStroke basicStroke = new BasicStroke(strokeWidth); StrokeStyleEnum strokeStyle = StrokeStyleEnum.getByName(getProperty(PROPERTY_STROKE_STYLE)); if (strokeStyle != null) { switch (strokeStyle) { case SOLID: { //do nothing; already created stroke is good break; }/* w ww . ja v a 2s. c o m*/ case DOTTED: { basicStroke = new BasicStroke(basicStroke.getLineWidth(), basicStroke.getEndCap(), basicStroke.getLineJoin(), basicStroke.getMiterLimit(), new float[] { 1.0f, 1.0f }, basicStroke.getDashPhase()); break; } case DASHED: { basicStroke = new BasicStroke(basicStroke.getLineWidth(), basicStroke.getEndCap(), basicStroke.getLineJoin(), basicStroke.getMiterLimit(), new float[] { 10.0f, 10.0f }, basicStroke.getDashPhase()); break; } } } return basicStroke; }
From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java
/** * Returns the stroke used to outline data items. The default * implementation passes control to the//from w w w . j a va 2 s . c o m * {@link #lookupSeriesOutlineStroke(int)} method. You can override this * method if you require different behaviour. * * @param row the row (or series) index (zero-based). * @param column the column (or category) index (zero-based). * @return The stroke (never <code>null</code>). */ @Override public Stroke getItemOutlineStroke(int row, int column) { Number z = dataset.getZ(row, column); BasicStroke stroke = DEFAULT_OUTLINE_STROKE; if (shouldHighlight(row, column)) { stroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL); } if (z == null) { stroke = new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(), stroke.getMiterLimit(), new float[] { 5.0f, 5.0f }, 0.0f); } return stroke; }
From source file:org.moeaframework.analysis.plot.Plot.java
/** * Modifies the line thickness or point size in the last dataset. The * size is applied to all series in the dataset. * // w ww .j ava2 s . c om * @param size the size * @return a reference to this {@code Plot} instance */ public Plot withSize(float size) { if (chart.getPlot() instanceof XYPlot) { XYPlot plot = chart.getXYPlot(); XYItemRenderer renderer = plot.getRenderer(currentDataset); if (renderer instanceof XYDotRenderer) { ((XYDotRenderer) renderer).setDotWidth((int) (size * 2)); ((XYDotRenderer) renderer).setDotHeight((int) (size * 2)); } else if (renderer.getBaseStroke() instanceof BasicStroke) { BasicStroke oldStroke = (BasicStroke) renderer.getBaseStroke(); BasicStroke newStroke = new BasicStroke(size, oldStroke.getEndCap(), oldStroke.getLineJoin(), oldStroke.getMiterLimit(), oldStroke.getDashArray(), oldStroke.getDashPhase()); renderer.setBaseStroke(newStroke); } else { renderer.setBaseStroke(new BasicStroke(size, 1, 1)); } } return this; }
From source file:org.jfree.experimental.swt.SWTGraphics2D.java
/** * 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()/*from www .jav a 2 s .c o m*/ */ public void setStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } if (stroke instanceof BasicStroke) { BasicStroke bs = (BasicStroke) stroke; this.gc.setLineWidth((int) bs.getLineWidth()); this.gc.setLineJoin(toSwtLineJoin(bs.getLineJoin())); this.gc.setLineCap(toSwtLineCap(bs.getEndCap())); // 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."); } }
From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java
private void updateGraph() { XYSeriesCollection dataset = new XYSeriesCollection(); Collection<Stairs> loadProfileEnities = transform( filter(loadProfilesController.getTreeItems(), new IsStairsPredicate()), new LoadProfileEntityToStairsFunction()); GraphPointsCalculator calc = new GraphPointsCalculator(); Map<String, Set<Point>> pointsMap = calc.calculatePoints(loadProfileEnities); for (Entry<String, Set<Point>> entry : pointsMap.entrySet()) { final XYSeries series = new XYSeries(entry.getKey()); for (Point point : entry.getValue()) { series.add(point.getX(), point.getY()); }//ww w . j av a 2 s .c o m dataset.addSeries(series); } String name = txtName.getText(); chart = ChartFactory.createXYLineChart(name, "t (min)", "Executions (1/h)", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); double maxX = 0; for (OneTime oneTime : getOneTimes()) { String key = oneTime.operation.getName(); XYSeries series; try { // We need the series in order to retrieve paint and stroke series = dataset.getSeries(key); } catch (UnknownKeyException ex) { series = new XYSeries(key); dataset.addSeries(series); } int index = dataset.getSeriesIndex(key); BasicStroke stroke = (BasicStroke) renderer.lookupSeriesStroke(index); stroke = new BasicStroke(stroke.getLineWidth() + 1f, stroke.getEndCap(), stroke.getLineJoin(), stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()); Color paint = (Color) renderer.lookupSeriesPaint(index); paint = new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), 160); double height = rangeAxis.getUpperBound() * .05; // five percent of range double width = domainAxis.getUpperBound() * .01; // one percent of range double center = oneTime.t0; double left = center - width / 2; double right = center + width / 2; // We only add annotations for one times, but nothing to the series plot.addAnnotation(new XYPolygonAnnotation(new double[] { left, 0d, center, height, right, 0d }, stroke, paint, paint)); maxX = max(maxX, right); } for (Marker marker : getMarkers()) { IntervalMarker im = new IntervalMarker(marker.left, marker.right); im.setLabel(marker.name); im.setLabelFont(new Font(getFont().getName(), getFont().getStyle(), getFont().getSize() + 1)); im.setLabelAnchor(RectangleAnchor.TOP); im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d)); im.setLabelPaint(Color.BLACK); im.setAlpha(.3f); im.setPaint(Color.WHITE); im.setOutlinePaint(Color.BLACK); im.setOutlineStroke(new BasicStroke(1.0f)); plot.addDomainMarker(im, Layer.BACKGROUND); maxX = max(maxX, marker.right); } if (domainAxis.getUpperBound() < maxX) { domainAxis.setUpperBound(maxX * 1.05); } chartPanel.setChart(chart); }