/* * @(#)CanvasPanel.java 1.6 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.BorderLayout; import com.sun.java.swing.JPanel; import com.sun.java.swing.border.EmptyBorder; import com.sun.java.swing.border.SoftBevelBorder; import com.sun.java.swing.border.CompoundBorder; /** * The panel for the J2DCanvas demos & ToolBar. * Other component types welcome. */ public class CanvasPanel extends JPanel { public J2DCanvas canvas; public ToolBar toolbar; public String className; public CanvasPanel(TheLayout tl, JPanel p) { setLayout(new BorderLayout()); int top = (p.getComponentCount()+1 >= 3) ? 0 : 5; int left = ((p.getComponentCount()+1) % 2) == 0 ? 0 : 5; EmptyBorder eb = new EmptyBorder(top,left,5,5); SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.RAISED); setBorder(new CompoundBorder(eb, sbb)); try { className = tl.className; Class theC = Class.forName(tl.className); Component cmp = (Component) theC.newInstance(); if (cmp instanceof J2DCanvas) { canvas = (J2DCanvas) cmp; canvas.setup(); add(canvas); toolbar = new ToolBar(tl, this); add("South", toolbar); } else add(cmp); } catch (Exception e) { e.printStackTrace(); } } }