1 /*
2 *
3 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Oracle nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44 import static java.awt.Color.WHITE;
45 import static java.awt.Color.YELLOW;
46 import java.awt.AlphaComposite;
47 import java.awt.Color;
48 import java.awt.Graphics2D;
49 import java.awt.Image;
50 import java.awt.Shape;
51 import java.awt.font.TextLayout;
52 import java.awt.geom.Ellipse2D;
53 import java.awt.geom.Rectangle2D;
54 import java.awt.geom.RoundRectangle2D;
55 import java2d.Surface;
56
57
58 /**
59 * Compositing shapes on images.
60 */
61 @SuppressWarnings("serial")
62 public class ACimages extends Surface {
63
64 private static final String s[] = { "box", "fight", "magnify",
65 "boxwave", "globe", "snooze",
66 "tip", "thumbsup", "dukeplug" };
67 private static Image imgs[] = new Image[s.length];
68 private static Color colors[] = { BLUE, CYAN, GREEN,
69 MAGENTA, ORANGE, PINK, RED, YELLOW, LIGHT_GRAY };
70
71 public ACimages() {
72 setBackground(WHITE);
73 for (int i = 0; i < imgs.length; i++) {
74 imgs[i] = getImage(s[i] + ".png");
75 }
76 }
77
78 @Override
79 public void render(int w, int h, Graphics2D g2) {
80
81 float alpha = 0.0f;
82 int iw = w / 3;
83 int ih = (h - 45) / 3;
84 float xx = 0, yy = 15;
85
86 for (int i = 0; i < imgs.length; i++) {
87
88 xx = (i % 3 == 0) ? 0 : xx + w / 3;
104 Shape shape = null;
105
106 switch (i % 3) {
107 case 0:
108 shape = new Ellipse2D.Float(xx, yy, iw, ih);
109 break;
110 case 1:
111 shape = new RoundRectangle2D.Float(xx, yy, iw, ih, 25, 25);
112 break;
113 case 2:
114 shape = new Rectangle2D.Float(xx, yy, iw, ih);
115 break;
116 }
117 g2.setColor(colors[i]);
118 g2.setComposite(ac);
119 g2.fill(shape);
120 g2.drawImage(imgs[i], (int) xx, (int) yy, iw, ih, null);
121 }
122 }
123
124 public static void main(String s[]) {
125 createDemoFrame(new ACimages());
126 }
127 }
|
1 /*
2 *
3 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Oracle nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
44 import static java.awt.Color.WHITE;
45 import static java.awt.Color.YELLOW;
46 import java.awt.AlphaComposite;
47 import java.awt.Color;
48 import java.awt.Graphics2D;
49 import java.awt.Image;
50 import java.awt.Shape;
51 import java.awt.font.TextLayout;
52 import java.awt.geom.Ellipse2D;
53 import java.awt.geom.Rectangle2D;
54 import java.awt.geom.RoundRectangle2D;
55 import java2d.Surface;
56
57
58 /**
59 * Compositing shapes on images.
60 */
61 @SuppressWarnings("serial")
62 public class ACimages extends Surface {
63
64 private static final String[] s = { "box", "fight", "magnify",
65 "boxwave", "globe", "snooze",
66 "tip", "thumbsup", "dukeplug" };
67 private static Image[] imgs = new Image[s.length];
68 private static Color[] colors = { BLUE, CYAN, GREEN,
69 MAGENTA, ORANGE, PINK, RED, YELLOW, LIGHT_GRAY };
70
71 public ACimages() {
72 setBackground(WHITE);
73 for (int i = 0; i < imgs.length; i++) {
74 imgs[i] = getImage(s[i] + ".png");
75 }
76 }
77
78 @Override
79 public void render(int w, int h, Graphics2D g2) {
80
81 float alpha = 0.0f;
82 int iw = w / 3;
83 int ih = (h - 45) / 3;
84 float xx = 0, yy = 15;
85
86 for (int i = 0; i < imgs.length; i++) {
87
88 xx = (i % 3 == 0) ? 0 : xx + w / 3;
104 Shape shape = null;
105
106 switch (i % 3) {
107 case 0:
108 shape = new Ellipse2D.Float(xx, yy, iw, ih);
109 break;
110 case 1:
111 shape = new RoundRectangle2D.Float(xx, yy, iw, ih, 25, 25);
112 break;
113 case 2:
114 shape = new Rectangle2D.Float(xx, yy, iw, ih);
115 break;
116 }
117 g2.setColor(colors[i]);
118 g2.setComposite(ac);
119 g2.fill(shape);
120 g2.drawImage(imgs[i], (int) xx, (int) yy, iw, ih, null);
121 }
122 }
123
124 public static void main(String[] s) {
125 createDemoFrame(new ACimages());
126 }
127 }
|