List of usage examples for java.awt Paint getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
/** * Serialises a <code>Paint</code> object. * * @param paint the paint 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 va2 s .com public static void writePaint(final Paint paint, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (paint != null) { stream.writeBoolean(false); stream.writeObject(paint.getClass()); if (paint instanceof Serializable) { stream.writeObject(paint); } else if (paint instanceof GradientPaint) { final GradientPaint gp = (GradientPaint) paint; stream.writeFloat((float) gp.getPoint1().getX()); stream.writeFloat((float) gp.getPoint1().getY()); stream.writeObject(gp.getColor1()); stream.writeFloat((float) gp.getPoint2().getX()); stream.writeFloat((float) gp.getPoint2().getY()); stream.writeObject(gp.getColor2()); stream.writeBoolean(gp.isCyclic()); } } else { stream.writeBoolean(true); } }
From source file:PaintUtils.java
private static Paint resizeLinearGradient(Paint p, int width, int height) { try {// w ww. j a v a 2 s .c o m Point2D[] pts = new Point2D[2]; pts[0] = (Point2D) invokeMethod(p, "getStartPoint"); pts[1] = (Point2D) invokeMethod(p, "getEndPoint"); pts = adjustPoints(pts, width, height); float[] fractions = (float[]) invokeMethod(p, "getFractions"); Color[] colors = (Color[]) invokeMethod(p, "getColors"); Constructor<?> con = p.getClass().getDeclaredConstructor(Point2D.class, Point2D.class, new float[0].getClass(), new Color[0].getClass()); return (Paint) con.newInstance(pts[0], pts[1], fractions, colors); } catch (Exception ex) { ex.printStackTrace(); } return p; }
From source file:PaintUtils.java
/** Resizes a gradient to fill the width and height available. If the * gradient is left to right it will be resized to fill the entire width. * If the gradient is top to bottom it will be resized to fill the entire * height. If the gradient is on an angle it will be resized to go from * one corner to the other of the rectangle formed by (0,0 -> width,height). * * This method can resize java.awt.GradientPaint, java.awt.LinearGradientPaint, * and the LinearGradientPaint implementation from Apache's Batik project. Note, * this method does not require the MultipleGradientPaint.jar from Apache to * compile or to run. MultipleGradientPaint.jar *is* required if you want * to resize the LinearGradientPaint from that jar. * * Any paint passed into this method which is not a kind of gradient paint (like * a Color or TexturePaint) will be returned unmodified. It will not throw * an exception. If the gradient cannot be resized due to other errors the * original paint will be returned unmodified. It will not throw an * exception./*from w w w.j a v a 2s . com*/ * */ public static Paint resizeGradient(Paint p, int width, int height) { if (p == null) return p; if (p instanceof GradientPaint) { GradientPaint gp = (GradientPaint) p; Point2D[] pts = new Point2D[2]; pts[0] = gp.getPoint1(); pts[1] = gp.getPoint2(); pts = adjustPoints(pts, width, height); return new GradientPaint(pts[0], gp.getColor1(), pts[1], gp.getColor2(), gp.isCyclic()); } if ("java.awt.LinearGradientPaint".equals(p.getClass().getName()) || "org.apache.batik.ext.awt.LinearGradientPaint".equals(p.getClass().getName())) { return resizeLinearGradient(p, width, height); } return p; }
From source file:org.apache.fop.render.pdf.pdfbox.PSPDFGraphics2D.java
private void transformCoords(float[] coords, Paint paint, boolean axialShading) { try {//from w w w. j a v a 2 s.com Field f = paint.getClass().getDeclaredField("matrix"); f.setAccessible(true); Matrix ctm = (Matrix) f.get(paint); AffineTransform at = ctm.createAffineTransform(); if (axialShading) { at.transform(coords, 0, coords, 0, 2); } else { at.transform(coords, 0, coords, 0, 1); at.transform(coords, 3, coords, 3, 1); coords[2] *= ctm.getScalingFactorX(); coords[5] *= ctm.getScalingFactorX(); } } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }