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
/**
* BlueCove - Java library for Bluetooth
* Copyright (C) 2006-2007 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.awt;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import net.sf.bluecove.Configuration;

public class ObexClientConnectionDialog extends Dialog {

private static final long serialVersionUID = 1L;

private static final String configObexConnectionURL = "obexConnectionURL";

Button btnCancel, btnPut, btnGet, btnDisconnect;

TextField tfURL;

Choice choiceAllURLs;

TextField tfName;

TextField tfData;

Checkbox cbTimeout;

Label status;

ObexClientConnectionThread thread;

Timer monitorTimer;

private class ObexConnectionMonitor extends TimerTask {

public void run() {
if (thread != null) {
status.setText(thread.status);
if (!thread.isRunning) {
btnDisconnect.setEnabled(false);
btnPut.setEnabled(true);
btnGet.setEnabled(true);
}
} else {
status.setText("Idle");
btnDisconnect.setEnabled(false);
btnPut.setEnabled(true);
btnGet.setEnabled(true);
}
}
}

public ObexClientConnectionDialog(Frame owner) {
super(owner, "OBEX Client", false);

Font font = new Font("Monospaced", Font.PLAIN, Configuration.screenSizeSmall ? 9 : 12);
this.setFont(font);

GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;

Panel panelItems = new BorderPanel(gridbag);
panelItems.setFont(font);
this.add(panelItems, BorderLayout.NORTH);

Label l = new Label("URL:");
panelItems.add(l);
panelItems.add(tfURL = new TextField("", 25));
c.gridwidth = 1;
gridbag.setConstraints(l, c);
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(tfURL, c);

if (Configuration.storage != null) {
tfURL.setText(Configuration.storage.retriveData(configObexConnectionURL));
}

Label l1 = new Label("Discovered:");
panelItems.add(l1);
choiceAllURLs = new Choice();
c.gridwidth = 1;
gridbag.setConstraints(l1, c);
panelItems.add(choiceAllURLs);
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(choiceAllURLs, c);

Font logFont = new Font("Monospaced", Font.PLAIN, Configuration.screenSizeSmall ? 9 : 12);
choiceAllURLs.setFont(logFont);

ServiceRecords.populateChoice(choiceAllURLs, true);
choiceAllURLs.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
selectURL();
}
});

Label l2 = new Label("Data:");
panelItems.add(l2);
panelItems.add(tfData = new TextField("Test Obex Message " + new Date().toString()));
c.gridwidth = 1;
gridbag.setConstraints(l2, c);
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(tfData, c);

Label l3 = new Label("Name:");
panelItems.add(l3);
panelItems.add(tfName = new TextField("test.txt"));
c.gridwidth = 1;
gridbag.setConstraints(l3, c);
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(tfName, c);

Label l4 = new Label("Timeouts:");
panelItems.add(l4);
panelItems.add(cbTimeout = new Checkbox());
c.gridwidth = 1;
gridbag.setConstraints(l4, c);
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(cbTimeout, c);

Label ls = new Label("Status:");
panelItems.add(ls);
c.gridwidth = 1;
gridbag.setConstraints(ls, c);

status = new Label("Idle");
panelItems.add(status);
c.gridwidth = 2;
gridbag.setConstraints(status, c);

Panel panelBtns = new Panel();
panelBtns.setFont(font);
this.add(panelBtns, BorderLayout.SOUTH);

panelBtns.add(btnPut = new Button("Put"));
btnPut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
send(true);
}
});

panelBtns.add(btnGet = new Button("Get"));
btnGet.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
send(false);
}
});

panelBtns.add(btnDisconnect = new Button("Disconnect"));
btnDisconnect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
shutdown();
}
});
btnDisconnect.setEnabled(false);

panelBtns.add(btnCancel = new Button("Cancel"));
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onClose();
}
});

this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onClose();
}
});
this.pack();
OkCancelDialog.centerParent(this);

try {
monitorTimer = new Timer();
monitorTimer.schedule(new ObexConnectionMonitor(), 1000, 700);
} catch (Throwable java11) {
}
}

protected void selectURL() {
String url = ServiceRecords.getChoiceURL(choiceAllURLs);
if (url != null) {
tfURL.setText(url);
}
}

protected void send(boolean isPut) {
if (thread != null) {
thread.shutdown();
thread = null;
}
if (Configuration.storage != null) {
Configuration.storage.storeData(configObexConnectionURL, tfURL.getText());
}
thread = new ObexClientConnectionThread(tfURL.getText(), tfName.getText(), tfData.getText(), isPut);
thread.timeouts = cbTimeout.getState();
thread.setDaemon(true);
thread.start();
btnDisconnect.setEnabled(true);
btnPut.setEnabled(false);
btnGet.setEnabled(false);
}

public void shutdown() {
if (thread != null) {
thread.shutdown();
thread = null;
}
}

protected void onClose() {
shutdown();
try {
monitorTimer.cancel();
} catch (Throwable java11) {
}
setVisible(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

r2471 by skarzhevskyy on Nov 30, 2008   Diff
Change license to Apache License,
Version 2.0, Update headers
r2450 by skarzhevskyy on Nov 14, 2008   Diff
Implementation of
DiscoveryAgent.retrieveDevices on MS
stack
New interface functions for other
stacks.
r2408 by skarzhevskyy on Oct 9, 2008   Diff
organize product to modules
All revisions of this file

File info

Size: 6921 bytes, 261 lines

File properties

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