1 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.applet.*; 6 import java.io.*; 7 import org.ozoneDB.tools.ChartCanvas; 8 9 10 11 public class CattellApplet extends Applet implements ActionListener, ItemListener { 12 13 14 15 class BenchmarkThread extends Thread { 16 private boolean chartOnly = true; 17 private String [] args = null; 18 19 20 21 public BenchmarkThread( boolean co, String [] a ) { 22 chartOnly = co; 23 args = a; 24 } 25 26 27 28 public void run() { 29 } 30 } 31 32 33 34 public class AppletWriter extends Writer { 35 36 37 38 public AppletWriter() { 39 } 40 41 42 43 public void write( char[] cbuf, int off, int len ) throws IOException { 44 String text = new String ( cbuf, off, len ); 45 if (outText != null) { 46 outText.append( text ); 47 } 48 if (chart != null) { 49 int tpos = text.indexOf( "time: " ); 50 if (tpos > -1) { 51 tpos += 6; 52 int mpos = text.indexOf( "ms", tpos ); 53 if (mpos > -1) { 54 chart.appendTime( new Integer ( text.substring( tpos, mpos ).trim() ).intValue() ); 55 } 56 } 57 } 58 } 59 60 61 62 public void flush() throws IOException { 63 } 64 65 66 67 public void close() throws IOException { 68 } 69 } 70 71 72 protected Button startButton; 73 protected Choice testChoice; 74 protected TextField sizeText; 75 protected TextField nameText; 76 protected TextField serverText; 77 protected TextArea outText; 78 protected Label statusLabel; 79 protected ChartCanvas chart; 80 81 82 83 public void init() { 84 init( false ); 85 } 86 87 88 89 public void init( boolean chartOnly ) { 90 setLayout( new BorderLayout() ); 91 92 if (!chartOnly) { 93 Panel panel = new Panel(); 94 panel.setLayout( new FlowLayout( FlowLayout.LEFT ) ); 95 96 startButton = new Button( " Start " ); 97 startButton.setFont( new Font( "Monospaced", Font.BOLD, 14 ) ); 98 startButton.addActionListener( this ); 99 panel.add( startButton ); 100 101 testChoice = new Choice(); 102 testChoice.add( "Help" ); 103 testChoice.add( "1 Create" ); 104 testChoice.add( "2 Lookup" ); 105 testChoice.add( "3 Traversal" ); 106 testChoice.add( "4 Ins & del" ); 107 testChoice.add( "5 Insert" ); 108 testChoice.add( "6 Ins*1000" ); 109 testChoice.add( "7 Traversal" ); 110 testChoice.add( "8 Insert" ); 111 testChoice.addItemListener( this ); 112 panel.add( testChoice ); 113 114 sizeText = new TextField( "1000", 5 ); 115 sizeText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) ); 116 sizeText.addActionListener( this ); 117 panel.add( sizeText ); 119 120 nameText = new TextField( "cattell", 9 ); 121 nameText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) ); 122 nameText.addActionListener( this ); 123 panel.add( nameText ); 125 126 serverText = new TextField( "localhost", 9 ); 127 serverText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) ); 128 serverText.addActionListener( this ); 129 panel.add( serverText ); 131 132 add( "North", panel ); 133 134 panel = new Panel(); 135 panel.setLayout( new BorderLayout() ); 136 137 outText = new TextArea(); 138 panel.add( outText, "North" ); 139 140 chart = new ChartCanvas(); 141 panel.add( chart, "Center" ); 142 143 add( "Center", panel ); 144 145 statusLabel = new Label( "Test:Build - Size:1000 - Name:cattell " ); 146 add( "South", statusLabel ); 147 } else { 148 chart = new ChartCanvas(); 149 add( "Center", chart ); 150 } 151 } 152 153 154 155 public void itemStateChanged( ItemEvent e ) { 156 String [] defaults = {"0", "1000", "100", "7", "100", "100", "10", "10", "10"}; 157 if (testChoice.getSelectedIndex() > -1) { 158 sizeText.setText( defaults[testChoice.getSelectedIndex()] ); 159 } 160 } 161 162 163 164 public void actionPerformed( ActionEvent e ) { 165 int test = testChoice.getSelectedIndex(); 166 int size = Integer.valueOf( sizeText.getText() ).intValue(); 167 String name = nameText.getText(); 168 String server = serverText.getText(); 169 statusLabel.setText( "Test:" + test + " Size:" + size + " Name:" + name ); 170 171 String [] args = {"" + test, "" + size, "" + name, "" + server}; 172 runBenchmark( args ); 173 } 174 175 176 177 public void runBenchmark( String [] args ) { 178 CattellImpl.main( args ); 179 } 180 181 182 183 static class MyAdapter extends WindowAdapter { 184 185 186 public void windowClosing( WindowEvent e ) { 187 System.exit( 0 ); 188 } 189 } 190 191 192 193 public static void main( String [] args ) { 194 boolean chartOnly = false; 195 String [] cattellArgs = new String [0]; 196 int argCount = 0; 197 198 if (args.length > 0) { 199 for (int i = 0; i < args.length; i++) { 200 if (args[i].equals( "-chart" )) { 201 chartOnly = true; 202 argCount++; 203 } 204 } 205 } 206 207 Frame f = new Frame( "Cattell Benchmark" ); 208 CattellApplet applet = new CattellApplet(); 209 210 applet.init( chartOnly ); 211 applet.start(); 212 213 f.add( "Center", applet ); 214 f.pack(); 215 f.setSize( chartOnly ? 300 : 500, chartOnly ? 120 : 400 ); 216 f.show(); 217 f.addWindowListener( new MyAdapter() ); 218 219 cattellArgs = new String [args.length - argCount]; 220 System.arraycopy( args, argCount, cattellArgs, 0, cattellArgs.length ); 221 cattellArgs = applet.chart.filterAndApplyArgs( cattellArgs ); 222 if (chartOnly) { 223 applet.runBenchmark( cattellArgs ); 224 } 225 } 226 } 227 | Popular Tags |