List of usage examples for java.awt Stroke getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
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. j a va 2s. c om*/ 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:org.apache.fop.afp.AFPGraphics2D.java
/** * Apply the stroke to the AFP graphics object. * This takes the java stroke and outputs the appropriate settings * to the AFP graphics object so that the stroke attributes are handled. * * @param stroke the java stroke// ww w. ja v a 2 s. com */ protected void applyStroke(Stroke stroke) { if (stroke instanceof BasicStroke) { BasicStroke basicStroke = (BasicStroke) stroke; // set line width and correct it; NOTE: apparently we need to correct the width so that the // output looks OK since the default with depends on the output device float lineWidth = basicStroke.getLineWidth(); float correction = paintingState.getLineWidthCorrection(); graphicsObj.setLineWidth(lineWidth * correction); //No line join, miter limit and end cap support in GOCA. :-( // set line type/style (note: this is an approximation at best!) float[] dashArray = basicStroke.getDashArray(); if (paintingState.setDashArray(dashArray)) { byte type = GraphicsSetLineType.DEFAULT; // normally SOLID if (dashArray != null) { type = GraphicsSetLineType.DOTTED; // default to plain DOTTED if dashed line // float offset = basicStroke.getDashPhase(); if (dashArray.length == 2) { if (dashArray[0] < dashArray[1]) { type = GraphicsSetLineType.SHORT_DASHED; } else if (dashArray[0] > dashArray[1]) { type = GraphicsSetLineType.LONG_DASHED; } } else if (dashArray.length == 4) { if (dashArray[0] > dashArray[1] && dashArray[2] < dashArray[3]) { type = GraphicsSetLineType.DASH_DOT; } else if (dashArray[0] < dashArray[1] && dashArray[2] < dashArray[3]) { type = GraphicsSetLineType.DOUBLE_DOTTED; } } else if (dashArray.length == 6) { if (dashArray[0] > dashArray[1] && dashArray[2] < dashArray[3] && dashArray[4] < dashArray[5]) { type = GraphicsSetLineType.DASH_DOUBLE_DOTTED; } } } graphicsObj.setLineType(type); } } else { LOG.warn("Unsupported Stroke: " + stroke.getClass().getName()); } }