类java.awt.TexturePaint源码实例Demo

下面列出了怎么用java.awt.TexturePaint的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u_jdk   文件: RenderTests.java
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
源代码2 项目: amidst   文件: Drawer.java
@CalledOnlyBy(AmidstThread.EDT)
public Drawer(
		FragmentGraph graph,
		FragmentGraphToScreenTranslator translator,
		Zoom zoom,
		Movement movement,
		List<Widget> widgets,
		Iterable<FragmentDrawer> drawers,
		Setting<Dimension> dimensionSetting,
		Graphics2DAccelerationCounter accelerationCounter) {
	this.graph = graph;
	this.translator = translator;
	this.zoom = zoom;
	this.movement = movement;
	this.widgets = widgets;
	this.drawers = drawers;
	this.dimensionSetting = dimensionSetting;
	this.accelerationCounter = accelerationCounter;
	this.voidTexturePaint = new TexturePaint(
			VOID_TEXTURE,
			new Rectangle(0, 0, VOID_TEXTURE.getWidth(), VOID_TEXTURE.getHeight()));
}
 
源代码3 项目: MeteoInfo   文件: Draw.java
/**
 * Fill polygon
 *
 * @param points The points array
 * @param g Graphics2D
 * @param aPGB Polygon break
 */
public static void fillPolygon(PointF[] points, Graphics2D g, PolygonBreak aPGB) {
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
    for (int i = 0; i < points.length; i++) {
        if (i == 0) {
            path.moveTo(points[i].X, points[i].Y);
        } else {
            path.lineTo(points[i].X, points[i].Y);
        }
    }
    path.closePath();

    if (aPGB != null) {
        if (aPGB.isUsingHatchStyle()) {
            int size = aPGB.getStyleSize();
            BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
            Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
            g.setPaint(new TexturePaint(bi, rect));
            g.fill(path);
        } else {
            g.fill(path);
        }
    } else {
        g.fill(path);
    }
}
 
源代码4 项目: MeteoInfo   文件: Draw.java
/**
 * Fill polygon
 *
 * @param points The points array
 * @param g Graphics2D
 * @param aPGB Polygon break
 */
public static void fillPolygon(PointD[] points, Graphics2D g, PolygonBreak aPGB) {
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length);
    for (int i = 0; i < points.length; i++) {
        if (i == 0) {
            path.moveTo(points[i].X, points[i].Y);
        } else {
            path.lineTo(points[i].X, points[i].Y);
        }
    }
    path.closePath();

    if (aPGB != null) {
        if (aPGB.isUsingHatchStyle()) {
            int size = aPGB.getStyleSize();
            BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
            Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
            g.setPaint(new TexturePaint(bi, rect));
            g.fill(path);
        } else {
            g.fill(path);
        }
    } else {
        g.fill(path);
    }
}
 
源代码5 项目: pumpernickel   文件: ColorWellUI.java
@Override
public void paint(Graphics g0, JComponent c) {
	Graphics2D g = (Graphics2D) g0;
	JColorWell well = (JColorWell) c;
	Color color = well.getColorSelectionModel().getSelectedColor();
	Border border = c.getBorder();
	Insets borderInsets = border.getBorderInsets(c);
	if (color.getAlpha() < 255) {
		TexturePaint checkers = PlafPaintUtils.getCheckerBoard(8);
		g.setPaint(checkers);
		g.fillRect(borderInsets.left, borderInsets.top, c.getWidth()
				- borderInsets.left - borderInsets.right, c.getHeight()
				- borderInsets.top - borderInsets.bottom);
	}
	g.setColor(color);
	g.fillRect(borderInsets.left, borderInsets.top, c.getWidth()
			- borderInsets.left - borderInsets.right, c.getHeight()
			- borderInsets.top - borderInsets.bottom);
}
 
源代码6 项目: MeteoInfo   文件: Draw.java
/**
 * Draw rectangle
 *
 * @param aPoint Start point
 * @param width Width
 * @param height Height
 * @param aPGB Polygon break
 * @param g Graphics2D
 */
public static void drawRectangle(PointF aPoint, float width, float height, PolygonBreak aPGB, Graphics2D g) {
    Color aColor = aPGB.getColor();
    if (aPGB.isDrawFill()) {
        if (aPGB.isUsingHatchStyle()) {
            int size = aPGB.getStyleSize();
            BufferedImage bi = getHatchImage(aPGB.getStyle(), size, aPGB.getColor(), aPGB.getBackColor());
            Rectangle2D rect = new Rectangle2D.Double(0, 0, size, size);
            g.setPaint(new TexturePaint(bi, rect));
            g.fill(new Rectangle.Float(aPoint.X, aPoint.Y, width, height));
        } else {
            g.setColor(aColor);
            g.fill(new Rectangle.Float(aPoint.X, aPoint.Y, width, height));
        }
    }
    if (aPGB.isDrawOutline()) {
        g.setColor(aPGB.getOutlineColor());
        g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
        g.draw(new Rectangle.Float(aPoint.X, aPoint.Y, width, height));
    }
}
 
源代码7 项目: dragonwell8_jdk   文件: RenderTests.java
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
public void doPaint(Graphics2D g2d) {
    BufferedImage patternImage = new BufferedImage(2,2,BufferedImage.TYPE_INT_ARGB);
            Graphics gImage = patternImage.getGraphics();
            gImage.setColor(Color.WHITE);
            gImage.drawLine(0,1,1,0);
            gImage.setColor(Color.BLACK);
            gImage.drawLine(0,0,1,1);
            gImage.dispose();

            Rectangle2D.Double shape = new Rectangle2D.Double(0,0,DIM*6/5, DIM*8/5);
            g2d.setPaint(new TexturePaint(patternImage, new Rectangle2D.Double(0,0,
                    DIM*6/50, DIM*8/50)));
            g2d.fill(shape);
            g2d.setPaint(Color.BLACK);
            g2d.draw(shape);

}
 
源代码9 项目: openjdk-8   文件: RenderTests.java
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
源代码10 项目: openjdk-jdk8u   文件: RenderTests.java
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
源代码11 项目: mars-sim   文件: TexturedText.java
public void paint(Graphics g) {
  Graphics2D g2 = (Graphics2D) g;

  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
      RenderingHints.VALUE_ANTIALIAS_ON);
  Font font = new Font("Times New Roman", Font.PLAIN, 72);
  g2.setFont(font);

  String s = "Java Source and Support";
  Dimension d = getSize();
  float x = 20, y = 100;

  BufferedImage bi = getTextureImage();
  Rectangle r = new Rectangle(0, 0, bi.getWidth(), bi.getHeight());
  TexturePaint tp = new TexturePaint(bi, r);
  g2.setPaint(tp);

  g2.drawString(s, x, y);
}
 
源代码12 项目: jdk8u-dev-jdk   文件: RenderTests.java
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
源代码13 项目: jdk8u-jdk   文件: RenderTests.java
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: RenderTests.java
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
源代码15 项目: jdk8u_jdk   文件: TexturePaintPrintingTest.java
public void doPaint(Graphics2D g2d) {
    BufferedImage patternImage = new BufferedImage(2,2,BufferedImage.TYPE_INT_ARGB);
            Graphics gImage = patternImage.getGraphics();
            gImage.setColor(Color.WHITE);
            gImage.drawLine(0,1,1,0);
            gImage.setColor(Color.BLACK);
            gImage.drawLine(0,0,1,1);
            gImage.dispose();

            Rectangle2D.Double shape = new Rectangle2D.Double(0,0,DIM*6/5, DIM*8/5);
            g2d.setPaint(new TexturePaint(patternImage, new Rectangle2D.Double(0,0,
                    DIM*6/50, DIM*8/50)));
            g2d.fill(shape);
            g2d.setPaint(Color.BLACK);
            g2d.draw(shape);

}
 
public void doPaint(Graphics2D g2d) {
    BufferedImage patternImage = new BufferedImage(2,2,BufferedImage.TYPE_INT_ARGB);
            Graphics gImage = patternImage.getGraphics();
            gImage.setColor(Color.WHITE);
            gImage.drawLine(0,1,1,0);
            gImage.setColor(Color.BLACK);
            gImage.drawLine(0,0,1,1);
            gImage.dispose();

            Rectangle2D.Double shape = new Rectangle2D.Double(0,0,DIM*6/5, DIM*8/5);
            g2d.setPaint(new TexturePaint(patternImage, new Rectangle2D.Double(0,0,
                    DIM*6/50, DIM*8/50)));
            g2d.fill(shape);
            g2d.setPaint(Color.BLACK);
            g2d.draw(shape);

}
 
源代码17 项目: dsworkbench   文件: WelcomePanel.java
/** Creates new form WelcomePanel */
public WelcomePanel() {
    initComponents();
    setOpaque(true);
    welcomeTooltipMap.put(jxHelpLabel, "<html> <h2 style='color:#953333; font-weight: bold;'>Integrierte Hilfe</h2> DS Workbench bietet eine umfangreiche Hilfe, die du im Programm jederzeit &uuml;ber <strong>F1</strong> aufrufen kannst. Dabei wird versucht, das passende Hilfethema f&uuml;r die Ansicht, in der du dich gerade befindest, auszuw&auml;hlen. Es schadet aber auch nicht, einfach mal so in der Hilfe zu st&ouml;bern um neue Funktionen zu entdecken. Einsteiger sollten in jedem Fall die ersten drei Kapitel der Wichtigen Grundlagen gelesen haben.</html>");
    welcomeTooltipMap.put(jxCommunityLabel, "<html> <h2 style='color:#953333; font-weight: bold;'>Die DS Workbench Community</h2> Nat&uuml;rlich gibt es neben dir noch eine Vielzahl anderer Spieler, die DS Workbench regelm&auml;&szlig;ig und intensiv benutzen. Einen perfekten Anlaufpunkt f&uuml;r alle Benutzer bietet das DS Workbench Forum, wo man immer jemanden trifft mit dem man Erfahrungen austauschen und wo man Fragen stellen kann.</html>");
    welcomeTooltipMap.put(jxIdeaLabel, "<html> <h2 style='color:#953333; font-weight: bold;'>Verbesserungen und Ideen </h2> Gibt es irgendwas wo du meinst, dass es in DS Workbench fehlt und was anderen Benutzern auch helfen k&ouml;nnte? Hast du eine Idee, wie man DS Workbench verbessern oder die Handhabung vereinfachen k&ouml;nnte? Dann bietet dieser Bereich im DS Workbench Forum die perfekte Anlaufstelle f&uuml;r dich. Trau dich und hilf mit, DS Workbench  zu verbessern. </html>");
    welcomeTooltipMap.put(jxFacebookLabel, "<html> <h2 style='color:#953333; font-weight: bold;'>DS Workbench @ Facebook</h2> Nat&uuml;rlich geh&ouml;rt es heutzutage fast zum guten Ton, bei Facebook in irgendeiner Art und Weise vertreten zu sein. Auch DS Workbench hat eine eigene Facebook Seite, mit deren Hilfe ihr euch jederzeit &uuml;ber aktuelle News oder Geschehnisse im Zusammenhang mit DS Workbench informieren k&ouml;nnt.</html>");
    welcomeTooltipMap.put(jContentLabel, "<html> <h2 style='color:#953333'>Willkommen bei DS Workbench</h2> Wenn du diese Seite siehst, dann hast du DS Workbench erfolgreich installiert und die ersten Schritte ebenso erfolgreich gemeistert. Eigentlich steht nun einer unbeschwerten Angriffsplanung und -durchf&uuml;hrung nichts mehr im Wege. Erlaube mir trotzdem kurz auf einige Dinge hinzuweisen, die dir m&ouml;glicherweise beim <b>Umgang mit DS Workbench helfen</b> oder aber dir die M&ouml;glichkeit geben, einen wichtigen Teil zur <b>Weiterentwicklung und stetigen Verbesserung</b> dieses Programms beizutragen. Fahre einfach mit der Maus &uuml;ber eins der vier Symbole in den Ecken, um hilfreiche und interessante Informationen rund um DS Workbench zu erfahren. Klicke auf ein Symbol, um direkt zum entsprechenden Ziel zu gelangen. Die Eintr&auml;ge findest du sp&auml;ter auch im Hauptmen&uuml; unter 'Sonstiges'. <br> <h3 style='color:#953333'> Nun aber viel Spa&szlig; mit DS Workbench.</h3> </html>");
    try {
        back = ImageIO.read(WelcomePanel.class.getResource("/images/c.gif"));
    } catch (Exception ignored) {
    }
    if (back != null) {
        setBackgroundPainter(new MattePainter(new TexturePaint(back, new Rectangle2D.Float(0, 0, 200, 20))));
    }
}
 
源代码18 项目: mars-sim   文件: TrafficLight.java
public BufferedImage createRedOffImage(final int WIDTH, final int HEIGHT) {
    final GraphicsConfiguration GFX_CONF = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    if (WIDTH <= 0 || HEIGHT <= 0) {
        return GFX_CONF.createCompatibleImage(1, 1, java.awt.Transparency.TRANSLUCENT);
    }
    final BufferedImage IMAGE = GFX_CONF.createCompatibleImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();
    final Ellipse2D LIGHT_OFF = new Ellipse2D.Double(0.17346938775510204 * IMAGE_WIDTH, 0.07553956834532374 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.1906474820143885 * IMAGE_HEIGHT), (0.32653061224489793f * IMAGE_WIDTH), new float[]{0.0f, 1.0f}, new Color[]{new Color(1f, 0f, 0f, 0.2470588235f), new Color(1f, 0f, 0f, 0.0470588235f)}));
    G2.fill(LIGHT_OFF);

    final Ellipse2D INNER_SHADOW = new Ellipse2D.Double(0.17346938775510204 * IMAGE_WIDTH, 0.07553956834532374 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.1906474820143885 * IMAGE_HEIGHT), (0.32653061224489793f * IMAGE_WIDTH), new float[]{0.0f, 0.55f, 0.5501f, 0.78f, 0.79f, 1.0f}, new Color[]{new Color(0.0039215686f, 0.0039215686f, 0.0039215686f, 0f), new Color(0f, 0f, 0f, 0f), new Color(0f, 0f, 0f, 0f), new Color(0f, 0f, 0f, 0.1215686275f), new Color(0f, 0f, 0f, 0.1294117647f), new Color(0f, 0f, 0f, 0.4980392157f)}));
    G2.fill(INNER_SHADOW);

    final TexturePaint HATCH_PAINT = new TexturePaint(HATCH_TEXTURE, new java.awt.Rectangle(0, 0, 2, 2));
    G2.setPaint(HATCH_PAINT);
    G2.fill(INNER_SHADOW);

    G2.dispose();
    return IMAGE;
}
 
源代码19 项目: openjdk-8   文件: TransformedPaintTest.java
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
源代码20 项目: pumpernickel   文件: VectorImageTest.java
public static TexturePaint getCheckerBoard(int checkerSize, Color color1,
		Color color2) {
	BufferedImage bi = new BufferedImage(2 * checkerSize, 2 * checkerSize,
			BufferedImage.TYPE_INT_RGB);
	Graphics2D g = bi.createGraphics();
	g.setColor(color1);
	g.fillRect(0, 0, 2 * checkerSize, 2 * checkerSize);
	g.setColor(color2);
	g.fillRect(0, 0, checkerSize, checkerSize);
	g.fillRect(checkerSize, checkerSize, checkerSize, checkerSize);
	g.dispose();
	return new TexturePaint(bi,
			new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));
}
 
源代码21 项目: dragonwell8_jdk   文件: SunGraphics2D.java
/**
 * Sets the Paint in the current graphics state.
 * @param paint The Paint object to be used to generate color in
 * the rendering process.
 * @see java.awt.Graphics#setColor
 * @see GradientPaint
 * @see TexturePaint
 */
public void setPaint(Paint paint) {
    if (paint instanceof Color) {
        setColor((Color) paint);
        return;
    }
    if (paint == null || this.paint == paint) {
        return;
    }
    this.paint = paint;
    if (imageComp == CompositeType.SrcOverNoEa) {
        // special case where compState depends on opacity of paint
        if (paint.getTransparency() == Transparency.OPAQUE) {
            if (compositeState != COMP_ISCOPY) {
                compositeState = COMP_ISCOPY;
            }
        } else {
            if (compositeState == COMP_ISCOPY) {
                compositeState = COMP_ALPHA;
            }
        }
    }
    Class<? extends Paint> paintClass = paint.getClass();
    if (paintClass == GradientPaint.class) {
        paintState = PAINT_GRADIENT;
    } else if (paintClass == LinearGradientPaint.class) {
        paintState = PAINT_LIN_GRADIENT;
    } else if (paintClass == RadialGradientPaint.class) {
        paintState = PAINT_RAD_GRADIENT;
    } else if (paintClass == TexturePaint.class) {
        paintState = PAINT_TEXTURE;
    } else {
        paintState = PAINT_CUSTOM;
    }
    validFontInfo = false;
    invalidatePipe();
}
 
源代码22 项目: pumpernickel   文件: TransformedTexturePaint.java
private void readObject(java.io.ObjectInputStream in)
		throws IOException, ClassNotFoundException {
	FilteredObjectInputStream fin = new FilteredObjectInputStream(in);

	int internalVersion = fin.readInt();
	if (internalVersion == 0) {
		transform = (AffineTransform) fin.readObject();
		texturePaint = (TexturePaint) fin.readObject();
	} else {
		throw new IOException(
				"Unsupported internal version: " + internalVersion);
	}
}
 
源代码23 项目: dragonwell8_jdk   文件: TransformedPaintTest.java
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
@Override
public SerializationWrapper<?> filter(Object object) {
	if (object instanceof TexturePaint) {
		TexturePaint p = (TexturePaint) object;
		return new TexturePaintSerializationWrapper(p);
	}
	return null;
}
 
源代码25 项目: TencentKona-8   文件: TransformedPaintTest.java
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
源代码26 项目: buffer_bci   文件: PaintAlpha.java
/**
 * Create a new (if possible, darker) <code>Paint</code> of the same Type.
 * If the Type is not supported, the original <code>Paint</code> is returned.
 * <p>
 * @param paint a <code>Paint</code> implementation
 * (e.g. {@link Color}, {@link GradientPaint}, {@link TexturePaint},..)
 * <p>
 * @return a (usually new, see above) <code>Paint</code>
 */
public static Paint darker(Paint paint) {

    if (paint instanceof Color) {
        return darker((Color) paint);
    }
    if (legacyAlpha == true) {
        /*
         * Legacy? Just return the original Paint.
         * (this corresponds EXACTLY to how Paints used to be darkened)
         */
        return paint;
    }
    if (paint instanceof GradientPaint) {
        return darker((GradientPaint) paint);
    }
    if (paint instanceof LinearGradientPaint) {
        return darkerLinearGradientPaint((LinearGradientPaint) paint);
    }
    if (paint instanceof RadialGradientPaint) {
        return darkerRadialGradientPaint((RadialGradientPaint) paint);
    }
    if (paint instanceof TexturePaint) {
        try {
            return darkerTexturePaint((TexturePaint) paint);
        }
        catch (Exception e) {
            /*
             * Lots can go wrong while fiddling with Images, Color Models
             * & such!  If anything at all goes awry, just return the original
             * TexturePaint.  (TexturePaint's are immutable anyway, so no harm
             * done)
             */
            return paint;
        }
    }
    return paint;
}
 
源代码27 项目: jdk8u60   文件: BufferedPaints.java
static void setPaint(RenderQueue rq, SunGraphics2D sg2d,
                     Paint paint, int ctxflags)
{
    if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
        setColor(rq, sg2d.pixel);
    } else {
        boolean useMask = (ctxflags & BufferedContext.USE_MASK) != 0;
        switch (sg2d.paintState) {
        case SunGraphics2D.PAINT_GRADIENT:
            setGradientPaint(rq, sg2d,
                             (GradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_LIN_GRADIENT:
            setLinearGradientPaint(rq, sg2d,
                                   (LinearGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_RAD_GRADIENT:
            setRadialGradientPaint(rq, sg2d,
                                   (RadialGradientPaint)paint, useMask);
            break;
        case SunGraphics2D.PAINT_TEXTURE:
            setTexturePaint(rq, sg2d,
                            (TexturePaint)paint, useMask);
            break;
        default:
            break;
        }
    }
}
 
源代码28 项目: jdk8u60   文件: SunGraphics2D.java
/**
 * Sets the Paint in the current graphics state.
 * @param paint The Paint object to be used to generate color in
 * the rendering process.
 * @see java.awt.Graphics#setColor
 * @see GradientPaint
 * @see TexturePaint
 */
public void setPaint(Paint paint) {
    if (paint instanceof Color) {
        setColor((Color) paint);
        return;
    }
    if (paint == null || this.paint == paint) {
        return;
    }
    this.paint = paint;
    if (imageComp == CompositeType.SrcOverNoEa) {
        // special case where compState depends on opacity of paint
        if (paint.getTransparency() == Transparency.OPAQUE) {
            if (compositeState != COMP_ISCOPY) {
                compositeState = COMP_ISCOPY;
            }
        } else {
            if (compositeState == COMP_ISCOPY) {
                compositeState = COMP_ALPHA;
            }
        }
    }
    Class<? extends Paint> paintClass = paint.getClass();
    if (paintClass == GradientPaint.class) {
        paintState = PAINT_GRADIENT;
    } else if (paintClass == LinearGradientPaint.class) {
        paintState = PAINT_LIN_GRADIENT;
    } else if (paintClass == RadialGradientPaint.class) {
        paintState = PAINT_RAD_GRADIENT;
    } else if (paintClass == TexturePaint.class) {
        paintState = PAINT_TEXTURE;
    } else {
        paintState = PAINT_CUSTOM;
    }
    validFontInfo = false;
    invalidatePipe();
}
 
源代码29 项目: astor   文件: SerialUtilitiesTests.java
/**
 * Serialize a <code>TexturePaint</code>, restore it, and check for
 * equality.  Since this class is not serializable, we expect null as the
 * result.
 */
public void testTexturePaintSerialization() {

    Paint p1 = new TexturePaint(
            new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB),
            new Rectangle2D.Double(0, 0, 5, 5));
    Paint p2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(buffer);
        SerialUtilities.writePaint(p1, out);
        out.close();

        ByteArrayInputStream bias = new ByteArrayInputStream(
                buffer.toByteArray());
        ObjectInputStream in = new ObjectInputStream(bias);
        p2 = SerialUtilities.readPaint(in);
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    assertNull(p2);

}
 
源代码30 项目: jdk8u60   文件: TransformedPaintTest.java
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
 类所在包
 同包方法