JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.field
Class Field

java.lang.Object
  |
  +--com.klg.jclass.field.Field
All Implemented Interfaces:
ComboBoxModel, EventListener, JCValueListener, ListModel, Serializable

public class Field
extends Object
implements Serializable, 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

Nested Class Summary
 class Field.TextFieldContent
           
 
Field Summary
protected  boolean allow_text_change
           
static int AS_IS
           
protected  boolean auto_complete_mode
           
protected  boolean beepOnInvalid
           
static int CLEAR_FIELD
           
protected  Locale current
           
protected  boolean doing_commit
           
protected  boolean doing_completion
           
protected  Class edit_class
           
protected  Object edit_initial_value
           
protected  boolean has_focus
           
protected  boolean in_contents_change
           
protected  boolean in_set_selected_item
           
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
           
static int LOWERCASE
           
protected  boolean okayToBeep
           
static int RESTORE_DEFAULT
           
static int RESTORE_PREVIOUS
           
protected  boolean restoringPrevious
           
protected  boolean select_all
           
protected  boolean select_on_enter
           
protected  boolean set_selected_item_called
           
static int SHOW_INVALID
           
protected  int state
           
static int UNDEREDIT
           
protected  boolean upDownPressed
           
static int UPPERCASE
           
static int VALID
           
protected  com.klg.jclass.field.validate.JCValidator validator
           
protected  Color validBackground
           
protected  Color validForeground
           
protected  com.klg.jclass.util.value.JCValueModel valueModel
           
protected  Component vc
           
 
Constructor Summary
Field(Component vc, com.klg.jclass.field.validate.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.
protected  void calcAutoCompleteMode(com.klg.jclass.field.JCComboField combo)
          Calculate auto_complete_mode value.
 void commitEdit()
          Commits the current field under edit.
 void commitEdit(AWTEvent e)
          Commits the current field under edit.
protected  void doCommitEdit(AWTEvent e)
          Commits the current field under edit.
protected  void fireContentsChanged(Object source, int index0, int index1)
          Called when the combo box's item list changes (which happens when the picklist changes).
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.
 com.klg.jclass.field.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.
 com.klg.jclass.field.JCInvalidInfo getInvalidInfo()
          Returns the Invalid properties.
protected  int getInvalidPolicy()
          Returns the value of invalidPolicy.
 Object getSelectedItem()
          Get the currently selected item (and format accordingly)
 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.
 com.klg.jclass.field.validate.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 restorePickList()
          Restore the picklist to its original value before AutoRefinement changed it.
protected  void setBeepOnInvalid(boolean beep)
          Sets the value of beepOnInvalid.
 void setCellEditor(boolean isCellEditor)
          Sets the is_cell_editor property Default is false
 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(com.klg.jclass.field.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(com.klg.jclass.field.JCInvalidInfo info)
          Sets the Invalid properties.
protected  void setInvalidPolicy(int policy)
          Sets the invalid policy.
 void setSelectedItem(Object anItem)
          Set an item from the picklist on the text field
 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(com.klg.jclass.field.validate.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(com.klg.jclass.field.validate.TextCursorEvent e)
          Invoked before the field's cursor is moved.
 void textValueChangeBegin(com.klg.jclass.field.validate.TextEvent e)
          Invoked before the field's value is changed.
 void textValueChangeEnd(com.klg.jclass.field.validate.TextEvent e)
          Invoked after the field's value is changed.
protected  void turnOffAutoCompleteMode()
          Turn off auto_complete_mode.
 void valueChanged(com.klg.jclass.util.value.JCValueEvent event)
          The method informs a listener that the value has been changed.
 void valueChanging(com.klg.jclass.util.value.JCValueEvent event)
          The value is changing.
 
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
See Also:
Constant Field Values

UNDEREDIT

public static final int UNDEREDIT
See Also:
Constant Field Values

INVALID

public static final int INVALID
See Also:
Constant Field Values

SHOW_INVALID

public static final int SHOW_INVALID
See Also:
Constant Field Values

RESTORE_DEFAULT

public static final int RESTORE_DEFAULT
See Also:
Constant Field Values

RESTORE_PREVIOUS

public static final int RESTORE_PREVIOUS
See Also:
Constant Field Values

CLEAR_FIELD

public static final int CLEAR_FIELD
See Also:
Constant Field Values

AS_IS

public static final int AS_IS
See Also:
Constant Field Values

UPPERCASE

public static final int UPPERCASE
See Also:
Constant Field Values

LOWERCASE

public static final int LOWERCASE
See Also:
Constant Field Values

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

validator

protected com.klg.jclass.field.validate.JCValidator validator

current

protected Locale current

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

auto_complete_mode

protected boolean auto_complete_mode

doing_completion

protected boolean doing_completion

doing_commit

protected boolean doing_commit

in_set_selected_item

protected boolean in_set_selected_item

set_selected_item_called

protected boolean set_selected_item_called

in_contents_change

protected boolean in_contents_change

upDownPressed

protected boolean upDownPressed

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

restoringPrevious

protected boolean restoringPrevious
Constructor Detail

Field

public Field(Component vc,
             com.klg.jclass.field.validate.JCValidator validator)
Parameters:
vc - visual component used to control input;
validator - validator used to validate "value."
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(com.klg.jclass.field.DataProperties data_properties)
Sets a Bean property which wraps the validator, data model, and Field objects properties into one property.


setCellEditor

public void setCellEditor(boolean isCellEditor)
Sets the is_cell_editor property Default is false

Parameters:
isCellEditor - The new value of is_cell_editor

getDataProperties

public com.klg.jclass.field.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 com.klg.jclass.field.JCInvalidInfo getInvalidInfo()
Returns the Invalid properties. The Invalid properties are beepOnInvalid, invalidForeground, invalidBackground, and invalidPolicy.


setInvalidInfo

public void setInvalidInfo(com.klg.jclass.field.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 com.klg.jclass.field.validate.JCValidator getValidator()
Returns the current validator being used by this field of the field.


setValidator

public void setValidator(com.klg.jclass.field.validate.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. If a combo box and the popup is visible, make it go away.


doCommitEdit

protected void doCommitEdit(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(com.klg.jclass.field.validate.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(com.klg.jclass.field.validate.TextEvent e)
Invoked after the field's value is changed. Any changes made to the event are ignored.


textCursorMoveBegin

public void textCursorMoveBegin(com.klg.jclass.field.validate.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.

Specified by:
getSize in interface ListModel

getElementAt

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

Specified by:
getElementAt in interface ListModel

addListDataListener

public void addListDataListener(ListDataListener l)
Specified by:
addListDataListener in interface ListModel

removeListDataListener

public void removeListDataListener(ListDataListener l)
Specified by:
removeListDataListener in interface ListModel

fireContentsChanged

protected void fireContentsChanged(Object source,
                                   int index0,
                                   int index1)
Called when the combo box's item list changes (which happens when the picklist changes).

Parameters:
source - The ListModel that changed, typically "this".
index0 - One end of the new interval (ignored in this context)
index1 - The other end of the new interval (ignored in this context)
See Also:
EventListenerList, DefaultListModel

restorePickList

protected void restorePickList()
Restore the picklist to its original value before AutoRefinement changed it.


setSelectedItem

public void setSelectedItem(Object anItem)
Set an item from the picklist on the text field

Specified by:
setSelectedItem in interface ComboBoxModel

getSelectedItem

public Object getSelectedItem()
Get the currently selected item (and format accordingly)

Specified by:
getSelectedItem in interface ComboBoxModel

calcAutoCompleteMode

protected void calcAutoCompleteMode(com.klg.jclass.field.JCComboField combo)
Calculate auto_complete_mode value.


turnOffAutoCompleteMode

protected void turnOffAutoCompleteMode()
Turn off auto_complete_mode. Remove any highlighting. Restore the picklist.


valueChanging

public void valueChanging(com.klg.jclass.util.value.JCValueEvent event)
Description copied from interface: JCValueListener
The value is changing. A listener may further change the new_value or abort the change altogether. In the case of an abort (initiatied by calling event.setAllowChange(false)), the valueChanged method will never be called.

Specified by:
valueChanging in interface JCValueListener
Parameters:
event - The event generated by the value changing

valueChanged

public void valueChanged(com.klg.jclass.util.value.JCValueEvent event)
Description copied from interface: JCValueListener
The method informs a listener that the value has been changed.

Specified by:
valueChanged in interface JCValueListener
Parameters:
event - The event generated by the value changed

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 © 2004 Quest Software Inc..
All rights reserved.