LiveGraph
data visualisation and analysis framework

org.LiveGraph.gui
Class RealNumFieldValueChangeAdaptor

java.lang.Object
  extended by org.LiveGraph.gui.RealNumFieldValueChangeAdaptor
All Implemented Interfaces:
java.awt.event.FocusListener, java.awt.event.KeyListener, java.util.EventListener

public abstract class RealNumFieldValueChangeAdaptor
extends java.lang.Object
implements java.awt.event.FocusListener, java.awt.event.KeyListener

This validating adaptor listens to focusLost-messages of a JTextField. If at that moment the field contains a valid double value (as a string), the valueChanged(JTextField, double)-method is called. That method must be overridden by subclasses to take some appropriate action. If, however, the field does not contain a valid double value, the valueChanged(JTextField, double)-method is not called and a tooltip with an error message is displayed near the text fiels. The last known "good" value is then restored.

This product includes software developed by the LiveGraph project and its contributors.
(http://www.live-graph.org)
Copyright (c) 2007 G. Paperin.
All rights reserved.

File: RealNumFieldValueChangeAdaptor.java

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:

1. Redistributions of source code must retain the above acknowledgement of the LiveGraph project and its web-site, the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the LiveGraph project and its web-site, the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived software must display the following acknowledgement:
This product includes software developed by the LiveGraph project and its contributors.
(http://www.live-graph.org)

4. All advertising materials distributed in form of HTML pages or any other technology permitting active hyper-links that mention features or use of this software or any derived software must display the acknowledgment specified in condition 3 of this agreement, and in addition, include a visible and working hyper-link to the LiveGraph homepage (http://www.live-graph.org).

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version:
"1.1.1"
Author:
Greg Paperin (http://www.paperin.org)

Field Summary
private  double defaultValue
           
private  java.util.HashMap<javax.swing.JTextField,java.lang.Double> lastLegalvaluesCache
           
static long TOOLTIP_DISPLAY_LEN
          Display length for the error messgae tooltip in milliseconds.
 
Constructor Summary
RealNumFieldValueChangeAdaptor(double defaultValue)
          Constructor.
 
Method Summary
 void focusGained(java.awt.event.FocusEvent e)
          Does nothing.
 void focusLost(java.awt.event.FocusEvent e)
          Catches the focus lost event and performs field validation.
 void handleEvent(javax.swing.JTextField field)
          Performs the validation and handles appropriately.
 void keyPressed(java.awt.event.KeyEvent e)
          Catches the enter pressed event and performs field validation.
 void keyReleased(java.awt.event.KeyEvent e)
          Does nothing.
 void keyTyped(java.awt.event.KeyEvent e)
          Does nothing.
abstract  double valueChanged(javax.swing.JTextField field, double newValue)
          Subclasses must override that in order to take the appropriate action when the field contains a valid double value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOOLTIP_DISPLAY_LEN

public static final long TOOLTIP_DISPLAY_LEN
Display length for the error messgae tooltip in milliseconds.

See Also:
Constant Field Values

defaultValue

private double defaultValue

lastLegalvaluesCache

private java.util.HashMap<javax.swing.JTextField,java.lang.Double> lastLegalvaluesCache
Constructor Detail

RealNumFieldValueChangeAdaptor

public RealNumFieldValueChangeAdaptor(double defaultValue)
Constructor.

Parameters:
defaultValue - Default "good" value.
Method Detail

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Does nothing.

Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Catches the focus lost event and performs field validation.

Specified by:
focusLost in interface java.awt.event.FocusListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Catches the enter pressed event and performs field validation.

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Does nothing.

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Does nothing.

Specified by:
keyTyped in interface java.awt.event.KeyListener

handleEvent

public void handleEvent(javax.swing.JTextField field)
Performs the validation and handles appropriately.

Parameters:
field - The text field that generated the event.

valueChanged

public abstract double valueChanged(javax.swing.JTextField field,
                                    double newValue)
Subclasses must override that in order to take the appropriate action when the field contains a valid double value.

Parameters:
field - The text field containing the value.
newValue - The double value in the field.
Returns:
A string representing the value returned by this method will be used instead of the current field content.

LiveGraph
data visualisation and analysis framework