001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/gui/StatsDialog.java,v 1.1 2005/04/20 21:04:59 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is Java 3D(tm) Fly Through.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dfly.utils.gui;
019:
020: import org.jdesktop.j3d.utils.scenegraph.traverser.TreeScan;
021: import org.jdesktop.j3d.utils.scenegraph.traverser.GeometrySizeProcessor;
022:
023: import org.jdesktop.j3dfly.utils.behaviors.PerfBehaviorListener;
024: import org.jdesktop.j3dfly.utils.behaviors.PerfBehavior;
025:
026: /**
027: *
028: * @author Paul Byrne
029: * @version 1.19, 01/18/02
030: */
031: public class StatsDialog extends javax.swing.JDialog implements
032: PerfBehaviorListener {
033:
034: private javax.media.j3d.BranchGroup toolBG;
035: private PerfBehavior perfBehavior = null;
036: private float[] fpsAvg = new float[30];
037: private int avgCounter = 0;
038: private int avgLimit = 0;
039:
040: /** Creates new StatsDialog and add the performance measuring behavior
041: * as a child of toolBG
042: */
043: public StatsDialog(java.awt.Frame parent,
044: javax.media.j3d.BranchGroup toolBG) {
045: super (parent, false);
046: this .toolBG = toolBG;
047: initComponents();
048: pack();
049:
050: for (int i = 0; i < fpsAvg.length; i++)
051: fpsAvg[i] = 0f;
052: }
053:
054: public void show() {
055: super .show();
056: if (perfBehavior != null) {
057: fpsTF.setText("Calibrating");
058: //trianglespsTF.setText( "Calibrating" );
059: perfBehavior.calibrate();
060: }
061: }
062:
063: /**
064: * Enable the Frame-per-second gathering of the Stats
065: */
066: public void setEnable(boolean enable) {
067: if (perfBehavior != null) {
068: perfBehavior.setEnable(enable);
069: }
070: }
071:
072: /**
073: * Extract Geometry statistics from all the branch groups
074: * If any of the graphs are compiled then Not Available (N/A) will
075: * appear in the dialog.
076: */
077: public void calcGeometryStats(
078: javax.media.j3d.BranchGroup[] branchGroups) {
079: boolean compiled = false;
080: int nullCount = 0;
081: for (int i = 0; i < branchGroups.length; i++) {
082: if (branchGroups[i] != null)
083: compiled |= branchGroups[i].isCompiled();
084: else
085: nullCount++;
086: }
087:
088: if (nullCount == branchGroups.length) {
089: clearData("0");
090: return;
091: }
092:
093: if (!compiled) {
094: GeometrySizeProcessor processor = new GeometrySizeProcessor();
095: TreeScan scan = new TreeScan();
096:
097: for (int i = 0; i < branchGroups.length; i++) {
098: scan.findNode(branchGroups[i],
099: javax.media.j3d.Shape3D.class, processor,
100: false, true);
101: }
102:
103: triangleCountTF.setText(Long.toString(processor
104: .getTriangleCount()));
105: quadCountTF
106: .setText(Long.toString(processor.getQuadCount()));
107: lineCountTF
108: .setText(Long.toString(processor.getLineCount()));
109: pointCountTF.setText(Long.toString(processor
110: .getPointCount()));
111:
112: vertexInStripsTF.setText(floatToString(processor
113: .getStripPercentage(), 1));
114: stripLengthTF.setText(floatToString(processor
115: .getAverageStripLength(), 3));
116:
117: int[] triangleDistribution = processor
118: .getTriangleStripDistribution();
119: int[] triFanDistribution = processor
120: .getTriangleFanDistribution();
121:
122: for (int i = 1; i < triangleDistribution.length; i++) {
123: stripSizeTable.setValueAt(new Integer(
124: triangleDistribution[i]), i - 1, 1);
125: stripSizeTable.setValueAt(new Integer(
126: triFanDistribution[i]), i - 1, 2);
127: }
128:
129: shape3DcountTF.setText(Integer.toString(processor
130: .getShape3DCount()));
131: appearanceCountTF.setText(Integer.toString(processor
132: .getAppearanceCount()));
133: } else {
134: clearData("N/A");
135: }
136: if (perfBehavior == null) {
137: perfBehavior = new PerfBehavior();
138: perfBehavior.addPerfBehaviorListener(this );
139: perfBehavior.setEnable(false);
140: toolBG.addChild(perfBehavior);
141: } else {
142: fpsTF.setText("Calibrating");
143: fpsAvgTF.setText("Calibrating");
144: perfBehavior.calibrate();
145: perfBehavior.setEnable(true);
146: }
147: }
148:
149: /**
150: * Clear all the GUI data fields to the string provided
151: */
152: private void clearData(String str) {
153: triangleCountTF.setText(str);
154: quadCountTF.setText(str);
155: lineCountTF.setText(str);
156: pointCountTF.setText(str);
157: vertexInStripsTF.setText(str);
158: stripLengthTF.setText(str);
159: shape3DcountTF.setText(str);
160: appearanceCountTF.setText(str);
161: for (int i = 1; i < 15; i++) {
162: stripSizeTable.setValueAt(str, i - 1, 1);
163: stripSizeTable.setValueAt(str, i - 1, 2);
164: }
165: }
166:
167: /**
168: * Extract the geometry statistics from the graph
169: *
170: * If bg is null 0 is displayed in the stats and the
171: */
172: public void calcGeometryStats(javax.media.j3d.BranchGroup bg) {
173: calcGeometryStats(new javax.media.j3d.BranchGroup[] { bg });
174: }
175:
176: /** This method is called from within the constructor to
177: * initialize the form.
178: * WARNING: Do NOT modify this code. The content of this method is
179: * always regenerated by the FormEditor.
180: */
181: private void initComponents() {//GEN-BEGIN:initComponents
182: buttonP = new javax.swing.JPanel();
183: closeB = new javax.swing.JButton();
184: statsP = new javax.swing.JPanel();
185: geometryStatsP = new javax.swing.JPanel();
186: jLabel1 = new javax.swing.JLabel();
187: jLabel2 = new javax.swing.JLabel();
188: jLabel3 = new javax.swing.JLabel();
189: jLabel4 = new javax.swing.JLabel();
190: triangleCountTF = new javax.swing.JTextField();
191: quadCountTF = new javax.swing.JTextField();
192: lineCountTF = new javax.swing.JTextField();
193: pointCountTF = new javax.swing.JTextField();
194: jLabel5 = new javax.swing.JLabel();
195: jLabel6 = new javax.swing.JLabel();
196: vertexInStripsTF = new javax.swing.JTextField();
197: stripLengthTF = new javax.swing.JTextField();
198: jLabel7 = new javax.swing.JLabel();
199: jLabel8 = new javax.swing.JLabel();
200: jLabel18 = new javax.swing.JLabel();
201: stripStatsP = new javax.swing.JPanel();
202: jScrollPane1 = new javax.swing.JScrollPane();
203: stripSizeTable = new javax.swing.JTable();
204: sgAndPerfStats = new javax.swing.JPanel();
205: performanceP = new javax.swing.JPanel();
206: jLabel9 = new javax.swing.JLabel();
207: fpsTF = new javax.swing.JTextField();
208: fpsAvgTF = new javax.swing.JTextField();
209: scenegraphStatsP = new javax.swing.JPanel();
210: jLabel11 = new javax.swing.JLabel();
211: shape3DcountTF = new javax.swing.JTextField();
212: jLabel12 = new javax.swing.JLabel();
213: appearanceCountTF = new javax.swing.JTextField();
214:
215: addWindowListener(new java.awt.event.WindowAdapter() {
216: public void windowClosing(java.awt.event.WindowEvent evt) {
217: closeDialog(evt);
218: }
219: });
220:
221: closeB.setText("Close");
222: closeB.addActionListener(new java.awt.event.ActionListener() {
223: public void actionPerformed(java.awt.event.ActionEvent evt) {
224: closeBActionPerformed(evt);
225: }
226: });
227:
228: buttonP.add(closeB);
229:
230: getContentPane().add(buttonP, java.awt.BorderLayout.SOUTH);
231:
232: statsP.setLayout(new java.awt.GridBagLayout());
233: java.awt.GridBagConstraints gridBagConstraints1;
234:
235: geometryStatsP.setLayout(new java.awt.GridBagLayout());
236: java.awt.GridBagConstraints gridBagConstraints2;
237:
238: geometryStatsP.setBorder(new javax.swing.border.TitledBorder(
239: new javax.swing.border.EtchedBorder(),
240: "Geometry Statistics"));
241: jLabel1.setText("Triangle Count :");
242: gridBagConstraints2 = new java.awt.GridBagConstraints();
243: gridBagConstraints2.gridx = 0;
244: gridBagConstraints2.gridy = 1;
245: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
246: gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
247: geometryStatsP.add(jLabel1, gridBagConstraints2);
248:
249: jLabel2.setText("Quad Count :");
250: gridBagConstraints2 = new java.awt.GridBagConstraints();
251: gridBagConstraints2.gridx = 0;
252: gridBagConstraints2.gridy = 2;
253: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
254: gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
255: geometryStatsP.add(jLabel2, gridBagConstraints2);
256:
257: jLabel3.setText("Line Count :");
258: gridBagConstraints2 = new java.awt.GridBagConstraints();
259: gridBagConstraints2.gridx = 0;
260: gridBagConstraints2.gridy = 3;
261: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
262: gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
263: geometryStatsP.add(jLabel3, gridBagConstraints2);
264:
265: jLabel4.setText("Point Count :");
266: gridBagConstraints2 = new java.awt.GridBagConstraints();
267: gridBagConstraints2.gridx = 0;
268: gridBagConstraints2.gridy = 4;
269: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
270: gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
271: geometryStatsP.add(jLabel4, gridBagConstraints2);
272:
273: triangleCountTF.setEditable(false);
274: triangleCountTF.setColumns(7);
275: triangleCountTF.setText("jTextField1");
276: triangleCountTF
277: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
278: triangleCountTF.setMinimumSize(new java.awt.Dimension(63, 21));
279: gridBagConstraints2 = new java.awt.GridBagConstraints();
280: gridBagConstraints2.gridx = 1;
281: gridBagConstraints2.gridy = 1;
282: geometryStatsP.add(triangleCountTF, gridBagConstraints2);
283:
284: quadCountTF.setEditable(false);
285: quadCountTF.setColumns(7);
286: quadCountTF.setText("jTextField1");
287: quadCountTF
288: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
289: quadCountTF.setMinimumSize(new java.awt.Dimension(63, 21));
290: gridBagConstraints2 = new java.awt.GridBagConstraints();
291: gridBagConstraints2.gridx = 1;
292: gridBagConstraints2.gridy = 2;
293: geometryStatsP.add(quadCountTF, gridBagConstraints2);
294:
295: lineCountTF.setEditable(false);
296: lineCountTF.setColumns(7);
297: lineCountTF.setText("jTextField1");
298: lineCountTF
299: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
300: lineCountTF.setMinimumSize(new java.awt.Dimension(63, 21));
301: gridBagConstraints2 = new java.awt.GridBagConstraints();
302: gridBagConstraints2.gridx = 1;
303: gridBagConstraints2.gridy = 3;
304: geometryStatsP.add(lineCountTF, gridBagConstraints2);
305:
306: pointCountTF.setEditable(false);
307: pointCountTF.setColumns(7);
308: pointCountTF.setText("jTextField1");
309: pointCountTF
310: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
311: pointCountTF.setMinimumSize(new java.awt.Dimension(63, 21));
312: pointCountTF
313: .addActionListener(new java.awt.event.ActionListener() {
314: public void actionPerformed(
315: java.awt.event.ActionEvent evt) {
316: jTextField4ActionPerformed(evt);
317: }
318: });
319:
320: gridBagConstraints2 = new java.awt.GridBagConstraints();
321: gridBagConstraints2.gridx = 1;
322: gridBagConstraints2.gridy = 4;
323: geometryStatsP.add(pointCountTF, gridBagConstraints2);
324:
325: jLabel5.setText("Vertex In Strips :");
326: gridBagConstraints2 = new java.awt.GridBagConstraints();
327: gridBagConstraints2.gridx = 0;
328: gridBagConstraints2.gridy = 5;
329: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
330: gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
331: geometryStatsP.add(jLabel5, gridBagConstraints2);
332:
333: jLabel6.setText("Average Strip Length :");
334: gridBagConstraints2 = new java.awt.GridBagConstraints();
335: gridBagConstraints2.gridx = 0;
336: gridBagConstraints2.gridy = 6;
337: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
338: gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
339: geometryStatsP.add(jLabel6, gridBagConstraints2);
340:
341: vertexInStripsTF.setEditable(false);
342: vertexInStripsTF.setColumns(4);
343: vertexInStripsTF.setText("jTextField6");
344: vertexInStripsTF
345: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
346: vertexInStripsTF.setMinimumSize(new java.awt.Dimension(36, 21));
347: gridBagConstraints2 = new java.awt.GridBagConstraints();
348: gridBagConstraints2.gridx = 1;
349: gridBagConstraints2.gridy = 5;
350: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
351: geometryStatsP.add(vertexInStripsTF, gridBagConstraints2);
352:
353: stripLengthTF
354: .setToolTipText("Average Number of vertices per strip");
355: stripLengthTF.setEditable(false);
356: stripLengthTF.setColumns(7);
357: stripLengthTF.setText("jTextField7");
358: stripLengthTF
359: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
360: stripLengthTF.setMinimumSize(new java.awt.Dimension(63, 21));
361: gridBagConstraints2 = new java.awt.GridBagConstraints();
362: gridBagConstraints2.gridx = 1;
363: gridBagConstraints2.gridy = 6;
364: geometryStatsP.add(stripLengthTF, gridBagConstraints2);
365:
366: jLabel7.setText("%");
367: gridBagConstraints2 = new java.awt.GridBagConstraints();
368: gridBagConstraints2.gridx = 2;
369: gridBagConstraints2.gridy = 5;
370: gridBagConstraints2.insets = new java.awt.Insets(0, 4, 0, 0);
371: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
372: geometryStatsP.add(jLabel7, gridBagConstraints2);
373:
374: jLabel8.setText("Stats for all Geometry in Scene Graph");
375: gridBagConstraints2 = new java.awt.GridBagConstraints();
376: gridBagConstraints2.gridwidth = 3;
377: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 4, 0);
378: geometryStatsP.add(jLabel8, gridBagConstraints2);
379:
380: jLabel18.setText("vertices");
381: gridBagConstraints2 = new java.awt.GridBagConstraints();
382: gridBagConstraints2.gridx = 2;
383: gridBagConstraints2.gridy = 6;
384: gridBagConstraints2.insets = new java.awt.Insets(0, 4, 0, 0);
385: geometryStatsP.add(jLabel18, gridBagConstraints2);
386:
387: gridBagConstraints1 = new java.awt.GridBagConstraints();
388: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
389: gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
390: statsP.add(geometryStatsP, gridBagConstraints1);
391:
392: stripStatsP.setLayout(new java.awt.BorderLayout());
393:
394: stripStatsP.setBorder(new javax.swing.border.TitledBorder(
395: "Strip Sizes"));
396: jScrollPane1.setMinimumSize(new java.awt.Dimension(100, 100));
397: jScrollPane1.setMaximumSize(new java.awt.Dimension(243, 242));
398: stripSizeTable
399: .setToolTipText("Distribution of Strip lengths for Triangle Strips and Fans");
400: stripSizeTable
401: .setModel(new javax.swing.table.DefaultTableModel(
402: new Object[][] {
403: { "1", new Integer(0), new Integer(0) },
404: { "2", new Integer(0), new Integer(0) },
405: { "3", new Integer(0), new Integer(0) },
406: { "4", new Integer(0), new Integer(0) },
407: { "5", new Integer(0), new Integer(0) },
408: { "6", new Integer(0), new Integer(0) },
409: { "7", new Integer(0), new Integer(0) },
410: { "8", new Integer(0), new Integer(0) },
411: { "9", new Integer(0), new Integer(0) },
412: { "10-19", new Integer(0),
413: new Integer(0) },
414: { "20-49", new Integer(0),
415: new Integer(0) },
416: { "49-99", new Integer(0),
417: new Integer(0) },
418: { "100-999", new Integer(0),
419: new Integer(0) },
420: { ">1000", new Integer(0),
421: new Integer(0) } },
422: new String[] { "Strip Length",
423: "Tri Strip\nCount", "Tri Fan Count" }) {
424: Class[] types = new Class[] {
425: java.lang.String.class,
426: java.lang.Integer.class,
427: java.lang.Integer.class };
428: boolean[] canEdit = new boolean[] { false, false,
429: false };
430:
431: public Class getColumnClass(int columnIndex) {
432: return types[columnIndex];
433: }
434:
435: public boolean isCellEditable(int rowIndex,
436: int columnIndex) {
437: return canEdit[columnIndex];
438: }
439: });
440: stripSizeTable
441: .setPreferredSize(new java.awt.Dimension(230, 224));
442: stripSizeTable
443: .setPreferredScrollableViewportSize(new java.awt.Dimension(
444: 230, 224));
445: jScrollPane1.setViewportView(stripSizeTable);
446:
447: stripStatsP.add(jScrollPane1, java.awt.BorderLayout.CENTER);
448:
449: gridBagConstraints1 = new java.awt.GridBagConstraints();
450: gridBagConstraints1.gridx = 1;
451: gridBagConstraints1.gridy = 0;
452: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
453: gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
454: statsP.add(stripStatsP, gridBagConstraints1);
455:
456: sgAndPerfStats.setLayout(new javax.swing.BoxLayout(
457: sgAndPerfStats, javax.swing.BoxLayout.Y_AXIS));
458:
459: performanceP.setLayout(new java.awt.GridBagLayout());
460: java.awt.GridBagConstraints gridBagConstraints3;
461:
462: performanceP.setBorder(new javax.swing.border.TitledBorder(
463: new javax.swing.border.EtchedBorder(), "Performance"));
464: jLabel9.setText("Frames per second :");
465: gridBagConstraints3 = new java.awt.GridBagConstraints();
466: gridBagConstraints3.insets = new java.awt.Insets(0, 0, 0, 3);
467: gridBagConstraints3.anchor = java.awt.GridBagConstraints.EAST;
468: performanceP.add(jLabel9, gridBagConstraints3);
469:
470: fpsTF.setEditable(false);
471: fpsTF.setColumns(7);
472: fpsTF.setText("Calibrating");
473: fpsTF.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
474: fpsTF.setPreferredSize(new java.awt.Dimension(70, 21));
475: fpsTF.setMinimumSize(new java.awt.Dimension(60, 21));
476: gridBagConstraints3 = new java.awt.GridBagConstraints();
477: gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST;
478: performanceP.add(fpsTF, gridBagConstraints3);
479:
480: fpsAvgTF.setToolTipText("FPS Averaged over a longer period");
481: fpsAvgTF.setEditable(false);
482: fpsAvgTF.setColumns(7);
483: fpsAvgTF.setText("Calibrating");
484: fpsAvgTF
485: .setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
486: fpsAvgTF.setMinimumSize(new java.awt.Dimension(60, 21));
487: gridBagConstraints3 = new java.awt.GridBagConstraints();
488: gridBagConstraints3.gridx = 1;
489: gridBagConstraints3.gridy = 1;
490: gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST;
491: performanceP.add(fpsAvgTF, gridBagConstraints3);
492:
493: sgAndPerfStats.add(performanceP);
494:
495: scenegraphStatsP.setLayout(new java.awt.GridBagLayout());
496: java.awt.GridBagConstraints gridBagConstraints4;
497:
498: scenegraphStatsP.setBorder(new javax.swing.border.TitledBorder(
499: "SceneGraph Stats"));
500: jLabel11.setText("Shape3D Count :");
501: gridBagConstraints4 = new java.awt.GridBagConstraints();
502: gridBagConstraints4.insets = new java.awt.Insets(0, 0, 0, 4);
503: gridBagConstraints4.anchor = java.awt.GridBagConstraints.EAST;
504: scenegraphStatsP.add(jLabel11, gridBagConstraints4);
505:
506: shape3DcountTF.setEditable(false);
507: shape3DcountTF.setColumns(5);
508: shape3DcountTF.setText("jTextField1");
509: shape3DcountTF.setMinimumSize(new java.awt.Dimension(45, 21));
510: gridBagConstraints4 = new java.awt.GridBagConstraints();
511: gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
512: scenegraphStatsP.add(shape3DcountTF, gridBagConstraints4);
513:
514: jLabel12.setText("Appearance Count :");
515: gridBagConstraints4 = new java.awt.GridBagConstraints();
516: gridBagConstraints4.gridx = 0;
517: gridBagConstraints4.gridy = 1;
518: gridBagConstraints4.insets = new java.awt.Insets(0, 0, 0, 4);
519: gridBagConstraints4.anchor = java.awt.GridBagConstraints.EAST;
520: scenegraphStatsP.add(jLabel12, gridBagConstraints4);
521:
522: appearanceCountTF.setEditable(false);
523: appearanceCountTF.setColumns(5);
524: appearanceCountTF.setText("jTextField2");
525: appearanceCountTF
526: .setMinimumSize(new java.awt.Dimension(45, 21));
527: gridBagConstraints4 = new java.awt.GridBagConstraints();
528: gridBagConstraints4.gridx = 1;
529: gridBagConstraints4.gridy = 1;
530: gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
531: scenegraphStatsP.add(appearanceCountTF, gridBagConstraints4);
532:
533: sgAndPerfStats.add(scenegraphStatsP);
534:
535: gridBagConstraints1 = new java.awt.GridBagConstraints();
536: gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
537: statsP.add(sgAndPerfStats, gridBagConstraints1);
538:
539: getContentPane().add(statsP, java.awt.BorderLayout.CENTER);
540:
541: }//GEN-END:initComponents
542:
543: private void jTextField4ActionPerformed(
544: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
545: // Add your handling code here:
546: }//GEN-LAST:event_jTextField4ActionPerformed
547:
548: private void closeBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeBActionPerformed
549: // Add your handling code here:
550: closeDialog();
551: }//GEN-LAST:event_closeBActionPerformed
552:
553: /** Closes the dialog */
554: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
555: closeDialog();
556: }//GEN-LAST:event_closeDialog
557:
558: private void closeDialog() {
559: setVisible(false);
560: if (perfBehavior != null)
561: perfBehavior.setEnable(false);
562: dispose();
563: }
564:
565: // Variables declaration - do not modify//GEN-BEGIN:variables
566: private javax.swing.JPanel buttonP;
567: private javax.swing.JButton closeB;
568: private javax.swing.JPanel statsP;
569: private javax.swing.JPanel geometryStatsP;
570: private javax.swing.JLabel jLabel1;
571: private javax.swing.JLabel jLabel2;
572: private javax.swing.JLabel jLabel3;
573: private javax.swing.JLabel jLabel4;
574: private javax.swing.JTextField triangleCountTF;
575: private javax.swing.JTextField quadCountTF;
576: private javax.swing.JTextField lineCountTF;
577: private javax.swing.JTextField pointCountTF;
578: private javax.swing.JLabel jLabel5;
579: private javax.swing.JLabel jLabel6;
580: private javax.swing.JTextField vertexInStripsTF;
581: private javax.swing.JTextField stripLengthTF;
582: private javax.swing.JLabel jLabel7;
583: private javax.swing.JLabel jLabel8;
584: private javax.swing.JLabel jLabel18;
585: private javax.swing.JPanel stripStatsP;
586: private javax.swing.JScrollPane jScrollPane1;
587: private javax.swing.JTable stripSizeTable;
588: private javax.swing.JPanel sgAndPerfStats;
589: private javax.swing.JPanel performanceP;
590: private javax.swing.JLabel jLabel9;
591: private javax.swing.JTextField fpsTF;
592: private javax.swing.JTextField fpsAvgTF;
593: private javax.swing.JPanel scenegraphStatsP;
594: private javax.swing.JLabel jLabel11;
595: private javax.swing.JTextField shape3DcountTF;
596: private javax.swing.JLabel jLabel12;
597: private javax.swing.JTextField appearanceCountTF;
598:
599: // End of variables declaration//GEN-END:variables
600:
601: /** Called when new performance figures are available
602: */
603: public void updatePerformanceFigures(float framesPerSecond) {
604: fpsAvg[avgCounter++] = framesPerSecond;
605: if (avgCounter == fpsAvg.length)
606: avgCounter = 0;
607:
608: if (avgLimit < fpsAvg.length)
609: avgLimit++;
610:
611: float avg = 0;
612: for (int i = 0; i < fpsAvg.length; i++)
613: avg += fpsAvg[i];
614: avg /= avgLimit;
615:
616: fpsTF.setText(floatToString(framesPerSecond, 2));
617: fpsAvgTF.setText(floatToString(avg, 2));
618: //trianglespsTF.setText( Double.toString( framesPerSecond * triangleCount ));
619: }
620:
621: /**
622: * Convert the float to a string and trim it to the
623: * specified number of decimalPlaces
624: */
625: private String floatToString(float number, int decimalPlaces) {
626: String str = Float.toString(number);
627:
628: int dot = str.lastIndexOf('.');
629: if (dot == -1 || dot >= str.length() - decimalPlaces)
630: return str;
631:
632: return str.substring(0, dot + decimalPlaces + 1);
633: }
634: }
|