diff -r b26acd06ea60 -r ac50fd48361b sdkcreationmw/sdkconnectivityfw/emuconnectmanager/epdt_java/src/com/nokia/epdt/plugins/s60/pan/PanPluginJPanel.java --- a/sdkcreationmw/sdkconnectivityfw/emuconnectmanager/epdt_java/src/com/nokia/epdt/plugins/s60/pan/PanPluginJPanel.java Mon Mar 08 12:09:11 2010 +0530 +++ b/sdkcreationmw/sdkconnectivityfw/emuconnectmanager/epdt_java/src/com/nokia/epdt/plugins/s60/pan/PanPluginJPanel.java Wed Apr 21 09:56:53 2010 +0530 @@ -1,61 +1,53 @@ /* -* Copyright (c) 2000 - 2006 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: + * Copyright (c) 2000 - 2006 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". * -*/ - + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ package com.nokia.epdt.plugins.s60.pan; /* java.awt */ import java.awt.Component; -import java.awt.BorderLayout; +import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.awt.GridBagConstraints; - -/* java.awt.event */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -/* javax.swing */ -import javax.swing.Icon; -import javax.swing.JOptionPane; -import javax.swing.JPanel; +import javax.swing.ButtonGroup; +import javax.swing.JComboBox; import javax.swing.JLabel; -import javax.swing.JComboBox; +import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.ButtonGroup; - -/* javax.swing.border */ import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; -/* com.nokia.wtk.util.gui */ +import org.apache.log4j.Logger; + +import com.nokia.epdt.core.CoreUtils; +import com.nokia.wtk.util.gui.BorderPanel; import com.nokia.wtk.util.gui.GUI; -import com.nokia.wtk.util.gui.BorderPanel; /** * PanPluginJPanel * * @version 1.0 */ -class PanPluginJPanel extends JPanel -{ +class PanPluginJPanel extends JPanel { + private static Logger log = Logger.getLogger(PanPluginJPanel.class); private static final int GAP = 6; private static final String AUTO_PORT = "auto"; - private static final String[] HCI_MODULES = new String[]{"BCSP", "H4", - "USB"}; + private static final String[] HCI_MODULES = new String[] { "BCSP"/*, "H4", "USB"*/ }; private static final int HCI_USB_INDEX = 2; private static final int MAX_COM_PORTS = 16; @@ -67,30 +59,24 @@ private JRadioButton bluetoothDisableJRadioButton; private JRadioButton bluetoothEnableJRadioButton; private JComboBox bluetoothHciJComboBox; - private JComboBox irdaComPortJComboBox; - private JRadioButton irdaDisableJRadioButton; - private JRadioButton irdaEnableJRadioButton; /** * Creates new form PanPluginJPanel * @param plugin the plugin that creates this panel * @param connected true if we are connected to the emulator */ - PanPluginJPanel(PanPlugin plugin) - { + PanPluginJPanel(PanPlugin plugin) { super(new GridBagLayout()); panPlugin = plugin; panModel = plugin.getModel(); initComponents(); } - private static String getResString(String key) - { + private static String getResString(String key) { return PanResourceBundle.getInstance().getValue(key); } - JPanel buildOnePanel(String t, JRadioButton b1, JRadioButton b2, JPanel c) - { + JPanel buildOnePanel(String t, JRadioButton b1, JRadioButton b2, JPanel c) { BorderPanel bp = new BorderPanel(b2); bp.getContentPanel().add(c); @@ -120,15 +106,11 @@ /** This method is called from within the constructor to * initialize the form. */ - private void initComponents() - { + private void initComponents() { Object[] btComPorts = new Object[MAX_COM_PORTS]; - Object[] irdaComPorts = new Object[MAX_COM_PORTS]; - for (int i = 0; i < MAX_COM_PORTS; i++) - { + for (int i = 0; i < MAX_COM_PORTS; i++) { String label = Integer.toString(i + 1); btComPorts[i] = new ComPortItem(label); - irdaComPorts[i] = label; } bluetoothDisableJRadioButton = new JRadioButton( @@ -137,21 +119,16 @@ getResString(PanConstants.BLUETOOTH_ENABLE_LABEL)); bluetoothComPortJComboBox = new JComboBox(btComPorts); bluetoothHciJComboBox = new JComboBox(HCI_MODULES); - irdaDisableJRadioButton = new JRadioButton( - getResString(PanConstants.IRDA_DISABLE_LABEL)); - irdaEnableJRadioButton = new JRadioButton( - getResString(PanConstants.IRDA_ENABLE_LABEL)); - irdaComPortJComboBox = new JComboBox(irdaComPorts); // Bluetooth JPanel bluetoothEnableJPanel = GUI - .createRowPanel(new Component[]{ + .createRowPanel(new Component[] { new JLabel( getResString(PanConstants.BLUETOOTH_COM_PORT_LABEL)), bluetoothComPortJComboBox, new JLabel( getResString(PanConstants.BLUETOOTH_COM_HCI_LABEL)), - bluetoothHciJComboBox}); + bluetoothHciJComboBox }); JPanel bluetoothJPanel = buildOnePanel( getResString(PanConstants.BLUETOOTH_BORDER_TITLE), @@ -160,76 +137,31 @@ ButtonGroup bluetoothButtonGroup = new ButtonGroup(); bluetoothButtonGroup.add(bluetoothDisableJRadioButton); - bluetoothDisableJRadioButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { + bluetoothDisableJRadioButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { bluetoothDisableJRadioButtonActionPerformed(evt); } }); bluetoothButtonGroup.add(bluetoothEnableJRadioButton); - bluetoothEnableJRadioButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { + bluetoothEnableJRadioButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { bluetoothEnableJRadioButtonActionPerformed(evt); } }); - bluetoothComPortJComboBox.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { + bluetoothComPortJComboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { bluetoothComPortJComboBoxActionPerformed(evt); } }); - bluetoothHciJComboBox.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { + bluetoothHciJComboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { bluetoothHciJComboBoxActionPerformed(evt); } }); - // IRDA - JPanel irdaEnableJPanel = GUI.createRowPanel(new Component[]{ - new JLabel(getResString(PanConstants.IRDA_COM_PORT_LABEL)), - irdaComPortJComboBox}); - - JPanel irdaJPanel = buildOnePanel( - getResString(PanConstants.IRDA_BORDER_TITLE), - irdaDisableJRadioButton, irdaEnableJRadioButton, - irdaEnableJPanel); - - ButtonGroup irdaButtonGroup = new ButtonGroup(); - irdaButtonGroup.add(irdaDisableJRadioButton); - irdaDisableJRadioButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - irdaDisableJRadioButtonActionPerformed(evt); - } - }); - - irdaButtonGroup.add(irdaEnableJRadioButton); - irdaEnableJRadioButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - irdaEnableJRadioButtonActionPerformed(evt); - } - }); - - irdaComPortJComboBox.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - irdaComPortJComboBoxActionPerformed(evt); - } - }); - JPanel row = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridheight = GridBagConstraints.REMAINDER; @@ -241,7 +173,6 @@ gbc.insets.right = 0; gbc.gridwidth = GridBagConstraints.REMAINDER; - row.add(irdaJPanel, gbc); gbc.gridheight = 1; gbc.fill = GridBagConstraints.HORIZONTAL; @@ -255,103 +186,83 @@ //Set the initial values, obtained from .esk files: update(); + log.debug("Done initComponents"); } /** * Update UI components from Model: */ - public void update() - { + public void update() { + log.debug("update() updateInProgress: " + updateInProgress); // Update Bluetooth panel - if (!updateInProgress) - {//If the function is not called as the result of components updates, - //i.e. there is no update ongiong already - updateInProgress = true; - boolean bluetoothEnabled = panModel.isBluetoothEnabled(); - int hci = panModel.getBluetoothHci(); - boolean usb = (hci == HCI_USB_INDEX); - bluetoothDisableJRadioButton.setSelected(!bluetoothEnabled); - bluetoothEnableJRadioButton.setSelected(bluetoothEnabled); - bluetoothHciJComboBox.setSelectedIndex(bluetoothEnabled ? hci : -1); - bluetoothHciJComboBox.setEnabled(bluetoothEnabled); - bluetoothComPortJComboBox.setEnabled(bluetoothEnabled); - bluetoothComPortJComboBox.setSelectedIndex(panModel - .getBluetoothComPort()); - bluetoothComPortJComboBox.setEnabled(bluetoothEnabled && !usb); + try { + if (!updateInProgress) + log.debug("Inside if loop of update"); + {//If the function is not called as the result of components updates, + //i.e. there is no update ongiong already + updateInProgress = true; + boolean bluetoothEnabled = panModel.isBluetoothEnabled(); + log.debug("bluetooth Enable: " + bluetoothEnabled); + int hci = panModel.getBluetoothHci(); + boolean usb = (hci == HCI_USB_INDEX); + log.debug("hci USB index: " + hci); + bluetoothDisableJRadioButton.setSelected(!bluetoothEnabled); + bluetoothEnableJRadioButton.setSelected(bluetoothEnabled); + bluetoothHciJComboBox.setSelectedIndex(bluetoothEnabled ? hci + : -1); + bluetoothHciJComboBox.setEnabled(bluetoothEnabled); + bluetoothComPortJComboBox.setEnabled(bluetoothEnabled); + log.debug("bluetooth COM port: " + panModel.getBluetoothComPort()); + bluetoothComPortJComboBox.setSelectedIndex(panModel + .getBluetoothComPort()); + bluetoothComPortJComboBox.setEnabled(bluetoothEnabled && !usb); - // Update IRDA panel - boolean irdaEnabled = panModel.isIrdaEnabled(); - irdaDisableJRadioButton.setSelected(!irdaEnabled); - irdaEnableJRadioButton.setSelected(irdaEnabled); - irdaComPortJComboBox.setEnabled(irdaEnabled); - irdaComPortJComboBox.setSelectedIndex(panModel.getIrdaComPort()); - updateInProgress = false; + updateInProgress = false; + log.debug("If loop over"); + } + } catch (RuntimeException e) { + log.debug("Runtime Exception: " + e.getMessage()); + e.printStackTrace(); } } - private void irdaComPortJComboBoxActionPerformed(ActionEvent evt) - { - if (!updateInProgress) - {//I.e. if update came from UI - if (panModel.getBluetoothHci() == panModel.BT_HCI_USB_INDEX || - //HCI is not USB, where com port is selected automatically - irdaComPortJComboBox.getSelectedIndex() != panModel - .getBluetoothComPort()) - //or com ports are different - { - panModel - .setIrdaComPort(irdaComPortJComboBox.getSelectedIndex()); - panPlugin.pluginModelChangedAction(); - } else - { - irdaComPortJComboBox - .setSelectedIndex(panModel.getIrdaComPort()); - JOptionPane.showMessageDialog(this, - getResString("comPortEqualWarning"), - getResString("dialogTitle"), JOptionPane.ERROR_MESSAGE); + private void bluetoothEnableJRadioButtonActionPerformed(ActionEvent evt) { + if (!updateInProgress) {//I.e. if update came from UI + + log.debug(CoreUtils.EpocRoot() + FindAvailablePort.EXECUTABLE_FILE_NAME); + + FindAvailablePort availPort = FindAvailablePort.findAvailablePort(); + String port = null; + try { + port = availPort.getAvailablePortForBT(CoreUtils.EpocRoot() + + FindAvailablePort.EXECUTABLE_FILE_NAME); + + if (port == null) { + log.debug(FindAvailablePort.NO_AVAILABLE_PORT_MESSAGE); + // We set the default values of com ports (COM 1) when + // switching from disabled mode + panModel.setBluetoothComPort(0); + } else { + log.debug(FindAvailablePort.AVAILABLE_PORT_MESSAGE + port); + // Set the port + int setTempPort = Integer.parseInt(port.trim())-1; + panModel.setBluetoothComPort(setTempPort); + System.out.println("Output: " + port); + } + } catch (Exception e) { + log.debug("Error reading COM port. BT enabled. Port set to 1."); + // Set the default port 1 as a BT port and enable the BT + panModel.setBluetoothComPort(0); + e.printStackTrace(); } - } - } - private void irdaEnableJRadioButtonActionPerformed(ActionEvent evt) - { - if (!updateInProgress) - {//I.e. if update came from UI - //We set the default values of com ports (COM 1) when switching - //from disabled mode - panModel.setIrdaComPort(0); panPlugin.pluginModelChangedAction(); update(); } } - private void irdaDisableJRadioButtonActionPerformed(ActionEvent evt) - { - if (!updateInProgress) - {//I.e. if update came from UI - //Setting com port to -1 means disabling it - panModel.setIrdaComPort(-1); - panPlugin.pluginModelChangedAction(); - update(); - } - } - - private void bluetoothEnableJRadioButtonActionPerformed(ActionEvent evt) - { - if (!updateInProgress) - {//I.e. if update came from UI - //We set the default values of com ports (COM 1) when switching - //from disabled mode - panModel.setBluetoothComPort(0); - panPlugin.pluginModelChangedAction(); - update(); - } - } - - private void bluetoothDisableJRadioButtonActionPerformed(ActionEvent evt) - { - if (!updateInProgress) - {//I.e. if update came from UI + private void bluetoothDisableJRadioButtonActionPerformed(ActionEvent evt) { + if (!updateInProgress) {//I.e. if update came from UI //Setting com port to -1 means disabling it panModel.setBluetoothComPort(-1); panPlugin.pluginModelChangedAction(); @@ -359,13 +270,10 @@ } } - private void bluetoothHciJComboBoxActionPerformed(ActionEvent evt) - { - if (!updateInProgress) - {//I.e. if update came from UI + private void bluetoothHciJComboBoxActionPerformed(ActionEvent evt) { + if (!updateInProgress) {//I.e. if update came from UI int index = bluetoothHciJComboBox.getSelectedIndex(); - if (index >= 0) - { + if (index >= 0) { panModel.setBluetoothHci(index); panPlugin.pluginModelChangedAction(); update(); @@ -373,38 +281,25 @@ } } - private void bluetoothComPortJComboBoxActionPerformed(ActionEvent evt) - { - if (!updateInProgress) - {//I.e. if update came from UI - if (bluetoothComPortJComboBox.getSelectedIndex() != panModel - .getIrdaComPort()) - { - panModel.setBluetoothComPort(bluetoothComPortJComboBox - .getSelectedIndex()); - panPlugin.pluginModelChangedAction(); - } else - { - bluetoothComPortJComboBox.setSelectedIndex(panModel - .getBluetoothComPort()); - JOptionPane.showMessageDialog(this, - getResString("comPortEqualWarning"), - getResString("dialogTitle"), JOptionPane.ERROR_MESSAGE); - } + private void bluetoothComPortJComboBoxActionPerformed(ActionEvent evt) { + if (!updateInProgress) {//I.e. if update came from UI + + panModel.setBluetoothComPort(bluetoothComPortJComboBox + .getSelectedIndex()); + panPlugin.pluginModelChangedAction(); } } - private class ComPortItem - { + private class ComPortItem { private String comPortNumber; - ComPortItem(String label) - { + + ComPortItem(String label) { comPortNumber = label; } - public String toString() - { - return panModel.getBluetoothHci() == HCI_USB_INDEX - ? AUTO_PORT + + public String toString() { + + return panModel.getBluetoothHci() == HCI_USB_INDEX ? AUTO_PORT : comPortNumber; } }