1 /* J2dBenchmarkGUI.java -- GUI for java2d benchmarker
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.classpath.examples.java2d;
40 import java.awt.BorderLayout;
41 import java.awt.Color;
42 import java.awt.Container;
43 import java.awt.GridBagConstraints;
44 import java.awt.GridBagLayout;
45 import java.awt.GridLayout;
46 import java.awt.Insets;
47 import java.awt.event.ActionEvent;
48 import java.awt.event.ActionListener;
49 import java.awt.event.WindowAdapter;
50 import java.awt.event.WindowEvent;
51 import java.util.ArrayList;
52 import java.util.Hashtable;
53 import java.util.Iterator;
54 import java.util.logging.Handler;
55 import java.util.logging.Level;
56 import java.util.logging.LogRecord;
58 import javax.swing.Box;
59 import javax.swing.BoxLayout;
60 import javax.swing.ButtonGroup;
61 import javax.swing.JButton;
62 import javax.swing.JCheckBox;
63 import javax.swing.JComboBox;
64 import javax.swing.JComponent;
65 import javax.swing.JFrame;
66 import javax.swing.JLabel;
67 import javax.swing.JPanel;
68 import javax.swing.JRadioButton;
69 import javax.swing.JScrollPane;
70 import javax.swing.JTextArea;
71 import javax.swing.JTextField;
72 import javax.swing.border.BevelBorder;
75 * Extends the J2dBenchmark to provide a GUI for selecting options and tests.
77 public class J2dBenchmarkGUI
78 implements ActionListener
85 JCheckBox withClipping;
87 JCheckBox zeroClipping;
89 JCheckBox singleBuffer;
91 JCheckBox doubleBuffer;
93 public J2dBenchmarkGUI()
98 public static void main(String[] args)
100 new J2dBenchmarkGUI().run();
104 * Sets up the initial GUI
108 // Store all elements in a hashtable so that they can be passed into the
110 Hashtable elements = new Hashtable();
113 final JFrame frame = new JFrame("Java2D benchmark");
114 errorLabel = new JLabel(" ");
116 JPanel panel = new JPanel();
117 panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
118 Container content = frame.getContentPane();
120 // Display options for dimensions, iterations, test size, etc
121 JPanel options = new JPanel(new GridLayout(0, 2));
123 options.add(new JLabel("Height: "));
124 JTextField heightField = new JTextField(Integer.toString(J2dBenchmark.DEFAULT_SCREEN_HEIGHT));
125 heightField.setColumns(5);
126 options.add(heightField);
127 elements.put("height", heightField);
129 options.add(new JLabel("Width: "));
130 JTextField widthField = new JTextField(Integer.toString(J2dBenchmark.DEFAULT_SCREEN_WIDTH));
131 widthField.setColumns(5);
132 options.add(widthField);
133 elements.put("width", widthField);
135 options.add(new JLabel("Iterations: "));
136 JTextField iterField = new JTextField("1");
137 iterField.setColumns(5);
138 options.add(iterField);
139 elements.put("iterations", iterField);
141 options.add(new JLabel("Test size: "));
142 JTextField testSizeField = new JTextField(Integer.toString(J2dBenchmark.DEFAULT_TEST_SIZE));
143 testSizeField.setColumns(5);
144 options.add(testSizeField);
145 elements.put("size", testSizeField);
147 options.add(new JLabel("Test without clipping: "));
148 noClipping = new JCheckBox("", true);
149 noClipping.addActionListener(this);
150 options.add(noClipping);
151 elements.put("noclip", noClipping);
153 options.add(new JLabel("Test with clipping: "));
154 withClipping = new JCheckBox("", true);
155 withClipping.addActionListener(this);
156 options.add(withClipping);
157 elements.put("withclip", withClipping);
159 options.add(new JLabel("Test with clipping to zero: "));
160 zeroClipping = new JCheckBox("", true);
161 zeroClipping.addActionListener(this);
162 options.add(zeroClipping);
163 elements.put("zeroclip", zeroClipping);
165 options.add(new JLabel("Run single-buffer test: "));
166 singleBuffer = new JCheckBox("", true);
167 singleBuffer.addActionListener(this);
168 options.add(singleBuffer);
169 elements.put("singlebuffer", singleBuffer);
171 options.add(new JLabel("Run double-buffer test: "));
172 doubleBuffer = new JCheckBox("", true);
173 doubleBuffer.addActionListener(this);
174 options.add(doubleBuffer);
175 elements.put("doublebuffer", doubleBuffer);
177 // Allow user to select tests to run
178 JPanel tests = new JPanel();
179 tests.setLayout(new BoxLayout(tests, BoxLayout.PAGE_AXIS));
180 tests.setBorder(new BevelBorder(BevelBorder.RAISED));
181 tests.add(new JLabel("Shapes to test:"));
183 JCheckBox test_arcDraw = new JCheckBox("Arc", true);
184 tests.add(test_arcDraw);
185 elements.put("test_arcDraw", test_arcDraw);
187 JCheckBox test_ccurveDraw = new JCheckBox("Cubic Curve", true);
188 tests.add(test_ccurveDraw);
189 elements.put("test_ccurveDraw", test_ccurveDraw);
191 JCheckBox test_ellipseDraw = new JCheckBox("Ellipse", true);
192 tests.add(test_ellipseDraw);
193 elements.put("test_ellipseDraw", test_ellipseDraw);
196 JCheckBox test_pathDraw = new JCheckBox("General Path", true);
197 tests.add(test_pathDraw);
198 elements.put("test_pathDraw", test_pathDraw);
201 JCheckBox test_lineDraw = new JCheckBox("Line", true);
202 tests.add(test_lineDraw);
203 elements.put("test_lineDraw", test_lineDraw);
205 JCheckBox test_qcurveDraw = new JCheckBox("Quadratic Curve", true);
206 tests.add(test_qcurveDraw);
207 elements.put("test_qcurveDraw", test_qcurveDraw);
209 JCheckBox test_rectDraw = new JCheckBox("Rectangle", true);
210 tests.add(test_rectDraw);
211 elements.put("test_rectDraw", test_rectDraw);
213 JCheckBox test_rrectDraw = new JCheckBox("Round Rectangle", true);
214 tests.add(test_rrectDraw);
215 elements.put("test_rrectDraw", test_rrectDraw);
217 JCheckBox test_image = new JCheckBox("Images", true);
218 tests.add(test_image);
219 elements.put("test_image", test_image);
221 // Additional image-processing options
222 JPanel extras = new JPanel();
223 extras.setBorder(new BevelBorder(BevelBorder.LOWERED));
224 GridBagLayout layout = new GridBagLayout();
225 GridBagConstraints gbc = new GridBagConstraints();
226 gbc.anchor = GridBagConstraints.NORTHWEST;
227 gbc.insets = new Insets(5, 2, 15, 15);
228 extras.setLayout(layout);
230 // Filling (solid, gradient, or texture)
231 JPanel opt_Fill = new JPanel();
232 opt_Fill.setLayout(new BoxLayout(opt_Fill, BoxLayout.PAGE_AXIS));
233 JLabel opt_FillLabel = new JLabel("Filling:");
234 opt_FillLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
235 opt_Fill.add(opt_FillLabel);
237 ButtonGroup opt_FillGroup = new ButtonGroup();
238 JRadioButton opt_FillSolid = new JRadioButton("Solid colour", true);
239 opt_FillSolid.setActionCommand("solid");
240 opt_Fill.add(opt_FillSolid);
241 opt_FillGroup.add(opt_FillSolid);
242 JRadioButton opt_FillGradient = new JRadioButton("Gradient", false);
243 opt_FillGradient.setActionCommand("gradient");
244 opt_Fill.add(opt_FillGradient);
245 opt_FillGroup.add(opt_FillGradient);
246 JRadioButton opt_FillTexture = new JRadioButton("Texture", false);
247 opt_FillTexture.setActionCommand("texture");
248 opt_Fill.add(opt_FillTexture);
249 opt_FillGroup.add(opt_FillTexture);
250 JTextField opt_FillTextureFile = new JTextField("texture file");
251 opt_FillTextureFile.setAlignmentX(JComponent.LEFT_ALIGNMENT);
252 opt_Fill.add(opt_FillTextureFile);
253 elements.put("opt_FillGroup", opt_FillGroup);
254 elements.put("opt_FillTextureFile", opt_FillTextureFile);
255 layout.setConstraints(opt_Fill, gbc);
256 extras.add(opt_Fill);
259 JPanel opt_Stroke = new JPanel();
260 opt_Stroke.setLayout(new BoxLayout(opt_Stroke, BoxLayout.PAGE_AXIS));
261 JLabel opt_StrokeLabel = new JLabel("Stroke:");
262 opt_StrokeLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
263 opt_Stroke.add(opt_StrokeLabel);
264 JCheckBox opt_StrokeRandom = new JCheckBox("random", false);
265 elements.put("opt_StrokeRandom", opt_StrokeRandom);
266 opt_Stroke.add(opt_StrokeRandom);
267 gbc.gridwidth = GridBagConstraints.REMAINDER;
268 layout.setConstraints(opt_Stroke, gbc);
269 extras.add(opt_Stroke);
272 JPanel opt_Alias = new JPanel();
273 opt_Alias.setLayout(new BoxLayout(opt_Alias, BoxLayout.PAGE_AXIS));
274 JLabel opt_AliasLabel = new JLabel("Anti-Aliasing:");
275 opt_AliasLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
276 opt_Alias.add(opt_AliasLabel);
277 JCheckBox opt_AliasOn = new JCheckBox("on", false);
278 elements.put("opt_AliasOn", opt_AliasOn);
279 opt_Alias.add(opt_AliasOn);
281 layout.setConstraints(opt_Alias, gbc);
282 extras.add(opt_Alias);
285 JPanel opt_Composite = new JPanel();
286 opt_Composite.setLayout(new BoxLayout(opt_Composite, BoxLayout.PAGE_AXIS));
287 JLabel opt_CompositeLabel = new JLabel("Alpha Composite:");
288 opt_CompositeLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
289 opt_Composite.add(opt_CompositeLabel);
290 JTextField opt_CompositeValue = new JTextField("1.0");
291 opt_CompositeValue.setAlignmentX(JComponent.LEFT_ALIGNMENT);
292 elements.put("opt_CompositeValue", opt_CompositeValue);
293 opt_Composite.add(opt_CompositeValue);
294 gbc.gridwidth = GridBagConstraints.REMAINDER;
295 layout.setConstraints(opt_Composite, gbc);
296 extras.add(opt_Composite);
299 // TODO: allow user-defined matrices for AffineTransform
300 // (backend already has hooks for it, need to create gui)
301 JLabel opt_TransformLabel = new JLabel("Transformations:");
302 opt_TransformLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
303 gbc.insets = new Insets(5, 2, 0, 15);
304 layout.setConstraints(opt_TransformLabel, gbc);
305 extras.add(opt_TransformLabel);
307 JPanel opt_Transform_Translate = new JPanel(new GridLayout(0, 2, 5, 5));
308 opt_Transform_Translate.add(new JLabel("x-axis translation "));
309 JTextField opt_TransformTranslateX = new JTextField("0");
310 opt_TransformTranslateX.setAlignmentX(JComponent.LEFT_ALIGNMENT);
311 opt_Transform_Translate.add(opt_TransformTranslateX);
312 elements.put("opt_TransformTranslateX", opt_TransformTranslateX);
313 opt_Transform_Translate.add(new JLabel("y-axis translation "));
314 JTextField opt_TransformTranslateY = new JTextField("0");
315 opt_TransformTranslateY.setAlignmentX(JComponent.LEFT_ALIGNMENT);
316 opt_Transform_Translate.add(opt_TransformTranslateY);
317 elements.put("opt_TransformTranslateY", opt_TransformTranslateY);
319 gbc.insets = new Insets(0, 2, 5, 15);
320 layout.setConstraints(opt_Transform_Translate, gbc);
321 extras.add(opt_Transform_Translate);
323 JPanel opt_Transform_Shear = new JPanel(new GridLayout(0, 2, 5, 5));
324 opt_Transform_Shear.add(new JLabel("x-axis shear "));
325 JTextField opt_TransformShearX = new JTextField("0");
326 opt_TransformShearX.setAlignmentX(JComponent.LEFT_ALIGNMENT);
327 opt_Transform_Shear.add(opt_TransformShearX);
328 elements.put("opt_TransformShearX", opt_TransformShearX);
329 opt_Transform_Shear.add(new JLabel("y-axis shear "));
330 JTextField opt_TransformShearY = new JTextField("0");
331 opt_Transform_Shear.add(opt_TransformShearY);
332 elements.put("opt_TransformShearY", opt_TransformShearY);
333 gbc.gridwidth = GridBagConstraints.REMAINDER;
334 layout.setConstraints(opt_Transform_Shear, gbc);
335 extras.add(opt_Transform_Shear);
337 JPanel opt_Transform_Rotate = new JPanel(new GridLayout(0, 2, 5, 5));
338 opt_Transform_Rotate.add(new JLabel("rotation (radians) "));
339 JTextField opt_TransformRotate = new JTextField("0");
340 opt_Transform_Rotate.add(opt_TransformRotate);
341 elements.put("opt_TransformRotate", opt_TransformRotate);
342 layout.setConstraints(opt_Transform_Rotate, gbc);
343 extras.add(opt_Transform_Rotate);
345 // Final submit button
346 JPanel submit = new JPanel();
347 submit.setLayout(new BoxLayout(submit, BoxLayout.PAGE_AXIS));
349 JButton rectButton = new JButton("Run benchmark");
350 rectButton.setAlignmentX(JComponent.CENTER_ALIGNMENT);
351 submit.add(rectButton, BorderLayout.CENTER);
353 errorLabel.setAlignmentX(JComponent.CENTER_ALIGNMENT);
354 errorLabel.setForeground(Color.RED);
355 submit.add(errorLabel);
357 rectButton.addActionListener(new Harness(elements, errorLabel));
360 JPanel body = new JPanel();
361 body.setLayout(new BoxLayout(body, BoxLayout.LINE_AXIS));
362 options.setAlignmentX(JComponent.LEFT_ALIGNMENT);
364 body.add(Box.createHorizontalStrut(50));
365 tests.setAlignmentX(JComponent.RIGHT_ALIGNMENT);
368 body.setAlignmentX(JComponent.CENTER_ALIGNMENT);
370 extras.setAlignmentX(JComponent.CENTER_ALIGNMENT);
372 submit.setAlignmentX(JComponent.CENTER_ALIGNMENT);
375 content.add(panel, BorderLayout.CENTER);
377 // Leave some breathing space in the frame
380 frame.addWindowListener(new WindowAdapter()
382 public void windowClosing(WindowEvent e)
384 frame.setVisible(false);
393 * Handles user events on the options GUI, ensuring that user input is valid
395 public void actionPerformed(ActionEvent ev)
397 if (! noClipping.isSelected() && ! withClipping.isSelected()
398 && ! zeroClipping.isSelected())
399 errorLabel.setText("You must select at least one clipping option");
401 else if (! singleBuffer.isSelected() && ! doubleBuffer.isSelected())
402 errorLabel.setText("You must select at least one buffering option");
405 errorLabel.setText(" ");
409 * Parses GUI input and sets options in the benchmarker
411 private class Harness
412 implements ActionListener
419 * Creates a new Harness object
421 * @param elements Hashtable containing the swing elements from the GUI
422 * @param errorLabel JLabel on which to display any error messages
424 public Harness(Hashtable elements, JLabel errorLabel)
428 this.elements = elements;
429 this.errorLabel = errorLabel;
433 * Handles user button-clicks, parsing the form, setting options, and
434 * starting the J2dBenchmark
436 * @param ae event that triggered this action
438 public void actionPerformed(ActionEvent ae)
442 // Create benchmarker object
443 final JFrame frame = new JFrame("Java2D benchmark");
444 J2dBenchmarkWrapper speed = new J2dBenchmarkWrapper(frame);
447 speed.setDimensions(Integer.parseInt(((JTextField) elements.get("width")).getText()),
448 Integer.parseInt(((JTextField) elements.get("height")).getText()));
450 speed.setIterations(Integer.parseInt(((JTextField) elements.get("iterations")).getText()));
451 speed.setTestSize(Integer.parseInt(((JTextField) elements.get("size")).getText()));
453 speed.setClipping(((JCheckBox) elements.get("noclip")).isSelected(),
454 ((JCheckBox) elements.get("withclip")).isSelected(),
455 ((JCheckBox) elements.get("zeroclip")).isSelected());
457 speed.setBuffers(((JCheckBox) elements.get("singlebuffer")).isSelected(),
458 ((JCheckBox) elements.get("doublebuffer")).isSelected());
460 // Set additional processing options
461 speed.setFill(((ButtonGroup) elements.get("opt_FillGroup")).getSelection().getActionCommand(),
462 ((JTextField) elements.get("opt_FillTextureFile")).getText());
464 speed.setStroke(((JCheckBox) elements.get("opt_StrokeRandom")).isSelected());
466 speed.setAlias(((JCheckBox) elements.get("opt_AliasOn")).isSelected());
468 speed.setComposite(Float.parseFloat(((JTextField) elements.get("opt_CompositeValue")).getText()));
470 speed.setTranslation(Integer.parseInt(((JTextField) elements.get("opt_TransformTranslateX")).getText()),
471 Integer.parseInt(((JTextField) elements.get("opt_TransformTranslateY")).getText()));
473 speed.setRotation(Double.parseDouble(((JTextField) elements.get("opt_TransformRotate")).getText()));
475 speed.setShear(Double.parseDouble(((JTextField) elements.get("opt_TransformShearX")).getText()),
476 Double.parseDouble(((JTextField) elements.get("opt_TransformShearY")).getText()));
480 if (((JCheckBox) elements.get("test_arcDraw")).isSelected())
481 testSuite |= J2dBenchmarkWrapper.J2DTEST_ARC;
482 if (((JCheckBox) elements.get("test_ccurveDraw")).isSelected())
483 testSuite |= J2dBenchmarkWrapper.J2DTEST_CUBICCURVE;
484 if (((JCheckBox) elements.get("test_ellipseDraw")).isSelected())
485 testSuite |= J2dBenchmarkWrapper.J2DTEST_ELLIPSE;
486 //if (((JCheckBox)elements.get("test_pathDraw")).isSelected())
487 // testSuite |= J2dBenchmarkWrapper.J2DTEST_GENERALPATH;
488 if (((JCheckBox) elements.get("test_lineDraw")).isSelected())
489 testSuite |= J2dBenchmarkWrapper.J2DTEST_LINE;
490 if (((JCheckBox) elements.get("test_qcurveDraw")).isSelected())
491 testSuite |= J2dBenchmarkWrapper.J2DTEST_QUADCURVE;
492 if (((JCheckBox) elements.get("test_rectDraw")).isSelected())
493 testSuite |= J2dBenchmarkWrapper.J2DTEST_RECTANGLE;
494 if (((JCheckBox) elements.get("test_rrectDraw")).isSelected())
495 testSuite |= J2dBenchmarkWrapper.J2DTEST_ROUNDRECTANGLE;
496 if (((JCheckBox) elements.get("test_image")).isSelected())
497 testSuite |= J2dBenchmarkWrapper.J2DTEST_IMAGE;
501 speed.setTests(testSuite);
503 String initResult = speed.init();
505 if (initResult == null)
508 frame.add(speed, BorderLayout.CENTER);
510 Integer.parseInt(((JTextField) elements.get("width")).getText()),
511 Integer.parseInt(((JTextField) elements.get("height")).getText()));
512 frame.setVisible(true);
514 // Insets are correctly set only after the native peer was
516 Insets insets = frame.getInsets();
517 frame.setSize(frame.getWidth() + insets.right + insets.left,
518 frame.getHeight() + insets.top + insets.bottom);
520 // Clear any old error messages
521 errorLabel.setText(" ");
524 errorLabel.setText(initResult);
527 errorLabel.setText("Please select at least one test.");
529 catch (NumberFormatException e)
531 errorLabel.setText("Please enter valid integers");
537 * Wrapper for the J2dBenchmark, which outputs the results to a GUI
538 * instead of the command-line
540 private class J2dBenchmarkWrapper
545 ResultsDisplay display;
548 * Create new J2dBenchmarkWrapper object
550 * @param frame parent frame
552 public J2dBenchmarkWrapper(JFrame frame)
554 // Redirect log messages to the custom handler
555 logger.setUseParentHandlers(false);
556 display = new ResultsDisplay();
557 display.setLevel(Level.INFO);
558 logger.addHandler(display);
564 * Set dimensions of benchmarking canvas
566 * @param width width of canvas
567 * @param height height of canvas
569 public void setDimensions(int width, int height)
571 screenHeight = height;
573 setSize(width, height);
577 * Set number of iterations
579 * @param it number of iterations
581 public void setIterations(int it)
587 * Set size of each test
589 * @param size size of test
591 public void setTestSize(int size)
597 * Set clipping options
599 * @param no run test with no clipping
600 * @param with run test with clipping
601 * @param zero run test with clipping to zero
603 public void setClipping(boolean no, boolean with, boolean zero)
605 this.noClippingFlag = no;
606 this.withClippingFlag = with;
607 this.zeroClippingFlag = zero;
611 * Set buffering options
613 * @param single run test without double-buffering
614 * @param doubleb run test with double-buffering
616 public void setBuffers(boolean single, boolean doubleb)
618 this.singleBufferFlag = single;
619 this.doubleBufferFlag = doubleb;
625 * @param type fill type: "solid", "gradient", or "texture"
626 * @param file filename to use if texturing
628 public void setFill(String type, String file)
630 if (type.equals("gradient"))
631 this.gradientFlag = true;
632 else if (type.equals("texture"))
641 * @param stroke boolean flag to use random stroking or not
643 public void setStroke(boolean stroke)
645 this.strokeFlag = stroke;
649 * Set anti-aliasing options
651 * @param alias boolean flag to use anti-aliasing or not
653 public void setAlias(boolean alias)
655 this.antialiasFlag = alias;
659 * Set alpha composite
661 * @param alpha alpha composite
663 public void setComposite(float alpha)
665 this.composite = alpha;
669 * Set translation values
671 * @param x x-axis translation
672 * @param y y-axis translation
674 public void setTranslation(int x, int y)
683 * @param theta angle to rotate by (radians)
685 public void setRotation(double theta)
693 * @param x x-axis shear value
694 * @param y-axis shear value
696 public void setShear(double x, double y)
705 * @param tests bit-shifted list of tests (see J2dBenchmark constants)
707 public void setTests(int tests)
713 * Saves test report after each iteration
717 // Report test results to the GUI display
718 ArrayList results = new ArrayList();
719 for (Iterator i = testSetMap.testIterator(); i.hasNext();)
721 TestRecorder recorder = testSetMap.getTest((String) i.next());
723 results.add("TEST " + recorder.getTestName() + ": average "
724 + recorder.getAverage() + "ms [" + recorder.getMinTime()
725 + "-" + recorder.getMaxTime() + "]");
728 display.report(results);
732 * Disables current frame and displays test results
736 // Clear benchmarking canvas and display results instead
737 myFrame.setVisible(false);
744 * GUI to display results of benchmarking
746 private class ResultsDisplay
748 implements ActionListener
751 * Allow user to select results from each iteration
753 JComboBox iterations;
756 * Area to print results in
761 * Allow user to view summary or full details of test report
766 * Store all test results
768 ArrayList testResults;
771 * Store all test details
773 ArrayList testDetails;
776 * Initialize variables
778 public ResultsDisplay()
780 testResults = new ArrayList();
781 testDetails = new ArrayList();
782 testDetails.add(new ArrayList());
786 * Parse all results and display on a GUI
791 JFrame frame = new JFrame("Java2D benchmark results");
792 Container cp = frame.getContentPane();
794 // Non-editable text area for the results
795 results = new JTextArea();
796 results.setEditable(false);
798 results.setColumns(60);
800 // Checkbox to optionally display details (ie log messages)
801 details = new JCheckBox("Details", false);
802 details.addActionListener(this);
804 // Combo box to allow selection of iteration number
805 iterations = new JComboBox();
806 iterations.addActionListener(this);
807 for (int i = 0; i < testResults.size(); i++)
808 iterations.addItem("Iteration #" + (i + 1));
811 JPanel topleft = new JPanel();
812 topleft.add(new JLabel("View results from: "));
813 topleft.add(iterations);
814 topleft.setAlignmentX(JComponent.LEFT_ALIGNMENT);
815 details.setAlignmentX(JComponent.RIGHT_ALIGNMENT);
816 JPanel top = new JPanel();
817 top.setLayout(new BoxLayout(top, BoxLayout.LINE_AXIS));
821 cp.add(top, BorderLayout.NORTH);
822 cp.add(new JScrollPane(results), BorderLayout.SOUTH);
829 * This overrides the logger publish method, which accepts log messages and
830 * saves them for later display
832 * @param record information about the log event
834 public void publish(LogRecord record)
836 ((ArrayList) testDetails.get(testDetails.size() - 1)).add(record.getMessage());
840 * Accepts a test summary report, generated after each iteration of a test
842 * @param results test results
844 public void report(ArrayList results)
846 testResults.add(results);
847 testDetails.add(new ArrayList());
851 * Provided as part of the Handler interface; not used
858 * Provided as part of the Handler interface; not used
865 * Handle user-generated events on the results GUI
867 public void actionPerformed(ActionEvent ev)
869 // Display information about the requested iteration
870 int iteration = iterations.getSelectedIndex();
873 // Display summary or details, as requested
875 if (details.isSelected())
876 it = ((ArrayList) testDetails.get(iteration)).iterator();
878 it = ((ArrayList) testResults.get(iteration)).iterator();
880 // Parse the ArrayList's
883 message = message + ((String) it.next() + "\n");
887 results.setText(message);