home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / JBuilder8.iso / Solaris / resource / jre / demo / plugin / jfc / Java2D / src / java2d / Java2DemoApplet.java < prev    next >
Encoding:
Java Source  |  2002-09-06  |  6.7 KB  |  178 lines

  1. /*
  2.  * Copyright (c) 2002 Sun Microsystems, Inc. All  Rights Reserved.
  3.  * 
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  * 
  8.  * -Redistributions of source code must retain the above copyright
  9.  *  notice, this list of conditions and the following disclaimer.
  10.  * 
  11.  * -Redistribution in binary form must reproduct the above copyright
  12.  *  notice, this list of conditions and the following disclaimer in
  13.  *  the documentation and/or other materials provided with the distribution.
  14.  * 
  15.  * Neither the name of Sun Microsystems, Inc. or the names of contributors
  16.  * may be used to endorse or promote products derived from this software
  17.  * without specific prior written permission.
  18.  * 
  19.  * This software is provided "AS IS," without a warranty of any kind. ALL
  20.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
  21.  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  22.  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
  23.  * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
  24.  * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
  25.  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
  26.  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
  27.  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
  28.  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
  29.  * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  30.  * 
  31.  * You acknowledge that Software is not designed, licensed or intended for
  32.  * use in the design, construction, operation or maintenance of any nuclear
  33.  * facility.
  34.  */
  35.  
  36.  
  37. package java2d;
  38.  
  39. import java.awt.*;
  40. import javax.swing.*;
  41.  
  42.  
  43. /**
  44.  * A demo that shows Java2D features. 
  45.  *
  46.  * Parameters that can be used in the Java2Demo.html file inside
  47.  * the applet tag to customize demo runs :
  48.               <param name="runs" value="10">
  49.               <param name="delay" value="10">
  50.               <param name="ccthread" value=" ">
  51.               <param name="screen" value="5">
  52.               <param name="antialias" value="true">
  53.               <param name="rendering" value="true">
  54.               <param name="texture" value="true">
  55.               <param name="composite" value="true">
  56.               <param name="verbose" value=" ">
  57.               <param name="buffers" value="3,10">
  58.               <param name="verbose" value=" ">
  59.               <param name="zoom" value=" ">
  60.  *
  61.  * @version @(#)Java2DemoApplet.java    1.16 02/06/13
  62.  * @author Brian Lichtenwalter  (Framework, Intro, demos)
  63.  * @author Jim Graham           (demos)
  64.  */
  65. public class Java2DemoApplet extends JApplet {
  66.  
  67.     public static JApplet applet;
  68.  
  69.  
  70.     public void init() {
  71.  
  72.         applet = this;
  73.  
  74.         JPanel panel = new JPanel();
  75.         getContentPane().add(panel,BorderLayout.CENTER);
  76.         panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
  77.  
  78.         JPanel progressPanel = new JPanel() {
  79.             public Insets getInsets() {
  80.                 return new Insets(40,30,20,30);
  81.             }
  82.         };
  83.         progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
  84.  
  85.         panel.add(Box.createGlue());
  86.         panel.add(progressPanel);
  87.         panel.add(Box.createGlue());
  88.  
  89.         progressPanel.add(Box.createGlue());
  90.  
  91.         Dimension d = new Dimension(400, 20);
  92.         Java2Demo.progressLabel = new JLabel("Loading, please wait...");
  93.         Java2Demo.progressLabel.setMaximumSize(d);
  94.         progressPanel.add(Java2Demo.progressLabel);
  95.         progressPanel.add(Box.createRigidArea(new Dimension(1,20)));
  96.  
  97.         Java2Demo.progressBar = new JProgressBar();
  98.         Java2Demo.progressBar.setStringPainted(true);
  99.         Java2Demo.progressLabel.setLabelFor(Java2Demo.progressBar);
  100.         Java2Demo.progressBar.setAlignmentX(CENTER_ALIGNMENT);
  101.         Java2Demo.progressBar.setMaximumSize(d);
  102.         Java2Demo.progressBar.setMinimum(0);
  103.         Java2Demo.progressBar.setValue(0);
  104.         progressPanel.add(Java2Demo.progressBar);
  105.         progressPanel.add(Box.createGlue());
  106.         progressPanel.add(Box.createGlue());
  107.  
  108.         Rectangle ab = getContentPane().getBounds();
  109.         panel.setPreferredSize(new Dimension(ab.width,ab.height));
  110.         getContentPane().add(panel,BorderLayout.CENTER);
  111.         validate();
  112.         setVisible(true);
  113.  
  114.         Java2Demo.demo = new Java2Demo();
  115.         getContentPane().remove(panel);
  116.         getContentPane().setLayout(new BorderLayout());
  117.         getContentPane().add(Java2Demo.demo, BorderLayout.CENTER);
  118.  
  119.         String param = null;
  120.  
  121.         if ((param = getParameter("delay")) != null) {
  122.             RunWindow.delay = Integer.parseInt(param);
  123.         } 
  124.         if (getParameter("ccthread") != null) {
  125.             Java2Demo.demo.ccthreadCB.setSelected(true);
  126.         }
  127.         if ((param = getParameter("screen")) != null) {
  128.             Java2Demo.demo.controls.screenCombo.setSelectedIndex(Integer.parseInt(param));
  129.         } 
  130.         if ((param = getParameter("antialias")) != null) {
  131.             Java2Demo.demo.controls.aliasCB.setSelected(param.endsWith("true"));
  132.         } 
  133.         if ((param = getParameter("rendering")) != null) {
  134.             Java2Demo.demo.controls.renderCB.setSelected(param.endsWith("true"));
  135.         } 
  136.         if ((param = getParameter("texture")) != null) {
  137.             Java2Demo.demo.controls.textureCB.setSelected(param.endsWith("true"));
  138.         } 
  139.         if ((param = getParameter("composite")) != null) {
  140.             Java2Demo.demo.controls.compositeCB.setSelected(param.endsWith("true"));
  141.         } 
  142.         if (getParameter("verbose") != null) {
  143.             Java2Demo.demo.verboseCB.setSelected(true);
  144.         } 
  145.         if ((param = getParameter("columns")) != null) {
  146.             DemoGroup.columns = Integer.parseInt(param);
  147.         } 
  148.         if ((param = getParameter("buffers")) != null) {
  149.             // usage -buffers=3,10
  150.             RunWindow.buffersFlag = true;
  151.             int i = param.indexOf(',');
  152.             String s1 = param.substring(0, i);
  153.             RunWindow.bufBeg = Integer.parseInt(s1);
  154.             s1 = param.substring(i+1, param.length());
  155.             RunWindow.bufEnd = Integer.parseInt(s1);
  156.         } 
  157.         if (getParameter("zoom") != null) {
  158.             RunWindow.zoomCB.setSelected(true);
  159.         }
  160.         if ((param = getParameter("runs")) != null) {
  161.             RunWindow.numRuns = Integer.parseInt(param);
  162.             Java2Demo.demo.createRunWindow();
  163.             RunWindow.runB.doClick();
  164.         } 
  165.         validate();
  166.         repaint();
  167.         Java2Demo.demo.requestDefaultFocus();
  168.     }
  169.  
  170.     public void start() {
  171.         Java2Demo.demo.start();
  172.     }
  173.  
  174.     public void stop() {
  175.         Java2Demo.demo.stop();
  176.     }
  177. }
  178.