My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/**
* BlueCove - Java library for Bluetooth
* Copyright (C) 2006-2009 Vlad Skarzhevskyy
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @author vlads
* @version $Id$
*/
package net.sf.bluecove.swing;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import net.sf.bluecove.Configuration;
import net.sf.bluecove.Switcher;
import net.sf.bluecove.se.BlueCoveSpecific;
import net.sf.bluecove.se.FileStorage;
import net.sf.bluecove.se.JavaSECommon;
import net.sf.bluecove.se.UIHelper;

import org.bluecove.tester.log.Logger;
import org.bluecove.tester.log.LoggerAppender;
import org.bluecove.tester.util.TimeUtils;

/**
*
*
*/
public class Main extends JFrame implements LoggerAppender {

private static final long serialVersionUID = 1L;

private JTextArea output = null;

private int outputLines = 0;

private Vector logLinesQueue = new Vector();

private boolean logUpdaterRunning = false;

JMenuItem debugOn;

public static void main(String[] args) {
JavaSECommon.initOnce();
Configuration.storage = new FileStorage();

Main app = new Main();
app.setVisible(true);

Logger.debug("Stated app");
Logger.debug("OS:" + System.getProperty("os.name") + "|" + System.getProperty("os.version") + "|"
+ System.getProperty("os.arch"));
Logger.debug("Java:" + System.getProperty("java.vendor") + " " + System.getProperty("java.version") + " " +System.getProperty("java.vm.version"));
}

Main() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent w) {
quit();
}
});

Logger.addAppender(this);
BlueCoveSpecific.addAppender(this);

this.setTitle("BlueCove tester");

final JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menuBluetooth = new JMenu("Bluetooth");

final JMenuItem serverStart = addMenu(menuBluetooth, "Server Start", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startServer();
updateTitle();
}
}, KeyEvent.VK_5);

final JMenuItem serverStop = addMenu(menuBluetooth, "Server Stop", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.serverShutdown();
}
}, KeyEvent.VK_6);

final JMenuItem clientStart = addMenu(menuBluetooth, "Client Start", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startClient();
updateTitle();
}
}, KeyEvent.VK_2);

final JMenuItem clientStop = addMenu(menuBluetooth, "Client Stop", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.clientShutdown();
}
}, KeyEvent.VK_3);

final JMenuItem tckStart;
if (Configuration.likedTCKAgent) {
tckStart = addMenu(menuBluetooth, "Start TCK Agent", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startTCKAgent();
}
});
} else {
tckStart = null;
}

addMenu(menuBluetooth, "Discovery", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startDiscovery();
updateTitle();
}
}, KeyEvent.VK_MULTIPLY);

addMenu(menuBluetooth, "Services Search", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startServicesSearch();
updateTitle();
}
}, KeyEvent.VK_7);

addMenu(menuBluetooth, "Client Stress Start", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startClientStress();
updateTitle();
}
});

addMenu(menuBluetooth, "Client selectService Start", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startClientSelectService();
updateTitle();
}
});

addMenu(menuBluetooth, "Client Last service Start", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startClientLastURl();
updateTitle();
}
});

addMenu(menuBluetooth, "Client Last device Start", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.startClientLastDevice();
updateTitle();
}
});

final JMenuItem stop = addMenu(menuBluetooth, "Stop all work", new ActionListener() {
public void actionPerformed(ActionEvent e) {
Switcher.clientShutdown();
Switcher.serverShutdown();
}
}, KeyEvent.VK_S);

addMenu(menuBluetooth, "Quit", new ActionListener() {
public void actionPerformed(ActionEvent e) {
quit();
}
}, KeyEvent.VK_X);

menuBar.add(menuBluetooth);

JMenu menuLogs = new JMenu("Logs");

debugOn = addMenu(menuLogs, "BlueCove Debug ON", new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean dbg = BlueCoveSpecific.changeDebug();
if (dbg) {
debugOn.setText("BlueCove Debug OFF");
} else {
debugOn.setText("BlueCove Debug ON");
}
}
});

addMenu(menuLogs, "Clear Log", new ActionListener() {
public void actionPerformed(ActionEvent e) {
clear();
}
}, KeyEvent.VK_Z);

addMenu(menuLogs, "Print FailureLog", new ActionListener() {
public void actionPerformed(ActionEvent e) {
UIHelper.printFailureLog();
}
}, KeyEvent.VK_4);

addMenu(menuLogs, "Clear Stats", new ActionListener() {
public void actionPerformed(ActionEvent e) {
UIHelper.clearStats();
}
});

if (JavaSECommon.isJava5()) {
addMenu(menuLogs, "ThreadDump", new ActionListener() {
public void actionPerformed(ActionEvent e) {
JavaSECommon.threadDump();
}
});
}

menuBar.add(menuLogs);

output = new JTextArea("");
output.setEditable(false);
Font logFont = new Font("Monospaced", Font.PLAIN, 12);
output.setFont(logFont);

JScrollPane scroll = new JScrollPane(output, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
getContentPane().add(scroll);

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
if (screenSize.height < 400) {
Configuration.screenSizeSmall = true;
Font smallLogFont = new Font("Monospaced", Font.PLAIN, 9);
output.setFont(smallLogFont);
}

if (screenSize.width > 600) {
screenSize.setSize(240, 320);
}
if (this.isResizable()) {
Rectangle b = this.getBounds();
b.x = Integer.valueOf(Configuration.getStorageData("main.x", "0")).intValue();
b.y = Integer.valueOf(Configuration.getStorageData("main.y", "0")).intValue();
b.height = Integer.valueOf(Configuration.getStorageData("main.height", String.valueOf(screenSize.height)))
.intValue();
b.width = Integer.valueOf(Configuration.getStorageData("main.width", String.valueOf(screenSize.width)))
.intValue();
this.setBounds(b);
}
}

private JMenuItem addMenu(JMenu menu, String name, ActionListener l) {
return addMenu(menu, name, l, 0);
}

private JMenuItem addMenu(JMenu menu, String name, ActionListener l, int key) {
JMenuItem menuItem = new JMenuItem(name);
menuItem.addActionListener(l);
menu.add(menuItem);
if (key != 0) {
// menuItem.setShortcut(new MenuShortcut(key, false));
}
return menuItem;
}

private void updateTitle() {
this.setTitle(UIHelper.getMainWindowTitle());
}

private void clear() {
if (output == null) {
return;
}
output.setText("");
outputLines = 0;
}

private void quit() {
Logger.debug("quit");
Switcher.clientShutdown();
Switcher.serverShutdownOnExit();

Rectangle b = this.getBounds();
Configuration.storeData("main.x", String.valueOf(b.x));
Configuration.storeData("main.y", String.valueOf(b.y));
Configuration.storeData("main.height", String.valueOf(b.height));
Configuration.storeData("main.width", String.valueOf(b.width));

Logger.removeAppender(this);
BlueCoveSpecific.removeAppender();

// this.dispose();
System.exit(0);
}

public void appendLog(int level, String message, Throwable throwable) {
if (output == null) {
return;
}
final StringBuffer buf = new StringBuffer();

if (Configuration.logTimeStamp) {
String time = TimeUtils.timeNowToString();
buf.append(time).append(" ");
}

switch (level) {
case Logger.ERROR:
// errorCount ++;
buf.append("e.");
break;
case Logger.WARN:
buf.append("w.");
break;
case Logger.INFO:
buf.append("i.");
break;
}
buf.append(message);
if (throwable != null) {
buf.append(' ');
String className = throwable.getClass().getName();
buf.append(className.substring(1 + className.lastIndexOf('.')));
if (throwable.getMessage() != null) {
buf.append(':');
buf.append(throwable.getMessage());
}
}
buf.append("\n");
boolean createUpdater = false;
synchronized (logLinesQueue) {
if (logLinesQueue.isEmpty()) {
createUpdater = true;
} else {
createUpdater = !logUpdaterRunning;
}
logLinesQueue.addElement(buf.toString());
}
if (createUpdater) {
try {
EventQueue.invokeLater(new AwtLogUpdater());
} catch (NoSuchMethodError java1) {
(new AwtLogUpdater()).run();
}
}
}

private class AwtLogUpdater implements Runnable {

private String getNextLine() {
synchronized (logLinesQueue) {
if (logLinesQueue.isEmpty()) {
return null;
}
String line = (String) logLinesQueue.firstElement();
logLinesQueue.removeElementAt(0);
return line;
}
}

public void run() {
int oneCallCount = 0;
synchronized (logLinesQueue) {
logUpdaterRunning = true;
}
String line;
try {
while ((line = getNextLine()) != null) {
output.append(line);
outputLines++;
if (outputLines > 5000) {
clear();
}
oneCallCount++;
if (oneCallCount > 40) {
break;
}
}
} finally {
synchronized (logLinesQueue) {
logUpdaterRunning = false;
}
}
}
}
}

Change log

r2937 by skarzhevskyy on Mar 20, 2009   Diff
tests on Windows Mobile
Go to: 
Project members, sign in to write a code review

Older revisions

r2916 by skarzhevskyy on Mar 13, 2009   Diff
Updated javadocs and Copyright
r2607 by skarzhevskyy on Dec 17, 2008   Diff
OBEX tests in J2ME
r2471 by skarzhevskyy on Nov 30, 2008   Diff
Change license to Apache License,
Version 2.0, Update headers
All revisions of this file

File info

Size: 10852 bytes, 404 lines

File properties

svn:mime-type
text/plain
svn:eol-style
native
svn:keywords
Date Author Id Revision
Powered by Google Project Hosting