Source Code Cross Referenced for FPSCounterDemo.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3d » examples » fps_counter » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » org.jdesktop.j3d.examples.fps_counter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: FPSCounterDemo.java,v $
003:         *
004:         * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * - Redistribution of source code must retain the above copyright
011:         *   notice, this list of conditions and the following disclaimer.
012:         *
013:         * - Redistribution in binary form must reproduce the above copyright
014:         *   notice, this list of conditions and the following disclaimer in
015:         *   the documentation and/or other materials provided with the
016:         *   distribution.
017:         *
018:         * Neither the name of Sun Microsystems, Inc. or the names of
019:         * contributors may be used to endorse or promote products derived
020:         * from this software without specific prior written permission.
021:         *
022:         * This software is provided "AS IS," without a warranty of any
023:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026:         * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027:         * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028:         * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029:         * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030:         * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031:         * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032:         * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033:         * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034:         * POSSIBILITY OF SUCH DAMAGES.
035:         *
036:         * You acknowledge that this software is not designed, licensed or
037:         * intended for use in the design, construction, operation or
038:         * maintenance of any nuclear facility.
039:         *
040:         * $Revision: 1.4 $
041:         * $Date: 2007/02/09 17:21:38 $
042:         * $State: Exp $
043:         */
044:
045:        package org.jdesktop.j3d.examples.fps_counter;
046:
047:        import com.sun.j3d.utils.universe.*;
048:        import com.sun.j3d.utils.geometry.ColorCube;
049:        import javax.media.j3d.*;
050:        import javax.vecmath.*;
051:        import java.awt.GraphicsConfiguration;
052:        import javax.swing.JOptionPane;
053:
054:        /**
055:         * This program demonstrates the use of the frames per second counter.
056:         * The program displays a rotating cube and sets up the FPSCounter to compute
057:         * the frame rate. The FPSCounter is set up with default values:
058:         * 	- run indefinitely
059:         * 	- 2 sec. warmup time
060:         * 	- display average frame rate every fifth sampling interval.
061:         * The default values can be changed through the command line
062:         * arguments. Use FPSCounterDemo1 -h for help on the various arguments.
063:         */
064:        public class FPSCounterDemo extends javax.swing.JFrame {
065:
066:            private SimpleUniverse univ = null;
067:            private BranchGroup scene = null;
068:            private FPSCounter fpsCounter = new FPSCounter();
069:
070:            BranchGroup createSceneGraph() {
071:                // Create the root of the branch graph
072:                BranchGroup objRoot = new BranchGroup();
073:
074:                // Create the TransformGroup node and initialize it to the
075:                // identity. Enable the TRANSFORM_WRITE capability so that
076:                // our behavior code can modify it at run time. Add it to
077:                // the root of the subgraph.
078:                TransformGroup objTrans = new TransformGroup();
079:                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
080:                objRoot.addChild(objTrans);
081:
082:                // Create a simple Shape3D node; add it to the scene graph.
083:                objTrans.addChild(new ColorCube(0.4));
084:
085:                // Create a new Behavior object that will perform the
086:                // desired operation on the specified transform and add
087:                // it into the scene graph.
088:                Transform3D yAxis = new Transform3D();
089:                Alpha rotationAlpha = new Alpha(-1, 4000);
090:
091:                RotationInterpolator rotator = new RotationInterpolator(
092:                        rotationAlpha, objTrans, yAxis, 0.0f,
093:                        (float) Math.PI * 2.0f);
094:                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
095:                        0.0, 0.0), 100.0);
096:                rotator.setSchedulingBounds(bounds);
097:                objRoot.addChild(rotator);
098:
099:                // Create the Framecounter behavior
100:                fpsCounter.setSchedulingBounds(bounds);
101:                objRoot.addChild(fpsCounter);
102:
103:                return objRoot;
104:            }
105:
106:            private Canvas3D createUniverse() {
107:                // Get the preferred graphics configuration for the default screen
108:                GraphicsConfiguration config = SimpleUniverse
109:                        .getPreferredConfiguration();
110:
111:                // Create a Canvas3D using the preferred configuration
112:                Canvas3D c = new Canvas3D(config);
113:
114:                // Create simple universe with view branch
115:                univ = new SimpleUniverse(c);
116:
117:                // This will move the ViewPlatform back a bit so the
118:                // objects in the scene can be viewed.
119:                univ.getViewingPlatform().setNominalViewingTransform();
120:
121:                return c;
122:            }
123:
124:            /**
125:             * Creates new form FPSCounterDemo
126:             */
127:            public FPSCounterDemo() {
128:                // Initialize the GUI components
129:                initComponents();
130:
131:                // Create Canvas3D and SimpleUniverse; add canvas to drawing panel
132:                Canvas3D c = createUniverse();
133:                drawingPanel.add(c, java.awt.BorderLayout.CENTER);
134:
135:                // Create the content branch and add it to the universe
136:                scene = createSceneGraph();
137:                univ.addBranchGraph(scene);
138:
139:                JOptionPane
140:                        .showMessageDialog(
141:                                this ,
142:                                ("This program measures the number of frames rendered per second.\n"
143:                                        + "Note that the frame rate is limited by the refresh rate of the monitor.\n"
144:                                        + "To get the true frame rate you need to disable vertical retrace.\n\n"
145:                                        + "On Windows(tm) you do this through the Control Panel.\n\n"
146:                                        + "On Solaris set the environment variable OGL_NO_VBLANK"),
147:                                "Frame Counter",
148:                                JOptionPane.INFORMATION_MESSAGE);
149:
150:            }
151:
152:            /** Parses the commandline for the various switches to set the FPSCounter
153:             * variables.
154:             * All arguments are of the form <i>-name value</i>.
155:             * All -name arguments can be shortened to one character. All the value
156:             * arguments take a number. The arguments accepted are :
157:             * <ul>
158:             * <li>warmupTime : Specifies amount of time the FPSCounter should wait
159:             * for the HotSpot<sup><font size="-2">TM</font></sup> VM to perform
160:             * initial optimizations. Specified in milliseconds<br>
161:             * <li>loopCount  : Specifies the number of sampling intervals over which
162:             * the FPSCounter should calculate the aggregate and average frame rate.
163:             * Specified as a count. <br>
164:             * <li>maxLoops   : Specifies that the FPSCounter should run for only
165:             * these many sampling intervals. Specified as number. If this argument
166:             * is not specified, the FPSCounter runs indefinitely. <br>
167:             * <li>help	   : Prints the accepted arguments. <br>
168:             * </ul>
169:             */
170:            private void parseArgs(String args[]) {
171:                for (int i = 0; i < args.length; i++) {
172:                    if (args[i].startsWith("-")) {
173:                        if (args[i].startsWith("w", 1)) {
174:                            i++;
175:                            System.out.println("Warmup time : " + args[i]);
176:                            int w = new Integer(args[i]).intValue();
177:                            fpsCounter.setWarmupTime(w);
178:                        } else if (args[i].startsWith("l", 1)) {
179:                            i++;
180:                            System.out.println("Loop count : " + args[i]);
181:                            int l = new Integer(args[i]).intValue();
182:                            fpsCounter.setLoopCount(l);
183:                        } else if (args[i].startsWith("m", 1)) {
184:                            i++;
185:                            System.out.println("Max Loop Count : " + args[i]);
186:                            int m = new Integer(args[i]).intValue();
187:                            fpsCounter.setMaxLoops(m);
188:                        } else if (args[i].startsWith("h", 1)) {
189:                            System.out
190:                                    .println("Usage : FPSCounterDemo [-name value]\n"
191:                                            + "All arguments are of the form: -name value. All -name arguments can be\n"
192:                                            + "shortened to one character. All the value arguments take a number. The\n"
193:                                            + "arguments accepted are:\n\n"
194:                                            + "    -warmupTime : Specifies amount of time the FPSCounter should wait\n"
195:                                            + "        for the HotSpot(tm) VM to perform initial\n"
196:                                            + "        optimizations. Specified in milliseconds\n\n"
197:                                            + "    -loopCount : Specifies the number of sampling intervals over which\n"
198:                                            + "        the FPSCounter should calculate the aggregate and average\n"
199:                                            + "        frame rate. Specified as a count\n\n"
200:                                            + "    -maxLoops : Specifies that the FPSCounter should run for only these\n"
201:                                            + "        many sampling intervals. Specified as number. If this argument\n"
202:                                            + "        is not specified, the FPSCounter runs indefinitely.\n\n"
203:                                            + "    -help : Prints this message.");
204:                        }
205:                    }
206:                }
207:            }
208:
209:            // ----------------------------------------------------------------
210:
211:            /** This method is called from within the constructor to
212:             * initialize the form.
213:             * WARNING: Do NOT modify this code. The content of this method is
214:             * always regenerated by the Form Editor.
215:             */
216:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
217:            private void initComponents() {
218:                drawingPanel = new javax.swing.JPanel();
219:
220:                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
221:                setTitle("FPSCounterDemo");
222:                drawingPanel.setLayout(new java.awt.BorderLayout());
223:
224:                drawingPanel.setPreferredSize(new java.awt.Dimension(250, 250));
225:                getContentPane()
226:                        .add(drawingPanel, java.awt.BorderLayout.CENTER);
227:
228:                pack();
229:            }// </editor-fold>//GEN-END:initComponents
230:
231:            /**
232:             * @param args the command line arguments
233:             */
234:            public static void main(final String args[]) {
235:                java.awt.EventQueue.invokeLater(new Runnable() {
236:                    public void run() {
237:                        FPSCounterDemo fp = new FPSCounterDemo();
238:                        fp.parseArgs(args);
239:                        fp.setVisible(true);
240:                    }
241:                });
242:            }
243:
244:            // Variables declaration - do not modify//GEN-BEGIN:variables
245:            private javax.swing.JPanel drawingPanel;
246:            // End of variables declaration//GEN-END:variables
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.