Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

Copyright © 2006 Sun Microsystems, Inc. All rights reserved.

JSR-209 (Final Approval Ballot)

javax.microedition.plaf
Class PlatformFactory

java.lang.Object
  extended byjavax.microedition.plaf.PlatformFactory

public abstract class PlatformFactory
extends java.lang.Object

This class provides the factory for creating objects that delegate the implementation of UI components. The actual architecture of this delegation is implementation specific. It is implied that an implementation of AGUI will include one PlatformFactory for each Pluggable Look and Feel installed. The PlatformFactory acts as a registry binding references to Swing UI components to their delegates in the pluggable look and feel implementation. This API would not be used by application programmers, but it is required by the implementation of a user interface API such as AGUI.

When the VM boots, a property will be read to find out the name of the class that extends this abstract PlatformFactory class. The class thus named will be installed as the PlatformFactory, which the static getPlatformFactory() method will return. This property is -

 javax.microedition.plaf.plaformfactory
 

See Also:
ComponentUI

Constructor Summary
protected PlatformFactory()
           
 
Method Summary
abstract  ComponentUI createPlatformObject(java.lang.Object apiObject)
           Creates a ComponentUI for a given UI component object.
abstract  java.lang.Class getPlatformClass(java.lang.Class apiClass)
           This method returns the Class that refers to the delegate for a given UI component.
static PlatformFactory getPlatformFactory()
          Return the PlatformFactory currently installed and defined by the property:
abstract  ComponentUI getPlatformObject(java.lang.Object apiObject)
           This method returns an object for a given public UI class.
 java.lang.Object getPlatformResource(java.lang.Object key)
          Method to retrieve platform resources such as fonts, colors, icons, etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlatformFactory

protected PlatformFactory()
Method Detail

getPlatformFactory

public static PlatformFactory getPlatformFactory()
Return the PlatformFactory currently installed and defined by the property:

 javax.microedition.plaf.plaformfactory
 

Returns:
return the current factory this method should be security protected.

getPlatformClass

public abstract java.lang.Class getPlatformClass(java.lang.Class apiClass)

This method returns the Class that refers to the delegate for a given UI component. It returns a registered platform class for a given UI component class. If no implementaton class is registered null is returned. The primary use for this method is to use reflection to identify implementation specific extension methods or interfaces before instances are created. E.g.

 Class delegateClass = factory.getPlatformClass(JButton.class);
 

Parameters:
apiClass - The Class object referring to a given public UI class, for example a Swing component. The returned Class must extend ComponentUI
Returns:
The registered platform support class for a given api class.

getPlatformObject

public abstract ComponentUI getPlatformObject(java.lang.Object apiObject)

This method returns an object for a given public UI class. E.g. in a Swing UI implementation, a JComponent is passed into the method. It returns the current plaf implementation for a given UI class or null if none has been created for this object.


 private Object delegate = null;
 public void eventDelegate(KeyEvent e) {
    //We need the delegate to do something 
    PlatformFactory pf = PlatformFactory.getPlatformFactory();
    Object source =  e.getSource();
    my_delegate = pf.getPlatformObject(this);
    if( delegate != null && delegate instanceof ButtonUI ) {
		//do something 
    }
 }
 

Parameters:
apiObject - the UI component object who's delegate is required
Returns:
the ComponentUI previously constructed by createPlatformObject()

createPlatformObject

public abstract ComponentUI createPlatformObject(java.lang.Object apiObject)

Creates a ComponentUI for a given UI component object. It must be called in the constructor chain of the UI component class. Subsequent calls to getPlatformObject() for this apiObject must return this platform object. The object can be shared with multiple UI objects, but must exist after the UI component instance constructor returns.

 private ButtonUI my_delegate = null;
 
 public JButton() {
    PlatformFactory pf = PlatformFactory.getPlatformFactory();
    my_delegate = (ButtonUI)pf.createPlatformObject(this);
 }
 

Parameters:
apiObject - the UI component object for which a delegate is required.
Returns:
the new ComponentUI created by calling this method.

getPlatformResource

public java.lang.Object getPlatformResource(java.lang.Object key)
Method to retrieve platform resources such as fonts, colors, icons, etc.


JSR-209 (Final Approval Ballot)

Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 209 specification.