previous next trail start tutorial home feedback openwings.org

Service UI Development

There are many kinds of user interfaces. Most people are familiar with a Graphical User Interface (GUI) that provides a simple pictorial view of a service or a program. But a user interface could include other types of services. Examples are a voice interface, a text interface or any other service that a component may provide or publish.

If you are new to user interfaces in Java or need general guidance on building Java user interfaces using AWT or Swing classes, Sun's Java tutorial is a good resource.

In some cases, a service user may not be familiar with the exact interface describing a service. A common concept is the idea of a "toolbar" or "desktop" application that provides user access to a variety of services in the system. In this scenario the user chooses a service based on what it can do, not necessarily a specified interface. To enable users to access the services they choose, there must be a mechanism to attach a user interface adapter to a service.

This adapter is called a Service User Interface (ServiceUI). The user interface is a piece of mobile code that can be obtained along with a service object to wrap it in a user interface. Providing several different Service UIs for a service can make it possible for end users to access services from a variety of devices.

The ServiceUI functionality described in the Component API is based on a factory pattern. Instead of publishing an actual user interface object along with a service, an object called a UserInterfaceFactory is published. The factory is an object that can be downloaded along with a service to produce an appropriate user interface in the client component.

The reason for this indirection comes from the nature of user interface objects themselves. Since user interfaces are fairly device specific, the objects they contain are often quite tied to the context, and don't serialize for transmission to other programs. For example, you can't create a java.awt.Frame in one JVM, serialize it, pass it to another JVM, deserialize it, and use it.

The code below illustrates an example of how a ServiceUI can be used:

1

 

public class SampleComponent implements GokSysUIIntf

2

 

{

3

 public SampleComponent()

4

 {

5

  try

6

  {

7

    UniqueID serviceID = UniqueIDFactory.getUniqueID();

8

 

9

    // provide a service UI Interface

10

    ComponentComplex component = ComponentFactory.getComponentComplex();

11

 

12

    ProvideServiceParameters params = new ProvideServiceParameters();

13

 

14

    SampleUIFactory factory = new SampleUIFactory();

15

    params.addUserInterfaceFactory(factory);

16

    params.setDisplayName("GOK");

17

    params.setServiceName("GOK");

18

 

19

    component.provideService( SampleInterface.class,

20

      component.distributeObject(SampleInterface.class, this), params);

21

  } // end try

22

  catch(Exception e)

23

  {

24

    System.out.println(" exception " + e.toString() );

25

    e.printStackTrace();

26

  } // end catch

27

 

28

 } // end SampleComponent

29

 

 public void setVideoConfig( ... )

30

 

 {

31

 

  ...

32

 

 }

33

 

} // end class

This is the constructor for a class "SampleComponent" that provides user interfaces for controlling a GOK service. First a unique identifier is obtained from the UniqueIDFactory (Line 7). A unique identifier is needed because Component Services uses unique identifiers for services. Next a ComponentComplex object is obtained from the ComponentFactory (Line 10) since every service is associated with a component. To provide a GOK service, parameters will be required (Line 12). Notice a new class, SampleUIFactory, is instantiated (Line 14). SampleUIFactory implements the UserInterfaceFactory interface and provides methods that get supported service interfaces and supported UI classes (shown below). The parameters associated with this service are assigned in Lines 15 through 17. This is how the factory pattern is achieved. Finally, the component service is provided (Line 19).

The code below illustrates an example of how the UserInterfaceFactory interface is implemented.

1

public class SampleUIFactory implements UserInterfaceFactory

2

{

3

 /** getFrame constructs the JFrame with the service found

4

  *

5

  * @param obj the service object

6

  * @returns JFrame the newly constructed UI

7

  */

8

  public JFrame getJFrame(Object obj)

9

  {

10

    Jframe frame = null;

11

    try

12

    {

13

      GokSysUIIntf service = (GokSysUIIntf)obj;

14

      frame = new VideoConfig(service);

15

    }

16

    catch (ClassException e)

17

    {

18

      System.out.println("Wrong service type");

19

    }

20

    return frame;

21

  }

22

 

23

  public Class[] getSupportedServiceInterfaces()

24

  {

25

    Class[] classes = new Class[] {GokSysUIIntf.class};

26

    return classes;

27

  }

28

 

29

  public Class[] getSupportedUIClasses()

30

  {

31

    Class[] classes = new Class[] {JFrame.class};

32

    return classes;

33

  }

34

} // end class

SampleUIFactory is used by Component Services to construct a UI upon download from the lookup service. The parameter being passed in method getJFrame() is some object (Line 8). The object is identified as a service of the type GokSysUIIntf (Line 13). This service is described in the GokSysUIIntf code shown at the bottom of this page. Next, the VideoConfig class, instantiated (Line 14). To facilitate understanding, the constructor of VideoConfig is shown:

public VideoConfig(GokSysUIIntf service);

VideoConfig handles GUI specifics such as setting the layout of the window and creating buttons and labels (code not shown). The VideoConfig class has an actionPerformed(ActionEvent e) method that is called when buttons in the GUI window are used. When a button is depressed, the configuration of the window changes resolution, quality or how many frames per second are displayed. This action is captured by the following lines of code in the actionPerformed method:

GokSysUIIntf service;
service.setVideoConfig(this, enableVideo, fps, quality, resolution);

This method is the same method as in the GokSysUIIntf interface. This is the interface that provides necessary video changes to other interested components.

1

public interface GokSysUIIntf extends AnotherSystemUICntlIntf

2

{

3

 /** This method is used to set the GOK video configuration

4

  *

5

  * @param source is the dialog that originated the video config chg

6

  * @param enable determines if the video source should be enabled

7

  * @param fps determines the frames per second of the video

8

  * @param resolution determines the size of the video

9

  * @param quality determines the quality of the video

10

  */

11

 

12

  public void setVideoConfig(Object source,

13

    boolean enable, int fps, int resolution, float quality)

14

  throws RemoteException;

15

} // end class

How other interested components are notified of video changes is described in the "Listeners" section of the Advanced Topics tutorial trail.

Next: Component Compilation

back to top

Copyright 2002, General Dynamics Decision Systems. All rights reserved.

previous next trail start tutorial home feedback openwings.org