⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorpattern.java

📁 Java生成PDF Java生成PDF Java生成PDF
💻 JAVA
字号:
// $Id: ColorPattern.java,v 1.5 2003/11/04 17:16:01 mike Exp $package org.faceless.pdf;import java.awt.*;/** * <p> * A ColorPattern is a subclass of <code>Paint</code> that can be used with * this library to fill shapes with a pattern. Currently the patterns must be * chosen from a list of predefined patterns, and are limited to two colors * (although this may change in future versions of the library). Prior to * version 1.2 of the library, this class was a subclass of <code>java.awt.Color</code>. * Here's an example. * </p> * <pre> *   PDFStyle style = new PDFStyle(); *   ColorPattern c = ColorPattern.star(Color.red, Color.blue, 20); *   style.setFillColor(c); *   page.setStyle(style); *   page.drawRectangle(100,100, 200,200); * </pre> * This will draw a rectangle filled with red stars on a blue background. * @since 1.1 */public class ColorPattern extends PeeredObject implements Paint, Cloneable{    final org.faceless.pdf2.PDFPattern pattern;     Object getPeer()    {        return pattern;    }    ColorPattern(org.faceless.pdf2.PDFPattern pattern)    {        this.pattern=pattern;    }    /**     * Create a new ColorPattern consisting of parallel stripes.     * @param background the background color of the pattern     * @param foreground the foreground color of the pattern     * @param on the width of each stripe, in points     * @param off the width of the space between each stripe, in points     * @param angle the angle of the stripe in degrees clockwise, with 0 at 12 o'clock     */    public static ColorPattern stripe(Color background, Color foreground, float on, float off, float angle)    {	return new ColorPattern(new org.faceless.pdf2.PDFPattern("Stripe"+((int)angle), 0, 0, on, off, foreground, background));    }    /**     * Create a new ColorPattern resembling a brick wall (specifically, a brick     * wall with a running pattern bond).     * @param background the background color of the pattern     * @param foreground the foreground color of the pattern     * @param width the width of each brick, in points     * @param height the height of each brick, in points     */    public static ColorPattern brick(Color background, Color foreground, float width, float height)    {	return new ColorPattern(new org.faceless.pdf2.PDFPattern("Brick", 0, 0, width, height*2, foreground, background));    }    /**     * Create a new ColorPattern with a simple check pattern.     * @param background the background color of the pattern     * @param foreground the foreground color of the pattern     * @param size the width and height of each check, in points     */    public static ColorPattern check(Color background, Color foreground, float size)    {	return new ColorPattern(new org.faceless.pdf2.PDFPattern("Check", 0, 0, size*2, size*2, foreground, background));    }    /**     * Create a new ColorPattern with a simple grid pattern.     * @param background the background color of the pattern     * @param foreground the foreground color of the pattern     * @param on the thickness of each line on the grid, in points     * @param off the distance between each line on the grid, in points     */    public static ColorPattern grid(Color background, Color foreground, float on, float off)    {	return new ColorPattern(new org.faceless.pdf2.PDFPattern("Grid", 0, 0, on+off, on+off, background, foreground));    }    /**     * Create a new ColorPattern with a spot pattern, similar to that used in     * halftoning patterns in newspapers.     * @param background the background color of the pattern     * @param foreground the foreground color of the pattern     * @param size the radius of each spot     */    public static ColorPattern spot(Color background, Color foreground, float size)    {	return new ColorPattern(new org.faceless.pdf2.PDFPattern("Spot", 0, 0, size*2, size*2, foreground, background));    }    /**     * Create a new ColorPattern with a polka dot pattern of random spots.     * @param background the background color of the pattern     * @param foreground the foreground color of the pattern     * @param size The size of the pattern in points. Each spot is between 10% and     * 20% of this size.     */    public static ColorPattern polka(Color background, Color foreground, float size)    {	return new ColorPattern(new org.faceless.pdf2.PDFPattern("Polka", 0, 0, size*2, size*2, foreground, background));    }    /**     * Create a new ColorPattern with a five-pointed star pattern, like that on     * the US flag.     * @param background the background color of the pattern     * @param foreground the foreground color of the pattern     * @param size the size of each star, in points     */    public static ColorPattern star(Color background, Color foreground, float size)    {	return new ColorPattern(new org.faceless.pdf2.PDFPattern("Star", 0, 0, size*2, size*2, foreground, background));    }    /**     * Return a copy of this ColorPattern with the brightness adjusted.     * Prior to version 1.2 this method adjusted the color inline and     * returned <code>void</code>.     *     * @param delta the amount to add the the brightness. The value     * should be between -1 and 1     * @param min the minimum allowable level of brightness. May     * be between 0 and 1     * @param max the maximum allowable level of brightness. May     * be between 0 and 1     */    public ColorPattern adjustBrightness(float delta, float min, float max)    {	return (ColorPattern)PeeredObject.getPeer(pattern.brightnessClone(delta,min,max));    }    public Object clone()    {//	return (ColorPattern)PeeredObject.getPeer(pattern.clone());	//TODO	throw new Error("Not implemented");    }    public int getTransparency()    {	return pattern.getTransparency();    }    /**     * As this method is intended for AWT use only, it is not implemented     * and will throw an <code>UnsupportedOperationException</code> if called     */    public PaintContext createContext(java.awt.image.ColorModel cm, Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, RenderingHints hints)    {        throw new UnsupportedOperationException("createContext not appropriate for ColorPattern");    }    /**     *  Return the background color of the pattern     */    public Color getBackgroundColor()    {        return null;    }    /**     *  Return the foreground color of the pattern     */    public Color getForegroundColor()    {        return null;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -