org.tbee.swing
Class FocusInterpreter

java.lang.Object
  extended by org.tbee.swing.FocusInterpreter
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener

public class FocusInterpreter
extends java.lang.Object
implements java.beans.PropertyChangeListener

This class interpretes keyboard focus movements and determines if the focus is lost - to a component within the same application (LOSING_FOCUS followed by a FOCUS_LOST) - or to something outside the application (just LOSING_FOCUS). This allows for more fine tuned behaviour in JTable by force writing an editing cell on FOCUS_LOST. Special consideration is take for popup menus: if though it would be a FOCUS_LOST, this is degraded to a LOSING_FOCUS. All components in the hierarchy to the one actually having focus are assumed to have focus also. This could be a JPanel with a component or a JTable where an editor is active. Listeners for this information must register using addFocusInterpreterListener( FocusInterpreter.FocusInterpreterListener ) This component weak-binds itself to the component, so that if the component could be garbage collected, the FocusInterpreter does not block that. On the next focus event, the FocusInterpreter will detect that the component is gone and will remove itself from the listeners and thus be garbage collected itself.

Version:
$Revision: 1.19 $

Nested Class Summary
static class FocusInterpreter.FocusInterpreterEvent
           
static interface FocusInterpreter.FocusInterpreterListener
           
 
Field Summary
static org.apache.log4j.Logger log4j
           
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
static int STATE_FOCUS_LOST
           
static int STATE_GAINED_FOCUS
           
static int STATE_LOSING_FOCUS
           
 
Constructor Summary
FocusInterpreter(java.awt.Component component)
          remember the component and start listening
 
Method Summary
 void addFocusListener(FocusInterpreter.FocusInterpreterListener l)
           
static java.lang.String describeState(int state)
           
 void fireFocusEvent(int state, java.awt.Component oldComponent, java.awt.Component newComponent)
           
 int getState()
           
 boolean isActive()
           
 void propertyChange(java.beans.PropertyChangeEvent ev)
          Interprete focus events
 void removeFocusListener(FocusInterpreter.FocusInterpreterListener l)
           
 void setState(int value)
           
 void start()
          start interpreting focus events
 void stop()
          stop interpreting focus events
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

log4j

public static org.apache.log4j.Logger log4j

STATE_FOCUS_LOST

public static final int STATE_FOCUS_LOST
See Also:
Constant Field Values

STATE_GAINED_FOCUS

public static final int STATE_GAINED_FOCUS
See Also:
Constant Field Values

STATE_LOSING_FOCUS

public static final int STATE_LOSING_FOCUS
See Also:
Constant Field Values
Constructor Detail

FocusInterpreter

public FocusInterpreter(java.awt.Component component)
remember the component and start listening

Method Detail

start

public void start()
start interpreting focus events


stop

public void stop()
stop interpreting focus events


isActive

public boolean isActive()

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent ev)
Interprete focus events

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getState

public int getState()

setState

public void setState(int value)

describeState

public static java.lang.String describeState(int state)
Parameters:
state -
Returns:

addFocusListener

public void addFocusListener(FocusInterpreter.FocusInterpreterListener l)

removeFocusListener

public void removeFocusListener(FocusInterpreter.FocusInterpreterListener l)

fireFocusEvent

public void fireFocusEvent(int state,
                           java.awt.Component oldComponent,
                           java.awt.Component newComponent)


Copyright © 2010. All Rights Reserved.