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

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.bluetooth.LocalDevice;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;

/**
*
*/
public class Main extends JFrame implements ActionListener, UserInteraction {

private static final long serialVersionUID = 1L;

private JLabel iconLabel;

private String status;

JProgressBar progressBar;

private ImageIcon btIcon;

private ImageIcon transferIcon;

private JButton btExit;

private OBEXServer server;

private static void createAndShowGUI(final String[] args) {
final Main app = new Main();
app.pack();
app.center();
app.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
app.initializeServer();
}
});
}

public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI(args);
}
});
}

private void center() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(((screenSize.width - this.getWidth()) / 2), ((screenSize.height - this.getHeight()) / 2));
}

private Main() {
super("BlueCove OBEX Server");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Image btImage = Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/icon.png"));
btIcon = new ImageIcon(btImage);
transferIcon = new ImageIcon((Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/transfer.png"))));

this.setIconImage(btImage);

JPanel contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(new BorderLayout(10, 10));
contentPane.setBorder(new EmptyBorder(10, 10, 10, 10));

JPanel progressPanel = new JPanel();
progressPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();

iconLabel = new JLabel();
iconLabel.setIcon(btIcon);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
progressPanel.add(iconLabel, c);

progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);

c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.REMAINDER;
progressPanel.add(progressBar, c);

getContentPane().add(progressPanel, BorderLayout.NORTH);

JPanel actionPanel = new JPanel();
actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.LINE_AXIS));
actionPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
actionPanel.add(Box.createHorizontalGlue());

actionPanel.add(btExit = new JButton("Exit"));
btExit.addActionListener(this);

contentPane.add(actionPanel, BorderLayout.SOUTH);

}

/*
* (non-Javadoc)
*
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btExit) {
shutdown();
System.exit(0);
}
}

public void showStatus(final String message) {
status = message;
progressBar.setString(message);
}

public void setProgressMaximum(int n) {
progressBar.setMaximum(n);
}

public void setProgressValue(int n) {
progressBar.setValue(n);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressBar.setString(status);
}
});
}

public void setProgressDone() {
progressBar.setValue(0);
}

protected void disabledBluetooth() {
showStatus("BlueCove not avalable");
iconLabel.setIcon(new ImageIcon((Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/bt-off.png")))));
}

private boolean initializeServer() {
try {
LocalDevice localDevice = LocalDevice.getLocalDevice();
if ("000000000000".equals(localDevice.getBluetoothAddress())) {
throw new Exception();
}
server = OBEXServer.startServer(this);
showStatus("BlueCove Ready");
return true;
} catch (Throwable e) {
Logger.debug(e);
disabledBluetooth();
return false;
}
}

private void shutdown() {
if (server != null) {
server.close();
}
}
}

Change log

r2916 by skarzhevskyy on Mar 13, 2009   Diff
Updated javadocs and Copyright
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
r2408 by skarzhevskyy on Oct 9, 2008   Diff
organize product to modules
r2276 by skarzhevskyy on Jun 9, 2008   Diff
show upload progress
All revisions of this file

File info

Size: 5402 bytes, 201 lines

File properties

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