DemoPanel.java
Upload User: cdlibang
Upload Date: 2016-07-17
Package Size: 774k
Code Size: 3k
Category:

2D Graphic

Development Platform:

Java

  1. /*
  2.  * @(#)DemoPanel.java 1.11 99/04/23
  3.  *
  4.  * Copyright (c) 1998, 1999 by Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7.  * modify and redistribute this software in source and binary code form,
  8.  * provided that i) this copyright notice and license appear on all copies of
  9.  * the software; and ii) Licensee does not utilize the software in a manner
  10.  * which is disparaging to Sun.
  11.  * 
  12.  * This software is provided "AS IS," without a warranty of any kind. ALL
  13.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22.  * POSSIBILITY OF SUCH DAMAGES.
  23.  * 
  24.  * This software is not designed or intended for use in on-line control of
  25.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26.  * the design, construction, operation or maintenance of any nuclear
  27.  * facility. Licensee represents and warrants that it will not use or
  28.  * redistribute the Software for such purposes.
  29.  */
  30. import java.awt.*;
  31. import javax.swing.JPanel;
  32. import javax.swing.border.EmptyBorder;
  33. import javax.swing.border.SoftBevelBorder;
  34. import javax.swing.border.CompoundBorder;
  35. /**
  36.  * The panel for the DemoSurface & Tools.
  37.  * Other component types welcome.
  38.  */
  39. public class DemoPanel extends JPanel {
  40.     public DemoSurface surface;
  41.     public Tools tools;
  42.     public String className;
  43.     public CustomControls custom;
  44.     public DemoPanel(Object obj) {
  45.         setLayout(new BorderLayout());
  46.         try {
  47.             if (obj instanceof String) {
  48.                 className = (String) obj;
  49.                 obj = Class.forName(className).newInstance();
  50.             }
  51.             if (obj instanceof DemoSurface) {
  52.                 add(surface = (DemoSurface) obj);
  53.                 add("South", tools = new Tools(surface));
  54.             } else if (obj instanceof Component) {
  55.                 add((Component) obj);
  56.             }
  57.             if (obj instanceof CustomControls) {
  58.                 custom = (CustomControls) obj;
  59.                 Component cmps[] = custom.getCustomControls();
  60.                 String constraints[] = custom.getCustomControlsConstraints();
  61.                 for (int i = 0; i < constraints.length; i++) {
  62.                     add(cmps[i], constraints[i]);
  63.                 }
  64.             }
  65.         } catch (Exception e) {
  66.             e.printStackTrace();
  67.         }
  68.     }
  69.     public void setDemoBorder(JPanel p) {
  70.         int top = (p.getComponentCount()+1 >= 3) ? 0 : 5;
  71.         int left = ((p.getComponentCount()+1) % 2) == 0 ? 0 : 5;
  72.         EmptyBorder eb = new EmptyBorder(top,left,5,5);
  73.         SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.RAISED);
  74.         setBorder(new CompoundBorder(eb, sbb));
  75.     }
  76. }