home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / J A V A / Java Development Kit V1.2 / jdk12-win32(1).exe / data1.cab / demos / demo / jfc / Java2D / CloningFeature.java < prev    next >
Encoding:
Java Source  |  1998-12-01  |  3.3 KB  |  135 lines

  1. /*
  2.  * @(#)CloningFeature.java    1.12 98/09/04
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15.  
  16. import java.awt.Component;
  17. import java.awt.Color;
  18. import java.awt.Font;
  19. import java.awt.BorderLayout;
  20. import java.awt.Dimension;
  21. import java.awt.event.MouseEvent;
  22. import javax.swing.JPanel;
  23. import javax.swing.JScrollPane;
  24. import javax.swing.JTextArea;
  25. import javax.swing.border.EmptyBorder;
  26. import javax.swing.border.SoftBevelBorder;
  27. import javax.swing.border.CompoundBorder;
  28.  
  29. /**
  30.  * Illustration of how to use the clone feature of the demo.
  31.  */
  32. public class CloningFeature extends JPanel implements Runnable {
  33.  
  34.     private Thread thread;
  35.     private JTextArea ta;
  36.  
  37.  
  38.     public CloningFeature() {
  39.  
  40.     setLayout(new BorderLayout());
  41.     EmptyBorder eb = new EmptyBorder(5,5,5,5);
  42.     SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.RAISED);
  43.     setBorder(new CompoundBorder(eb, sbb));
  44.  
  45.     ta = new JTextArea("Cloning Demonstrated\n\nClicking once on a demo\n");
  46.     ta.setMinimumSize(new Dimension(300,500));
  47.     JScrollPane scroller = new JScrollPane();
  48.     scroller.getViewport().add(ta);
  49.     ta.setFont(new Font("Dialog", Font.PLAIN, 14));
  50.     ta.setForeground(Color.black);
  51.     ta.setBackground(Color.lightGray);
  52.     ta.setEditable(false);
  53.  
  54.      add("Center", scroller);
  55.  
  56.     start();
  57.     }
  58.  
  59.     public void start() {
  60.     thread = new Thread(this);
  61.     thread.setPriority(Thread.MAX_PRIORITY);
  62.     thread.setName("CloningFeature");
  63.     thread.start();
  64.     }
  65.  
  66.     public void stop() {
  67.         thread = null;
  68.     }
  69.  
  70.  
  71.     private void sleep(long millis) {
  72.     try {
  73.         Thread.sleep(millis);
  74.     } catch (Exception e) {}
  75.     }
  76.  
  77.  
  78.     public void run() {
  79.  
  80.     sleep(2000);
  81.  
  82.     DemoGroup dg = Java2Demo.group[Java2Demo.tabbedPane.getSelectedIndex()];
  83.     DemoPanel dp = (DemoPanel) dg.getPanel().getComponent(0);
  84.     if (dp.surface == null) {
  85.         ta.append("Sorry your zeroth component is not a DemoSurface.");
  86.         return;
  87.     }
  88.  
  89.     dg.mouseClicked(new MouseEvent(dp.surface, MouseEvent.MOUSE_CLICKED, 0, 0, 10, 10, 1, false));
  90.  
  91.     sleep(4000);
  92.  
  93.     ta.append("Clicking the ToolBar double document button\n");
  94.     sleep(4000);
  95.  
  96.     dp = (DemoPanel) dg.clonePanels[0].getComponent(0);
  97.  
  98.     if (dp.toolbar != null) {
  99.         for (int i = 0; i < 3; i++) {
  100.             ta.append("   Cloning\n");
  101.             dp.toolbar.cloneB.doClick();
  102.         sleep(4000);
  103.         }
  104.     }
  105.  
  106.     ta.append("Changing attributes \n");
  107.  
  108.     sleep(4000);
  109.  
  110.     Component cmps[] = dg.clonePanels[0].getComponents();
  111.     for (int i = 0; i < cmps.length; i++) {
  112.         dp = (DemoPanel) cmps[i];
  113.         if (dp.toolbar == null)
  114.         continue;
  115.         switch (i) {
  116.         case 0 : ta.append("   Changing AntiAliasing\n");
  117.              dp.toolbar.aliasB.doClick();
  118.              break;
  119.         case 1 : ta.append("   Changing Composite & Texture\n");
  120.              dp.toolbar.compositeB.doClick();
  121.                  dp.toolbar.textureB.doClick();
  122.              break;
  123.         case 2 : ta.append("   Changing Screen\n");
  124.              dp.toolbar.imgTypeCombo.setSelectedIndex(4);
  125.              break;
  126.         case 3 : ta.append("   Removing a clone\n");
  127.              dp.toolbar.cloneB.doClick();
  128.         }
  129.         sleep(4000);
  130.     }
  131.  
  132.     ta.append("\nAll Done!");
  133.     }
  134. }
  135.