de.avetana.bluetooth.util
Class ServiceFinderPane

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byde.avetana.bluetooth.util.ServiceFinderPane
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, Cancelable, DiscoveryListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.swing.event.TreeSelectionListener

public class ServiceFinderPane
extends javax.swing.JPanel
implements Cancelable, java.awt.event.ActionListener, DiscoveryListener, javax.swing.event.TreeSelectionListener

COPYRIGHT:
(c) Copyright 2004 Avetana GmbH ALL RIGHTS RESERVED.

This file is part of the Avetana bluetooth API for Linux.

The Avetana bluetooth API for Linux is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

The Avetana bluetooth API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

The development of the Avetana bluetooth API is based on the work of Christian Lorenz (see the Javabluetooth Stack at http://www.javabluetooth.org) for some classes, on the work of the jbluez team (see http://jbluez.sourceforge.net/) and on the work of the bluez team (see the BlueZ linux Stack at http://www.bluez.org) for the C code. Classes, part of classes, C functions or part of C functions programmed by these teams and/or persons are explicitly mentioned.



Description:
JPanel that finds every bluetooth device with Services matching a search kriteria. The search kriteria (an Array of UUIDs) is given by the programmer as a parameter of the ServiceFinder constructor. If this parameterr is null, the ServiceFinder class will then look for every Services accepting RFCOMM connections.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static ProgressDialog m_dialog
           
 javax.swing.JButton m_refresh
           
 javax.swing.JButton m_select
           
 ServiceDescriptor selected
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.bluetooth.DiscoveryListener
INQUIRY_COMPLETED, INQUIRY_ERROR, INQUIRY_TERMINATED, SERVICE_SEARCH_COMPLETED, SERVICE_SEARCH_DEVICE_NOT_REACHABLE, SERVICE_SEARCH_ERROR, SERVICE_SEARCH_NO_RECORDS, SERVICE_SEARCH_TERMINATED
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ServiceFinderPane(java.awt.Window owner, java.lang.String localPrefName, UUID[] a_search)
          Constructs a new ServiceFinderPane object
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void addMouseListenerToTree(java.awt.event.MouseListener listener)
          Adds a mouse listener to the nested JTree
 void cancel()
          Called, when the cancel button is hit on the ProgressDialog
 void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod)
          Reaction of the class when a new device is discovered
 void doInquiry()
          Starts the HCI inquiry.
 void expandAll()
          Expands all the leafs of the tree in order to make them visible
 java.util.Vector getAllServices()
           
 javax.swing.JPanel getCommandPanel()
          Returns the JPanel containg all commands (JButtons)
 ServiceDescriptor getSelectedService()
          Returns the description of the selected service
 void inform(java.lang.String message)
          Shows an information message in the progress dialog
 void initStack()
          Inits the local BT stack
 void initTree()
          Inits the JTree component
 void inquiryCompleted(int discType)
          Called when an inquiry is completed.
 void servicesDiscovered(int transID, ServiceRecord[] servRecord)
          Reaction of the class when new services are discovered
 void serviceSearchCompleted(int transID, int respCode)
          Called when a service search is completed or was terminated because of an error.
 void setLocalPref(java.lang.String localPrefName, UUID[] a_search)
          Sets the local search and storing preferences and reloads them.
 void valueChanged(javax.swing.event.TreeSelectionEvent e)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

selected

public ServiceDescriptor selected

m_dialog

public static volatile ProgressDialog m_dialog

m_refresh

public javax.swing.JButton m_refresh

m_select

public javax.swing.JButton m_select
Constructor Detail

ServiceFinderPane

public ServiceFinderPane(java.awt.Window owner,
                         java.lang.String localPrefName,
                         UUID[] a_search)
                  throws java.lang.Exception
Constructs a new ServiceFinderPane object

Parameters:
owner - The window owner of the JPanel
localPrefName - The list of all services found are stored in the local user preferences. Each preference stored has a name. This variable allows the user to set this name
a_search - The search kriteria (an array of UUIds)
Throws:
java.lang.Exception
Method Detail

addMouseListenerToTree

public void addMouseListenerToTree(java.awt.event.MouseListener listener)
Adds a mouse listener to the nested JTree

Parameters:
listener - The mouse listener to be added

setLocalPref

public void setLocalPref(java.lang.String localPrefName,
                         UUID[] a_search)
Sets the local search and storing preferences and reloads them.

Parameters:
localPrefName - The storing preferences
a_search - The new search kriteria

getCommandPanel

public javax.swing.JPanel getCommandPanel()
Returns the JPanel containg all commands (JButtons)

Returns:

cancel

public void cancel()
Called, when the cancel button is hit on the ProgressDialog

Specified by:
cancel in interface Cancelable

initStack

public void initStack()
               throws java.lang.Exception
Inits the local BT stack

Throws:
java.lang.Exception

initTree

public void initTree()
Inits the JTree component


deviceDiscovered

public void deviceDiscovered(RemoteDevice btDevice,
                             DeviceClass cod)
Reaction of the class when a new device is discovered

Specified by:
deviceDiscovered in interface DiscoveryListener
Parameters:
btDevice - The new Remote device
cod - The device class
See Also:
DiscoveryAgent.startInquiry(int, javax.bluetooth.DiscoveryListener)

servicesDiscovered

public void servicesDiscovered(int transID,
                               ServiceRecord[] servRecord)
Reaction of the class when new services are discovered

Specified by:
servicesDiscovered in interface DiscoveryListener
Parameters:
transID - The SDP transaction ID
servRecord - The new services discovered
See Also:
DiscoveryAgent.searchServices(int[], javax.bluetooth.UUID[], javax.bluetooth.RemoteDevice, javax.bluetooth.DiscoveryListener)

inform

public void inform(java.lang.String message)
Shows an information message in the progress dialog

Parameters:
message - The information message

doInquiry

public void doInquiry()
Starts the HCI inquiry. After the end of the HCI inquiry, a service search is performed for each found remote device


getAllServices

public java.util.Vector getAllServices()

getSelectedService

public ServiceDescriptor getSelectedService()
Returns the description of the selected service

Returns:
The description of the selected service

expandAll

public void expandAll()
Expands all the leafs of the tree in order to make them visible


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

valueChanged

public void valueChanged(javax.swing.event.TreeSelectionEvent e)
Specified by:
valueChanged in interface javax.swing.event.TreeSelectionListener

inquiryCompleted

public void inquiryCompleted(int discType)
Description copied from interface: DiscoveryListener
Called when an inquiry is completed. The discType will be INQUIRY_COMPLETED if the inquiry ended normally or INQUIRY_TERMINATED if the inquiry was canceled by a call to DiscoveryAgent.cancelInquiry(). The discType will be INQUIRY_ERROR if an error occurred while processing the inquiry causing the inquiry to end abnormally.

Specified by:
inquiryCompleted in interface DiscoveryListener
Parameters:
discType - the type of request that was completed; either INQUIRY_COMPLETED, INQUIRY_TERMINATED, or INQUIRY_ERROR
See Also:
DiscoveryListener.INQUIRY_COMPLETED, DiscoveryListener.INQUIRY_TERMINATED, DiscoveryListener.INQUIRY_ERROR

serviceSearchCompleted

public void serviceSearchCompleted(int transID,
                                   int respCode)
Description copied from interface: DiscoveryListener
Called when a service search is completed or was terminated because of an error. Legal status values in the respCode argument include SERVICE_SEARCH_COMPLETED, SERVICE_SEARCH_TERMINATED, SERVICE_SEARCH_ERROR, SERVICE_SEARCH_NO_RECORDS and SERVICE_SEARCH_DEVICE_NOT_REACHABLE. The following table describes when each respCode will be used:
respCodeReason
SERVICE_SEARCH_COMPLETED if the service search completed normally
SERVICE_SEARCH_TERMINATED if the service search request was cancelled by a call to DiscoveryAgent.cancelServiceSearch()
SERVICE_SEARCH_ERROR if an error occurred while processing the request
SERVICE_SEARCH_NO_RECORDS if no records were found during the service search
SERVICE_SEARCH_DEVICE_NOT_REACHABLE if the device specified in the search request could not be reached or the local device could not establish a connection to the remote device

Specified by:
serviceSearchCompleted in interface DiscoveryListener
Parameters:
transID - the transaction ID identifying the request which initiated the service search
respCode - the response code that indicates the status of the transaction