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
55 import java.io.FileReader;
56 import java.util.ArrayList;
57 import java.util.List;
58 import java.util.logging.Level;
59 import java.util.logging.Logger;
60 import java2d.AnimatingControlsSurface;
61 import java2d.CustomControls;
62 import javax.swing.AbstractButton;
63 import javax.swing.JComboBox;
64 import javax.swing.JToggleButton;
65 import javax.swing.JToolBar;
66
67
68 /**
69 * Animated Bezier Curve shape with images at the control points.
70 * README.txt file scrolling up. Composited Image fading in and out.
71 */
72 @SuppressWarnings("serial")
73 public class BezierScroller extends AnimatingControlsSurface {
74
75 private static String appletStrs[] = { " ", "J2Ddemo",
76 "BezierScroller - Animated Bezier Curve shape with images",
77 "For README.txt file scrolling run in application mode", " " };
78 private static final int NUMPTS = 6;
79 private static Color greenBlend = new Color(0, 255, 0, 100);
80 private static Color blueBlend = new Color(0, 0, 255, 100);
81 private static Font font = new Font(Font.SERIF, Font.PLAIN, 12);
82 private static BasicStroke bs = new BasicStroke(3.0f);
83 private static Image hotj_img;
84 private static BufferedImage img;
85 private static final int UP = 0;
86 private static final int DOWN = 1;
87 private float animpts[] = new float[NUMPTS * 2];
88 private float deltas[] = new float[NUMPTS * 2];
89 private BufferedReader reader;
90 private int nStrs;
91 private int strH;
92 private int yy, ix, iy, imgX;
93 private List<String> vector, appletVector;
94 private float alpha = 0.2f;
95 private int alphaDirection;
96 protected boolean doImage, doShape, doText;
97 protected boolean buttonToggle;
98
99 /*
100 * Using this to scale down globe.png since we want a smaller version,
101 * I know it is 100 x 160 and has a transparent pixel.
102 */
103 private Image scaled(Image src) {
104 int sw = src.getWidth(null);
105 int sh = src.getHeight(null);
106 int dw = sw/5;
107 int dh = sh/5;
108 BufferedImage bi =
276 cury = ctrlpts[i + 1];
277 } else {
278 curx = ctrlpts[0];
279 cury = ctrlpts[1];
280 }
281 midx = (curx + prevx) / 2.0f;
282 midy = (cury + prevy) / 2.0f;
283 float x2 = (prevx + midx) / 2.0f;
284 float y2 = (prevy + midy) / 2.0f;
285 gp.curveTo(x1, y1, x2, y2, midx, midy);
286 }
287 gp.closePath();
288
289 g2.setColor(blueBlend);
290 g2.setStroke(bs);
291 g2.draw(gp);
292 g2.setColor(greenBlend);
293 g2.fill(gp);
294
295 PathIterator pi = gp.getPathIterator(null);
296 float pts[] = new float[6];
297 while (!pi.isDone()) {
298 if (pi.currentSegment(pts) == PathIterator.SEG_CUBICTO) {
299 g2.drawImage(hotj_img, (int) pts[0], (int) pts[1], this);
300 }
301 pi.next();
302 }
303 }
304
305 if (doImage) {
306 AlphaComposite ac = AlphaComposite.getInstance(
307 AlphaComposite.SRC_OVER, alpha);
308 g2.setComposite(ac);
309 g2.drawImage(img.getSubimage(imgX, 0, 80, 80), ix, iy, this);
310 }
311 }
312
313 public static void main(String argv[]) {
314 createDemoFrame(new BezierScroller());
315 }
316
317
318 static final class DemoControls extends CustomControls implements
319 ActionListener {
320
321 BezierScroller demo;
322 JToolBar toolbar;
323 JComboBox combo;
324
325 public DemoControls(BezierScroller demo) {
326 super(demo.name);
327 this.demo = demo;
328 add(toolbar = new JToolBar());
329 toolbar.setFloatable(false);
330 addTool("Image", false);
331 addTool("Shape", true);
332 addTool("Text", true);
333 }
|
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
55 import java.io.FileReader;
56 import java.util.ArrayList;
57 import java.util.List;
58 import java.util.logging.Level;
59 import java.util.logging.Logger;
60 import java2d.AnimatingControlsSurface;
61 import java2d.CustomControls;
62 import javax.swing.AbstractButton;
63 import javax.swing.JComboBox;
64 import javax.swing.JToggleButton;
65 import javax.swing.JToolBar;
66
67
68 /**
69 * Animated Bezier Curve shape with images at the control points.
70 * README.txt file scrolling up. Composited Image fading in and out.
71 */
72 @SuppressWarnings("serial")
73 public class BezierScroller extends AnimatingControlsSurface {
74
75 private static String[] appletStrs = { " ", "J2Ddemo",
76 "BezierScroller - Animated Bezier Curve shape with images",
77 "For README.txt file scrolling run in application mode", " " };
78 private static final int NUMPTS = 6;
79 private static Color greenBlend = new Color(0, 255, 0, 100);
80 private static Color blueBlend = new Color(0, 0, 255, 100);
81 private static Font font = new Font(Font.SERIF, Font.PLAIN, 12);
82 private static BasicStroke bs = new BasicStroke(3.0f);
83 private static Image hotj_img;
84 private static BufferedImage img;
85 private static final int UP = 0;
86 private static final int DOWN = 1;
87 private float[] animpts = new float[NUMPTS * 2];
88 private float[] deltas = new float[NUMPTS * 2];
89 private BufferedReader reader;
90 private int nStrs;
91 private int strH;
92 private int yy, ix, iy, imgX;
93 private List<String> vector, appletVector;
94 private float alpha = 0.2f;
95 private int alphaDirection;
96 protected boolean doImage, doShape, doText;
97 protected boolean buttonToggle;
98
99 /*
100 * Using this to scale down globe.png since we want a smaller version,
101 * I know it is 100 x 160 and has a transparent pixel.
102 */
103 private Image scaled(Image src) {
104 int sw = src.getWidth(null);
105 int sh = src.getHeight(null);
106 int dw = sw/5;
107 int dh = sh/5;
108 BufferedImage bi =
276 cury = ctrlpts[i + 1];
277 } else {
278 curx = ctrlpts[0];
279 cury = ctrlpts[1];
280 }
281 midx = (curx + prevx) / 2.0f;
282 midy = (cury + prevy) / 2.0f;
283 float x2 = (prevx + midx) / 2.0f;
284 float y2 = (prevy + midy) / 2.0f;
285 gp.curveTo(x1, y1, x2, y2, midx, midy);
286 }
287 gp.closePath();
288
289 g2.setColor(blueBlend);
290 g2.setStroke(bs);
291 g2.draw(gp);
292 g2.setColor(greenBlend);
293 g2.fill(gp);
294
295 PathIterator pi = gp.getPathIterator(null);
296 float[] pts = new float[6];
297 while (!pi.isDone()) {
298 if (pi.currentSegment(pts) == PathIterator.SEG_CUBICTO) {
299 g2.drawImage(hotj_img, (int) pts[0], (int) pts[1], this);
300 }
301 pi.next();
302 }
303 }
304
305 if (doImage) {
306 AlphaComposite ac = AlphaComposite.getInstance(
307 AlphaComposite.SRC_OVER, alpha);
308 g2.setComposite(ac);
309 g2.drawImage(img.getSubimage(imgX, 0, 80, 80), ix, iy, this);
310 }
311 }
312
313 public static void main(String[] argv) {
314 createDemoFrame(new BezierScroller());
315 }
316
317
318 static final class DemoControls extends CustomControls implements
319 ActionListener {
320
321 BezierScroller demo;
322 JToolBar toolbar;
323 JComboBox combo;
324
325 public DemoControls(BezierScroller demo) {
326 super(demo.name);
327 this.demo = demo;
328 add(toolbar = new JToolBar());
329 toolbar.setFloatable(false);
330 addTool("Image", false);
331 addTool("Shape", true);
332 addTool("Text", true);
333 }
|