Intro.java
Upload User: cdlibang
Upload Date: 2016-07-17
Package Size: 774k
Code Size: 58k
Category:

2D Graphic

Development Platform:

Java

  1. /*
  2.  * @(#)Intro.java 1.6 99/08/16
  3.  *
  4.  * Copyright (c) 1998, 1999 by Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  * 
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  * 
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30. import java.awt.*;
  31. import java.awt.event.*;
  32. import java.awt.geom.*;
  33. import java.awt.image.BufferedImage;
  34. import java.awt.image.DataBuffer;
  35. import java.awt.font.*;
  36. import javax.swing.*;
  37. import javax.swing.border.*;
  38. import javax.swing.table.*;
  39. import javax.swing.event.*;
  40. import java.util.Vector;
  41. import java.util.List;
  42. import java.util.Arrays;
  43. /**
  44.  * Introduction to the Java2Demo.  
  45.  *
  46.  * @version @(#)Intro.java 1.6 99/08/16
  47.  * @author Brian Lichtenwalter
  48.  */
  49. public class Intro extends JPanel {
  50.     static Color black = new Color(20, 20, 20); 
  51.     static Color white = new Color(240, 240, 255); 
  52.     static Color red = new Color(149, 43, 42);
  53.     static Color blue = new Color(94, 105, 176); 
  54.     static Color yellow = new Color(255, 255, 140);
  55.     static Surface surface;
  56.     private ScenesTable scenesTable;
  57.     private boolean doTable;
  58.     public Intro() {
  59.         EmptyBorder eb = new EmptyBorder(80,110,80,110);
  60.         BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);
  61.         setBorder(new CompoundBorder(eb,bb));
  62.         setLayout(new BorderLayout());
  63.         setBackground(Color.gray);
  64.         setToolTipText("click for scene table");
  65.         add(surface = new Surface());
  66.         addMouseListener(new MouseAdapter() {
  67.             public void mouseClicked(MouseEvent e) {
  68.                removeAll();
  69.                if ((doTable = !doTable)) {
  70.                    setToolTipText("click for animation");
  71.                    surface.stop();
  72.                    if (scenesTable == null) {
  73.                        scenesTable = new ScenesTable();
  74.                    }
  75.                    add(scenesTable);
  76.                } else {
  77.                    setToolTipText("click for scene table");
  78.                    surface.start();
  79.                    add(surface);
  80.                }
  81.                revalidate();
  82.                repaint();
  83.             }
  84.         });
  85.     }
  86.     public void start() {
  87.         if (!doTable) {
  88.             surface.start();
  89.         }
  90.     }
  91.     public void stop() {
  92.         if (!doTable) {
  93.            surface.stop();
  94.         }
  95.     }
  96.     public static void main(String argv[]) {
  97.         final Intro intro = new Intro();
  98.         WindowListener l = new WindowAdapter() {
  99.             public void windowClosing(WindowEvent e) {System.exit(0);}
  100.             public void windowDeiconified(WindowEvent e) { intro.start(); }
  101.             public void windowIconified(WindowEvent e) { intro.stop(); }
  102.         };
  103.         JFrame f = new JFrame("Java2D Demo - Intro");
  104.         f.addWindowListener(l);
  105.         f.getContentPane().add("Center", intro);
  106.         f.pack();
  107.         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  108.         int w = 720;
  109.         int h = 510;
  110.         f.setLocation(screenSize.width/2 - w/2, screenSize.height/2 - h/2);
  111.         f.setSize(w, h);
  112.         f.show();
  113.         intro.start();
  114.     }
  115.     /**
  116.      * ScenesTable is the list of scenes known to the Director.
  117.      * Scene participation, scene name and scene pause amount columns.
  118.      * Global animation delay for scene's steps.
  119.      */
  120.     static class ScenesTable extends JPanel implements ActionListener, ChangeListener {
  121.         private JTable table;
  122.         private TableModel dataModel;
  123.         public ScenesTable() {
  124.             setBackground(Color.white);
  125.             setLayout(new BorderLayout());
  126.             final String[] names = { "", "Scenes", "Pause" };
  127.     
  128.             dataModel = new AbstractTableModel() {
  129.                 public int getColumnCount() { return names.length; }
  130.                 public int getRowCount() { return surface.director.size();}
  131.                 public Object getValueAt(int row, int col) { 
  132.                     Surface.Scene scene = (Surface.Scene) surface.director.get(row); 
  133.                     if (col == 0) {
  134.                         return scene.participate;
  135.                     } else if (col == 1) {
  136.                         return scene.name;
  137.                     } else { 
  138.                         return scene.pauseAmt;
  139.                    }
  140.                 }
  141.                 public String getColumnName(int col) {return names[col]; }
  142.                 public Class getColumnClass(int c) {
  143.                     return getValueAt(0, c).getClass();
  144.                 }
  145.                 public boolean isCellEditable(int row, int col) {
  146.                     return col != 1 ? true : false;
  147.                 }
  148.                 public void setValueAt(Object aValue, int row, int col) {
  149.                     Surface.Scene scene = (Surface.Scene) surface.director.get(row); 
  150.                     if (col == 0) {
  151.                         scene.participate = aValue;
  152.                     } else if (col == 1) {
  153.                         scene.name = aValue;
  154.                     } else { 
  155.                         scene.pauseAmt = aValue;
  156.                     }
  157.                 }
  158.             };
  159.     
  160.             table = new JTable(dataModel);
  161.             TableColumn col = table.getColumn("");
  162.             col.setWidth(16);
  163.             col.setMinWidth(16);
  164.             col.setMaxWidth(20);
  165.             col = table.getColumn("Pause");
  166.             col.setWidth(60);
  167.             col.setMinWidth(60);
  168.             col.setMaxWidth(60);
  169.             table.sizeColumnsToFit(0);
  170.         
  171.             JScrollPane scrollpane = new JScrollPane(table);
  172.             add(scrollpane);
  173.  
  174.             JPanel panel = new JPanel(new BorderLayout());
  175.             JButton b = new JButton("Unselect All");
  176.             b.setHorizontalAlignment(JButton.LEFT);
  177.             Font font = new Font("serif", Font.PLAIN, 10);
  178.             b.setFont(font);
  179.             b.addActionListener(this);
  180.             panel.add("West", b);
  181.             JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 200, (int) surface.sleepAmt);
  182.             slider.addChangeListener(this);
  183.             TitledBorder tb = new TitledBorder(new EtchedBorder());
  184.             tb.setTitleFont(font);
  185.             tb.setTitle("Anim delay = " + String.valueOf(surface.sleepAmt) + " ms");
  186.             slider.setBorder(tb);
  187.             slider.setPreferredSize(new Dimension(140,40));
  188.             slider.setMinimumSize(new Dimension(100,40));
  189.             slider.setMaximumSize(new Dimension(180,40));
  190.             panel.add("East", slider);
  191.             add("South", panel);
  192.         }
  193.         public void actionPerformed(ActionEvent e) {
  194.             JButton b = (JButton) e.getSource();
  195.             b.setSelected(!b.isSelected());
  196.             b.setText(b.isSelected() ? "Select All" : "Unselect All");
  197.             for (int i = 0; i < surface.director.size(); i++) {
  198.                 Surface.Scene scene = (Surface.Scene) surface.director.get(i); 
  199.                 scene.participate = new Boolean(!b.isSelected());
  200.             }
  201.     table.tableChanged(new TableModelEvent(dataModel));
  202.         }
  203.         public void stateChanged(ChangeEvent e) {
  204.             JSlider slider = (JSlider) e.getSource();
  205.             int value = slider.getValue();
  206.             TitledBorder tb = (TitledBorder) slider.getBorder();
  207.             tb.setTitle("Anim delay = " + String.valueOf(value) + " ms");
  208.             surface.sleepAmt = (long) value;
  209.             slider.repaint();
  210.         }
  211.     }  // End ScenesTable class
  212.     /**
  213.      * Surface is the stage where the Director plays its scenes.
  214.      */
  215.     static class Surface extends JPanel implements Runnable {
  216.         static Surface surf;
  217.         static Image cupanim, java_logo;
  218.         static BufferedImage bimg;
  219.         static List list;                  // a cache for DdE part 
  220.         public Director director;
  221.         public int index;
  222.         public long sleepAmt = 30;
  223.         private Thread thread;
  224.         public Surface() {
  225.             surf = this;
  226.             setBackground(black);
  227.             setLayout(new BorderLayout());
  228.             addMouseListener(new MouseAdapter() {
  229.                 public void mouseClicked(MouseEvent e) {
  230.                     if (thread == null) start(); else stop();
  231.                 }
  232.             });
  233.             cupanim = DemoImages.getImage("cupanim.gif", this);
  234.             java_logo = DemoImages.getImage("java_logo.gif", this);
  235.             director = new Director();
  236.         }
  237.         static FontMetrics getMetrics(Font font) {
  238.             return surf.getFontMetrics(font);
  239.         }
  240.         public void paint(Graphics g) {
  241.             Dimension d = getSize();
  242.             if (bimg == null || bimg.getWidth() != d.width || bimg.getHeight() != d.height) {
  243.                 bimg = (BufferedImage) createImage(d.width, d.height);  
  244.                 // reset future scenes
  245.                 for (int i = index+1; i < director.size(); i++) {
  246.                     ((Scene) director.get(i)).reset(d.width, d.height);
  247.                 }
  248.                 createShuffledList();
  249.             }
  250.             Scene scene = (Scene) director.get(index);
  251.             if (scene.index <= scene.length) {
  252.                 if (thread != null) {
  253.                     scene.step(d.width, d.height);
  254.                 }
  255.                 Graphics2D g2 = bimg.createGraphics();
  256.                 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
  257.                                     RenderingHints.VALUE_ANTIALIAS_ON);
  258.                 g2.setBackground(getBackground());
  259.                 g2.clearRect(0, 0, d.width, d.height);
  260.     
  261.                 scene.render(d.width, d.height, g2);
  262.                 if (thread != null) {
  263.                     // increment scene.index after scene.render
  264.                     scene.index++;      
  265.                 }
  266.                 g2.dispose();
  267.             }
  268.             g.drawImage(bimg, 0, 0, this);
  269.         }
  270.         public void start() {
  271.             if (thread == null) {
  272.                 thread = new Thread(this);
  273.                 thread.setPriority(Thread.MIN_PRIORITY);
  274.                 thread.setName("Intro");
  275.                 thread.start();
  276.             }
  277.         }
  278.     
  279.         public synchronized void stop() {
  280.             if (thread != null) {
  281.                 thread.interrupt();
  282.             }
  283.             thread = null;
  284.             notifyAll();
  285.         }
  286.         public void reset() {
  287.             index = 0;
  288.             Dimension d = getSize();
  289.             for (int i = 0; i < director.size(); i++) {
  290.                 ((Scene) director.get(i)).reset(d.width, d.height);
  291.             }
  292.         }
  293.       
  294.         /**
  295.          * create a shuffled list for the DdE part - Dither Dissolve Effect
  296.          */
  297.         private void createShuffledList() {
  298.             int size = bimg.getRaster().getDataBuffer().getSize();
  299.             Integer array[] = new Integer[size];
  300.             for (int j = 0; j < array.length; j++) {
  301.                  array[j] = new Integer(j);
  302.             }
  303.             java.util.Collections.shuffle(list = Arrays.asList(array));
  304.         }
  305.     
  306.         public void run() {
  307.             Thread me = Thread.currentThread();
  308.             while (thread == me && !isShowing() || getSize().width <= 0) {
  309.                 try {
  310.                     thread.sleep(500);
  311.                 } catch (InterruptedException e) { return; }
  312.             }
  313.             if (index == 0) {
  314.                 reset();
  315.             }
  316.             while (thread == me) {
  317.                 Scene scene = (Scene) director.get(index);
  318.                 if (((Boolean) scene.participate).booleanValue()) {
  319.                     repaint();
  320.                     try {
  321.                         thread.sleep(sleepAmt);
  322.                     } catch (InterruptedException e) { break; }
  323.                     if (scene.index > scene.length) {
  324.                         scene.pause(thread);
  325.                         if (++index >= director.size()) {
  326.                             reset();
  327.                         }
  328.                     }
  329.                 } else {
  330.                    if (++index >= director.size()) {
  331.                         reset();
  332.                    }
  333.                 }
  334.             }
  335.             thread = null;
  336.         }
  337.         /**
  338.          * Part is a piece of the scene.  Classes must implement Part
  339.          * inorder to participate in a scene.
  340.          */
  341.         interface Part {
  342.             public void reset(int newwidth, int newheight);
  343.             public void step(int w, int h);
  344.             public void render(int w, int h, Graphics2D g2);
  345.             public int getBegin();
  346.             public int getEnd();
  347.         }
  348.         /**
  349.          * Director is the holder of the scenes, their names & pause amounts
  350.          * between scenes.
  351.          */
  352.         static class Director extends Vector {
  353.             GradientPaint gp = new GradientPaint(0,40,blue,38,2,black);
  354.             Font f1 = new Font("serif", Font.PLAIN, 200);
  355.             Font f2 = new Font("serif", Font.PLAIN, 120);
  356.             Font f3 = new Font("serif", Font.PLAIN, 72);
  357.             Object parts[][][] = {
  358.                { { "J  -  scale text on gradient", "0" },
  359.                  { new GpE(GpE.BURI, black, blue, 0, 20),
  360.                    new TxE("J", f1, TxE.SCI, yellow, 2, 20) } },
  361.                { { "2  -  scale & rotate text on gradient" , "0" },
  362.                  { new GpE(GpE.BURI, blue, black, 0, 22),
  363.                    new TxE("2", f1, TxE.RI | TxE.SCI, yellow, 2, 22) } },
  364.                { { "D  -  scale text on gradient", "0" },
  365.                  { new GpE(GpE.BURI, black, blue, 0, 20),
  366.                    new TxE("D", f1, TxE.SCI, yellow, 2, 20) } },
  367.                { { "Java2D  -  scale & rotate text on gradient", "1000" },
  368.                  { new GpE(GpE.SIH, blue, black, 0, 40),
  369.                    new TxE("Java2D", f2, TxE.RI | TxE.SCI, yellow, 0, 40) }},
  370.                { { "Previous scene dither dissolve out", "0"},
  371.                  { new DdE(0, 20) }},
  372.                { { "Graphics Features", "999" },
  373.                  { new Temp(Temp.RECT, null, 0, 15),
  374.                    new Temp(Temp.IMG, java_logo, 2, 15),
  375.                    new Temp(Temp.RNA | Temp.INA, java_logo, 16, 130),
  376.                    new Features(Features.GRAPHICS, 16, 130) }},
  377.                { { "Java2D  -  texture text on gradient", "1000"},
  378.                  { new GpE(GpE.WI, blue, black, 0, 20),
  379.                    new GpE(GpE.WD, blue, black, 21, 40),
  380.                    new TpE(TpE.OI | TpE.NF, black, yellow, 4, 0, 10),
  381.                    new TpE(TpE.OD | TpE.NF, black, yellow, 4, 11, 20),
  382.                    new TpE(TpE.OI | TpE.NF | TpE.HAF, black, yellow,5,21,40),
  383.                    new TxE("Java2D", f2, 0, null, 0, 40) }},
  384.                { { "Previous scene random close out", "0"},
  385.                  { new CoE(CoE.RAND, 0, 20) } },
  386.                { { "Text Features", "999" },
  387.                  { new Temp(Temp.RECT, null, 0, 15),
  388.                    new Temp(Temp.IMG, java_logo, 2, 15),
  389.                    new Temp(Temp.RNA | Temp.INA, java_logo, 16, 130),
  390.                    new Features(Features.TEXT, 16, 130) }},
  391.                { { "Java2D  -  composite text on texture", "1000"},
  392.                  { new TpE(TpE.RI, black, gp, 40, 0, 20),
  393.                    new TpE(TpE.RD, black, gp, 40, 21, 40),
  394.                    new TpE(TpE.RI, black, gp, 40, 41, 60),
  395.                    new TxE("Java2D", f2, TxE.AC, yellow, 0, 60) }},
  396.                { { "Previous scene dither dissolve out", "0"},
  397.                  { new DdE(0, 20) }},
  398.                { { "Imaging Features", "999" },
  399.                  { new Temp(Temp.RECT, null, 0, 15),
  400.                    new Temp(Temp.IMG, java_logo, 2, 15),
  401.                    new Temp(Temp.RNA | Temp.INA, java_logo, 16, 130),
  402.                    new Features(Features.IMAGES, 16, 130) }},
  403.                { { "Java2D  -  text on gradient", "1000" },
  404.                  { new GpE(GpE.SDH, blue, black, 0, 20),
  405.                    new GpE(GpE.SIH, blue, black, 21, 40),
  406.                    new GpE(GpE.SDH, blue, black, 41, 50),
  407.                    new GpE(GpE.INC | GpE.NF, red, yellow, 0, 50),
  408.                    new TxE("Java2D", f2, TxE.NOP, null, 0, 50) }},
  409.                { { "Previous scene ellipse close out", "0"},
  410.                  { new CoE(CoE.OVAL, 0, 20) } },
  411.                { { "Color Features", "999" },
  412.                  { new Temp(Temp.RECT, null, 0, 15),
  413.                    new Temp(Temp.IMG, java_logo, 2, 15),
  414.                    new Temp(Temp.RNA | Temp.INA, java_logo, 16, 99),
  415.                    new Features(Features.COLOR, 16, 99) }},
  416.                { { "Java2D  -  composite and rotate text on paints", "2000" },
  417.                  { new GpE(GpE.BURI, black, blue, 0, 20),
  418.                    new GpE(GpE.BURD, black, blue, 21, 30),
  419.                    new TpE(TpE.OI | TpE.HAF, black, blue, 10, 31, 40),
  420.                    new TxE("Java2D", f2, TxE.AC | TxE.RI, yellow, 0, 40) }},
  421.                { { "Previous scene subimage transform out", "0" },
  422.                  { new SiE(60, 60, 0, 40) }},
  423.                { { "CREDITS  -  transform in", "1000" },
  424.                  { new LnE(LnE.ACI | LnE.ZOOMI | LnE.RI, 0, 60),
  425.                    new TxE("CREDITS", f3, TxE.AC | TxE.SCI, Color.red,20,30),
  426.                    new TxE("CREDITS", f3, TxE.SCXD, Color.red, 31, 38),
  427.                    new TxE("CREDITS", f3, TxE.SCXI, Color.red, 39, 48),
  428.                    new TxE("CREDITS", f3, TxE.SCXD, Color.red, 49, 54),
  429.                    new TxE("CREDITS", f3, TxE.SCXI, Color.red, 55, 60) }},
  430.                { { "CREDITS  -  transform out", "0" },
  431.                  { new LnE(LnE.ACD | LnE.ZOOMD | LnE.RD, 0, 45),
  432.                    new TxE("CREDITS", f3, 0, Color.red, 0, 9),
  433.                    new TxE("CREDITS", f3, TxE.SCD | TxE.RD, Color.red,10,30)}},
  434.                { { "Contributors", "1000" },
  435.                  { new Temp(Temp.RECT, null, 0, 30),
  436.                    new Temp(Temp.IMG, cupanim, 4, 30),
  437.                    new Temp(Temp.RNA | Temp.INA, cupanim, 31, 200),
  438.                    new Contributors(34, 200) } },
  439.             };
  440.             public Director() {
  441.                 for (int i = 0; i < parts.length; i++) {
  442.                     Vector v = new Vector();
  443.                     for (int j = 0; j < parts[i][1].length; j++) {
  444.                         v.addElement(parts[i][1][j]);
  445.                     }
  446.                     addElement(new Scene(v, parts[i][0][0], parts[i][0][1]));
  447.                 }
  448.             }
  449.         }
  450.         
  451.         /**
  452.          * Scene is the manager of the parts.
  453.          */
  454.         static class Scene extends Object {
  455.             public Object name;
  456.             public Object participate = new Boolean(true);
  457.             public Object pauseAmt;
  458.             public Vector parts;
  459.             public int index;
  460.             public int length;
  461.             public Scene(Vector parts, Object name, Object pauseAmt) {
  462.                 this.name = name;
  463.                 this.parts = parts;
  464.                 this.pauseAmt = pauseAmt;
  465.                 for (int i = 0; i < parts.size(); i++) {
  466.                     if (((Part) parts.get(i)).getEnd() > length) {
  467.                         length = ((Part) parts.get(i)).getEnd();
  468.                     }
  469.                 }
  470.             }
  471.             public void reset(int w, int h) {
  472.                 index = 0;
  473.                 for (int i = 0; i < parts.size(); i++) {
  474.                     ((Part) parts.get(i)).reset(w, h);
  475.                 }
  476.             }
  477.             public void step(int w, int h) {
  478.                 for (int i = 0; i < parts.size(); i++) {
  479.                     Part part = (Part) parts.get(i);
  480.                     if (index >= part.getBegin() && index <= part.getEnd()) {
  481.                         part.step(w, h);
  482.                     }
  483.                 }
  484.             }
  485.             public void render(int w, int h, Graphics2D g2) {
  486.                 for (int i = 0; i < parts.size(); i++) {
  487.                     Part part = (Part) parts.get(i);
  488.                     if (index >= part.getBegin() && index <= part.getEnd()) {
  489.                         part.render(w, h, g2);
  490.                     }
  491.                 }
  492.             }
  493.             public void pause(Thread thread) {
  494.                 try {
  495.                     thread.sleep(Long.parseLong((String) pauseAmt));
  496.                 } catch (Exception e) { }
  497.                 System.gc();
  498.             }
  499.         } // End Scene class
  500.         /**
  501.          * Text Effect.  Transformation of characters.  Clip or fill.
  502.          */
  503.         static class TxE implements Part {
  504.             static final int INC  = 1;
  505.             static final int DEC  = 2;
  506.             static final int R    = 4;            // rotate
  507.             static final int RI   = R | INC;
  508.             static final int RD   = R | DEC;
  509.             static final int SC   = 8;            // scale
  510.             static final int SCI  = SC | INC;
  511.             static final int SCD  = SC | DEC;    
  512.             static final int SCX  = 16;           // scale invert x
  513.             static final int SCXI = SCX | SC | INC;
  514.             static final int SCXD = SCX | SC | DEC; 
  515.             static final int SCY  = 32;           // scale invert y
  516.             static final int SCYI = SCY | SC | INC;
  517.             static final int SCYD = SCY | SC | DEC; 
  518.             static final int AC   = 64;           // AlphaComposite
  519.             static final int CLIP = 128;          // Clipping
  520.             static final int NOP  = 512;          // No Paint 
  521.             private int beginning, ending;
  522.             private int type;
  523.             private double rIncr, sIncr;
  524.             private double sx, sy, rotate;
  525.             private Shape shapes[], txShapes[];
  526.             private int sw;
  527.             private int numRev;
  528.             private Paint paint;
  529.             public TxE(String text, 
  530.                            Font font, 
  531.                            int type, 
  532.                            Paint paint,
  533.                            int beg, 
  534.                            int end) {
  535.                 this.type = type;
  536.                 this.paint = paint;
  537.                 this.beginning = beg;
  538.                 this.ending = end;
  539.                 setIncrements(2);
  540.                 
  541.                 char[] chars = text.toCharArray();
  542.                 shapes = new Shape[chars.length];
  543.                 txShapes = new Shape[chars.length];
  544.                 FontRenderContext frc = new FontRenderContext(null,true,true);
  545.                 TextLayout tl = new TextLayout(text, font, frc);
  546.                 sw = (int) tl.getOutline(null).getBounds().getWidth();
  547.                 for (int j = 0; j < chars.length; j++) {
  548.                     String s = String.valueOf(chars[j]);
  549.                     shapes[j] = new TextLayout(s, font, frc).getOutline(null);
  550.                 }
  551.             }
  552.             public void setIncrements(double numRevolutions) {
  553.                 this.numRev = (int) numRevolutions;
  554.                 rIncr = 360.0 / ((ending - beginning) / numRevolutions);
  555.                 sIncr = 1.0 / (ending - beginning);
  556.                 if ((type & SCX) != 0 || (type & SCY) != 0) {
  557.                     sIncr *= 2;
  558.                 }
  559.                 if ((type & DEC) != 0) {
  560.                     rIncr = -rIncr;
  561.                     sIncr = -sIncr;
  562.                 }
  563.             }
  564.             public void reset(int w, int h) {
  565.                 if (type == SCXI) {
  566.                     sx = -1.0;  sy = 1.0;
  567.                 } else if (type == SCYI) {
  568.                     sx = 1.0;  sy = -1.0;
  569.                 } else {
  570.                     sx = sy = (type & DEC) != 0 ? 1.0 : 0.0;  
  571.                 }
  572.                 rotate = 0;
  573.             }
  574.        
  575.             public void step(int w, int h) {
  576.         
  577.                 float charWidth = w/2-sw/2;
  578.         
  579.                 for (int i = 0; i < shapes.length; i++) {
  580.                     AffineTransform at = new AffineTransform();
  581.                     Rectangle2D maxBounds = shapes[i].getBounds();
  582.                     at.translate(charWidth, h/2+maxBounds.getHeight()/2);
  583.                     charWidth += (float) maxBounds.getWidth() + 1;
  584.                     Shape shape = at.createTransformedShape(shapes[i]);
  585.                     Rectangle2D b1 = shape.getBounds2D();
  586.         
  587.                     if ((type & R) != 0) {
  588.                         at.rotate(Math.toRadians(rotate)); 
  589.                     }
  590.                     if ((type & SC) != 0) {
  591.                         at.scale(sx, sy);
  592.                     }
  593.                     shape = at.createTransformedShape(shapes[i]);
  594.                     Rectangle2D b2 = shape.getBounds2D();
  595.       
  596.                     double xx = (b1.getX()+b1.getWidth()/2)
  597.                                 - (b2.getX()+b2.getWidth()/2);
  598.                     double yy = (b1.getY()+b1.getHeight()/2)
  599.                                 - (b2.getY()+b2.getHeight()/2);
  600.                     AffineTransform toCenterAT = new AffineTransform();
  601.                     toCenterAT.translate(xx, yy);
  602.                     toCenterAT.concatenate(at);
  603.                     txShapes[i] = toCenterAT.createTransformedShape(shapes[i]);
  604.                 }
  605.                 // avoid over rotation
  606.                 if (Math.abs(rotate) <= numRev * 360) {
  607.                     rotate += rIncr;
  608.                     if ((type & SCX) != 0) {
  609.                         sx += sIncr;
  610.                     } else if ((type & SCY) != 0) {
  611.                         sy += sIncr;
  612.                     } else {
  613.                         sx += sIncr; sy += sIncr;
  614.                     }
  615.                 }
  616.             }
  617.             public void render(int w, int h, Graphics2D g2) {
  618.                 Composite saveAC = null;
  619.                 if ((type & AC) != 0 && sx > 0 && sx < 1) {
  620.                     saveAC = g2.getComposite();
  621.                     g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) sx));
  622.                 }
  623.                 GeneralPath path = null;
  624.                 if ((type & CLIP) != 0) {
  625.                     path = new GeneralPath();
  626.                 }
  627.                 if (paint != null) {
  628.                     g2.setPaint(paint);
  629.                 }
  630.                 for (int i = 0; i < txShapes.length; i++) {
  631.                     if ((type & CLIP) != 0) {
  632.                        path.append(txShapes[i], false);
  633.                     } else {
  634.                        g2.fill(txShapes[i]);
  635.                     }
  636.                 }
  637.                 if ((type & CLIP) != 0) {
  638.                     g2.clip(path);
  639.                 }
  640.                 if (saveAC != null) {
  641.                    g2.setComposite(saveAC);
  642.                 }
  643.             }
  644.             public int getBegin() {
  645.                 return beginning;
  646.             }
  647.             public int getEnd() {
  648.                 return ending;
  649.             }
  650.         } // End TxE class
  651.         /**
  652.          * GradientPaint Effect.  Burst, split, horizontal and 
  653.          * vertical gradient fill effects.
  654.          */
  655.         static class GpE implements Part {
  656.             static final int INC = 1;             // increasing
  657.             static final int DEC = 2;             // decreasing
  658.             static final int CNT = 4;             // center
  659.             static final int WID = 8;             // width 
  660.             static final int WI  = WID | INC;             
  661.             static final int WD  = WID | DEC;            
  662.             static final int HEI = 16;            // height
  663.             static final int HI  = HEI | INC;            
  664.             static final int HD  = HEI | DEC;            
  665.             static final int SPL = 32 | CNT;      // split 
  666.             static final int SIW = SPL | INC | WID;
  667.             static final int SDW = SPL | DEC | WID;
  668.             static final int SIH = SPL | INC | HEI;
  669.             static final int SDH = SPL | DEC | HEI;
  670.             static final int BUR = 64 | CNT;     // burst 
  671.             static final int BURI = BUR | INC;    
  672.             static final int BURD = BUR | DEC;   
  673.             static final int NF = 128;           // no fill
  674.             private Color c1, c2;
  675.             private int beginning, ending;
  676.             private float incr, index;
  677.             private Vector rect = new Vector();
  678.             private Vector grad = new Vector();
  679.             private int type;
  680.             public GpE(int type, Color c1, Color c2, int beg, int end) {
  681.                 this.type = type;
  682.                 this.c1 = c1;
  683.                 this.c2 = c2;
  684.                 this.beginning = beg;
  685.                 this.ending = end;
  686.             }
  687.             public void reset(int w, int h) {
  688.                 incr = 1.0f / (ending - beginning);
  689.                 if ((type & CNT) != 0) {
  690.                     incr /= 2.3f;
  691.                 }
  692.                 if ((type & CNT) != 0 && (type & INC) != 0) {
  693.                     index = 0.5f;
  694.                 } else if ((type & DEC) != 0) {
  695.                     index = 1.0f;
  696.                     incr = -incr;
  697.                 } else {
  698.                     index = 0.0f;
  699.                 }
  700.                 index += incr;
  701.             }
  702.        
  703.             public void step(int w, int h) {
  704.                 rect.clear();
  705.                 grad.clear();
  706.                 if ((type & WID) != 0) {
  707.                     float w2 = 0, x1 = 0, x2 = 0;
  708.                     if ((type & SPL) != 0) {
  709.                         w2 = w * 0.5f;
  710.                         x1 = w * (1.0f - index);
  711.                         x2 = w * index;
  712.                     } else {
  713.                         w2 = w * index;
  714.                         x1 = x2 = w2;
  715.                     }
  716.                     rect.addElement(new Rectangle2D.Float(0, 0, w2, h));
  717.                     rect.addElement(new Rectangle2D.Float(w2, 0, w-w2, h));
  718.                     grad.addElement(new GradientPaint(0,0,c1,x1,0,c2));
  719.                     grad.addElement(new GradientPaint(x2,0,c2,w,0,c1));
  720.                 } else if ((type & HEI) != 0) {
  721.                     float h2 = 0, y1 = 0, y2 = 0;
  722.                     if ((type & SPL) != 0) {
  723.                         h2 = h * 0.5f;
  724.                         y1 = h * (1.0f - index);
  725.                         y2 = h * index;
  726.                     } else {
  727.                         h2 = h * index;
  728.                         y1 = y2 = h2;
  729.                     }
  730.                     rect.addElement(new Rectangle2D.Float(0, 0, w, h2));
  731.                     rect.addElement(new Rectangle2D.Float(0, h2, w, h-h2));
  732.                     grad.addElement(new GradientPaint(0,0,c1,0,y1,c2));
  733.                     grad.addElement(new GradientPaint(0,y2,c2,0,h,c1));
  734.                 } else if ((type & BUR) != 0) {
  735.                     float w2 = w/2;
  736.                     float h2 = h/2;
  737.                     rect.addElement(new Rectangle2D.Float(0, 0, w2, h2));
  738.                     rect.addElement(new Rectangle2D.Float(w2, 0, w2, h2));
  739.                     rect.addElement(new Rectangle2D.Float(0, h2, w2, h2));
  740.                     rect.addElement(new Rectangle2D.Float(w2, h2, w2, h2));
  741.                     float x1 = w * (1.0f - index);
  742.                     float x2 = w * index;
  743.                     float y1 = h * (1.0f - index);
  744.                     float y2 = h * index;
  745.                     grad.addElement(new GradientPaint(0,0,c1,x1,y1,c2));
  746.                     grad.addElement(new GradientPaint(w,0,c1,x2,y1,c2));
  747.                     grad.addElement(new GradientPaint(0,h,c1,x1,y2,c2));
  748.                     grad.addElement(new GradientPaint(w,h,c1,x2,y2,c2));
  749.                 } else if ((type & NF) != 0) {
  750.                     float x = w * index;
  751.                     float y = h * index;
  752.                     grad.addElement(new GradientPaint(0,0,c1,0,y,c2));
  753.                 }
  754.                 if ((type & INC) != 0 || (type & DEC) != 0) {
  755.                     index += incr;
  756.                 }
  757.             }
  758.             public void render(int w, int h, Graphics2D g2) {
  759.                 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
  760.                                 RenderingHints.VALUE_ANTIALIAS_OFF);
  761.                 for (int i = 0; i < grad.size(); i++) {
  762.                     g2.setPaint((GradientPaint) grad.get(i));
  763.                     if ((type & NF) == 0) {
  764.                         g2.fill((Rectangle2D) rect.get(i));
  765.                     }
  766.                 }
  767.                 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
  768.                                 RenderingHints.VALUE_ANTIALIAS_ON);
  769.             }
  770.             public int getBegin() {
  771.                 return beginning;
  772.             }
  773.             public int getEnd() {
  774.                 return ending;
  775.             }
  776.         } // End GpE class
  777.         /**
  778.          * TexturePaint Effect.  Expand and collapse a texture. 
  779.          */
  780.         static class TpE implements Part {
  781.             static final int INC = 1;             // increasing
  782.             static final int DEC = 2;             // decreasing
  783.             static final int OVAL = 4;            // oval
  784.             static final int RECT = 8;            // rectangle 
  785.             static final int HAF = 16;            // half oval or rect size
  786.             static final int OI = OVAL | INC; 
  787.             static final int OD = OVAL | DEC;
  788.             static final int RI = RECT | INC;
  789.             static final int RD = RECT | DEC;
  790.             static final int NF = 32;             // no fill 
  791.             private Paint p1, p2;
  792.             private int beginning, ending;
  793.             private float incr, index;
  794.             private TexturePaint texture;
  795.             private int type;
  796.             private int size;
  797.             private BufferedImage bimg;
  798.             private Rectangle rect;
  799.             public TpE(int type, Paint p1, Paint p2, int size,
  800.                                    int beg, int end) {
  801.                 this.type = type;
  802.                 this.p1 = p1;
  803.                 this.p2 = p2;
  804.                 this.beginning = beg;
  805.                 this.ending = end;
  806.                 setTextureSize(size);
  807.             }
  808.             public void setTextureSize(int size) {
  809.                 this.size = size;
  810.                 bimg = new BufferedImage(size,size,BufferedImage.TYPE_INT_RGB);
  811.                 rect = new Rectangle(0,0,size,size);
  812.             }
  813.             public void reset(int w, int h) {
  814.                 incr = (float) (size) / (float) (ending - beginning);
  815.                 if ((type & HAF) != 0) {
  816.                    incr /= 2;
  817.                 }
  818.                 if ((type & DEC) != 0) {
  819.                     index = size;
  820.                     if ((type & HAF) != 0) {
  821.                        index /= 2;
  822.                     }
  823.                     incr = -incr;
  824.                 } else {
  825.                     index = 0.0f;
  826.                 }
  827.                 index += incr;
  828.             }
  829.        
  830.             public void step(int w, int h) {
  831.                 Graphics2D g2 = bimg.createGraphics();
  832.                 g2.setPaint(p1);
  833.                 g2.fillRect(0,0,size,size);
  834.                 g2.setPaint(p2);
  835.                 if ((type & OVAL) != 0) {
  836.                     g2.fill(new Ellipse2D.Float(0,0,index,index));
  837.                 } else if ((type & RECT) != 0) {
  838.                     g2.fill(new Rectangle2D.Float(0,0,index,index));
  839.                 }
  840.                 texture = new TexturePaint(bimg, rect);
  841.                 g2.dispose();
  842.                 index += incr;
  843.             }
  844.             public void render(int w, int h, Graphics2D g2) {
  845.                 g2.setPaint(texture);
  846.                 if ((type & NF) == 0) {
  847.                     g2.fillRect(0, 0, w, h);
  848.                 }
  849.             }
  850.             public int getBegin() {
  851.                 return beginning;
  852.             }
  853.             public int getEnd() {
  854.                 return ending;
  855.             }
  856.         } // End TpE class
  857.         /**
  858.          * Close out effect.  Close out the buffered image with different 
  859.          * geometry shapes.
  860.          */
  861.         static class CoE implements Part {
  862.             static final int WID  = 1;            
  863.             static final int HEI  = 2;           
  864.             static final int OVAL = 4;            
  865.             static final int RECT = 8;           
  866.             static final int RAND = 16;           
  867.             static final int ARC  = 32;           
  868.             private int type;
  869.             private int beginning, ending;
  870.             private BufferedImage bimg;
  871.             private Shape shape;
  872.             private double zoom, extent;
  873.             private double zIncr, eIncr;
  874.             private boolean doRandom;
  875.             public CoE(int type, int beg, int end) {
  876.                 this.type = type;
  877.                 this.beginning = beg;
  878.                 this.ending = end;
  879.                 zIncr = -(2.0 / (ending - beginning));
  880.                 eIncr = 360.0 / (ending - beginning);
  881.                 doRandom = (type & RAND) != 0;
  882.             }
  883.             public void reset(int w, int h) {
  884.                 if (doRandom) {
  885.                     int num = (int) (Math.random() * 5.0);
  886.                     switch (num) {
  887.                         case 0 : type = OVAL; break;
  888.                         case 1 : type = RECT; break;
  889.                         case 2 : type = RECT | WID; break;
  890.                         case 3 : type = RECT | HEI; break;
  891.                         case 4 : type = ARC; break;
  892.                         default : type = OVAL; 
  893.                     }
  894.                 }
  895.                 shape = null;
  896.                 bimg = null;
  897.                 extent = 360.0;
  898.                 zoom = 2.0;
  899.             }
  900.             public void step(int w, int h) {
  901.                 if (bimg == null) {
  902.                     int biw = Surface.bimg.getWidth();
  903.                     int bih = Surface.bimg.getHeight();
  904.                     bimg = new BufferedImage(biw, bih, BufferedImage.TYPE_INT_RGB);
  905.                     Graphics2D big = bimg.createGraphics();
  906.                     big.drawImage(Surface.bimg, 0, 0, null);
  907.                 }
  908.                 double z = Math.min(w, h) * zoom;
  909.                 if ((type & OVAL) != 0) {
  910.                     shape = new Ellipse2D.Double(w/2-z/2,h/2-z/2,z,z);
  911.                 } else if ((type & ARC) != 0) {
  912.                     shape = new Arc2D.Double(-100,-100,w+200,h+200,90,extent,Arc2D.PIE);
  913.                     extent -= eIncr;
  914.                 } else if ((type & RECT) != 0) {
  915.                     if ((type & WID) != 0) {
  916.                         shape = new Rectangle2D.Double(w/2-z/2,0,z,h);
  917.                     } else if ((type & HEI) != 0) {
  918.                         shape = new Rectangle2D.Double(0,h/2-z/2,w,z);
  919.                     } else {
  920.                         shape = new Rectangle2D.Double(w/2-z/2,h/2-z/2,z,z);
  921.                     }
  922.                 }
  923.                 zoom += zIncr;
  924.             }
  925.             public void render(int w, int h, Graphics2D g2) {
  926.                 g2.clip(shape);
  927.                 g2.draw(shape);
  928.                 g2.drawImage(bimg, 0, 0, null);
  929.             }
  930.             public int getBegin() {
  931.                 return beginning;
  932.             }
  933.             public int getEnd() {
  934.                 return ending;
  935.             }
  936.         } // End CoE class
  937.         /**
  938.          * Dither Dissolve Effect.  Render a shuffled list of pixels black
  939.          * from the buffered image.
  940.          *
  941.          * The shuffled list is created in the Surface class 
  942.          * createShuffledList() method.  
  943.          */
  944.         static class DdE implements Part {
  945.             private int beginning, ending;
  946.             private BufferedImage bimg;
  947.             private DataBuffer db;
  948.             private int eNum;   // element number
  949.             private int cSize;  // chunk size
  950.             public DdE(int beg, int end) {
  951.                 this.beginning = beg;
  952.                 this.ending = end;
  953.             }
  954.             public void reset(int w, int h) {
  955.                 bimg = null;
  956.             }
  957.             public void step(int w, int h) {
  958.                 if (bimg == null) {
  959.                     int biw = Surface.bimg.getWidth();
  960.                     int bih = Surface.bimg.getHeight();
  961.                     bimg = new BufferedImage(biw, bih, BufferedImage.TYPE_INT_RGB);
  962.                     Graphics2D big = bimg.createGraphics();
  963.                     big.drawImage(Surface.bimg, 0, 0, null);
  964.                     db = bimg.getRaster().getDataBuffer();
  965.                     cSize = list.size() / (ending - beginning);
  966.                     eNum = -cSize;
  967.                 }
  968.                 eNum += cSize;
  969.             }
  970.             public void render(int w, int h, Graphics2D g2) {
  971.                 int black = 20 << 16 | 20 << 8 | 20;
  972.                 for (int j = eNum; j < eNum+cSize && j < list.size();j++) {
  973.                     int val = ((Integer) list.get(j)).intValue();
  974.                     db.setElem(val, black);
  975.                 }
  976.                 g2.drawImage(bimg, 0, 0, null);
  977.             }
  978.             public int getBegin() {
  979.                 return beginning;
  980.             }
  981.             public int getEnd() {
  982.                 return ending;
  983.             }
  984.         } // End DdE class
  985.         /**
  986.          * Subimage effect.  Subimage the scene's buffered
  987.          * image then rotate and scale down the subimages.
  988.          */
  989.         static class SiE implements Part {
  990.             private int beginning, ending;
  991.             private BufferedImage bimg;
  992.             private double rIncr, sIncr;
  993.             private double scale, rotate;
  994.             private int siw, sih;
  995.             private Vector subs = new Vector(20);
  996.             private Vector pts = new Vector(20);
  997.             public SiE(int siw, int sih, int beg, int end) {
  998.                 this.siw = siw;
  999.                 this.sih = sih;
  1000.                 this.beginning = beg;
  1001.                 this.ending = end;
  1002.                 rIncr = 360.0 / (ending - beginning);
  1003.                 sIncr = 1.0 / (ending - beginning);
  1004.             }
  1005.             public void reset(int w, int h) {
  1006.                 scale = 1.0;  
  1007.                 rotate = 0.0;
  1008.                 bimg = null;
  1009.                 subs.clear();
  1010.                 pts.clear();
  1011.             }
  1012.             public void step(int w, int h) {
  1013.                 if (bimg == null) {
  1014.                     int biw = Surface.bimg.getWidth();
  1015.                     int bih = Surface.bimg.getHeight();
  1016.                     bimg = new BufferedImage(biw, bih, BufferedImage.TYPE_INT_RGB);
  1017.                     Graphics2D big = bimg.createGraphics();
  1018.                     big.drawImage(Surface.bimg, 0, 0, null);
  1019.                     for (int x = 0; x < w && scale > 0.0; x+=siw) {
  1020.                         int ww = x+siw < w ? siw : w-x;
  1021.                         for (int y = 0; y < h; y+=sih) {
  1022.                             int hh = y+sih < h ? sih : h-y;
  1023.                             subs.addElement(bimg.getSubimage(x,y,ww,hh));    
  1024.                             pts.addElement(new Point(x, y));
  1025.                         }
  1026.                     }
  1027.                 }
  1028.                 
  1029.                 rotate += rIncr;
  1030.                 scale -= sIncr;
  1031.             }
  1032.             public void render(int w, int h, Graphics2D g2) {
  1033.                 AffineTransform saveTx = g2.getTransform();
  1034.                 g2.setColor(blue);
  1035.                 for (int i = 0; i < subs.size() && scale > 0.0; i++) {
  1036.                     BufferedImage bi = (BufferedImage) subs.get(i);
  1037.                     Point p = (Point) pts.get(i);
  1038.                     int ww = bi.getWidth();
  1039.                     int hh = bi.getHeight();
  1040.                     AffineTransform at = new AffineTransform();
  1041.                     at.rotate(Math.toRadians(rotate), p.x+ww/2, p.y+hh/2); 
  1042.                     at.translate(p.x, p.y);
  1043.                     at.scale(scale, scale);
  1044.                     Rectangle b1 = new Rectangle(0, 0, ww, hh);
  1045.                     Shape shape = at.createTransformedShape(b1);
  1046.                     Rectangle2D b2 = shape.getBounds2D();
  1047.                     double xx = (p.x+ww/2) - (b2.getX()+b2.getWidth()/2);
  1048.                     double yy = (p.y+hh/2) - (b2.getY()+b2.getHeight()/2);
  1049.                     AffineTransform toCenterAT = new AffineTransform();
  1050.                     toCenterAT.translate(xx, yy);
  1051.                     toCenterAT.concatenate(at);
  1052.                     g2.setTransform(toCenterAT);
  1053.                     g2.drawImage(bi, 0, 0, null);
  1054.                     g2.draw(b1);
  1055.                 }
  1056.                 g2.setTransform(saveTx);
  1057.             }
  1058.             public int getBegin() {
  1059.                 return beginning;
  1060.             }
  1061.             public int getEnd() {
  1062.                 return ending;
  1063.             }
  1064.         } // End SiE class
  1065.         /**
  1066.          * Line Effect.  Flattened ellipse with lines from the center 
  1067.          * to the edge.  Expand or collapse the ellipse.  Fade in or out 
  1068.          * the lines.
  1069.          */
  1070.         static class LnE implements Part {
  1071.             static final int INC  = 1;
  1072.             static final int DEC  = 2;
  1073.             static final int R    = 4;              // rotate
  1074.             static final int RI   = R | INC;
  1075.             static final int RD   = R | DEC;
  1076.             static final int ZOOM   = 8;            // zoom
  1077.             static final int ZOOMI  = ZOOM | INC;
  1078.             static final int ZOOMD  = ZOOM | DEC;    
  1079.             static final int AC   = 32;             // AlphaComposite
  1080.             static final int ACI   = 32 | INC;
  1081.             static final int ACD   = 32 | DEC; 
  1082.             private int beginning, ending;
  1083.             private double rIncr, rotate;
  1084.             private double zIncr, zoom;
  1085.             private Vector pts = new Vector();
  1086.             private float alpha, aIncr;
  1087.             private int type;
  1088.             public LnE(int type, int beg, int end) {
  1089.                 this.type = type;
  1090.                 this.beginning = beg;
  1091.                 this.ending = end;
  1092.                 rIncr = 360.0 / (ending - beginning);
  1093.                 aIncr = 0.9f / (ending - beginning);
  1094.                 zIncr = 2.0 / (ending - beginning);
  1095.                 if ((type & DEC) != 0) {
  1096.                     rIncr = -rIncr;
  1097.                     aIncr = -aIncr;
  1098.                     zIncr = -zIncr;
  1099.                 }
  1100.             }
  1101.             public void generatePts(int w, int h, double sizeF) {
  1102.                 pts.clear();
  1103.                 double size = Math.min(w, h) * sizeF;
  1104.                 Ellipse2D ellipse = new Ellipse2D.Double(w/2-size/2,h/2-size/2,size,size);
  1105.                 PathIterator pi = ellipse.getPathIterator(null, 0.8);
  1106.                 while ( !pi.isDone() ) {
  1107.                     double[] pt = new double[6];
  1108.                     switch ( pi.currentSegment(pt) ) {
  1109.                         case FlatteningPathIterator.SEG_MOVETO:
  1110.                         case FlatteningPathIterator.SEG_LINETO:
  1111.                             pts.addElement(new Point2D.Double(pt[0], pt[1]));
  1112.                     }
  1113.                     pi.next();
  1114.                 }
  1115.             }
  1116.             public void reset(int w, int h) {
  1117.                 if ((type & DEC) != 0) {
  1118.                     rotate = 360;
  1119.                     alpha = 1.0f;
  1120.                     zoom = 2.0;
  1121.                 } else {
  1122.                     rotate = alpha = 0;
  1123.                     zoom = 0;
  1124.                 }
  1125.                 if ((type & ZOOM) == 0) {
  1126.                     generatePts(w, h, 0.5);
  1127.                 }
  1128.             }
  1129.             public void step(int w, int h) {
  1130.                 if ((type & ZOOM) != 0) {
  1131.                     generatePts(w, h, zoom += zIncr);
  1132.                 }
  1133.                 if ((type & RI) != 0 || (type & RI) != 0) {
  1134.                    rotate += rIncr;
  1135.                 }
  1136.                 if ((type & ACI) != 0 || (type & ACD) != 0) {
  1137.                    alpha += aIncr;
  1138.                 }
  1139.             }
  1140.             public void render(int w, int h, Graphics2D g2) {
  1141.                 Composite saveAC = null;
  1142.                 if ((type & AC) != 0 && alpha >= 0 && alpha <= 1) {
  1143.                     saveAC = g2.getComposite();
  1144.                     g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
  1145.                 }
  1146.                 AffineTransform saveTx = null;
  1147.                 if ((type & R) != 0) {
  1148.                     saveTx = g2.getTransform();
  1149.                     AffineTransform at = new AffineTransform();
  1150.                     at.rotate(Math.toRadians(rotate), w/2, h/2); 
  1151.                     g2.setTransform(at);
  1152.                 }
  1153.                 Point2D p1 = new Point2D.Double(w/2, h/2);
  1154.                 g2.setColor(Color.yellow);
  1155.                 for (int i = 0; i < pts.size()-1; i++) {
  1156.                     g2.draw(new Line2D.Float(p1, (Point2D) pts.get(i)));
  1157.                 }
  1158.                 if (saveTx != null) {
  1159.                    g2.setTransform(saveTx);
  1160.                 }
  1161.                 if (saveAC != null) {
  1162.                    g2.setComposite(saveAC);
  1163.                 }
  1164.             }
  1165.             public int getBegin() {
  1166.                 return beginning;
  1167.             }
  1168.             public int getEnd() {
  1169.                 return ending;
  1170.             }
  1171.         } // End LnE class
  1172.         /**
  1173.          * Template for Features & Contributors consisting of translating
  1174.          * blue and red rectangles and an image going from transparent to
  1175.          * opaque.
  1176.          */
  1177.         static class Temp implements Part {
  1178.             static final int NOANIM = 1;
  1179.             static final int RECT   = 2;
  1180.             static final int RNA    = RECT | NOANIM;
  1181.             static final int IMG    = 4;
  1182.             static final int INA    = IMG | NOANIM;
  1183.             private int beginning, ending;
  1184.             private float alpha, aIncr;
  1185.             private int type;
  1186.             private Rectangle rect1, rect2;
  1187.             private int x, y, xIncr, yIncr;
  1188.             private Image img;
  1189.             public Temp(int type, Image img, int beg, int end) {
  1190.                 this.type = type;
  1191.                 this.img = img;
  1192.                 this.beginning = beg;
  1193.                 this.ending = end;
  1194.                 aIncr = 0.9f / (ending - beginning);
  1195.                 if ((type & NOANIM) != 0) {
  1196.                     alpha = 1.0f;
  1197.                 } 
  1198.             }
  1199.             public void reset(int w, int h) {
  1200.                 rect1 = new Rectangle(8, 20, w-20, 30);
  1201.                 rect2 = new Rectangle(20, 8, 30, h-20);
  1202.                 if ((type & NOANIM) == 0) {
  1203.                     alpha = 0.0f;
  1204.                     xIncr = w / (ending - beginning);
  1205.                     yIncr = h / (ending - beginning);
  1206.                     x = w+(int)(xIncr*1.4);
  1207.                     y = h+(int)(yIncr*1.4);
  1208.                 }
  1209.             }
  1210.             public void step(int w, int h) {
  1211.                 if ((type & NOANIM) != 0) {
  1212.                    return;
  1213.                 }
  1214.                 if ((type & RECT) != 0) {
  1215.                     rect1.setLocation(x-=xIncr, 20);
  1216.                     rect2.setLocation(20, y-=yIncr);
  1217.                 }
  1218.                 if ((type & IMG) != 0) {
  1219.                     alpha += aIncr;
  1220.                 }
  1221.             }
  1222.             public void render(int w, int h, Graphics2D g2) {
  1223.                 if ((type & RECT) != 0) {
  1224.                     g2.setColor(blue);
  1225.                     g2.fill(rect1);
  1226.                     g2.setColor(red);
  1227.                     g2.fill(rect2);
  1228.                 }
  1229.                 if ((type & IMG) != 0) {
  1230.                     Composite saveAC = g2.getComposite();
  1231.                     if (alpha >= 0 && alpha <= 1) {
  1232.                         g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
  1233.                     }
  1234.                     g2.drawImage(img, 30, 30, null);
  1235.                     g2.setComposite(saveAC);
  1236.                 }
  1237.             }
  1238.             public int getBegin() {
  1239.                 return beginning;
  1240.             }
  1241.             public int getEnd() {
  1242.                 return ending;
  1243.             }
  1244.         } // End Temp class
  1245.         /**
  1246.          * Features of Java2D.  Single character advancement effect.
  1247.          */
  1248.         static class Features implements Part {
  1249.             static final int GRAPHICS = 0;
  1250.             static final int TEXT = 1;
  1251.             static final int IMAGES = 2;
  1252.             static final int COLOR = 3;
  1253.             static Font font1 = new Font("serif", Font.BOLD, 38);
  1254.             static Font font2 = new Font("serif", Font.PLAIN, 24);
  1255.             static FontMetrics fm1 = Surface.getMetrics(font1);
  1256.             static FontMetrics fm2 = Surface.getMetrics(font2);
  1257.             static String table[][] = 
  1258.                 {{ "Graphics", "Antialiased rendering", "Bezier paths", 
  1259.                     "Transforms", "Compositing", "Stroking parameters" },
  1260.                  { "Text", "Extended font support", 
  1261.                    "Advanced text layout",  
  1262.                    "AttributeSets for font customization" },
  1263.                  { "Images", "Flexible image layouts",
  1264.                     "Extended imaging operations", 
  1265.                     "   Convolutions, Lookup Tables",
  1266.                     "RenderableImage interface"},
  1267.                  { "Color", "ICC profile support", "Color conversion", 
  1268.                    "Arbitrary color spaces"} };
  1269.             private String list[];
  1270.             private int beginning, ending;
  1271.             private int strH;
  1272.             private int endIndex, listIndex;
  1273.             private Vector v = new Vector();
  1274.            
  1275.             public Features(int type, int beg, int end) {
  1276.                 list = table[type];
  1277.                 this.beginning = beg;
  1278.                 this.ending = end;
  1279.             }
  1280.             public void reset(int w, int h) {
  1281.                 strH = (int) (fm2.getAscent()+fm2.getDescent());
  1282.                 endIndex = 1;
  1283.                 listIndex = 0;
  1284.                 v.clear();
  1285.                 v.addElement(list[listIndex].substring(0,endIndex));
  1286.             }
  1287.             public void step(int w, int h) {
  1288.                 if (listIndex < list.length) {
  1289.                     if (++endIndex > list[listIndex].length()) {
  1290.                         if (++listIndex < list.length) {
  1291.                             endIndex = 1;
  1292.                             v.addElement(list[listIndex].substring(0,endIndex));
  1293.                         }
  1294.                     } else {
  1295.                         v.set(listIndex, list[listIndex].substring(0,endIndex));
  1296.                     }
  1297.                 }
  1298.             }
  1299.             public void render(int w, int h, Graphics2D g2) {
  1300.                 g2.setColor(white);
  1301.                 g2.setFont(font1);
  1302.                 g2.drawString((String) v.get(0), 90, 85);
  1303.                 g2.setFont(font2);
  1304.                 for (int i = 1, y = 90; i < v.size(); i++) {
  1305.                     g2.drawString((String) v.get(i), 120, y += strH);
  1306.                 }
  1307.             }
  1308.             public int getBegin() {
  1309.                 return beginning;
  1310.             }
  1311.             public int getEnd() {
  1312.                 return ending;
  1313.             }
  1314.         } // End Features class
  1315.         /**
  1316.          * Scrolling text of Java2D contributors.
  1317.          */
  1318.         static class Contributors implements Part {
  1319.             static String members[] = 
  1320.             { 
  1321.                 "Brian Lichtenwalter", "Jeannette Hung", 
  1322.                 "Thanh Nguyen", "Jim Graham", "Jerry Evans", 
  1323.                 "John Raley", "Michael Peirce", "Robert Kim", 
  1324.                 "Jennifer Ball", "Deborah Adair", "Paul Charlton", 
  1325.                 "Dmitry Feld", "Gregory Stone", "Richard Blanchard", 
  1326.                 "Link Perry", "Phil Race", "Vincent Hardy", 
  1327.                 "Parry Kejriwal", "Doug Felt", "Rekha Rangarajan", 
  1328.                 "Paula Patel", "Michael Bundschuh", "Joe Warzecha", 
  1329.                 "Joey Beheler", "Aastha Bhardwaj", "Daniel Rice"
  1330.             };
  1331.             static Font font = new Font("serif", Font.PLAIN, 26);
  1332.             static FontMetrics fm = Surface.getMetrics(font);
  1333.             private int beginning, ending;
  1334.             private int nStrs, strH, index, yh, height;
  1335.             private Vector v = new Vector();
  1336.             private Vector cast = new Vector(members.length+3);
  1337.             private int counter, cntMod;
  1338.             private GradientPaint gp;
  1339.             public Contributors(int beg, int end) {
  1340.                 this.beginning = beg;
  1341.                 this.ending = end;
  1342.                 java.util.Arrays.sort(members);
  1343.                 cast.addElement("CONTRIBUTORS");
  1344.                 cast.addElement(" ");
  1345.                 for (int i = 0; i < members.length; i++) {
  1346.                     cast.addElement(members[i]);
  1347.                 }
  1348.                 cast.addElement(" "); cast.addElement(" ");
  1349.                 cntMod = (ending - beginning) / cast.size() - 1;
  1350.             }
  1351.             public void reset(int w, int h) {
  1352.                 v.clear();
  1353.                 strH = (int) (fm.getAscent()+fm.getDescent());
  1354.                 nStrs = (h-40)/strH + 1;
  1355.                 height = strH * (nStrs-1) + 48;
  1356.                 index = 0;
  1357.                 gp = new GradientPaint(0,h/2,Color.white,0,h+20,Color.black);
  1358.                 counter = 0;
  1359.             }
  1360.             public void step(int w, int h) {
  1361.                 if (counter++%cntMod == 0) {
  1362.                     if (index < cast.size()) {
  1363.                         v.addElement(cast.get(index));
  1364.                     }
  1365.                     if ((v.size() == nStrs || index >= cast.size()) && v.size() != 0) {
  1366.                         v.removeElementAt(0);
  1367.                     }
  1368.                     ++index;
  1369.                 }
  1370.             }
  1371.             public void render(int w, int h, Graphics2D g2) {
  1372.                 g2.setPaint(gp);
  1373.                 g2.setFont(font);
  1374.                 double remainder = counter%cntMod;
  1375.                 double incr = 1.0-remainder/cntMod;
  1376.                 incr = incr == 1.0 ? 0 : incr;
  1377.                 int y = (int) (incr * strH);
  1378.                 if (index >= cast.size()) {
  1379.                     y = yh + y; 
  1380.                 } else {
  1381.                     y = yh = height - v.size() * strH + y;
  1382.                 }
  1383.                 for (int i = 0; i < v.size(); i++) {
  1384.                     String s = (String) v.get(i);
  1385.                     g2.drawString(s, w/2-fm.stringWidth(s)/2, y += strH);
  1386.                 }
  1387.             }
  1388.             public int getBegin() {
  1389.                 return beginning;
  1390.             }
  1391.             public int getEnd() {
  1392.                 return ending;
  1393.             }
  1394.         } // End Contributors class
  1395.     } // End Surface class
  1396. } // End Intro class