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 / DemoPanel.java < prev    next >
Encoding:
Java Source  |  1998-12-01  |  2.0 KB  |  66 lines

  1. /*
  2.  * @(#)DemoPanel.java    1.9 98/09/13
  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.*;
  17. import javax.swing.JPanel;
  18. import javax.swing.border.EmptyBorder;
  19. import javax.swing.border.SoftBevelBorder;
  20. import javax.swing.border.CompoundBorder;
  21.  
  22.  
  23. /**
  24.  * The panel for the DemoSurface & ToolBar.
  25.  * Other component types welcome.
  26.  */
  27. public class DemoPanel extends JPanel {
  28.  
  29.     public DemoSurface surface;
  30.     public ToolBar toolbar;
  31.     public String className;
  32.  
  33.  
  34.     public DemoPanel(Object obj) {
  35.         setLayout(new BorderLayout());
  36.         try {
  37.             if (obj instanceof String) {
  38.                 className = (String) obj;
  39.                 obj = Class.forName(className).newInstance();
  40.             }
  41.             if (obj instanceof DemoSurface) {
  42.                 add(surface = (DemoSurface) obj);
  43.                 add("South", toolbar = new ToolBar(surface));
  44.             } else if (obj instanceof Component) {
  45.                 add((Component) obj);
  46.             }
  47.             if (obj instanceof CustomControls) {
  48.                 CustomControls custom = (CustomControls) obj;
  49.                 add(custom.getCustomControlsConstraint(), 
  50.                                 custom.getCustomControls());
  51.             }
  52.         } catch (Exception e) {
  53.             e.printStackTrace();
  54.         }
  55.     }
  56.  
  57.  
  58.     public void setDemoBorder(JPanel p) {
  59.         int top = (p.getComponentCount()+1 >= 3) ? 0 : 5;
  60.         int left = ((p.getComponentCount()+1) % 2) == 0 ? 0 : 5;
  61.         EmptyBorder eb = new EmptyBorder(top,left,5,5);
  62.         SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.RAISED);
  63.         setBorder(new CompoundBorder(eb, sbb));
  64.     }
  65. }
  66.