/* * @(#)CloneDemo.java 1.10 98/06/29 * * Copyright 1998 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of Sun Microsystems, Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Sun. */ import java.awt.Component; import java.awt.Color; import java.awt.Font; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.MouseEvent; import com.sun.java.swing.JPanel; import com.sun.java.swing.JScrollPane; import com.sun.java.swing.JTextArea; import com.sun.java.swing.border.EmptyBorder; import com.sun.java.swing.border.SoftBevelBorder; import com.sun.java.swing.border.CompoundBorder; /** * Illustration of how to use the clone feature of the demo. */ public class CloneDemo extends JPanel implements Runnable { private Thread thread; private JTextArea ta; public CloneDemo() { setLayout(new BorderLayout()); EmptyBorder eb = new EmptyBorder(5,5,5,5); SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.RAISED); setBorder(new CompoundBorder(eb, sbb)); ta = new JTextArea("Cloning Demonstrated\n\nClicking once on a demo\n"); ta.setMinimumSize(new Dimension(300,500)); JScrollPane scroller = new JScrollPane(); scroller.getViewport().add(ta); ta.setFont(new Font("Dialog", Font.PLAIN, 14)); ta.setForeground(Color.black); ta.setBackground(Color.lightGray); ta.setEditable(false); add("Center", scroller); start(); } public void start() { thread = new Thread(this); thread.setPriority(Thread.MAX_PRIORITY); thread.setName("CloneDemo"); thread.start(); } public void stop() { thread = null; } private void sleep(long millis) { try { Thread.sleep(millis); } catch (Exception e) {} } public void run() { sleep(2000); TheLayout tl = Java2Demo.layouts[Java2Demo.tabbedPane.getSelectedIndex()]; CanvasPanel cp = (CanvasPanel) tl.getPanel().getComponent(0); if (cp.canvas == null) { ta.append("Your Canvas is Null"); return; } tl.mouseClicked(new MouseEvent(cp.canvas, MouseEvent.MOUSE_CLICKED, 0, 0, 10, 10, 1, false)); sleep(4000); ta.append("Clicking the ToolBar double document button\n"); sleep(4000); cp = (CanvasPanel) tl.clonePanels[0].getComponent(0); if (cp.toolbar != null) { for (int i = 0; i < 3; i++) { ta.append(" Cloning\n"); cp.toolbar.cloneB.doClick(); sleep(4000); } } ta.append("Changing attributes \n"); sleep(4000); Component cps[] = tl.clonePanels[0].getComponents(); for (int i = 0; i < cps.length; i++) { cp = (CanvasPanel) cps[i]; if (cp.toolbar == null) continue; switch (i) { case 0 : ta.append(" Changing AntiAliasing\n"); cp.toolbar.aliasB.doClick(); break; case 1 : ta.append(" Changing Composite & Texture\n"); cp.toolbar.compositeB.doClick(); cp.toolbar.textureB.doClick(); break; case 2 : ta.append(" Changing Screen\n"); cp.toolbar.screenCombo.setSelectedIndex(4); break; case 3 : ta.append(" Removing a clone\n"); cp.toolbar.removeCloneB.doClick(); } sleep(4000); } ta.append("\nAll Done!"); } }