home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / JBuilder8.iso / Solaris / resource / jre / demo / plugin / jfc / Java2D / src / java2d / CloningFeature.java < prev    next >
Encoding:
Java Source  |  2002-09-06  |  5.8 KB  |  169 lines

  1. /*
  2.  * Copyright (c) 2002 Sun Microsystems, Inc. All  Rights Reserved.
  3.  * 
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  * 
  8.  * -Redistributions of source code must retain the above copyright
  9.  *  notice, this list of conditions and the following disclaimer.
  10.  * 
  11.  * -Redistribution in binary form must reproduct the above copyright
  12.  *  notice, this list of conditions and the following disclaimer in
  13.  *  the documentation and/or other materials provided with the distribution.
  14.  * 
  15.  * Neither the name of Sun Microsystems, Inc. or the names of contributors
  16.  * may be used to endorse or promote products derived from this software
  17.  * without specific prior written permission.
  18.  * 
  19.  * This software is provided "AS IS," without a warranty of any kind. ALL
  20.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
  21.  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  22.  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
  23.  * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
  24.  * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
  25.  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
  26.  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
  27.  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
  28.  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
  29.  * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  30.  * 
  31.  * You acknowledge that Software is not designed, licensed or intended for
  32.  * use in the design, construction, operation or maintenance of any nuclear
  33.  * facility.
  34.  */
  35.  
  36. /*
  37.  * @(#)CloningFeature.java    1.19 02/06/13
  38.  */
  39.  
  40.  
  41. package java2d;
  42.  
  43. import java.awt.Component;
  44. import java.awt.Color;
  45. import java.awt.Font;
  46. import java.awt.BorderLayout;
  47. import java.awt.Dimension;
  48. import java.awt.event.MouseEvent;
  49. import javax.swing.JPanel;
  50. import javax.swing.JScrollPane;
  51. import javax.swing.JTextArea;
  52. import javax.swing.border.EmptyBorder;
  53. import javax.swing.border.SoftBevelBorder;
  54. import javax.swing.border.CompoundBorder;
  55.  
  56. /**
  57.  * Illustration of how to use the clone feature of the demo.
  58.  */
  59. public class CloningFeature extends JPanel implements Runnable {
  60.  
  61.     private Thread thread;
  62.     private JTextArea ta;
  63.  
  64.  
  65.     public CloningFeature() {
  66.  
  67.         setLayout(new BorderLayout());
  68.         EmptyBorder eb = new EmptyBorder(5,5,5,5);
  69.         SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.RAISED);
  70.         setBorder(new CompoundBorder(eb, sbb));
  71.  
  72.         ta = new JTextArea("Cloning Demonstrated\n\nClicking once on a demo\n");
  73.         ta.setMinimumSize(new Dimension(300,500));
  74.         JScrollPane scroller = new JScrollPane();
  75.         scroller.getViewport().add(ta);
  76.         ta.setFont(new Font("Dialog", Font.PLAIN, 14));
  77.         ta.setForeground(Color.black);
  78.         ta.setBackground(Color.lightGray);
  79.         ta.setEditable(false);
  80.  
  81.         add("Center", scroller);
  82.  
  83.         start();
  84.     }
  85.  
  86.     public void start() {
  87.         thread = new Thread(this);
  88.         thread.setPriority(Thread.MAX_PRIORITY);
  89.         thread.setName("CloningFeature");
  90.         thread.start();
  91.     }
  92.  
  93.     public void stop() {
  94.         if (thread != null) {
  95.             thread.interrupt();
  96.         }
  97.         thread = null;
  98.     }
  99.  
  100.  
  101.     public void run() {
  102.  
  103.  
  104.         int index = Java2Demo.tabbedPane.getSelectedIndex();
  105.         if (index == 0) {
  106.            Java2Demo.tabbedPane.setSelectedIndex(1);
  107.            try { thread.sleep(3333); } catch (Exception e) { return; }
  108.         }
  109.  
  110.         if (!Java2Demo.controls.toolBarCB.isSelected()) {
  111.             Java2Demo.controls.toolBarCB.setSelected(true);
  112.             try { thread.sleep(2222); } catch (Exception e) { return; }
  113.         }
  114.  
  115.         index = Java2Demo.tabbedPane.getSelectedIndex()-1;
  116.         DemoGroup dg = Java2Demo.group[index];
  117.         DemoPanel dp = (DemoPanel) dg.getPanel().getComponent(0);
  118.         if (dp.surface == null) {
  119.             ta.append("Sorry your zeroth component is not a Surface.");
  120.             return;
  121.         } 
  122.  
  123.         dg.mouseClicked(new MouseEvent(dp.surface, MouseEvent.MOUSE_CLICKED, 0, 0, 10, 10, 1, false));
  124.  
  125.         try { thread.sleep(3333); } catch (Exception e) { return; }
  126.  
  127.         ta.append("Clicking the ToolBar double document button\n");
  128.         try { thread.sleep(3333); } catch (Exception e) { return; }
  129.  
  130.         dp = (DemoPanel) dg.clonePanels[0].getComponent(0);
  131.  
  132.         if (dp.tools != null) {
  133.             for (int i = 0; i < 3 && thread != null; i++) {
  134.                 ta.append("   Cloning\n");
  135.                 dp.tools.cloneB.doClick();
  136.                 try { thread.sleep(3333); } catch (Exception e) { return; }
  137.             }
  138.         }
  139.  
  140.         ta.append("Changing attributes \n");
  141.  
  142.         try { thread.sleep(3333); } catch (Exception e) { return; }
  143.  
  144.         Component cmps[] = dg.clonePanels[0].getComponents();
  145.         for (int i = 0; i < cmps.length && thread != null; i++) {
  146.             if ((dp = (DemoPanel) cmps[i]).tools == null) {
  147.                 continue;
  148.             }
  149.             switch (i) {
  150.                 case 0 : ta.append("   Changing AntiAliasing\n");
  151.                          dp.tools.aliasB.doClick();
  152.                          break;
  153.                 case 1 : ta.append("   Changing Composite & Texture\n");
  154.                          dp.tools.compositeB.doClick();
  155.                          dp.tools.textureB.doClick();
  156.                          break;
  157.                 case 2 : ta.append("   Changing Screen\n");
  158.                          dp.tools.screenCombo.setSelectedIndex(4);
  159.                          break;
  160.                 case 3 : ta.append("   Removing a clone\n");
  161.                          dp.tools.cloneB.doClick();
  162.             }
  163.             try { thread.sleep(3333); } catch (Exception e) { return; }
  164.         }
  165.  
  166.         ta.append("\nAll Done!");
  167.     }
  168. }
  169.