wt.clients.replication.unit
Class UnitAttributesPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended bywt.clients.replication.unit.UnitAttributesPanel
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

public class UnitAttributesPanel
extends Panel

UnitAttributesPanel is Java Bean component for manipulating wt.clients.replication.unit.UnitItem objects. It contains methods to specify the class of the object being manipulated and the attributes to be displayed. A label, maximum length, and edit/view may be specified for each attribute. The UnitAttributesPanel dynamically constructs a user interface based on the contained class and the specified information about the attributes. Boolean attributes are represented as checkboxes, Enumerated types as choice lists, string and integer values are shown in text fields. The following code demonstrates a possible use of this class:


	    Frame f = new Frame("AttributesPanel test");

	    UnitAttributesPanel attributeBean = new UnitAttributesPanel();
	    f.setSize(700,600);
	    f.setLayout(new BorderLayout());

       try
       {
	         attributeBean.setObjectClassName("wt.clients.replication.unit.UnitItem");
           {
		        java.lang.String[] tempString = new java.lang.String[4];
		        tempString[0] = new java.lang.String("Number");
		        tempString[1] = new java.lang.String("Name");
		        tempString[2] = new java.lang.String("Source");
		        tempString[3] = new java.lang.String("Type");
		        attributeBean.setAttributes(tempString);
		    }
		    {
		        java.lang.String[] tempString = new java.lang.String[4]; 

		        tempString[0] = new java.lang.String("Number:");
		        tempString[1] = new java.lang.String("Name:");
		        tempString[2] = new java.lang.String("Source:");
		        tempString[3] = new java.lang.String("Type:");
		    
	            attributeBean.setLabels(tempString);
           }
           {
		        java.lang.String[] tempString = new java.lang.String[4];

		        tempString[0] = "true";
		        tempString[1] = "true";
		        tempString[2] = "true";
		        tempString[3] = "true";
	            attributeBean.setEdits(tempString);
            }

       }
       catch ( WTPropertyVetoException wte)
       {
            wte.printStackTrace();
       }

	    f.add("Center",attributeBean);
	    f.pack();
	    f.show();


 


Supported API: true

Extendable: true

See Also:
wt.clients.replication.unit.UnitItem class, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  String[] attributes
           
private  Color background
           
private  Font crossLocaleFont
           
private  boolean[] edits
           
static String FALSE
           
private  Color foregound
           
protected  Vector getterMethods
           
protected  HelpContext helpContext
           
protected  HelpSystem helpSystem
           
private  String[] labels
           
protected  int MAX_TEXT_FIELD_LENGTH
           
private  String[] maxLen
           
private  Object object
           
private  String objectClassName
           
private  int[] separators
           
protected  Vector setterMethods
           
private  int[] spaces
           
protected  int TEXT_AREA_ROWS
           
static String TRUE
           
protected  Vector types
           
protected  Vector uiAttributes
           
protected  Vector uiLabels
           
 
Fields inherited from class java.awt.Panel
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
UnitAttributesPanel()
          Construct an empty UnitAttributesPanel
 
Method Summary
 void addHelpListener(PropertyChangeListener listener)
          Add a help listener for this component.
protected  Component createCheckbox(int i)
          Create a checkbox component for boolean attributes.
protected  int createComponents(Component comp, int x, int y, int width)
           
protected  Component createEnumeratedChoice(int i)
          Create a UI component for an EnumeratedType attribute.
protected  Component createHorizontalLine()
          Create a horizontal line to separate groups of attributes.
protected  void createLabels(int x, int y, int i)
          Create a label component at the specified grid position.
protected  Component createTextArea(int i)
          Create a text area component.
protected  Component createTextField(int i)
          Create a text field component.
protected  void createUI()
          Create the user interface by creating the components for each attribute.
 String[] getAttributes()
          Return the array of attribute names
protected  Object getAttrValue(Object obj, Method getter)
          Invoke the specified getter method on the specified object.
 Color getBackground()
           
protected  Class getClassContained()
          Get a Class object for the contained object or classname
 boolean[] getEditable()
          Return the array of booleans specifying if an attribute is editable.
 String[] getEdits()
          Return the array of strings specifying if an attribute is editable.
 boolean getEdits(int index)
          Get the edits value for the specified index.
 Font getFont()
           
 Color getForeground()
           
protected  Method getGetterMethod(String attribute)
          Get the getter method for the specified attribute.
 HelpContext getHelpContext()
          Return the help context.
 String[] getLabels()
          Return the labels used for the attributes.
 String[] getMaxLen()
          Return the maximum lengths for each attribute.
 Object getObject()
          Return the contained object.
 String getObjectClassName()
          Get the fully qualified class name of the contained object.
 String[] getSeparators()
          Get the position values of any separators.
protected  Method getSetterMethod(String attribute, Class returnType)
          Get the setter method for the specified attribute.
 String[] getSpaces()
          Get the array of spacer locations.
 void initializeHelp()
          Initialize the help system for this component.
protected  boolean isLargeString(int i)
          Determine if the string attribute is large ( longer than MAX_TEXT_FIELD_LENGTH).
protected  boolean isReadyForUI()
          Check if enough information is known to construct the user interface.
static void main(String[] args)
          A main method that demonstrates how to use this class and allows testing
protected  boolean needSeparatorNow(int i)
          Determine if a separator should placed at the specified position.
protected  boolean needSpaceNow(int i)
          Determine if a spacer should placed at the specified position.
 void setAttributes(String[] attributes)
          Set the attributes to be displayed for the contained object.
protected  void setAttrValue(Object obj, Method setter, Object value)
          Invoke the specified setter method on the object.
 void setBackground(Color color)
           
 void setEditable(boolean[] editValues)
          Set the editable values for each attribute.
 void setEdits(int index, boolean editValue)
          Set the edits value for the specified index.
 void setEdits(String[] editValues)
          Set the edits values for each attribute.
 void setFont(Font font)
           
 void setForeground(Color color)
           
 void setHelpContext(HelpContext helpContext)
          Set the help context.
 void setLabels(String[] labels)
          Set the labels for the attributes.
 void setMaxLen(String[] max_len)
          Set the maximum length for each attribute.
 void setObject(Object object)
          Set the contained object.
 Object setObjectAttributeValues()
          Transfers any user-modified values to the contained object.
 void setObjectClassName(String objectClassName)
          Set the fully qualified class name of the contained object.
 void setSeparators(int[] separators)
          Specify where any separators should be placed.
 void setSeparators(String[] separatorStrings)
          Specify where any separators should be placed.
 void setSpaces(int[] spaces)
          Set the location for any spacer elements
 void setSpaces(String[] spacerStrings)
          Set the location for any spacer elements
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFontMetrics, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, 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

attributes

private String[] attributes

labels

private String[] labels

maxLen

private String[] maxLen

edits

private boolean[] edits

separators

private int[] separators

spaces

private int[] spaces

foregound

private Color foregound

background

private Color background

object

private Object object

objectClassName

private String objectClassName

getterMethods

protected Vector getterMethods

setterMethods

protected Vector setterMethods

types

protected Vector types

uiLabels

protected Vector uiLabels

uiAttributes

protected Vector uiAttributes

helpSystem

protected HelpSystem helpSystem

helpContext

protected HelpContext helpContext

MAX_TEXT_FIELD_LENGTH

protected int MAX_TEXT_FIELD_LENGTH

TEXT_AREA_ROWS

protected int TEXT_AREA_ROWS

TRUE

public static final String TRUE
See Also:
Constant Field Values

FALSE

public static final String FALSE
See Also:
Constant Field Values

crossLocaleFont

private Font crossLocaleFont
Constructor Detail

UnitAttributesPanel

public UnitAttributesPanel()
Construct an empty UnitAttributesPanel

Method Detail

getObject

public Object getObject()
Return the contained object.

Returns:
the contained object

setObject

public void setObject(Object object)
Set the contained object.

Parameters:
object - the object to refresh

setObjectAttributeValues

public Object setObjectAttributeValues()
                                throws WTPropertyVetoException
Transfers any user-modified values to the contained object.

Returns:
the object with the modified values
Throws:
WTPropertyVetoException - if an exception was thrown when invoking the setter on the object.

getAttrValue

protected Object getAttrValue(Object obj,
                              Method getter)
Invoke the specified getter method on the specified object.

Parameters:
obj - the object to invoke the method on
getter - the getter method to invoke
Returns:
the value returned by the getter method

setAttrValue

protected void setAttrValue(Object obj,
                            Method setter,
                            Object value)
                     throws WTPropertyVetoException
Invoke the specified setter method on the object.

Parameters:
obj - the object to invoke the setter method on
setter - the method to invoke
value - the value to use in the setter method
Throws:
WTPropertyVetoException - if invoking the setter threw an exception

getObjectClassName

public String getObjectClassName()
Get the fully qualified class name of the contained object.

Returns:
the fully qualified class name of the contained object

setObjectClassName

public void setObjectClassName(String objectClassName)
                        throws WTPropertyVetoException
Set the fully qualified class name of the contained object.

Parameters:
objectClassName - the fully qualified class name of the contained object
Throws:
WTPropertyVetoException - if the class name is not valid.

setAttributes

public void setAttributes(String[] attributes)
                   throws WTPropertyVetoException
Set the attributes to be displayed for the contained object.

Parameters:
attributes - an array of attribute names
Throws:
WTPropertyVetoException - if any of the attributes are not valid for the contained class.

createLabels

protected void createLabels(int x,
                            int y,
                            int i)
Create a label component at the specified grid position.

Parameters:
x - the x position
y - the y position
i - the index in the labels array

createComponents

protected int createComponents(Component comp,
                               int x,
                               int y,
                               int width)

createEnumeratedChoice

protected Component createEnumeratedChoice(int i)
                                    throws PropertyVetoException
Create a UI component for an EnumeratedType attribute. If the attribute is editable, return an EnumeratedChoice, else return a text field.

Parameters:
i - index into components array
Returns:
the created component
Throws:
PropertyVetoException

createTextField

protected Component createTextField(int i)
Create a text field component. If the maximum length was specified for the attribute, set that value. If the attribute is editable, an editable text field is returned. If the attribute is not editable, use a simple label.

Parameters:
i - index into the attribute arrays
Returns:
the created component

createTextArea

protected Component createTextArea(int i)
Create a text area component. Text areas are created if the maximum length of the string attribute is more than MAX_TEXT_FIELD_LENGTH.

Parameters:
i - the index of the attribute
Returns:
the created component

createHorizontalLine

protected Component createHorizontalLine()
Create a horizontal line to separate groups of attributes.

Returns:
the created horizontal line component

createCheckbox

protected Component createCheckbox(int i)
Create a checkbox component for boolean attributes.

Parameters:
i - the index of the attribute
Returns:
the created component

isLargeString

protected boolean isLargeString(int i)
Determine if the string attribute is large ( longer than MAX_TEXT_FIELD_LENGTH).

Parameters:
i - the index of the attribute
Returns:
true if longer than MAX_TEXT_FIELD_LENGTH, false otherwise

needSpaceNow

protected boolean needSpaceNow(int i)
Determine if a spacer should placed at the specified position.

Parameters:
i - the index of the attribute
Returns:
true if a spacer is needed

needSeparatorNow

protected boolean needSeparatorNow(int i)
Determine if a separator should placed at the specified position.

Parameters:
i - the index of the attribute
Returns:
true if a separator is needed

createUI

protected void createUI()
Create the user interface by creating the components for each attribute.


getAttributes

public String[] getAttributes()
Return the array of attribute names

Returns:
an array of attribute names

getEditable

public boolean[] getEditable()
Return the array of booleans specifying if an attribute is editable.

Returns:
the array of booleans specifying if an attribute is editable

setEditable

public void setEditable(boolean[] editValues)
                 throws WTPropertyVetoException
Set the editable values for each attribute.

Parameters:
editValues - array of booleans indicating if the corresponding attribute is editable.
Throws:
WTPropertyVetoException

getEdits

public boolean getEdits(int index)
Get the edits value for the specified index.

Parameters:
index - the index for the attribute
Returns:
true if the attribute is editable

setEdits

public void setEdits(int index,
                     boolean editValue)
              throws WTPropertyVetoException
Set the edits value for the specified index.

Parameters:
index - the index for the attribute
editValue - true if the attribute should be editable
Throws:
WTPropertyVetoException

setEdits

public void setEdits(String[] editValues)
              throws WTPropertyVetoException
Set the edits values for each attribute.

Parameters:
editValues - array of strings indicating if the corresponding attribute is editable.
Throws:
WTPropertyVetoException

getEdits

public String[] getEdits()
Return the array of strings specifying if an attribute is editable.

Returns:
the array of strings specifying if an attribute is editable

setLabels

public void setLabels(String[] labels)
               throws WTPropertyVetoException
Set the labels for the attributes.

Parameters:
labels - an array of strings, each string is the label for the corresponding attribute.
Throws:
WTPropertyVetoException

isReadyForUI

protected boolean isReadyForUI()
Check if enough information is known to construct the user interface.

Returns:
true if the ui can be safely constructed

getLabels

public String[] getLabels()
Return the labels used for the attributes.

Returns:
an array of strings used for the attribute labels

setMaxLen

public void setMaxLen(String[] max_len)
               throws WTPropertyVetoException
Set the maximum length for each attribute. Note: this is only currently used to determine if a string value should be displayed in a text field or a text area. In the future it will be used to prevent user input of values greater than the maximum length specified. To leave the maximum length unspecified, use the empty string "".

Parameters:
max_len - an array of strings, each string representing the maximum length or value for the corresponding attribute.
Throws:
WTPropertyVetoException

getMaxLen

public String[] getMaxLen()
Return the maximum lengths for each attribute.

Returns:
an array of the maximum lengths for each attribute.

setSeparators

public void setSeparators(String[] separatorStrings)
                   throws WTPropertyVetoException
Specify where any separators should be placed.

Throws:
WTPropertyVetoException - if the value is not numeric

setSeparators

public void setSeparators(int[] separators)
                   throws WTPropertyVetoException
Specify where any separators should be placed.

Throws:
WTPropertyVetoException - if the value is not numeric

getSeparators

public String[] getSeparators()
Get the position values of any separators.

Returns:
an array of separator location values

setSpaces

public void setSpaces(String[] spacerStrings)
               throws WTPropertyVetoException
Set the location for any spacer elements

Parameters:
spacerStrings - array of spacer locations
Throws:
WTPropertyVetoException - is a location is not numeric

setSpaces

public void setSpaces(int[] spaces)
               throws WTPropertyVetoException
Set the location for any spacer elements

Throws:
WTPropertyVetoException - is a location is not numeric

getSpaces

public String[] getSpaces()
Get the array of spacer locations.

Returns:
array of spacer locations

setForeground

public void setForeground(Color color)

getForeground

public Color getForeground()

setBackground

public void setBackground(Color color)

getBackground

public Color getBackground()

setFont

public void setFont(Font font)

getFont

public Font getFont()

getClassContained

protected Class getClassContained()
Get a Class object for the contained object or classname

Returns:
the class for the ontained object or classname

getGetterMethod

protected Method getGetterMethod(String attribute)
Get the getter method for the specified attribute.

Parameters:
attribute - the name of the attribute
Returns:
the getter method

getSetterMethod

protected Method getSetterMethod(String attribute,
                                 Class returnType)
Get the setter method for the specified attribute.

Parameters:
attribute - the name of the attribute
returnType - the parameter type for the setter
Returns:
the setter method

setHelpContext

public void setHelpContext(HelpContext helpContext)
                    throws WTPropertyVetoException
Set the help context.

Parameters:
helpContext - the HelpContext to use
Throws:
WTPropertyVetoException - if the helpContext is invalid

getHelpContext

public HelpContext getHelpContext()
Return the help context.

Returns:
the current HelpContext

initializeHelp

public void initializeHelp()
Initialize the help system for this component.


addHelpListener

public void addHelpListener(PropertyChangeListener listener)
Add a help listener for this component.

Parameters:
listener - a new help listener

main

public static void main(String[] args)
A main method that demonstrates how to use this class and allows testing