java.awt.TexturePaint Java Examples

The following examples show how to use java.awt.TexturePaint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenderTests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: WelcomePanel.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
/** 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))));
    }
}
 
Example #3
Source File: RenderTests.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: Draw.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example #5
Source File: ColorWellUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@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);
}
 
Example #6
Source File: Draw.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #7
Source File: Draw.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #8
Source File: Drawer.java    From amidst with GNU General Public License v3.0 6 votes vote down vote up
@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()));
}
 
Example #9
Source File: TexturePaintPrintingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);

}
 
Example #10
Source File: RenderTests.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #11
Source File: TexturePaintPrintingTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);

}
 
Example #12
Source File: TexturePaintPrintingTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);

}
 
Example #13
Source File: RenderTests.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #14
Source File: TexturedText.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: RenderTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #16
Source File: RenderTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #17
Source File: RenderTests.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #18
Source File: TexturePaintSerializationWrapper.java    From pumpernickel with MIT License 5 votes vote down vote up
public TexturePaintSerializationWrapper(TexturePaint tp) {
	ImageSerializationWrapper image = new ImageSerializationWrapper(
			(RenderedImage) tp.getImage());
	map.put(KEY_IMAGE, image);

	Rectangle2DSerializationWrapper anchor = new Rectangle2DSerializationWrapper(
			tp.getAnchorRect());
	map.put(KEY_ANCHOR_RECT, anchor);
}
 
Example #19
Source File: TweenApplet.java    From universal-tween-engine with Apache License 2.0 5 votes vote down vote up
public MyCanvas() {
	Tween.enablePooling(false);
	Tween.registerAccessor(Sprite.class, new SpriteAccessor());
	addMouseListener(mouseAdapter);

	vialSprite = new Sprite("vial.png");
	vialSprite.setPosition(100, 100);

	try {
		BufferedImage bgImage = ImageIO.read(TweenApplet.class.getResource("/aurelienribon/tweenengine/applets/gfx/transparent-dark.png"));
		bgPaint = new TexturePaint(bgImage, new Rectangle(0, 0, bgImage.getWidth(), bgImage.getHeight()));
	} catch (IOException ex) {
	}
}
 
Example #20
Source File: TrafficLight.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public BufferedImage createYellowOffImage(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.38489208633093525 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.5 * IMAGE_HEIGHT), (0.32653061224489793f * IMAGE_WIDTH), new float[]{0.0f, 1.0f}, new Color[]{new Color(1f, 1f, 0f, 0.2470588235f), new Color(1f, 1f, 0f, 0.0470588235f)}));
    G2.fill(LIGHT_OFF);

    final Ellipse2D INNER_SHADOW = new Ellipse2D.Double(0.17346938775510204 * IMAGE_WIDTH, 0.38489208633093525 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.5 * 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;
}
 
Example #21
Source File: BufferedPaints.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    }
}
 
Example #22
Source File: BufferedPaints.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    }
}
 
Example #23
Source File: TransformedPaintTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: PageDrawer.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void drawBufferedImage(BufferedImage image, AffineTransform at) throws IOException
{
    graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
    setClip();
    AffineTransform imageTransform = new AffineTransform(at);
    PDSoftMask softMask = getGraphicsState().getSoftMask();
    if( softMask != null )
    {
        imageTransform.scale(1, -1);
        imageTransform.translate(0, -1);
        Paint awtPaint = new TexturePaint(image,
                new Rectangle2D.Double(imageTransform.getTranslateX(), imageTransform.getTranslateY(),
                        imageTransform.getScaleX(), imageTransform.getScaleY()));
        awtPaint = applySoftMaskToPaint(awtPaint, softMask);
        graphics.setPaint(awtPaint);
        Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1);
        if (isContentRendered())
        {
            graphics.fill(at.createTransformedShape(unitRect));
        }
    }
    else
    {
        COSBase transfer = getGraphicsState().getTransfer();
        if (transfer instanceof COSArray || transfer instanceof COSDictionary)
        {
            image = applyTransferFunction(image, transfer);
        }

        int width = image.getWidth();
        int height = image.getHeight();
        imageTransform.scale(1.0 / width, -1.0 / height);
        imageTransform.translate(0, -height);
        if (isContentRendered())
        {
            graphics.drawImage(image, imageTransform, null);
        }
    }
}
 
Example #25
Source File: PaintAlpha.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source File: SunGraphics2D.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #27
Source File: StarmapScreen.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Paint a vertically resizable area from images.
 * @param g2 the graphics
 * @param origin the bounding rectangle
 * @param top the left image
 * @param bottom the right image
 * @param fill the filler between the two images
 */
static void paintVertically(Graphics2D g2, Rectangle origin, BufferedImage top, BufferedImage bottom, BufferedImage fill) {
	g2.drawImage(top, origin.x, origin.y, null);
	g2.drawImage(bottom, origin.x, origin.y + origin.height - bottom.getHeight(), null);
	Paint pt = g2.getPaint();
    
    g2.setPaint(new TexturePaint(fill, 
    		new Rectangle(origin.x, origin.y  + top.getHeight()
    				, fill.getWidth(), fill.getHeight())));
    
    g2.fillRect(origin.x, origin.y + top.getHeight(), 
    		origin.width, origin.height - top.getHeight() - bottom.getHeight());
    
    g2.setPaint(pt);
}
 
Example #28
Source File: BufferedPaints.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
        }
    }
}
 
Example #29
Source File: DropTargetGlassPane.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private TexturePaint getIndicationPaint() {
    if (droppable != null && droppable.getKind() != modeKind) {
        BufferedImage image = new BufferedImage(2,2,BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = image.createGraphics();
        Color c = UIManager.getColor("Panel.dropTargetGlassPane");
        boolean isModeMixing = (droppable.getKind() == Constants.MODE_KIND_EDITOR
                    && windowDragAndDrop.getStartingTransfer().getKind() != Constants.MODE_KIND_EDITOR) ||
                    (droppable.getKind() != Constants.MODE_KIND_EDITOR
                    && windowDragAndDrop.getStartingTransfer().getKind() == Constants.MODE_KIND_EDITOR);
        if (c == null) {
            c = new Color(255, 90, 0);
        }
        if( isModeMixing ) {
            g2.setColor(c);
            g2.fillRect(0,0,1,1);
            g2.fillRect(1,1,1,1);
            g2.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 0));
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f));
            g2.fillRect(1,0,1,1);
            g2.fillRect(0,1,1,1);
        } else {
            g2.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 200));
            g2.fillRect( 0, 0, 2, 2);
        }
        texturePaint = new TexturePaint(image, new Rectangle(0,0,2,2));
        modeKind = droppable.getKind();
    }
    return texturePaint;
}
 
Example #30
Source File: TrafficLight.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public BufferedImage createGreenOffImage(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.6942446043165468 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.8093525179856115 * IMAGE_HEIGHT), (0.32653061224489793f * IMAGE_WIDTH), new float[]{0.0f, 1.0f}, new Color[]{new Color(0f, 1f, 0f, 0.2470588235f), new Color(0f, 1f, 0f, 0.0470588235f)}));
    G2.fill(LIGHT_OFF);

    final Ellipse2D INNER_SHADOW = new Ellipse2D.Double(0.17346938775510204 * IMAGE_WIDTH, 0.6942446043165468 * IMAGE_HEIGHT, 0.6530612244897959 * IMAGE_WIDTH, 0.2302158273381295 * IMAGE_HEIGHT);
    G2.setPaint(new RadialGradientPaint(new Point2D.Double(0.5 * IMAGE_WIDTH, 0.8093525179856115 * 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;
}