KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java2d > Java2DemoApplet


1 /*
2  * @(#)Java2DemoApplet.java 1.22 06/08/25
3  *
4  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * -Redistribution of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * -Redistribution in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
17  * be used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any kind. ALL
21  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
22  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
24  * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
25  * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
26  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
27  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
28  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
29  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  *
32  * You acknowledge that this software is not designed, licensed or intended
33  * for use in the design, construction, operation or maintenance of any
34  * nuclear facility.
35  */

36
37
38 package java2d;
39
40 import java.awt.*;
41 import javax.swing.*;
42
43
44 /**
45  * A demo that shows Java2D features.
46  *
47  * Parameters that can be used in the Java2Demo.html file inside
48  * the applet tag to customize demo runs :
49               <param name="runs" value="10">
50               <param name="delay" value="10">
51               <param name="ccthread" value=" ">
52               <param name="screen" value="5">
53               <param name="antialias" value="true">
54               <param name="rendering" value="true">
55               <param name="texture" value="true">
56               <param name="composite" value="true">
57               <param name="verbose" value=" ">
58               <param name="buffers" value="3,10">
59               <param name="verbose" value=" ">
60               <param name="zoom" value=" ">
61  *
62  * @version @(#)Java2DemoApplet.java 1.22 06/08/25
63  * @author Brian Lichtenwalter (Framework, Intro, demos)
64  * @author Jim Graham (demos)
65  */

66 public class Java2DemoApplet extends JApplet {
67
68     public static JApplet applet;
69
70
71     public void init() {
72
73         applet = this;
74
75         JPanel panel = new JPanel();
76         getContentPane().add(panel,BorderLayout.CENTER);
77         panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
78
79         JPanel progressPanel = new JPanel() {
80             public Insets getInsets() {
81                 return new Insets(40,30,20,30);
82             }
83         };
84         progressPanel.setLayout(new BoxLayout(progressPanel, BoxLayout.Y_AXIS));
85
86         panel.add(Box.createGlue());
87         panel.add(progressPanel);
88         panel.add(Box.createGlue());
89
90         progressPanel.add(Box.createGlue());
91
92         Dimension d = new Dimension(400, 20);
93         Java2Demo.progressLabel = new JLabel("Loading, please wait...");
94         Java2Demo.progressLabel.setMaximumSize(d);
95         progressPanel.add(Java2Demo.progressLabel);
96         progressPanel.add(Box.createRigidArea(new Dimension(1,20)));
97
98         Java2Demo.progressBar = new JProgressBar();
99         Java2Demo.progressBar.setStringPainted(true);
100         Java2Demo.progressLabel.setLabelFor(Java2Demo.progressBar);
101         Java2Demo.progressBar.setAlignmentX(CENTER_ALIGNMENT);
102         Java2Demo.progressBar.setMaximumSize(d);
103         Java2Demo.progressBar.setMinimum(0);
104         Java2Demo.progressBar.setValue(0);
105         progressPanel.add(Java2Demo.progressBar);
106         progressPanel.add(Box.createGlue());
107         progressPanel.add(Box.createGlue());
108
109         Rectangle ab = getContentPane().getBounds();
110         panel.setPreferredSize(new Dimension(ab.width,ab.height));
111         getContentPane().add(panel,BorderLayout.CENTER);
112         validate();
113         setVisible(true);
114
115         Java2Demo.demo = new Java2Demo();
116         getContentPane().remove(panel);
117         getContentPane().setLayout(new BorderLayout());
118         getContentPane().add(Java2Demo.demo, BorderLayout.CENTER);
119
120         String JavaDoc param = null;
121
122         if ((param = getParameter("delay")) != null) {
123             RunWindow.delay = Integer.parseInt(param);
124         }
125         if (getParameter("ccthread") != null) {
126             Java2Demo.demo.ccthreadCB.setSelected(true);
127         }
128         if ((param = getParameter("screen")) != null) {
129             Java2Demo.demo.controls.screenCombo.setSelectedIndex(Integer.parseInt(param));
130         }
131         if ((param = getParameter("antialias")) != null) {
132             Java2Demo.demo.controls.aliasCB.setSelected(param.endsWith("true"));
133         }
134         if ((param = getParameter("rendering")) != null) {
135             Java2Demo.demo.controls.renderCB.setSelected(param.endsWith("true"));
136         }
137         if ((param = getParameter("texture")) != null) {
138             Java2Demo.demo.controls.textureCB.setSelected(param.endsWith("true"));
139         }
140         if ((param = getParameter("composite")) != null) {
141             Java2Demo.demo.controls.compositeCB.setSelected(param.endsWith("true"));
142         }
143         if (getParameter("verbose") != null) {
144             Java2Demo.demo.verboseCB.setSelected(true);
145         }
146         if ((param = getParameter("columns")) != null) {
147             DemoGroup.columns = Integer.parseInt(param);
148         }
149         if ((param = getParameter("buffers")) != null) {
150             // usage -buffers=3,10
151
RunWindow.buffersFlag = true;
152             int i = param.indexOf(',');
153             String JavaDoc s1 = param.substring(0, i);
154             RunWindow.bufBeg = Integer.parseInt(s1);
155             s1 = param.substring(i+1, param.length());
156             RunWindow.bufEnd = Integer.parseInt(s1);
157         }
158         if (getParameter("zoom") != null) {
159             RunWindow.zoomCB.setSelected(true);
160         }
161         if ((param = getParameter("runs")) != null) {
162             RunWindow.numRuns = Integer.parseInt(param);
163             Java2Demo.demo.createRunWindow();
164             RunWindow.runB.doClick();
165         }
166         validate();
167         repaint();
168         requestDefaultFocus();
169     }
170
171     private void requestDefaultFocus() {
172         Container nearestRoot = getFocusCycleRootAncestor();
173         if (nearestRoot != null) {
174             nearestRoot.getFocusTraversalPolicy()
175                        .getDefaultComponent(nearestRoot)
176                        .requestFocus();
177         }
178     }
179
180     public void start() {
181         Java2Demo.demo.start();
182     }
183
184     public void stop() {
185         Java2Demo.demo.stop();
186     }
187 }
188
Popular Tags