com.numobjects.mathbeans
Class NamedField

com.numobjects.mathbeans.NamedField

public class NamedField
implements java.io.Serializable

NamedField is essentially a combination of a label and a text field. In 99% of the cases when you would want to use a text field, you would use a label with it to indicate the name for the value in the field. Therefore it is natural to combine Name and Value. The resulting combination (with some additional general and mathematical capabilities) is the NamedField. Here are some of its features.  
Math awareness By default the NamedField is math aware, i.e. it performs operations according to a formula entered by the user (like (187.21+248.97)*1.0825) when he presses Enter.
Prompt If the value field is empty it displays a prompt like "Enter value here". The prompt string can be set at any time.
Error message If the field is math aware and the user presses Enter to compute an uncomputable expression (like (1 + a)), it either displays for 5 seconds a blinking error message if the value field does not have the focus or underscores the expression with a zigzag line otherwise. The error message like "Can't compute this!" can be set at any time.
Rounding By setting the number of decimal places to be displayed after the decimal dot, the programmer controls the format of the number output.
Format The user can control the general appearance of the NamedField by setting fonts and alignments for the name label and the value field.
Translators The NamedField may be assigned a translator to translate the field's text into a numerical value and a back translator to translate a numerical value into the field's text. This feature may be used with date and time fields, percentages, boolean values, etc
Separator By default the NamedField has a separator between the label and the field. This separator is adjustable. Simply drag it with the mouse to wherever you like. The label text and the field text adjust accordingly.

See Also:
Serialized Form

Constructor Summary
NamedField()
          Constructor
NamedField(java.lang.String s)
          Constructor
NamedField(java.lang.String s, java.awt.Color color)
          Constructor
NamedField(java.lang.String name, java.lang.String value)
          Constructor
NamedField(java.lang.String name, java.lang.String value, java.awt.Color color)
          Constructor
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
          Adds action listener
 void addTextListener(java.awt.event.TextListener l)
          Adds text listener
 Translator getBackTranslator()
          Gets back translator (that translates values into text)
 int getCaretPosition()
          Gets caret position
 java.lang.String getErrorMessage()
          Gets error message return error message
 int getFieldAlignment()
          Gets field alignment
 java.awt.Font getFieldFont()
          Gets field font
 java.lang.String getFieldName()
          Gets name
 int getLabelAlignment()
          Gets label alignment
 java.awt.Font getLabelFont()
          Gets label font
 int getPrecision()
          Gets precision
 java.lang.String getPrompt()
          Gets prompt string
 int getRounding()
          Gets rounding
 java.lang.String getSelectedText()
          Gets selected text
 int getSelectionEnd()
          Gets selection end
 int getSelectionStart()
          Gets selection start
 int getSeparator()
          Gets separator position
 java.lang.String getText()
          Gets text
 Translator getTranslator()
          Gets translator (that translates text into values)
 java.lang.String getValue()
          Gets value
 java.lang.String getValue(boolean translate)
          Gets value with optional translation
 boolean isDisplayErrors()
          Queries display error property
 boolean isEditable()
          Queries editable property
 boolean isMathAware()
          Queries math awareness property
 boolean isPrompting()
          Queries prompting property
 boolean isResizable()
          Gets resizable property
 void removeActionListener(java.awt.event.ActionListener l)
          Removes action listener
 void removeTextListener(java.awt.event.TextListener l)
          Removes text listener
 void select(int start, int end)
          Selects text part
 void selectAll()
          Selects all text
 void setBackground(java.awt.Color color)
          Sets background color
 void setBackTranslator(Translator translator)
          Sets translator (to translate values into text)
 void setCaretPosition(int pos)
          Sets caret position
 void setDisplayErrors(boolean b)
          Sets display error property
 void setEditable(boolean flag)
          Sets editable property
 void setError(boolean b)
          Sets error
 void setError(boolean b, java.lang.String message)
          Sets error
 void setErrorMessage(java.lang.String message)
          Sets error message
 void setFieldAlignment(int alignment)
          Sets field alignment
 void setFieldFont(java.awt.Font font)
          Sets field font
 void setFieldName(java.lang.String name)
          Sets name
 void setFont(java.awt.Font font)
          Sets font
 void setForeground(java.awt.Color color)
          Sets foreground color
 void setLabelAlignment(int alignment)
          Sets label alignment
 void setLabelFont(java.awt.Font font)
          Sets label font
 void setMathAware(boolean b)
          Sets math awareness property
 void setPrecision(int value)
          Sets precision (the number of significant digits in the calculation); range 1 - 15, default precision is 6
 void setPrompt(java.lang.String prompt)
          Sets prompt text
 void setPrompting(boolean b)
          Sets prompting property
 void setResizable(boolean b)
          Sets resizable property
 void setRounding(int value)
          Sets rounding (the number of digits displayed after the decimal dot); range -1 - 15, default rounding is -1 (no rounding)
 void setSelectionEnd(int end)
          Sets selection end
 void setSelectionStart(int start)
          Sets selection start
 void setSeparator(int width)
          Sets separator position
 void setText(java.lang.String s)
          Sets text
 void setTranslator(Translator translator)
          Sets translator (to translate text into values)
 void setValue(java.lang.String s)
          Sets value
 void setValue(java.lang.String value, boolean translate)
          Sets value with optional back translation
 

Constructor Detail

NamedField

public NamedField()
Constructor

NamedField

public NamedField(java.lang.String s,
                  java.awt.Color color)
Constructor
Parameters:
s - name
color - background

NamedField

public NamedField(java.lang.String s)
Constructor
Parameters:
s - name

NamedField

public NamedField(java.lang.String name,
                  java.lang.String value,
                  java.awt.Color color)
Constructor
Parameters:
name - name
value - value
color - background

NamedField

public NamedField(java.lang.String name,
                  java.lang.String value)
Constructor
Parameters:
name - name
value - value
Method Detail

setFont

public void setFont(java.awt.Font font)
Sets font
Parameters:
font - font

setLabelFont

public void setLabelFont(java.awt.Font font)
Sets label font
Parameters:
font - font

getLabelFont

public java.awt.Font getLabelFont()
Gets label font
Returns:
label font

setFieldFont

public void setFieldFont(java.awt.Font font)
Sets field font
Parameters:
font - font

getFieldFont

public java.awt.Font getFieldFont()
Gets field font
Returns:
field font

setResizable

public void setResizable(boolean b)
Sets resizable property
Parameters:
b - property flag

isResizable

public boolean isResizable()
Gets resizable property
Returns:
property flag

setFieldName

public void setFieldName(java.lang.String name)
Sets name
Parameters:
name - name

getFieldName

public java.lang.String getFieldName()
Gets name
Returns:
name

setValue

public void setValue(java.lang.String s)
Sets value
Parameters:
value - value

setValue

public void setValue(java.lang.String value,
                     boolean translate)
Sets value with optional back translation
Parameters:
value -  
translate - translation flag

getValue

public java.lang.String getValue()
Gets value
Returns:
value

getValue

public java.lang.String getValue(boolean translate)
Gets value with optional translation
Parameters:
translate - translation flag
Returns:
value

setText

public void setText(java.lang.String s)
Sets text
Parameters:
s - text

getText

public java.lang.String getText()
Gets text
Returns:
value text

setLabelAlignment

public void setLabelAlignment(int alignment)
Sets label alignment
Parameters:
alignment - alignment

getLabelAlignment

public int getLabelAlignment()
Gets label alignment
Returns:
alignment

setFieldAlignment

public void setFieldAlignment(int alignment)
Sets field alignment
Parameters:
alignment - alignment

getFieldAlignment

public int getFieldAlignment()
Gets field alignment
Returns:
alignment

setPrecision

public void setPrecision(int value)
Sets precision (the number of significant digits in the calculation); range 1 - 15, default precision is 6
Parameters:
value - precision to set

getPrecision

public int getPrecision()
Gets precision
Returns:
precision value (the number of significant digits in the calculation)

setRounding

public void setRounding(int value)
Sets rounding (the number of digits displayed after the decimal dot); range -1 - 15, default rounding is -1 (no rounding)
Parameters:
value - rounding

getRounding

public int getRounding()
Gets rounding
Returns:
rounding value (the number of digits displayed after the decimal dot)

setSeparator

public void setSeparator(int width)
Sets separator position
Parameters:
width - position

getSeparator

public int getSeparator()
Gets separator position
Returns:
separator position

setPrompting

public void setPrompting(boolean b)
Sets prompting property
Parameters:
b - property flag

isPrompting

public boolean isPrompting()
Queries prompting property
Returns:
property flag

setPrompt

public void setPrompt(java.lang.String prompt)
Sets prompt text
Parameters:
prompt - prompt

getPrompt

public java.lang.String getPrompt()
Gets prompt string
Returns:
prompt string

setErrorMessage

public void setErrorMessage(java.lang.String message)
Sets error message
Parameters:
message - message

getErrorMessage

public java.lang.String getErrorMessage()
Gets error message return error message

setMathAware

public void setMathAware(boolean b)
Sets math awareness property
Parameters:
b - property flag

isMathAware

public boolean isMathAware()
Queries math awareness property
Returns:
property flag

setDisplayErrors

public void setDisplayErrors(boolean b)
Sets display error property
Parameters:
b - property flag

isDisplayErrors

public boolean isDisplayErrors()
Queries display error property
Returns:
property flag

setForeground

public void setForeground(java.awt.Color color)
Sets foreground color
Parameters:
color - color

setBackground

public void setBackground(java.awt.Color color)
Sets background color
Parameters:
color - color

addTextListener

public void addTextListener(java.awt.event.TextListener l)
Adds text listener
Parameters:
l - listener

removeTextListener

public void removeTextListener(java.awt.event.TextListener l)
Removes text listener
Parameters:
l - listener

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
Adds action listener
Parameters:
l - listener

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
Removes action listener
Parameters:
l - listener

getCaretPosition

public int getCaretPosition()
Gets caret position
Returns:
caret position

getSelectedText

public java.lang.String getSelectedText()
Gets selected text
Returns:
selected text

getSelectionEnd

public int getSelectionEnd()
Gets selection end
Returns:
selection end

getSelectionStart

public int getSelectionStart()
Gets selection start
Returns:
selection start

isEditable

public boolean isEditable()
Queries editable property
Returns:
editable property

select

public void select(int start,
                   int end)
Selects text part
Parameters:
start - selection start
end - selection end

selectAll

public void selectAll()
Selects all text

setCaretPosition

public void setCaretPosition(int pos)
Sets caret position
Parameters:
pos - position

setEditable

public void setEditable(boolean flag)
Sets editable property
Parameters:
flag - property flag

setSelectionEnd

public void setSelectionEnd(int end)
Sets selection end
Parameters:
end - end

setSelectionStart

public void setSelectionStart(int start)
Sets selection start
Parameters:
start - start

setError

public void setError(boolean b)
Sets error
Parameters:
b - error flag
message - message

setError

public void setError(boolean b,
                     java.lang.String message)
Sets error
Parameters:
b - error flag
message - message

setTranslator

public void setTranslator(Translator translator)
Sets translator (to translate text into values)
Parameters:
translator - translator

getTranslator

public Translator getTranslator()
Gets translator (that translates text into values)
Returns:
translator

setBackTranslator

public void setBackTranslator(Translator translator)
Sets translator (to translate values into text)
Parameters:
translator - translator

getBackTranslator

public Translator getBackTranslator()
Gets back translator (that translates values into text)
Returns:
translator