JClass 4.5.0 API
Documentation

com.klg.jclass.field
Class Field

java.lang.Object
  |
  +--com.klg.jclass.field.Field

public class Field
extends Object
implements Serializable, com.klg.jclass.util.value.JCValueListener, ComboBoxModel

Note that this class is not a part of the public API and is public as a side-effect of the implementation.

This is the "glue" class for JClass Field. It takes events from the Swing visual components and passes this information on to the generic "validator" that is set on the field. For clarity we note here that JClass Field "Validators" are actually "validators/formatters/parsers" Also that this class controls the posting of the Validation and Field events.

See Also:
Serialized Form

Inner Class Summary
 class Field.TextFieldContent
           
 
Field Summary
protected  boolean allow_text_change
           
static int AS_IS
           
protected  boolean beepOnInvalid
           
static int CLEAR_FIELD
           
protected  Locale current
           
protected  Object defaultValue
           
protected  com.klg.jclass.field.Field.TextFieldDocument document
           
protected  Class edit_class
           
protected  Object edit_initial_value
           
protected  Object event_source
           
protected  boolean has_focus
           
protected  boolean internal_text_change
           
protected  boolean internalBackgroundChange
           
protected  boolean internalForegroundChange
           
static int INVALID
           
protected  Color invalidBackground
           
protected  Color invalidForeground
           
protected  int invalidPolicy
           
protected  boolean is_cell_editor
           
protected  com.klg.jclass.field.Field.Listeners listener
           
static int LOWERCASE
           
protected  boolean okayToBeep
           
protected  Object previousValue
           
protected  com.klg.jclass.util.JCListenerList propertyListeners
           
static int RESTORE_DEFAULT
           
static int RESTORE_PREVIOUS
           
protected  boolean restoringPrevious
           
protected  boolean select_all
           
protected  boolean select_on_enter
           
static int SHOW_INVALID
           
protected  int state
           
static int UNDEREDIT
           
static int UPPERCASE
           
static int VALID
           
protected  JCValidator validator
           
protected  Color validBackground
           
protected  Color validForeground
           
protected  com.klg.jclass.util.JCListenerList valueListeners
           
protected  com.klg.jclass.util.value.JCValueModel valueModel
           
protected  Component vc
           
 
Constructor Summary
Field(Component vc, JCValidator validator)
           
 
Method Summary
 void addListDataListener(ListDataListener l)
           
 void addNotify()
          This should be called by the "vc" to inform the component that it has been added.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void addValueListener(com.klg.jclass.util.value.JCValueListener listener)
          Adds a listener for changes to the value.
 void commitEdit()
          Commits the current field under edit.
 void commitEdit(AWTEvent e)
          Commits the current field under edit.
protected  void fireValueChangedEvent(com.klg.jclass.util.value.JCValueEvent event)
          Fires a valueChanged event to the JCValuelisteners.
protected  void fireValueChangingEvent(com.klg.jclass.util.value.JCValueEvent event)
          Fires a valueChanging event to the JCValuelisteners.
 boolean getAllowTextChange()
          Used by the Visual Component to see if a call that has been made to its setText() method is permitted.
protected  boolean getBeepOnInvalid()
          Returns the value of beepOnInvalid.
 Component getComponent()
          Returns the visual component currently being used.
 DataProperties getDataProperties()
          Gets the Bean property which wraps the validator, data model, and Field objects properties into one property.
 Object getElementAt(int index)
          Returns the element at a given index in a pick list.
 Object getEventSource()
          Returns the Object that is being used as the source of posted events.
protected  Color getInvalidBackground()
          Returns the background color used in the visual component if the field is invalid.
protected  Color getInvalidForeground()
          Returns the foreground color used in the visual component if the field is invalid.
 JCInvalidInfo getInvalidInfo()
          Returns the Invalid properties.
protected  int getInvalidPolicy()
          Returns the value of invalidPolicy.
 Object getSelectedItem()
           
 boolean getSelectOnEnter()
          Returns a flag indicating the selection status on entering the field.
 int getSize()
          Returns the number of items in the pick list.
 int getState()
          Returns the state of the field.
protected  JTextField getTextField()
          Returns a JTextField given a component.
 JCValidator getValidator()
          Returns the current validator being used by this field of the field.
protected  Color getValidBackground()
          Returns the background color used in the visual component if the field is valid.
protected  Color getValidForeground()
          Returns the foreground color used in the visual component if the field is valid.
 Object getValue()
          Returns the internal value of the field.
 com.klg.jclass.util.value.JCValueModel getValueModel()
          Returns the data model being used by the field.
 Component getVisualComponent()
          This method is internal.
protected  void processFailure()
          Called either from after a failed parse or after a failed.
 void removeListDataListener(ListDataListener l)
           
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void removeValueListener(com.klg.jclass.util.value.JCValueListener listener)
          Removes a listener for changes to the value.
protected  void setBeepOnInvalid(boolean beep)
          Sets the value of beepOnInvalid.
 void setClass(Class c)
          Sets the internal value of the field.
protected  void setColors(Color background, Color foreground)
          Sets the background and foreground of the component.
 void setDataProperties(DataProperties data_properties)
          Sets a Bean property which wraps the validator, data model, and Field objects properties into one property.
 void setEventSource(Object o)
          Sets the Object that is being used as the source of posted events.
protected  void setInvalidBackground(Color background)
          Sets the background color used in the visual component if the field is invalid.
protected  void setInvalidForeground(Color foreground)
          Sets the foreground color used in the visual component if the field is invalid.
 void setInvalidInfo(JCInvalidInfo info)
          Sets the Invalid properties.
protected  void setInvalidPolicy(int policy)
          Sets the invalid policy.
 void setSelectedItem(Object anItem)
           
 void setSelectOnEnter(boolean select)
          Sets the flag that determines whether of not the Text Component is automatically selected when the component gains focus.
protected  void setStateInvalid()
          Does everything necessary to make the state invalid, including swapping colors.
protected  void setStateUnderEdit()
          Does everything necessary to make the state "under edit," including swapping colors.
protected  void setStateValid()
          Does everything necessary to make the state valid, including swapping colors.
protected  void setText(String text_string)
          Sets the actual text string of the visual component.
 void setValidator(JCValidator validator)
          Sets the validator being used by the field.
 void setValue(Object new_value)
          Sets the internal value of the field.
protected  void setValue(Object new_value, boolean exit_on_detecting_equality)
          Sets the internal value of the field.
protected  void setValueAndReformat(Object new_value)
          Sets the internal value of the field.
 void setValueModel(com.klg.jclass.util.value.JCValueModel value_model)
          Sets the data model being used by the field.
 void textCursorMoveBegin(TextCursorEvent e)
          Invoked before the field's cursor is moved.
 void textValueChangeBegin(TextEvent e)
          Invoked before the field's value is changed.
 void textValueChangeEnd(TextEvent e)
          Invoked after the field's value is changed.
 void valueChanged(com.klg.jclass.util.value.JCValueEvent event)
           
 void valueChanging(com.klg.jclass.util.value.JCValueEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALID

public static final int VALID

UNDEREDIT

public static final int UNDEREDIT

INVALID

public static final int INVALID

SHOW_INVALID

public static final int SHOW_INVALID

RESTORE_DEFAULT

public static final int RESTORE_DEFAULT

RESTORE_PREVIOUS

public static final int RESTORE_PREVIOUS

CLEAR_FIELD

public static final int CLEAR_FIELD

AS_IS

public static final int AS_IS

UPPERCASE

public static final int UPPERCASE

LOWERCASE

public static final int LOWERCASE

internalBackgroundChange

protected boolean internalBackgroundChange

internalForegroundChange

protected boolean internalForegroundChange

invalidBackground

protected Color invalidBackground

invalidForeground

protected Color invalidForeground

validBackground

protected Color validBackground

validForeground

protected Color validForeground

select_on_enter

protected boolean select_on_enter

edit_initial_value

protected Object edit_initial_value

edit_class

protected Class edit_class

defaultValue

protected Object defaultValue

previousValue

protected Object previousValue

validator

protected JCValidator validator

current

protected Locale current

event_source

protected Object event_source

vc

protected Component vc

state

protected int state

invalidPolicy

protected int invalidPolicy

beepOnInvalid

protected boolean beepOnInvalid

internal_text_change

protected boolean internal_text_change

has_focus

protected boolean has_focus

propertyListeners

protected com.klg.jclass.util.JCListenerList propertyListeners

valueListeners

protected com.klg.jclass.util.JCListenerList valueListeners

listener

protected com.klg.jclass.field.Field.Listeners listener

okayToBeep

protected boolean okayToBeep

allow_text_change

protected boolean allow_text_change

is_cell_editor

protected boolean is_cell_editor

select_all

protected boolean select_all

valueModel

protected com.klg.jclass.util.value.JCValueModel valueModel

document

protected com.klg.jclass.field.Field.TextFieldDocument document

restoringPrevious

protected boolean restoringPrevious
Constructor Detail

Field

public Field(Component vc,
             JCValidator validator)
Parameters:
vc - visual component used to control input;
validator - validator used to validate "value."
value - object validated by validator; This must match the validator.
Method Detail

getTextField

protected JTextField getTextField()
Returns a JTextField given a component. If visual component does not have a JTextField, returns null.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.
Parameters:
listener - The PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.
Parameters:
listener - The PropertyChangeListener to be removed

addValueListener

public void addValueListener(com.klg.jclass.util.value.JCValueListener listener)
Adds a listener for changes to the value.
Parameters:
listener - The ValueListener to be added

removeValueListener

public void removeValueListener(com.klg.jclass.util.value.JCValueListener listener)
Removes a listener for changes to the value.
Parameters:
listener - The ValueListener to be removed

setDataProperties

public void setDataProperties(DataProperties data_properties)
Sets a Bean property which wraps the validator, data model, and Field objects properties into one property.

getDataProperties

public DataProperties getDataProperties()
Gets the Bean property which wraps the validator, data model, and Field objects properties into one property.

addNotify

public void addNotify()
This should be called by the "vc" to inform the component that it has been added. This is a not ideal, but since there is no "AddListener" we do it this way.

getInvalidBackground

protected Color getInvalidBackground()
Returns the background color used in the visual component if the field is invalid.

setInvalidBackground

protected void setInvalidBackground(Color background)
Sets the background color used in the visual component if the field is invalid. By default this value is inherited from the background color of the component.
See Also:
Component.setBackground(java.awt.Color)

getInvalidForeground

protected Color getInvalidForeground()
Returns the foreground color used in the visual component if the field is invalid.

setInvalidForeground

protected void setInvalidForeground(Color foreground)
Sets the foreground color used in the visual component if the field is invalid. By default this value is inherited from the foreground color of the component.
See Also:
Component.setForeground(java.awt.Color)

getValidBackground

protected Color getValidBackground()
Returns the background color used in the visual component if the field is valid. By default, this value is inherited from the background color of the component.

getValidForeground

protected Color getValidForeground()
Returns the foreground color used in the visual component if the field is valid. By default, this value is inherited from the foreground color of the component.

getBeepOnInvalid

protected boolean getBeepOnInvalid()
Returns the value of beepOnInvalid.
See Also:
setBeepOnInvalid(boolean)

setBeepOnInvalid

protected void setBeepOnInvalid(boolean beep)
Sets the value of beepOnInvalid. If beepOnInvalid == true then the field will beep at the user whenever the state is switched to INVALID.
See Also:
setStateInvalid()

getInvalidPolicy

protected int getInvalidPolicy()
Returns the value of invalidPolicy.
See Also:
setInvalidPolicy(int)

setInvalidPolicy

protected void setInvalidPolicy(int policy)
Sets the invalid policy. The invalidPolicy governs what happens when a user enters invalid data in a field.
Value Meaning
SHOW_INVALID Show invalid value in the invalidBackground and Foreground colors
RESTORE_DEFAULT Restore the value to the defaultValue
RESTORE_PREVIOUS Restore the value to the previous valid value
CLEAR_FIELD Clear the field on invalid input


getInvalidInfo

public JCInvalidInfo getInvalidInfo()
Returns the Invalid properties. The Invalid properties are beepOnInvalid, invalidForeground, invalidBackground, and invalidPolicy.

setInvalidInfo

public void setInvalidInfo(JCInvalidInfo info)
Sets the Invalid properties. The Invalid properties are beepOnInvalid, invalidForeground, invalidBackground, and invalidPolicy.

getState

public int getState()
Returns the state of the field.
Value Meaning
VALID The field is valid
INVALID The field is invalid
UNDEREDIT The field is currently under edit and hence the state is indeterminate


getSelectOnEnter

public boolean getSelectOnEnter()
Returns a flag indicating the selection status on entering the field.
See Also:
setSelectOnEnter(boolean)

setSelectOnEnter

public void setSelectOnEnter(boolean select)
Sets the flag that determines whether of not the Text Component is automatically selected when the component gains focus. The default value for this is "false."

getValue

public Object getValue()
Returns the internal value of the field.

setValueAndReformat

protected void setValueAndReformat(Object new_value)
Sets the internal value of the field. The big difference between this and setValue() is that setValue ignores new values if they are the same and this method goes through the full formatting as if the value had not changed. This is useful when one of the components that controls formatting changes.

setClass

public void setClass(Class c)
Sets the internal value of the field.

setValue

public void setValue(Object new_value)
Sets the internal value of the field.

setValue

protected void setValue(Object new_value,
                        boolean exit_on_detecting_equality)
Sets the internal value of the field.

getAllowTextChange

public boolean getAllowTextChange()
Used by the Visual Component to see if a call that has been made to its setText() method is permitted.

setText

protected void setText(String text_string)
Sets the actual text string of the visual component.

getValueModel

public com.klg.jclass.util.value.JCValueModel getValueModel()
Returns the data model being used by the field.

setValueModel

public void setValueModel(com.klg.jclass.util.value.JCValueModel value_model)
Sets the data model being used by the field.

getValidator

public JCValidator getValidator()
Returns the current validator being used by this field of the field.

setValidator

public void setValidator(JCValidator validator)
Sets the validator being used by the field.

setColors

protected void setColors(Color background,
                         Color foreground)
Sets the background and foreground of the component.
Parameters:
background - if background is null, it will use the default background
foreground - if foreground is null, it will use the initial foreground

processFailure

protected void processFailure()
Called either from after a failed parse or after a failed.

setStateInvalid

protected void setStateInvalid()
Does everything necessary to make the state invalid, including swapping colors.

setStateValid

protected void setStateValid()
Does everything necessary to make the state valid, including swapping colors.

setStateUnderEdit

protected void setStateUnderEdit()
Does everything necessary to make the state "under edit," including swapping colors.

getComponent

public Component getComponent()
Returns the visual component currently being used.

getEventSource

public Object getEventSource()
Returns the Object that is being used as the source of posted events.

setEventSource

public void setEventSource(Object o)
Sets the Object that is being used as the source of posted events.

commitEdit

public void commitEdit()
Commits the current field under edit.

commitEdit

public void commitEdit(AWTEvent e)
Commits the current field under edit.

getVisualComponent

public Component getVisualComponent()
This method is internal. You should not have to call it.

textValueChangeBegin

public void textValueChangeBegin(TextEvent e)
Invoked before the field's value is changed. This routine invokes the AbstractValidator to check if a particular change is allowed. The event's values can be modified via its setXXX methods.

textValueChangeEnd

public void textValueChangeEnd(TextEvent e)
Invoked after the field's value is changed. Any changes made to the event are ignored.

textCursorMoveBegin

public void textCursorMoveBegin(TextCursorEvent e)
Invoked before the field's cursor is moved. The event's values can be modified via its setXXX methods.

getSize

public int getSize()
Returns the number of items in the pick list.

getElementAt

public Object getElementAt(int index)
Returns the element at a given index in a pick list.

addListDataListener

public void addListDataListener(ListDataListener l)

removeListDataListener

public void removeListDataListener(ListDataListener l)

setSelectedItem

public void setSelectedItem(Object anItem)
Specified by:
setSelectedItem in interface ComboBoxModel

getSelectedItem

public Object getSelectedItem()
Specified by:
getSelectedItem in interface ComboBoxModel

valueChanging

public void valueChanging(com.klg.jclass.util.value.JCValueEvent event)
Specified by:
valueChanging in interface com.klg.jclass.util.value.JCValueListener

valueChanged

public void valueChanged(com.klg.jclass.util.value.JCValueEvent event)
Specified by:
valueChanged in interface com.klg.jclass.util.value.JCValueListener

fireValueChangingEvent

protected void fireValueChangingEvent(com.klg.jclass.util.value.JCValueEvent event)
Fires a valueChanging event to the JCValuelisteners.

fireValueChangedEvent

protected void fireValueChangedEvent(com.klg.jclass.util.value.JCValueEvent event)
Fires a valueChanged event to the JCValuelisteners.

Copyright© 1999-2000 KL Group Inc.
All rights reserved.