Source code: com/eireneh/bible/book/swing/BenchmarkPane.java
1
2 package com.eireneh.bible.book.swing;
3
4 import java.awt.*;
5 import java.awt.event.*;
6 import javax.swing.*;
7
8 import com.eireneh.util.*;
9 import com.eireneh.swing.*;
10 import com.eireneh.bible.book.*;
11 import com.eireneh.bible.control.test.*;
12
13 /**
14 * BenchmarkPane allows an application to test the speed of a Bible by
15 * giving it some stress tests.
16 *
17 * <table border='1' cellPadding='3' cellSpacing='0' width="100%">
18 * <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
19 * Distribution Licence:<br />
20 * Project B is free software; you can redistribute it
21 * and/or modify it under the terms of the GNU General Public License,
22 * version 2 as published by the Free Software Foundation.<br />
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.<br />
27 * The License is available on the internet
28 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
29 * <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 * MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
31 * The copyright to this program is held by it's authors.
32 * </font></td></tr></table>
33 * @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
34 * @see docs.Licence
35 * @author Joe Walker
36 */
37 public class BenchmarkPane extends EirPanel
38 {
39 /**
40 * Basic constructor
41 */
42 public BenchmarkPane()
43 {
44 jbInit();
45 }
46
47 /**
48 * Create the GUI components
49 */
50 private void jbInit()
51 {
52 cbo_bible.setModel(mdl_bible);
53 btn_go.setMnemonic('G');
54 btn_go.setText("Go");
55 btn_go.addActionListener(new ActionListener()
56 {
57 public void actionPerformed(ActionEvent ev) { benchmark(); }
58 });
59
60 pnl_north.setLayout(new BorderLayout(5, 5));
61 pnl_north.add(btn_go, BorderLayout.EAST);
62 pnl_north.add(cbo_bible, BorderLayout.CENTER);
63
64 txt_results.setColumns(30);
65 txt_results.setRows(10);
66 scr_results.getViewport().add(txt_results, null);
67
68 this.setLayout(new BorderLayout(5, 5));
69 this.add(pnl_north, BorderLayout.NORTH);
70 this.add(scr_results, BorderLayout.CENTER);
71 }
72
73 /**
74 * Show this Panel in a new dialog
75 */
76 public void showInDialog(Component parent)
77 {
78 showInDialog(parent, "Benchmark", false);
79 }
80
81 /**
82 * Run the benchmark on the selected Bible
83 */
84 private void benchmark()
85 {
86 Bible bible = mdl_bible.getSelectedBible();
87
88 Speed speed = new Speed(bible);
89 speed.run();
90
91 try
92 {
93 float time = speed.getBenchmark() / 1000;
94 txt_results.append("Benchmark for '"+bible.getName()+"': "+time+"s\n");
95 }
96 catch (Exception ex)
97 {
98 Reporter.informUser(this, ex);
99 txt_results.append("Benchmark failed. No timing available.\n");
100 }
101 }
102
103 /* GUI componenets */
104 private BiblesComboBoxModel mdl_bible = new BiblesComboBoxModel();
105 private JPanel pnl_north = new JPanel();
106 private JButton btn_go = new JButton();
107 private JComboBox cbo_bible = new JComboBox();
108 private JScrollPane scr_results = new JScrollPane();
109 private JTextArea txt_results = new JTextArea();
110 }