KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java2d > Intro


1 /*
2  * @(#)Intro.java 1.29 06/08/29
3  *
4  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * -Redistribution of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * -Redistribution in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
17  * be used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any kind. ALL
21  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
22  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
24  * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
25  * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
26  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
27  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
28  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
29  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  *
32  * You acknowledge that this software is not designed, licensed or intended
33  * for use in the design, construction, operation or maintenance of any
34  * nuclear facility.
35  */

36
37
38 package java2d;
39
40 import java.awt.*;
41 import java.awt.event.*;
42 import java.awt.geom.*;
43 import java.awt.image.BufferedImage JavaDoc;
44 import java.awt.image.DataBuffer JavaDoc;
45 import java.awt.font.*;
46 import javax.swing.*;
47 import javax.swing.border.*;
48 import javax.swing.table.*;
49 import javax.swing.event.*;
50 import java.util.Vector JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Arrays JavaDoc;
53
54 import static java.awt.Color JavaDoc.*;
55
56
57
58 /**
59  * Introduction to the Java2Demo.
60  *
61  * @version @(#)Intro.java 1.29 06/08/29
62  * @author Brian Lichtenwalter
63  */

64 public class Intro extends JPanel {
65
66     private static Color JavaDoc myBlack = new Color JavaDoc( 20, 20, 20);
67     private static Color JavaDoc myWhite = new Color JavaDoc(240, 240, 255);
68     private static Color JavaDoc myRed = new Color JavaDoc(149, 43, 42);
69     private static Color JavaDoc myBlue = new Color JavaDoc( 94, 105, 176);
70     private static Color JavaDoc myYellow = new Color JavaDoc(255, 255, 140);
71
72     private ScenesTable scenesTable;
73     private boolean doTable;
74
75     static Surface surface;
76
77
78     public Intro() {
79         EmptyBorder eb = new EmptyBorder(80,110,80,110);
80         BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);
81         setBorder(new CompoundBorder(eb,bb));
82         setLayout(new BorderLayout());
83         setBackground(GRAY);
84         setToolTipText("click for scene table");
85         add(surface = new Surface());
86         addMouseListener(new MouseAdapter() {
87             public void mouseClicked(MouseEvent e) {
88                removeAll();
89                if ((doTable = !doTable)) {
90                    setToolTipText("click for animation");
91                    surface.stop();
92                    if (scenesTable == null) {
93                        scenesTable = new ScenesTable();
94                    }
95                    add(scenesTable);
96                } else {
97                    setToolTipText("click for scene table");
98                    surface.start();
99                    add(surface);
100                }
101                revalidate();
102                repaint();
103             }
104         });
105     }
106
107
108     public void start() {
109         if (!doTable) {
110             surface.start();
111         }
112     }
113
114
115     public void stop() {
116         if (!doTable) {
117            surface.stop();
118         }
119     }
120
121
122     public static void main(String JavaDoc argv[]) {
123         final Intro intro = new Intro();
124         WindowListener l = new WindowAdapter() {
125             public void windowClosing (WindowEvent e) { System.exit(0); }
126             public void windowDeiconified(WindowEvent e) { intro.start(); }
127             public void windowIconified (WindowEvent e) { intro.stop(); }
128         };
129         JFrame f = new JFrame("Java2D Demo - Intro");
130         f.addWindowListener(l);
131         f.getContentPane().add("Center", intro);
132         f.pack();
133         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
134         int w = 720;
135         int h = 510;
136         f.setLocation(screenSize.width/2 - w/2, screenSize.height/2 - h/2);
137         f.setSize(w, h);
138         f.setVisible(true);
139         intro.start();
140     }
141
142
143     /**
144      * ScenesTable is the list of scenes known to the Director.
145      * Scene participation, scene name and scene pause amount columns.
146      * Global animation delay for scene's steps.
147      */

148     static class ScenesTable extends JPanel implements ActionListener, ChangeListener {
149
150         private JTable table;
151         private TableModel dataModel;
152
153         public ScenesTable() {
154             setBackground(WHITE);
155             setLayout(new BorderLayout());
156             final String JavaDoc[] names = { "", "Scenes", "Pause" };
157     
158             dataModel = new AbstractTableModel() {
159                 public int getColumnCount() { return names.length; }
160                 public int getRowCount() { return surface.director.size();}
161                 public Object JavaDoc getValueAt(int row, int col) {
162                     Surface.Scene scene = (Surface.Scene) surface.director.get(row);
163                     if (col == 0) {
164                         return scene.participate;
165                     } else if (col == 1) {
166                         return scene.name;
167                     } else {
168                         return scene.pauseAmt;
169                    }
170                 }
171                 public String JavaDoc getColumnName(int col) {return names[col]; }
172                 public Class JavaDoc getColumnClass(int c) {
173                     return getValueAt(0, c).getClass();
174                 }
175                 public boolean isCellEditable(int row, int col) {
176                     return col != 1 ? true : false;
177                 }
178                 public void setValueAt(Object JavaDoc aValue, int row, int col) {
179                     Surface.Scene scene = (Surface.Scene) surface.director.get(row);
180                     if (col == 0) {
181                         scene.participate = aValue;
182                     } else if (col == 1) {
183                         scene.name = aValue;
184                     } else {
185                         scene.pauseAmt = aValue;
186                     }
187                 }
188             };
189     
190             table = new JTable(dataModel);
191             TableColumn col = table.getColumn("");
192             col.setWidth(16);
193             col.setMinWidth(16);
194             col.setMaxWidth(20);
195             col = table.getColumn("Pause");
196             col.setWidth(60);
197             col.setMinWidth(60);
198             col.setMaxWidth(60);
199             table.sizeColumnsToFit(0);
200         
201             JScrollPane scrollpane = new JScrollPane(table);
202             add(scrollpane);
203  
204             JPanel panel = new JPanel(new BorderLayout());
205             JButton b = new JButton("Unselect All");
206             b.setHorizontalAlignment(JButton.LEFT);
207             Font font = new Font("serif", Font.PLAIN, 10);
208             b.setFont(font);
209             b.addActionListener(this);
210             panel.add("West", b);
211
212             JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 200, (int) surface.sleepAmt);
213             slider.addChangeListener(this);
214             TitledBorder tb = new TitledBorder(new EtchedBorder());
215             tb.setTitleFont(font);
216             tb.setTitle("Anim delay = " + String.valueOf(surface.sleepAmt) + " ms");
217             slider.setBorder(tb);
218             slider.setPreferredSize(new Dimension(140,40));
219             slider.setMinimumSize (new Dimension(100,40));
220             slider.setMaximumSize (new Dimension(180,40));
221             panel.add("East", slider);
222
223             add("South", panel);
224         }
225
226
227         public void actionPerformed(ActionEvent e) {
228             JButton b = (JButton) e.getSource();
229             b.setSelected(!b.isSelected());
230             b.setText(b.isSelected() ? "Select All" : "Unselect All");
231             for (int i = 0; i < surface.director.size(); i++) {
232                 Surface.Scene scene = (Surface.Scene) surface.director.get(i);
233                 scene.participate = Boolean.valueOf(!b.isSelected());
234             }
235         table.tableChanged(new TableModelEvent(dataModel));
236         }
237
238
239         public void stateChanged(ChangeEvent e) {
240             JSlider slider = (JSlider) e.getSource();
241             int value = slider.getValue();
242             TitledBorder tb = (TitledBorder) slider.getBorder();
243             tb.setTitle("Anim delay = " + String.valueOf(value) + " ms");
244             surface.sleepAmt = (long) value;
245             slider.repaint();
246         }
247     } // End ScenesTable class
248

249
250
251     /**
252      * Surface is the stage where the Director plays its scenes.
253      */

254     static class Surface extends JPanel implements Runnable JavaDoc {
255
256         static Surface surf;
257         static Image JavaDoc cupanim, java_logo;
258         static BufferedImage JavaDoc bimg;
259         public Director director;
260         public int index;
261         public long sleepAmt = 30;
262         private Thread JavaDoc thread;
263
264
265         public Surface() {
266             surf = this;
267             setBackground(myBlack);
268             setLayout(new BorderLayout());
269             addMouseListener(new MouseAdapter() {
270                 public void mouseClicked(MouseEvent e) {
271                     if (thread == null) start(); else stop();
272                 }
273             });
274             cupanim = DemoImages.getImage("cupanim.gif", this);
275             java_logo = DemoImages.getImage("java_logo.png", this);
276             director = new Director();
277         }
278
279
280         static FontMetrics getMetrics(Font font) {
281             return surf.getFontMetrics(font);
282         }
283
284
285         public void paint(Graphics g) {
286             Dimension d = getSize();
287         if (d.width <= 0 || d.height <= 0) {
288         return;
289         }
290             if (bimg == null ||
291                 bimg.getWidth() != d.width ||
292                 bimg.getHeight() != d.height) {
293                 bimg = getGraphicsConfiguration().createCompatibleImage(d.width, d.height);
294                 // reset future scenes
295
for (int i = index+1; i < director.size(); i++) {
296                     ((Scene) director.get(i)).reset(d.width, d.height);
297                 }
298             }
299
300             Scene scene = (Scene) director.get(index);
301             if (scene.index <= scene.length) {
302                 if (thread != null) {
303                     scene.step(d.width, d.height);
304                 }
305
306                 Graphics2D g2 = bimg.createGraphics();
307                 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
308                                     RenderingHints.VALUE_ANTIALIAS_ON);
309                 g2.setBackground(getBackground());
310                 g2.clearRect(0, 0, d.width, d.height);
311     
312                 scene.render(d.width, d.height, g2);
313
314                 if (thread != null) {
315                     // increment scene.index after scene.render
316
scene.index++;
317                 }
318                 g2.dispose();
319             }
320             g.drawImage(bimg, 0, 0, this);
321         }
322
323
324
325         public void start() {
326             if (thread == null) {
327                 thread = new Thread JavaDoc(this);
328                 thread.setPriority(Thread.MIN_PRIORITY);
329                 thread.setName("Intro");
330                 thread.start();
331             }
332         }
333     
334
335         public synchronized void stop() {
336             if (thread != null) {
337                 thread.interrupt();
338             }
339             thread = null;
340             notifyAll();
341         }
342
343
344         public void reset() {
345             index = 0;
346             Dimension d = getSize();
347             for (Scene scene : director) {
348                 scene.reset(d.width, d.height);
349             }
350         }
351
352     
353         public void run() {
354
355             Thread JavaDoc me = Thread.currentThread();
356
357             while (thread == me && !isShowing() || getSize().width <= 0) {
358                 try {
359                     thread.sleep(500);
360                 } catch (InterruptedException JavaDoc e) { return; }
361             }
362
363             if (index == 0) {
364                 reset();
365             }
366
367             while (thread == me) {
368                 Scene scene = (Scene) director.get(index);
369                 if (((Boolean JavaDoc) scene.participate).booleanValue()) {
370                     repaint();
371                     try {
372                         thread.sleep(sleepAmt);
373                     } catch (InterruptedException JavaDoc e) { break; }
374                     if (scene.index > scene.length) {
375                         scene.pause(thread);
376                         if (++index >= director.size()) {
377                             reset();
378                         }
379                     }
380                 } else {
381                    if (++index >= director.size()) {
382                         reset();
383                    }
384                 }
385             }
386             thread = null;
387         }
388
389
390
391         /**
392          * Part is a piece of the scene. Classes must implement Part
393          * in order to participate in a scene.
394          */

395         interface Part {
396             public void reset(int newwidth, int newheight);
397             public void step(int w, int h);
398             public void render(int w, int h, Graphics2D g2);
399             public int getBegin();
400             public int getEnd();
401         }
402
403
404
405         /**
406          * Director is the holder of the scenes, their names & pause amounts
407          * between scenes.
408          */

409         static class Director extends Vector JavaDoc<Scene> {
410
411             GradientPaint gp = new GradientPaint(0,40,myBlue,38,2,myBlack);
412             Font f1 = new Font("serif", Font.PLAIN, 200);
413             Font f2 = new Font("serif", Font.PLAIN, 120);
414             Font f3 = new Font("serif", Font.PLAIN, 72);
415             Object JavaDoc partsInfo[][][] = {
416                { { "J - scale text on gradient", "0" },
417                  { new GpE(GpE.BURI, myBlack, myBlue, 0, 20),
418                    new TxE("J", f1, TxE.SCI, myYellow, 2, 20) } },
419                { { "2 - scale & rotate text on gradient" , "0" },
420                  { new GpE(GpE.BURI, myBlue, myBlack, 0, 22),
421                    new TxE("2", f1, TxE.RI | TxE.SCI, myYellow, 2, 22) } },
422                { { "D - scale text on gradient", "0" },
423                  { new GpE(GpE.BURI, myBlack, myBlue, 0, 20),
424                    new TxE("D", f1, TxE.SCI, myYellow, 2, 20) } },
425                { { "Java2D - scale & rotate text on gradient", "1000" },
426                  { new GpE(GpE.SIH, myBlue, myBlack, 0, 40),
427                    new TxE("Java2D", f2, TxE.RI | TxE.SCI, myYellow, 0, 40) }},
428                { { "Previous scene dither dissolve out", "0"},
429                  { new DdE(0, 20, 1) }},
430                { { "Graphics Features", "999" },
431                  { new Temp(Temp.RECT, null, 0, 15),
432                    new Temp(Temp.IMG, java_logo, 2, 15),
433                    new Temp(Temp.RNA | Temp.INA, java_logo, 16, 130),
434                    new Features(Features.GRAPHICS, 16, 130) }},
435                { { "Java2D - texture text on gradient", "1000"},
436                  { new GpE(GpE.WI, myBlue, myBlack, 0, 20),
437                    new GpE(GpE.WD, myBlue, myBlack, 21, 40),
438                    new TpE(TpE.OI | TpE.NF, myBlack, myYellow, 4, 0, 10),
439                    new TpE(TpE.OD | TpE.NF, myBlack, myYellow, 4, 11, 20),
440                    new TpE(TpE.OI | TpE.NF | TpE.HAF, myBlack, myYellow,5,21,40),
441                    new TxE("Java2D", f2, 0, null, 0, 40) }},
442                { { "Previous scene random close out", "0"},
443                  { new CoE(CoE.RAND, 0, 20) } },
444                { { "Text Features", "999" },
445                  { new Temp(Temp.RECT, null, 0, 15),
446                    new Temp(Temp.IMG, java_logo, 2, 15),
447                    new Temp(Temp.RNA | Temp.INA, java_logo, 16, 130),
448                    new Features(Features.TEXT, 16, 130) }},
449                { { "Java2D - composite text on texture", "1000"},
450                  { new TpE(TpE.RI, myBlack, gp, 40, 0, 20),
451                    new TpE(TpE.RD, myBlack, gp, 40, 21, 40),
452                    new TpE(TpE.RI, myBlack, gp, 40, 41, 60),
453                    new TxE("Java2D", f2, TxE.AC, myYellow, 0, 60) }},
454                { { "Previous scene dither dissolve out", "0"},
455                  { new DdE(0, 20, 4) }},
456                { { "Imaging Features", "999" },
457                  { new Temp(Temp.RECT, null, 0, 15),
458                    new Temp(Temp.IMG, java_logo, 2, 15),
459                    new Temp(Temp.RNA | Temp.INA, java_logo, 16, 130),
460                    new Features(Features.IMAGES, 16, 130) }},
461                { { "Java2D - text on gradient", "1000" },
462                  { new GpE(GpE.SDH, myBlue, myBlack, 0, 20),
463                    new GpE(GpE.SIH, myBlue, myBlack, 21, 40),
464                    new GpE(GpE.SDH, myBlue, myBlack, 41, 50),
465                    new GpE(GpE.INC | GpE.NF, myRed, myYellow, 0, 50),
466                    new TxE("Java2D", f2, TxE.NOP, null, 0, 50) }},
467                { { "Previous scene ellipse close out", "0"},
468                  { new CoE(CoE.OVAL, 0, 20) } },
469                { { "Color Features", "999" },
470                  { new Temp(Temp.RECT, null, 0, 15),
471                    new Temp(Temp.IMG, java_logo, 2, 15),
472                    new Temp(Temp.RNA | Temp.INA, java_logo, 16, 99),
473                    new Features(Features.COLOR, 16, 99) }},
474                { { "Java2D - composite and rotate text on paints", "2000" },
475                  { new GpE(GpE.BURI, myBlack, myBlue, 0, 20),
476                    new GpE(GpE.BURD, myBlack, myBlue, 21, 30),
477                    new TpE(TpE.OI | TpE.HAF, myBlack, myBlue, 10, 31, 40),
478                    new TxE("Java2D", f2, TxE.AC | TxE.RI, myYellow, 0, 40) }},
479                { { "Previous scene subimage transform out", "0" },
480                  { new SiE(60, 60, 0, 40) }},
481                { { "CREDITS - transform in", "1000" },
482                  { new LnE(LnE.ACI | LnE.ZOOMI | LnE.RI, 0, 60),
483                    new TxE("CREDITS", f3, TxE.AC | TxE.SCI, RED,20,30),
484                    new TxE("CREDITS", f3, TxE.SCXD, RED, 31, 38),
485                    new TxE("CREDITS", f3, TxE.SCXI, RED, 39, 48),
486                    new TxE("CREDITS", f3, TxE.SCXD, RED, 49, 54),
487                    new TxE("CREDITS", f3, TxE.SCXI, RED, 55, 60) }},
488                { { "CREDITS - transform out", "0" },
489                  { new LnE(LnE.ACD | LnE.ZOOMD | LnE.RD, 0, 45),
490                    new TxE("CREDITS", f3, 0, RED, 0, 9),
491                    new TxE("CREDITS", f3, TxE.SCD | TxE.RD, RED,10,30)}},
492                { { "Contributors", "1000" },
493                  { new Temp(Temp.RECT, null, 0, 30),
494                    new Temp(Temp.IMG, cupanim, 4, 30),
495                    new Temp(Temp.RNA | Temp.INA, cupanim, 31, 200),
496                    new Contributors(34, 200) } },
497             };
498
499
500             public Director() {
501                 for (Object JavaDoc[][] partInfo : partsInfo ) {
502                     List JavaDoc<Part> parts = new Vector JavaDoc<Part>();
503                     for (Object JavaDoc part : partInfo[1]) {
504                         parts.add((Part)part);
505                     }
506                     addElement(new Scene(parts, partInfo[0][0], partInfo[0][1]));
507                 }
508             }
509         }
510         
511
512
513         /**
514          * Scene is the manager of the parts.
515          */

516         static class Scene extends Object JavaDoc {
517             public Object JavaDoc name;
518             public Object JavaDoc participate = Boolean.TRUE;
519             public Object JavaDoc pauseAmt;
520             public List JavaDoc<Part> parts;
521             public int index;
522             public int length;
523
524             public Scene(List JavaDoc<Part> parts, Object JavaDoc name, Object JavaDoc pauseAmt) {
525                 this.name = name;
526                 this.parts = parts;
527                 this.pauseAmt = pauseAmt;
528                 for (Part part : parts) {
529                     int partLength = part.getEnd();
530                     if (partLength > length) {
531                         length = partLength;
532                     }
533                 }
534             }
535
536             public void reset(int w, int h) {
537                 index = 0;
538                 for (int i = 0; i < parts.size(); i++) {
539                     ((Part) parts.get(i)).reset(w, h);
540                 }
541             }
542
543             public void step(int w, int h) {
544                 for (int i = 0; i < parts.size(); i++) {
545                     Part part = (Part) parts.get(i);
546                     if (index >= part.getBegin() && index <= part.getEnd()) {
547                         part.step(w, h);
548                     }
549                 }
550             }
551
552             public void render(int w, int h, Graphics2D g2) {
553                 for (int i = 0; i < parts.size(); i++) {
554                     Part part = (Part) parts.get(i);
555                     if (index >= part.getBegin() && index <= part.getEnd()) {
556                         part.render(w, h, g2);
557                     }
558                 }
559             }
560
561             public void pause(Thread JavaDoc thread) {
562                 try {
563                     thread.sleep(Long.parseLong((String JavaDoc) pauseAmt));
564                 } catch (Exception JavaDoc e) { }
565                 System.gc();
566             }
567         } // End Scene class
568

569
570
571         /**
572          * Text Effect. Transformation of characters. Clip or fill.
573          */

574         static class TxE implements Part {
575
576             static final int INC = 1;
577             static final int DEC = 2;
578             static final int R = 4; // rotate
579
static final int RI = R | INC;
580             static final int RD = R | DEC;
581             static final int SC = 8; // scale
582
static final int SCI = SC | INC;
583             static final int SCD = SC | DEC;
584             static final int SCX = 16; // scale invert x
585
static final int SCXI = SCX | SC | INC;
586             static final int SCXD = SCX | SC | DEC;
587             static final int SCY = 32; // scale invert y
588
static final int SCYI = SCY | SC | INC;
589             static final int SCYD = SCY | SC | DEC;
590             static final int AC = 64; // AlphaComposite
591
static final int CLIP = 128; // Clipping
592
static final int NOP = 512; // No Paint
593
private int beginning, ending;
594             private int type;
595             private double rIncr, sIncr;
596             private double sx, sy, rotate;
597             private Shape shapes[], txShapes[];
598             private int sw;
599             private int numRev;
600             private Paint paint;
601
602
603             public TxE(String JavaDoc text,
604                            Font font,
605                            int type,
606                            Paint paint,
607                            int beg,
608                            int end) {
609                 this.type = type;
610                 this.paint = paint;
611                 this.beginning = beg;
612                 this.ending = end;
613
614                 setIncrements(2);
615                 
616                 char[] chars = text.toCharArray();
617                 shapes = new Shape[chars.length];
618                 txShapes = new Shape[chars.length];
619                 FontRenderContext frc = new FontRenderContext(null,true,true);
620                 TextLayout tl = new TextLayout(text, font, frc);
621                 sw = (int) tl.getOutline(null).getBounds().getWidth();
622                 for (int j = 0; j < chars.length; j++) {
623                     String JavaDoc s = String.valueOf(chars[j]);
624                     shapes[j] = new TextLayout(s, font, frc).getOutline(null);
625                 }
626             }
627
628
629             public void setIncrements(double numRevolutions) {
630                 this.numRev = (int) numRevolutions;
631                 rIncr = 360.0 / ((ending - beginning) / numRevolutions);
632                 sIncr = 1.0 / (ending - beginning);
633                 if ((type & SCX) != 0 || (type & SCY) != 0) {
634                     sIncr *= 2;
635                 }
636                 if ((type & DEC) != 0) {
637                     rIncr = -rIncr;
638                     sIncr = -sIncr;
639                 }
640             }
641
642
643             public void reset(int w, int h) {
644                 if (type == SCXI) {
645                     sx = -1.0; sy = 1.0;
646                 } else if (type == SCYI) {
647                     sx = 1.0; sy = -1.0;
648                 } else {
649                     sx = sy = (type & DEC) != 0 ? 1.0 : 0.0;
650                 }
651                 rotate = 0;
652             }
653
654        
655             public void step(int w, int h) {
656         
657                 float charWidth = w/2-sw/2;
658         
659                 for (int i = 0; i < shapes.length; i++) {
660                     AffineTransform at = new AffineTransform();
661                     Rectangle2D maxBounds = shapes[i].getBounds();
662                     at.translate(charWidth, h/2+maxBounds.getHeight()/2);
663                     charWidth += (float) maxBounds.getWidth() + 1;
664                     Shape shape = at.createTransformedShape(shapes[i]);
665                     Rectangle2D b1 = shape.getBounds2D();
666         
667                     if ((type & R) != 0) {
668                         at.rotate(Math.toRadians(rotate));
669                     }
670                     if ((type & SC) != 0) {
671                         at.scale(sx, sy);
672                     }
673                     shape = at.createTransformedShape(shapes[i]);
674                     Rectangle2D b2 = shape.getBounds2D();
675       
676                     double xx = (b1.getX()+b1.getWidth()/2)
677                                 - (b2.getX()+b2.getWidth()/2);
678                     double yy = (b1.getY()+b1.getHeight()/2)
679                                 - (b2.getY()+b2.getHeight()/2);
680                     AffineTransform toCenterAT = new AffineTransform();
681                     toCenterAT.translate(xx, yy);
682                     toCenterAT.concatenate(at);
683                     txShapes[i] = toCenterAT.createTransformedShape(shapes[i]);
684                 }
685                 // avoid over rotation
686
if (Math.abs(rotate) <= numRev * 360) {
687                     rotate += rIncr;
688                     if ((type & SCX) != 0) {
689                         sx += sIncr;
690                     } else if ((type & SCY) != 0) {
691                         sy += sIncr;
692                     } else {
693                         sx += sIncr; sy += sIncr;
694                     }
695                 }
696             }
697
698
699             public void render(int w, int h, Graphics2D g2) {
700                 Composite saveAC = null;
701                 if ((type & AC) != 0 && sx > 0 && sx < 1) {
702                     saveAC = g2.getComposite();
703                     g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) sx));
704                 }
705                 GeneralPath path = null;
706                 if ((type & CLIP) != 0) {
707                     path = new GeneralPath();
708                 }
709                 if (paint != null) {
710                     g2.setPaint(paint);
711                 }
712                 for (int i = 0; i < txShapes.length; i++) {
713                     if ((type & CLIP) != 0) {
714                        path.append(txShapes[i], false);
715                     } else {
716                        g2.fill(txShapes[i]);
717                     }
718                 }
719                 if ((type & CLIP) != 0) {
720                     g2.clip(path);
721                 }
722                 if (saveAC != null) {
723                    g2.setComposite(saveAC);
724                 }
725             }
726
727
728             public int getBegin() {
729                 return beginning;
730             }
731
732             public int getEnd() {
733                 return ending;
734             }
735         } // End TxE class
736

737
738
739
740         /**
741          * GradientPaint Effect. Burst, split, horizontal and
742          * vertical gradient fill effects.
743          */

744         static class GpE implements Part {
745
746             static final int INC = 1; // increasing
747
static final int DEC = 2; // decreasing
748
static final int CNT = 4; // center
749
static final int WID = 8; // width
750
static final int WI = WID | INC;
751             static final int WD = WID | DEC;
752             static final int HEI = 16; // height
753
static final int HI = HEI | INC;
754             static final int HD = HEI | DEC;
755             static final int SPL = 32 | CNT; // split
756
static final int SIW = SPL | INC | WID;
757             static final int SDW = SPL | DEC | WID;
758             static final int SIH = SPL | INC | HEI;
759             static final int SDH = SPL | DEC | HEI;
760             static final int BUR = 64 | CNT; // burst
761
static final int BURI = BUR | INC;
762             static final int BURD = BUR | DEC;
763             static final int NF = 128; // no fill
764

765             private Color JavaDoc c1, c2;
766             private int beginning, ending;
767             private float incr, index;
768             private List JavaDoc<Rectangle2D> rect = new Vector JavaDoc<Rectangle2D>();
769             private List JavaDoc<GradientPaint> grad = new Vector JavaDoc<GradientPaint>();
770             private int type;
771
772
773             public GpE(int type, Color JavaDoc c1, Color JavaDoc c2, int beg, int end) {
774                 this.type = type;
775                 this.c1 = c1;
776                 this.c2 = c2;
777                 this.beginning = beg;
778                 this.ending = end;
779             }
780
781
782             public void reset(int w, int h) {
783                 incr = 1.0f / (ending - beginning);
784                 if ((type & CNT) != 0) {
785                     incr /= 2.3f;
786                 }
787                 if ((type & CNT) != 0 && (type & INC) != 0) {
788                     index = 0.5f;
789                 } else if ((type & DEC) != 0) {
790                     index = 1.0f;
791                     incr = -incr;
792                 } else {
793                     index = 0.0f;
794                 }
795                 index += incr;
796             }
797
798        
799             public void step(int w, int h) {
800                 rect.clear();
801                 grad.clear();
802
803                 if ((type & WID) != 0) {
804                     float w2 = 0, x1 = 0, x2 = 0;
805                     if ((type & SPL) != 0) {
806                         w2 = w * 0.5f;
807                         x1 = w * (1.0f - index);
808                         x2 = w * index;
809                     } else {
810                         w2 = w * index;
811                         x1 = x2 = w2;
812                     }
813                     rect.add(new Rectangle2D.Float( 0, 0, w2, h));
814                     rect.add(new Rectangle2D.Float(w2, 0, w-w2, h));
815                     grad.add(new GradientPaint( 0,0,c1,x1,0,c2));
816                     grad.add(new GradientPaint(x2,0,c2, w,0,c1));
817                 } else if ((type & HEI) != 0) {
818                     float h2 = 0, y1 = 0, y2 = 0;
819                     if ((type & SPL) != 0) {
820                         h2 = h * 0.5f;
821                         y1 = h * (1.0f - index);
822                         y2 = h * index;
823                     } else {
824                         h2 = h * index;
825                         y1 = y2 = h2;
826                     }
827                     rect.add(new Rectangle2D.Float(0, 0, w, h2));
828                     rect.add(new Rectangle2D.Float(0, h2, w, h-h2));
829                     grad.add(new GradientPaint(0, 0,c1,0,y1,c2));
830                     grad.add(new GradientPaint(0,y2,c2,0, h,c1));
831                 } else if ((type & BUR) != 0) {
832
833                     float w2 = w/2;
834                     float h2 = h/2;
835
836                     rect.add(new Rectangle2D.Float( 0, 0, w2, h2));
837                     rect.add(new Rectangle2D.Float(w2, 0, w2, h2));
838                     rect.add(new Rectangle2D.Float( 0, h2, w2, h2));
839                     rect.add(new Rectangle2D.Float(w2, h2, w2, h2));
840
841                     float x1 = w * (1.0f - index);
842                     float x2 = w * index;
843                     float y1 = h * (1.0f - index);
844                     float y2 = h * index;
845
846                     grad.add(new GradientPaint(0,0,c1,x1,y1,c2));
847                     grad.add(new GradientPaint(w,0,c1,x2,y1,c2));
848                     grad.add(new GradientPaint(0,h,c1,x1,y2,c2));
849                     grad.add(new GradientPaint(w,h,c1,x2,y2,c2));
850                 } else if ((type & NF) != 0) {
851                     float x = w * index;
852                     float y = h * index;
853                     grad.add(new GradientPaint(0,0,c1,0,y,c2));
854                 }
855
856                 if ((type & INC) != 0 || (type & DEC) != 0) {
857                     index += incr;
858                 }
859             }
860
861
862             public void render(int w, int h, Graphics2D g2) {
863                 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
864                                 RenderingHints.VALUE_ANTIALIAS_OFF);
865                 for (int i = 0; i < grad.size(); i++) {
866                     g2.setPaint((GradientPaint) grad.get(i));
867                     if ((type & NF) == 0) {
868                         g2.fill((Rectangle2D) rect.get(i));
869                     }
870                 }
871                 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
872                                 RenderingHints.VALUE_ANTIALIAS_ON);
873             }
874
875             public int getBegin() {
876                 return beginning;
877             }
878
879             public int getEnd() {
880                 return ending;
881             }
882         } // End GpE class
883

884
885
886         /**
887          * TexturePaint Effect. Expand and collapse a texture.
888          */

889         static class TpE implements Part {
890
891             static final int INC = 1; // increasing
892
static final int DEC = 2; // decreasing
893
static final int OVAL = 4; // oval
894
static final int RECT = 8; // rectangle
895
static final int HAF = 16; // half oval or rect size
896
static final int NF = 32; // no fill
897
static final int OI = OVAL | INC;
898             static final int OD = OVAL | DEC;
899             static final int RI = RECT | INC;
900             static final int RD = RECT | DEC;
901
902             private Paint p1, p2;
903             private int beginning, ending;
904             private float incr, index;
905             private TexturePaint texture;
906             private int type;
907             private int size;
908             private BufferedImage JavaDoc bimg;
909             private Rectangle rect;
910
911
912             public TpE(int type, Paint p1, Paint p2, int size,
913                                    int beg, int end) {
914                 this.type = type;
915                 this.p1 = p1;
916                 this.p2 = p2;
917                 this.beginning = beg;
918                 this.ending = end;
919                 setTextureSize(size);
920             }
921
922
923             public void setTextureSize(int size) {
924                 this.size = size;
925                 bimg = new BufferedImage JavaDoc(size,size,BufferedImage.TYPE_INT_RGB);
926                 rect = new Rectangle(0,0,size,size);
927             }
928
929
930             public void reset(int w, int h) {
931                 incr = (float) (size) / (float) (ending - beginning);
932                 if ((type & HAF) != 0) {
933                    incr /= 2;
934                 }
935                 if ((type & DEC) != 0) {
936                     index = size;
937                     if ((type & HAF) != 0) {
938                        index /= 2;
939                     }
940                     incr = -incr;
941                 } else {
942                     index = 0.0f;
943                 }
944                 index += incr;
945             }
946
947        
948             public void step(int w, int h) {
949                 Graphics2D g2 = bimg.createGraphics();
950                 g2.setPaint(p1);
951                 g2.fillRect(0,0,size,size);
952                 g2.setPaint(p2);
953                 if ((type & OVAL) != 0) {
954                     g2.fill(new Ellipse2D.Float(0,0,index,index));
955                 } else if ((type & RECT) != 0) {
956                     g2.fill(new Rectangle2D.Float(0,0,index,index));
957                 }
958                 texture = new TexturePaint(bimg, rect);
959                 g2.dispose();
960                 index += incr;
961             }
962
963
964             public void render(int w, int h, Graphics2D g2) {
965                 g2.setPaint(texture);
966                 if ((type & NF) == 0) {
967                     g2.fillRect(0, 0, w, h);
968                 }
969             }
970
971             public int getBegin() {
972                 return beginning;
973             }
974
975             public int getEnd() {
976                 return ending;
977             }
978         } // End TpE class
979

980
981
982         /**
983          * Close out effect. Close out the buffered image with different
984          * geometry shapes.
985          */

986         static class CoE implements Part {
987
988             static final int WID = 1;
989             static final int HEI = 2;
990             static final int OVAL = 4;
991             static final int RECT = 8;
992             static final int RAND = 16;
993             static final int ARC = 32;
994             private int type;
995             private int beginning, ending;
996             private BufferedImage JavaDoc bimg;
997             private Shape shape;
998             private double zoom, extent;
999             private double zIncr, eIncr;
1000            private boolean doRandom;
1001
1002
1003            public CoE(int type, int beg, int end) {
1004                this.type = type;
1005                this.beginning = beg;
1006                this.ending = end;
1007                zIncr = -(2.0 / (ending - beginning));
1008                eIncr = 360.0 / (ending - beginning);
1009                doRandom = (type & RAND) != 0;
1010            }
1011
1012
1013            public void reset(int w, int h) {
1014                if (doRandom) {
1015                    int num = (int) (Math.random() * 5.0);
1016                    switch (num) {
1017                        case 0 : type = OVAL; break;
1018                        case 1 : type = RECT; break;
1019                        case 2 : type = RECT | WID; break;
1020                        case 3 : type = RECT | HEI; break;
1021                        case 4 : type = ARC; break;
1022                        default : type = OVAL;
1023                    }
1024                }
1025                shape = null;
1026                bimg = null;
1027                extent = 360.0;
1028                zoom = 2.0;
1029            }
1030
1031
1032            public void step(int w, int h) {
1033                if (bimg == null) {
1034                    int biw = Surface.bimg.getWidth();
1035                    int bih = Surface.bimg.getHeight();
1036                    bimg = new BufferedImage JavaDoc(biw, bih, BufferedImage.TYPE_INT_RGB);
1037                    Graphics2D big = bimg.createGraphics();
1038                    big.drawImage(Surface.bimg, 0, 0, null);
1039                }
1040                double z = Math.min(w, h) * zoom;
1041                if ((type & OVAL) != 0) {
1042                    shape = new Ellipse2D.Double(w/2-z/2,h/2-z/2,z,z);
1043                } else if ((type & ARC) != 0) {
1044                    shape = new Arc2D.Double(-100,-100,w+200,h+200,90,extent,Arc2D.PIE);
1045                    extent -= eIncr;
1046                } else if ((type & RECT) != 0) {
1047                    if ((type & WID) != 0) {
1048                        shape = new Rectangle2D.Double( w/2-z/2, 0, z, h);
1049                    } else if ((type & HEI) != 0) {
1050                        shape = new Rectangle2D.Double( 0, h/2-z/2, w, z);
1051                    } else {
1052                        shape = new Rectangle2D.Double( w/2-z/2, h/2-z/2, z, z);
1053                    }
1054                }
1055                zoom += zIncr;
1056            }
1057
1058
1059            public void render(int w, int h, Graphics2D g2) {
1060                g2.clip(shape);
1061                g2.drawImage(bimg, 0, 0, null);
1062            }
1063
1064            public int getBegin() {
1065                return beginning;
1066            }
1067
1068            public int getEnd() {
1069                return ending;
1070            }
1071        } // End CoE class
1072

1073
1074
1075        /**
1076         * Dither Dissolve Effect. For each successive step in the animation,
1077         * a pseudo-random starting horizontal position is chosen using list,
1078         * and then the corresponding points created from xlist and ylist are
1079         * blacked out for the current "chunk". The x and y chunk starting
1080         * positions are each incremented by the associated chunk size, and
1081         * this process is repeated for the number of "steps" in the
1082         * animation, causing an equal number of pseudo-randomly picked
1083         * "blocks" to be blacked out during each step of the animation.
1084         */

1085        static class DdE implements Part {
1086
1087            private int beginning, ending;
1088            private BufferedImage JavaDoc bimg;
1089            private Graphics2D big;
1090            private List JavaDoc list, xlist, ylist;
1091            private int xeNum, yeNum; // element number
1092
private int xcSize, ycSize; // chunk size
1093
private int inc;
1094            private int blocksize;
1095
1096
1097            public DdE(int beg, int end, int blocksize) {
1098                this.beginning = beg;
1099                this.ending = end;
1100                this.blocksize = blocksize;
1101            }
1102
1103            private void createShuffledLists() {
1104                int width = bimg.getWidth();
1105                int height = bimg.getHeight();
1106                Integer JavaDoc xarray[] = new Integer JavaDoc[width];
1107                Integer JavaDoc yarray[] = new Integer JavaDoc[height];
1108                Integer JavaDoc array[] = new Integer JavaDoc[ending - beginning + 1];
1109                for (int i = 0; i < xarray.length; i++) {
1110                    xarray[i] = new Integer JavaDoc(i);
1111                }
1112                for (int j = 0; j < yarray.length; j++) {
1113                    yarray[j] = new Integer JavaDoc(j);
1114                }
1115                for (int k = 0; k < array.length; k++) {
1116                    array[k] = new Integer JavaDoc(k);
1117                }
1118                java.util.Collections.shuffle(xlist = Arrays.asList(xarray));
1119                java.util.Collections.shuffle(ylist = Arrays.asList(yarray));
1120                java.util.Collections.shuffle( list = Arrays.asList( array));
1121            }
1122
1123            public void reset(int w, int h) {
1124                bimg = null;
1125            }
1126
1127            public void step(int w, int h) {
1128                if(inc > ending) {
1129                    bimg = null;
1130                }
1131                if (bimg == null) {
1132                    int biw = Surface.bimg.getWidth();
1133                    int bih = Surface.bimg.getHeight();
1134                    bimg = new BufferedImage JavaDoc(biw, bih, BufferedImage.TYPE_INT_RGB);
1135                    createShuffledLists();
1136                    big = bimg.createGraphics();
1137                    big.drawImage(Surface.bimg, 0, 0, null);
1138                    xcSize = (xlist.size() / (ending - beginning)) + 1;
1139                    ycSize = (ylist.size() / (ending - beginning)) + 1;
1140                    xeNum = 0;
1141                    inc = 0;
1142                }
1143                xeNum = xcSize * ((Integer JavaDoc)list.get(inc)).intValue();
1144                yeNum = -ycSize;
1145                inc++;
1146            }
1147
1148
1149            public void render(int w, int h, Graphics2D g2) {
1150                big.setColor(myBlack);
1151
1152                for (int k = 0; k <= (ending - beginning); k++) {
1153                    if ((xeNum + xcSize) > xlist.size()) {
1154                        xeNum = 0;
1155                    } else {
1156                        xeNum += xcSize;
1157                    }
1158                    yeNum += ycSize;
1159
1160                    for (int i = xeNum; i < xeNum+xcSize && i < xlist.size(); i++) {
1161                        for (int j = yeNum; j < yeNum+ycSize && j < ylist.size(); j++) {
1162                            int xval = ((Integer JavaDoc)xlist.get(i)).intValue();
1163                            int yval = ((Integer JavaDoc)ylist.get(j)).intValue();
1164                            if (((xval % blocksize) == 0) &&
1165                                ((yval % blocksize) == 0)) {
1166                                big.fillRect(xval, yval, blocksize, blocksize);
1167                            }
1168                        }
1169                    }
1170                }
1171           
1172                g2.drawImage(bimg, 0, 0, null);
1173            }
1174
1175            public int getBegin() {
1176                return beginning;
1177            }
1178
1179            public int getEnd() {
1180                return ending;
1181            }
1182        } // End DdE class
1183

1184
1185        /**
1186         * Subimage effect. Subimage the scene's buffered
1187         * image then rotate and scale down the subimages.
1188         */

1189        static class SiE implements Part {
1190
1191            private int beginning, ending;
1192            private BufferedImage JavaDoc bimg;
1193            private double rIncr, sIncr;
1194            private double scale, rotate;
1195            private int siw, sih;
1196            private List JavaDoc<BufferedImage JavaDoc> subs = new Vector JavaDoc<BufferedImage JavaDoc>(20);
1197            private List JavaDoc<Point> pts = new Vector JavaDoc<Point>(20);
1198
1199
1200            public SiE(int siw, int sih, int beg, int end) {
1201                this.siw = siw;
1202                this.sih = sih;
1203                this.beginning = beg;
1204                this.ending = end;
1205                rIncr = 360.0 / (ending - beginning);
1206                sIncr = 1.0 / (ending - beginning);
1207            }
1208
1209
1210            public void reset(int w, int h) {
1211                scale = 1.0;
1212                rotate = 0.0;
1213                bimg = null;
1214                subs.clear();
1215                pts.clear();
1216            }
1217
1218
1219            public void step(int w, int h) {
1220                if (bimg == null) {
1221                    int biw = Surface.bimg.getWidth();
1222                    int bih = Surface.bimg.getHeight();
1223                    bimg = new BufferedImage JavaDoc(biw, bih, BufferedImage.TYPE_INT_RGB);
1224                    Graphics2D big = bimg.createGraphics();
1225                    big.drawImage(Surface.bimg, 0, 0, null);
1226                    for (int x = 0; x < w && scale > 0.0; x+=siw) {
1227                        int ww = x+siw < w ? siw : w-x;
1228                        for (int y = 0; y < h; y+=sih) {
1229                            int hh = y+sih < h ? sih : h-y;
1230                            subs.add(bimg.getSubimage(x,y,ww,hh));
1231                            pts.add(new Point(x, y));
1232                        }
1233                    }
1234                }
1235                
1236                rotate += rIncr;
1237                scale -= sIncr;
1238            }
1239
1240
1241            public void render(int w, int h, Graphics2D g2) {
1242                AffineTransform saveTx = g2.getTransform();
1243                g2.setColor(myBlue);
1244                for (int i = 0; i < subs.size() && scale > 0.0; i++) {
1245                    BufferedImage JavaDoc bi = (BufferedImage JavaDoc) subs.get(i);
1246                    Point p = (Point) pts.get(i);
1247                    int ww = bi.getWidth();
1248                    int hh = bi.getHeight();
1249                    AffineTransform at = new AffineTransform();
1250                    at.rotate(Math.toRadians(rotate), p.x+ww/2, p.y+hh/2);
1251                    at.translate(p.x, p.y);
1252                    at.scale(scale, scale);
1253
1254                    Rectangle b1 = new Rectangle(0, 0, ww, hh);
1255                    Shape shape = at.createTransformedShape(b1);
1256                    Rectangle2D b2 = shape.getBounds2D();
1257                    double xx = (p.x+ww/2) - (b2.getX()+b2.getWidth()/2);
1258                    double yy = (p.y+hh/2) - (b2.getY()+b2.getHeight()/2);
1259                    AffineTransform toCenterAT = new AffineTransform();
1260                    toCenterAT.translate(xx, yy);
1261                    toCenterAT.concatenate(at);
1262
1263                    g2.setTransform(toCenterAT);
1264                    g2.drawImage(bi, 0, 0, null);
1265                    g2.draw(b1);
1266                }
1267                g2.setTransform(saveTx);
1268            }
1269
1270            public int getBegin() {
1271                return beginning;
1272            }
1273
1274            public int getEnd() {
1275                return ending;
1276            }
1277        } // End SiE class
1278

1279
1280
1281
1282        /**
1283         * Line Effect. Flattened ellipse with lines from the center
1284         * to the edge. Expand or collapse the ellipse. Fade in or out
1285         * the lines.
1286         */

1287        static class LnE implements Part {
1288
1289            static final int INC = 1;
1290            static final int DEC = 2;
1291            static final int R = 4; // rotate
1292
static final int ZOOM = 8; // zoom
1293
static final int AC = 32; // AlphaComposite
1294
static final int RI = R | INC;
1295            static final int RD = R | DEC;
1296            static final int ZOOMI = ZOOM | INC;
1297            static final int ZOOMD = ZOOM | DEC;
1298            static final int ACI = AC | INC;
1299            static final int ACD = AC | DEC;
1300
1301            private int beginning, ending;
1302            private double rIncr, rotate;
1303            private double zIncr, zoom;
1304            private List JavaDoc<Point2D.Double> pts = new Vector JavaDoc<Point2D.Double>();
1305            private float alpha, aIncr;
1306            private int type;
1307
1308
1309            public LnE(int type, int beg, int end) {
1310                this.type = type;
1311                this.beginning = beg;
1312                this.ending = end;
1313                float range = ending - beginning;
1314                rIncr = 360.0f / range;
1315                aIncr = 0.9f / range;
1316                zIncr = 2.0f / range;
1317                if ((type & DEC) != 0) {
1318                    rIncr = -rIncr;
1319                    aIncr = -aIncr;
1320                    zIncr = -zIncr;
1321                }
1322            }
1323
1324
1325            public void generatePts(int w, int h, double sizeF) {
1326                pts.clear();
1327                double size = Math.min(w, h) * sizeF;
1328                Ellipse2D ellipse = new Ellipse2D.Double(w/2-size/2,h/2-size/2,size,size);
1329                PathIterator pi = ellipse.getPathIterator(null, 0.8);
1330                while ( !pi.isDone() ) {
1331                    double[] pt = new double[6];
1332                    switch ( pi.currentSegment(pt) ) {
1333                        case FlatteningPathIterator.SEG_MOVETO:
1334                        case FlatteningPathIterator.SEG_LINETO:
1335                            pts.add(new Point2D.Double(pt[0], pt[1]));
1336                    }
1337                    pi.next();
1338                }
1339            }
1340
1341
1342            public void reset(int w, int h) {
1343                if ((type & DEC) != 0) {
1344                    rotate = 360;
1345                    alpha = 1.0f;
1346                    zoom = 2.0;
1347                } else {
1348                    rotate = alpha = 0;
1349                    zoom = 0;
1350                }
1351                if ((type & ZOOM) == 0) {
1352                    generatePts(w, h, 0.5);
1353                }
1354            }
1355
1356
1357            public void step(int w, int h) {
1358                if ((type & ZOOM) != 0) {
1359                    generatePts(w, h, zoom += zIncr);
1360                }
1361                if ((type & RI) != 0 || (type & RI) != 0) {
1362                   rotate += rIncr;
1363                }
1364                if ((type & ACI) != 0 || (type & ACD) != 0) {
1365                   alpha += aIncr;
1366                }
1367            }
1368
1369
1370            public void render(int w, int h, Graphics2D g2) {
1371                Composite saveAC = null;
1372                if ((type & AC) != 0 && alpha >= 0 && alpha <= 1) {
1373                    saveAC = g2.getComposite();
1374                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
1375                }
1376                AffineTransform saveTx = null;
1377                if ((type & R) != 0) {
1378                    saveTx = g2.getTransform();
1379                    AffineTransform at = new AffineTransform();
1380                    at.rotate(Math.toRadians(rotate), w/2, h/2);
1381                    g2.setTransform(at);
1382                }
1383                Point2D p1 = new Point2D.Double(w/2, h/2);
1384                g2.setColor(YELLOW);
1385                for (Point2D pt : pts) {
1386                    g2.draw(new Line2D.Float(p1, (Point2D) pt));
1387                }
1388                if (saveTx != null) {
1389                   g2.setTransform(saveTx);
1390                }
1391                if (saveAC != null) {
1392                   g2.setComposite(saveAC);
1393                }
1394            }
1395
1396            public int getBegin() {
1397                return beginning;
1398            }
1399
1400            public int getEnd() {
1401                return ending;
1402            }
1403        } // End LnE class
1404

1405
1406
1407        /**
1408         * Template for Features & Contributors consisting of translating
1409         * blue and red rectangles and an image going from transparent to
1410         * opaque.
1411         */

1412        static class Temp implements Part {
1413
1414            static final int NOANIM = 1;
1415            static final int RECT = 2;
1416            static final int IMG = 4;
1417            static final int RNA = RECT | NOANIM;
1418            static final int INA = IMG | NOANIM;
1419
1420            private int beginning, ending;
1421            private float alpha, aIncr;
1422            private int type;
1423            private Rectangle rect1, rect2;
1424            private int x, y, xIncr, yIncr;
1425            private Image JavaDoc img;
1426
1427
1428            public Temp(int type, Image JavaDoc img, int beg, int end) {
1429                this.type = type;
1430                this.img = img;
1431                this.beginning = beg;
1432                this.ending = end;
1433                aIncr = 0.9f / (ending - beginning);
1434                if ((type & NOANIM) != 0) {
1435                    alpha = 1.0f;
1436                }
1437            }
1438
1439
1440            public void reset(int w, int h) {
1441                rect1 = new Rectangle(8, 20, w-20, 30);
1442                rect2 = new Rectangle(20, 8, 30, h-20);
1443                if ((type & NOANIM) == 0) {
1444                    alpha = 0.0f;
1445                    xIncr = w / (ending - beginning);
1446                    yIncr = h / (ending - beginning);
1447                    x = w+(int)(xIncr*1.4);
1448                    y = h+(int)(yIncr*1.4);
1449                }
1450            }
1451
1452
1453            public void step(int w, int h) {
1454                if ((type & NOANIM) != 0) {
1455                   return;
1456                }
1457                if ((type & RECT) != 0) {
1458                    rect1.setLocation(x-=xIncr, 20);
1459                    rect2.setLocation(20, y-=yIncr);
1460                }
1461                if ((type & IMG) != 0) {
1462                    alpha += aIncr;
1463                }
1464            }
1465
1466
1467            public void render(int w, int h, Graphics2D g2) {
1468                if ((type & RECT) != 0) {
1469                    g2.setColor(myBlue);
1470                    g2.fill(rect1);
1471                    g2.setColor(myRed);
1472                    g2.fill(rect2);
1473                }
1474                if ((type & IMG) != 0) {
1475                    Composite saveAC = g2.getComposite();
1476                    if (alpha >= 0 && alpha <= 1) {
1477                        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
1478                    }
1479                    g2.drawImage(img, 30, 30, null);
1480                    g2.setComposite(saveAC);
1481                }
1482            }
1483
1484            public int getBegin() {
1485                return beginning;
1486            }
1487
1488            public int getEnd() {
1489                return ending;
1490            }
1491        } // End Temp class
1492

1493
1494
1495        /**
1496         * Features of Java2D. Single character advancement effect.
1497         */

1498        static class Features implements Part {
1499
1500            static final int GRAPHICS = 0;
1501            static final int TEXT = 1;
1502            static final int IMAGES = 2;
1503            static final int COLOR = 3;
1504
1505            static Font font1 = new Font("serif", Font.BOLD, 38);
1506            static Font font2 = new Font("serif", Font.PLAIN, 24);
1507            static FontMetrics fm1 = Surface.getMetrics(font1);
1508            static FontMetrics fm2 = Surface.getMetrics(font2);
1509            static String JavaDoc table[][] =
1510                {{ "Graphics", "Antialiased rendering", "Bezier paths",
1511                    "Transforms", "Compositing", "Stroking parameters" },
1512                 { "Text", "Extended font support",
1513                   "Advanced text layout", "Dynamic font loading",
1514                   "AttributeSets for font customization" },
1515                 { "Images", "Flexible image layouts",
1516                    "Extended imaging operations",
1517                    " Convolutions, Lookup Tables",
1518                    "RenderableImage interface"},
1519                 { "Color", "ICC profile support", "Color conversion",
1520                   "Arbitrary color spaces"} };
1521            private String JavaDoc list[];
1522            private int beginning, ending;
1523            private int strH;
1524            private int endIndex, listIndex;
1525            private List JavaDoc<String JavaDoc> v = new Vector JavaDoc<String JavaDoc>();
1526           
1527
1528            public Features(int type, int beg, int end) {
1529                list = table[type];
1530                this.beginning = beg;
1531                this.ending = end;
1532            }
1533
1534
1535            public void reset(int w, int h) {
1536                strH = (int) (fm2.getAscent()+fm2.getDescent());
1537                endIndex = 1;
1538                listIndex = 0;
1539                v.clear();
1540                v.add(list[listIndex].substring(0,endIndex));
1541            }
1542
1543
1544            public void step(int w, int h) {
1545                if (listIndex < list.length) {
1546                    if (++endIndex > list[listIndex].length()) {
1547                        if (++listIndex < list.length) {
1548                            endIndex = 1;
1549                            v.add(list[listIndex].substring(0,endIndex));
1550                        }
1551                    } else {
1552                        v.set(listIndex, list[listIndex].substring(0,endIndex));
1553                    }
1554                }
1555            }
1556
1557
1558            public void render(int w, int h, Graphics2D g2) {
1559                g2.setColor(myWhite);
1560                g2.setFont(font1);
1561                g2.drawString((String JavaDoc) v.get(0), 90, 85);
1562                g2.setFont(font2);
1563                for (int i = 1, y = 90; i < v.size(); i++) {
1564                    g2.drawString((String JavaDoc) v.get(i), 120, y += strH);
1565                }
1566            }
1567
1568            public int getBegin() {
1569                return beginning;
1570            }
1571
1572            public int getEnd() {
1573                return ending;
1574            }
1575        } // End Features class
1576

1577
1578
1579        /**
1580         * Scrolling text of Java2D contributors.
1581         */

1582        static class Contributors implements Part {
1583
1584            static String JavaDoc members[] =
1585            {
1586                "Brian Lichtenwalter", "Jeannette Hung",
1587                "Thanh Nguyen", "Jim Graham", "Jerry Evans",
1588                "John Raley", "Michael Peirce", "Robert Kim",
1589                "Jennifer Ball", "Deborah Adair", "Paul Charlton",
1590                "Dmitry Feld", "Gregory Stone", "Richard Blanchard",
1591                "Link Perry", "Phil Race", "Vincent Hardy",
1592                "Parry Kejriwal", "Doug Felt", "Rekha Rangarajan",
1593                "Paula Patel", "Michael Bundschuh", "Joe Warzecha",
1594                "Joey Beheler", "Aastha Bhardwaj", "Daniel Rice",
1595                "Chris Campbell", "Shinsuke Fukuda", "Dmitri Trembovetski",
1596                "Chet Haase", "Jennifer Godinez", "Nicholas Talian",
1597                "Raul Vera", "Ankit Patel", "Ilya Bagrak",
1598                "Praveen Mohan", "Rakesh Menon"
1599            };
1600            static Font font = new Font("serif", Font.PLAIN, 26);
1601            static FontMetrics fm = Surface.getMetrics(font);
1602            private int beginning, ending;
1603            private int nStrs, strH, index, yh, height;
1604            private List JavaDoc<String JavaDoc> v = new Vector JavaDoc<String JavaDoc>();
1605            private List JavaDoc<String JavaDoc> cast = new Vector JavaDoc<String JavaDoc>(members.length+3);
1606            private int counter, cntMod;
1607            private GradientPaint gp;
1608
1609
1610            public Contributors(int beg, int end) {
1611                this.beginning = beg;
1612                this.ending = end;
1613                java.util.Arrays.sort(members);
1614                cast.add("CONTRIBUTORS");
1615                cast.add(" ");
1616                for (String JavaDoc member : members) {
1617                    cast.add(member);
1618                }
1619                cast.add(" ");
1620                cast.add(" ");
1621                cntMod = (ending - beginning) / cast.size() - 1;
1622            }
1623
1624
1625            public void reset(int w, int h) {
1626                v.clear();
1627                strH = (int) (fm.getAscent()+fm.getDescent());
1628                nStrs = (h-40)/strH + 1;
1629                height = strH * (nStrs-1) + 48;
1630                index = 0;
1631                gp = new GradientPaint(0, h/2, WHITE, 0, h+20, BLACK);
1632                counter = 0;
1633            }
1634
1635
1636            public void step(int w, int h) {
1637                if (counter++%cntMod == 0) {
1638                    if (index < cast.size()) {
1639                        v.add(cast.get(index));
1640                    }
1641                    if ((v.size() == nStrs || index >= cast.size()) && v.size() != 0) {
1642                        v.remove(0);
1643                    }
1644                    ++index;
1645                }
1646            }
1647
1648
1649            public void render(int w, int h, Graphics2D g2) {
1650                g2.setPaint(gp);
1651                g2.setFont(font);
1652                double remainder = counter%cntMod;
1653                double incr = 1.0 - remainder/cntMod;
1654                incr = incr == 1.0 ? 0 : incr;
1655                int y = (int) (incr * strH);
1656
1657                if (index >= cast.size()) {
1658                    y = yh + y;
1659                } else {
1660                    y = yh = height - v.size() * strH + y;
1661                }
1662                for (String JavaDoc s : v) {
1663                    g2.drawString(s, w/2-fm.stringWidth(s)/2, y += strH);
1664                }
1665            }
1666
1667            public int getBegin() {
1668                return beginning;
1669            }
1670
1671            public int getEnd() {
1672                return ending;
1673            }
1674        } // End Contributors class
1675

1676    } // End Surface class
1677
} // End Intro class
1678
Popular Tags