0
|
1 |
/*
|
1
|
2 |
* Copyright (c) 2000 - 2006 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
0
|
8 |
*
|
1
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
0
|
17 |
|
|
18 |
package com.nokia.epdt.plugins.s60.pan;
|
|
19 |
|
|
20 |
/* java.awt */
|
|
21 |
import java.awt.Component;
|
1
|
22 |
import java.awt.GridBagConstraints;
|
0
|
23 |
import java.awt.GridBagLayout;
|
|
24 |
import java.awt.event.ActionEvent;
|
|
25 |
import java.awt.event.ActionListener;
|
|
26 |
|
1
|
27 |
import javax.swing.ButtonGroup;
|
|
28 |
import javax.swing.JComboBox;
|
0
|
29 |
import javax.swing.JLabel;
|
1
|
30 |
import javax.swing.JPanel;
|
0
|
31 |
import javax.swing.JRadioButton;
|
|
32 |
import javax.swing.border.EmptyBorder;
|
|
33 |
import javax.swing.border.TitledBorder;
|
|
34 |
|
1
|
35 |
import org.apache.log4j.Logger;
|
|
36 |
|
|
37 |
import com.nokia.epdt.core.CoreUtils;
|
|
38 |
import com.nokia.wtk.util.gui.BorderPanel;
|
0
|
39 |
import com.nokia.wtk.util.gui.GUI;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* PanPluginJPanel
|
|
43 |
*
|
|
44 |
* @version 1.0
|
|
45 |
*/
|
1
|
46 |
class PanPluginJPanel extends JPanel {
|
|
47 |
private static Logger log = Logger.getLogger(PanPluginJPanel.class);
|
0
|
48 |
private static final int GAP = 6;
|
|
49 |
private static final String AUTO_PORT = "auto";
|
1
|
50 |
private static final String[] HCI_MODULES = new String[] { "BCSP"/*, "H4", "USB"*/ };
|
0
|
51 |
private static final int HCI_USB_INDEX = 2;
|
|
52 |
private static final int MAX_COM_PORTS = 16;
|
|
53 |
|
|
54 |
private PanModel panModel;
|
|
55 |
private PanPlugin panPlugin;
|
|
56 |
|
|
57 |
private boolean updateInProgress = false;
|
|
58 |
private JComboBox bluetoothComPortJComboBox;
|
|
59 |
private JRadioButton bluetoothDisableJRadioButton;
|
|
60 |
private JRadioButton bluetoothEnableJRadioButton;
|
|
61 |
private JComboBox bluetoothHciJComboBox;
|
|
62 |
|
|
63 |
/**
|
|
64 |
* Creates new form PanPluginJPanel
|
|
65 |
* @param plugin the plugin that creates this panel
|
|
66 |
* @param connected <code>true</code> if we are connected to the emulator
|
|
67 |
*/
|
1
|
68 |
PanPluginJPanel(PanPlugin plugin) {
|
0
|
69 |
super(new GridBagLayout());
|
|
70 |
panPlugin = plugin;
|
|
71 |
panModel = plugin.getModel();
|
|
72 |
initComponents();
|
|
73 |
}
|
|
74 |
|
1
|
75 |
private static String getResString(String key) {
|
0
|
76 |
return PanResourceBundle.getInstance().getValue(key);
|
|
77 |
}
|
|
78 |
|
1
|
79 |
JPanel buildOnePanel(String t, JRadioButton b1, JRadioButton b2, JPanel c) {
|
0
|
80 |
BorderPanel bp = new BorderPanel(b2);
|
|
81 |
bp.getContentPanel().add(c);
|
|
82 |
|
|
83 |
JPanel p = new JPanel(new GridBagLayout());
|
|
84 |
GridBagConstraints gbc = new GridBagConstraints();
|
|
85 |
|
|
86 |
gbc.weightx = 1.0;
|
|
87 |
gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
88 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
89 |
gbc.anchor = GridBagConstraints.NORTH;
|
|
90 |
gbc.insets.left = bp.getBorder().getBorderInsets(bp).left
|
|
91 |
+ BorderPanel.COMPONENT_INSET_H;
|
|
92 |
p.add(b1, gbc);
|
|
93 |
|
|
94 |
gbc.weighty = 1.0;
|
|
95 |
gbc.insets.left = 0;
|
|
96 |
gbc.fill = GridBagConstraints.BOTH;
|
|
97 |
gbc.gridheight = GridBagConstraints.REMAINDER;
|
|
98 |
p.add(bp, gbc);
|
|
99 |
|
|
100 |
int left = BorderPanel.COMPONENT_INSET_H + GAP;
|
|
101 |
c.setBorder(new EmptyBorder(0, left, GAP, GAP));
|
|
102 |
p.setBorder(new TitledBorder(t));
|
|
103 |
return p;
|
|
104 |
}
|
|
105 |
|
|
106 |
/** This method is called from within the constructor to
|
|
107 |
* initialize the form.
|
|
108 |
*/
|
1
|
109 |
private void initComponents() {
|
0
|
110 |
Object[] btComPorts = new Object[MAX_COM_PORTS];
|
1
|
111 |
for (int i = 0; i < MAX_COM_PORTS; i++) {
|
0
|
112 |
String label = Integer.toString(i + 1);
|
|
113 |
btComPorts[i] = new ComPortItem(label);
|
|
114 |
}
|
|
115 |
|
|
116 |
bluetoothDisableJRadioButton = new JRadioButton(
|
|
117 |
getResString(PanConstants.BLUETOOTH_DISABLE_LABEL));
|
|
118 |
bluetoothEnableJRadioButton = new JRadioButton(
|
|
119 |
getResString(PanConstants.BLUETOOTH_ENABLE_LABEL));
|
|
120 |
bluetoothComPortJComboBox = new JComboBox(btComPorts);
|
|
121 |
bluetoothHciJComboBox = new JComboBox(HCI_MODULES);
|
|
122 |
|
|
123 |
// Bluetooth
|
|
124 |
JPanel bluetoothEnableJPanel = GUI
|
1
|
125 |
.createRowPanel(new Component[] {
|
0
|
126 |
new JLabel(
|
|
127 |
getResString(PanConstants.BLUETOOTH_COM_PORT_LABEL)),
|
|
128 |
bluetoothComPortJComboBox,
|
|
129 |
new JLabel(
|
|
130 |
getResString(PanConstants.BLUETOOTH_COM_HCI_LABEL)),
|
1
|
131 |
bluetoothHciJComboBox });
|
0
|
132 |
|
|
133 |
JPanel bluetoothJPanel = buildOnePanel(
|
|
134 |
getResString(PanConstants.BLUETOOTH_BORDER_TITLE),
|
|
135 |
bluetoothDisableJRadioButton, bluetoothEnableJRadioButton,
|
|
136 |
bluetoothEnableJPanel);
|
|
137 |
|
|
138 |
ButtonGroup bluetoothButtonGroup = new ButtonGroup();
|
|
139 |
bluetoothButtonGroup.add(bluetoothDisableJRadioButton);
|
1
|
140 |
bluetoothDisableJRadioButton.addActionListener(new ActionListener() {
|
|
141 |
public void actionPerformed(ActionEvent evt) {
|
0
|
142 |
bluetoothDisableJRadioButtonActionPerformed(evt);
|
|
143 |
}
|
|
144 |
});
|
|
145 |
|
|
146 |
bluetoothButtonGroup.add(bluetoothEnableJRadioButton);
|
1
|
147 |
bluetoothEnableJRadioButton.addActionListener(new ActionListener() {
|
|
148 |
public void actionPerformed(ActionEvent evt) {
|
0
|
149 |
bluetoothEnableJRadioButtonActionPerformed(evt);
|
|
150 |
}
|
|
151 |
});
|
|
152 |
|
1
|
153 |
bluetoothComPortJComboBox.addActionListener(new ActionListener() {
|
|
154 |
public void actionPerformed(ActionEvent evt) {
|
0
|
155 |
bluetoothComPortJComboBoxActionPerformed(evt);
|
|
156 |
}
|
|
157 |
});
|
|
158 |
|
1
|
159 |
bluetoothHciJComboBox.addActionListener(new ActionListener() {
|
|
160 |
public void actionPerformed(ActionEvent evt) {
|
0
|
161 |
bluetoothHciJComboBoxActionPerformed(evt);
|
|
162 |
}
|
|
163 |
});
|
|
164 |
|
|
165 |
JPanel row = new JPanel(new GridBagLayout());
|
|
166 |
GridBagConstraints gbc = new GridBagConstraints();
|
|
167 |
gbc.gridheight = GridBagConstraints.REMAINDER;
|
|
168 |
gbc.fill = GridBagConstraints.BOTH;
|
|
169 |
gbc.insets.right = GAP;
|
|
170 |
gbc.weightx = 1.0;
|
|
171 |
gbc.weighty = 1.0;
|
|
172 |
row.add(bluetoothJPanel, gbc);
|
|
173 |
|
|
174 |
gbc.insets.right = 0;
|
|
175 |
gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
176 |
|
|
177 |
gbc.gridheight = 1;
|
|
178 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
179 |
gbc.anchor = GridBagConstraints.NORTH;
|
|
180 |
add(row, gbc);
|
|
181 |
|
|
182 |
gbc.gridheight = GridBagConstraints.REMAINDER;
|
|
183 |
gbc.anchor = GridBagConstraints.SOUTH;
|
|
184 |
|
|
185 |
setBorder(new EmptyBorder(GAP, GAP, GAP, GAP));
|
|
186 |
|
|
187 |
//Set the initial values, obtained from .esk files:
|
|
188 |
update();
|
1
|
189 |
log.debug("Done initComponents");
|
0
|
190 |
}
|
|
191 |
|
|
192 |
/**
|
|
193 |
* Update UI components from Model:
|
|
194 |
*/
|
1
|
195 |
public void update() {
|
|
196 |
log.debug("update() updateInProgress: " + updateInProgress);
|
0
|
197 |
// Update Bluetooth panel
|
1
|
198 |
try {
|
|
199 |
if (!updateInProgress)
|
|
200 |
log.debug("Inside if loop of update");
|
|
201 |
{//If the function is not called as the result of components updates,
|
|
202 |
//i.e. there is no update ongiong already
|
|
203 |
updateInProgress = true;
|
|
204 |
boolean bluetoothEnabled = panModel.isBluetoothEnabled();
|
|
205 |
log.debug("bluetooth Enable: " + bluetoothEnabled);
|
|
206 |
int hci = panModel.getBluetoothHci();
|
|
207 |
boolean usb = (hci == HCI_USB_INDEX);
|
|
208 |
log.debug("hci USB index: " + hci);
|
|
209 |
bluetoothDisableJRadioButton.setSelected(!bluetoothEnabled);
|
|
210 |
bluetoothEnableJRadioButton.setSelected(bluetoothEnabled);
|
|
211 |
bluetoothHciJComboBox.setSelectedIndex(bluetoothEnabled ? hci
|
|
212 |
: -1);
|
|
213 |
bluetoothHciJComboBox.setEnabled(bluetoothEnabled);
|
|
214 |
bluetoothComPortJComboBox.setEnabled(bluetoothEnabled);
|
|
215 |
log.debug("bluetooth COM port: " + panModel.getBluetoothComPort());
|
|
216 |
bluetoothComPortJComboBox.setSelectedIndex(panModel
|
|
217 |
.getBluetoothComPort());
|
|
218 |
bluetoothComPortJComboBox.setEnabled(bluetoothEnabled && !usb);
|
0
|
219 |
|
1
|
220 |
updateInProgress = false;
|
|
221 |
log.debug("If loop over");
|
|
222 |
}
|
|
223 |
} catch (RuntimeException e) {
|
|
224 |
log.debug("Runtime Exception: " + e.getMessage());
|
|
225 |
e.printStackTrace();
|
0
|
226 |
}
|
|
227 |
}
|
|
228 |
|
1
|
229 |
private void bluetoothEnableJRadioButtonActionPerformed(ActionEvent evt) {
|
|
230 |
if (!updateInProgress) {//I.e. if update came from UI
|
|
231 |
|
|
232 |
log.debug(CoreUtils.EpocRoot() + FindAvailablePort.EXECUTABLE_FILE_NAME);
|
|
233 |
|
|
234 |
FindAvailablePort availPort = FindAvailablePort.findAvailablePort();
|
|
235 |
String port = null;
|
|
236 |
try {
|
|
237 |
port = availPort.getAvailablePortForBT(CoreUtils.EpocRoot()
|
|
238 |
+ FindAvailablePort.EXECUTABLE_FILE_NAME);
|
|
239 |
|
|
240 |
if (port == null) {
|
|
241 |
log.debug(FindAvailablePort.NO_AVAILABLE_PORT_MESSAGE);
|
|
242 |
// We set the default values of com ports (COM 1) when
|
|
243 |
// switching from disabled mode
|
|
244 |
panModel.setBluetoothComPort(0);
|
|
245 |
} else {
|
|
246 |
log.debug(FindAvailablePort.AVAILABLE_PORT_MESSAGE + port);
|
|
247 |
// Set the port
|
|
248 |
int setTempPort = Integer.parseInt(port.trim())-1;
|
|
249 |
panModel.setBluetoothComPort(setTempPort);
|
|
250 |
System.out.println("Output: " + port);
|
|
251 |
}
|
|
252 |
} catch (Exception e) {
|
|
253 |
log.debug("Error reading COM port. BT enabled. Port set to 1.");
|
|
254 |
// Set the default port 1 as a BT port and enable the BT
|
|
255 |
panModel.setBluetoothComPort(0);
|
|
256 |
e.printStackTrace();
|
0
|
257 |
}
|
|
258 |
|
|
259 |
panPlugin.pluginModelChangedAction();
|
|
260 |
update();
|
|
261 |
}
|
|
262 |
}
|
|
263 |
|
1
|
264 |
private void bluetoothDisableJRadioButtonActionPerformed(ActionEvent evt) {
|
|
265 |
if (!updateInProgress) {//I.e. if update came from UI
|
0
|
266 |
//Setting com port to -1 means disabling it
|
|
267 |
panModel.setBluetoothComPort(-1);
|
|
268 |
panPlugin.pluginModelChangedAction();
|
|
269 |
update();
|
|
270 |
}
|
|
271 |
}
|
|
272 |
|
1
|
273 |
private void bluetoothHciJComboBoxActionPerformed(ActionEvent evt) {
|
|
274 |
if (!updateInProgress) {//I.e. if update came from UI
|
0
|
275 |
int index = bluetoothHciJComboBox.getSelectedIndex();
|
1
|
276 |
if (index >= 0) {
|
0
|
277 |
panModel.setBluetoothHci(index);
|
|
278 |
panPlugin.pluginModelChangedAction();
|
|
279 |
update();
|
|
280 |
}
|
|
281 |
}
|
|
282 |
}
|
|
283 |
|
1
|
284 |
private void bluetoothComPortJComboBoxActionPerformed(ActionEvent evt) {
|
|
285 |
if (!updateInProgress) {//I.e. if update came from UI
|
|
286 |
|
|
287 |
panModel.setBluetoothComPort(bluetoothComPortJComboBox
|
|
288 |
.getSelectedIndex());
|
|
289 |
panPlugin.pluginModelChangedAction();
|
0
|
290 |
}
|
|
291 |
}
|
|
292 |
|
1
|
293 |
private class ComPortItem {
|
0
|
294 |
private String comPortNumber;
|
1
|
295 |
|
|
296 |
ComPortItem(String label) {
|
0
|
297 |
comPortNumber = label;
|
|
298 |
}
|
1
|
299 |
|
|
300 |
public String toString() {
|
|
301 |
|
|
302 |
return panModel.getBluetoothHci() == HCI_USB_INDEX ? AUTO_PORT
|
0
|
303 |
: comPortNumber;
|
|
304 |
}
|
|
305 |
}
|
|
306 |
|
|
307 |
}
|