Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.gui4j.component
Class Gui4jTree.Gui4jTreeSelectionListener  view Gui4jTree.Gui4jTreeSelectionListener download Gui4jTree.Gui4jTreeSelectionListener.java

java.lang.Object
  extended byorg.gui4j.component.Gui4jTree.Gui4jTreeSelectionListener
All Implemented Interfaces:
java.util.EventListener, java.awt.event.FocusListener, java.awt.event.KeyListener, javax.swing.event.TreeSelectionListener
Enclosing class:
Gui4jTree

private abstract static class Gui4jTree.Gui4jTreeSelectionListener
extends java.lang.Object
implements javax.swing.event.TreeSelectionListener, java.awt.event.KeyListener, java.awt.event.FocusListener

Subclass of TreeSelectionListener. Implements a simple strategy to solve the problem that a lot of TreeSelectionEvents are generated and processed when the user keeps pressing the up and down arrow keys. To work correctly, the same instance of this listener must be registered in three ways with a tree, using JTree.addTreeSelectionListener(javax.swing.event.TreeSelectionListener)>JTree.addTreeSelectionListener(javax.swing.event.TreeSelectionListener) 55 , Component.addKeyListener(java.awt.event.KeyListener)>Component.addKeyListener(java.awt.event.KeyListener) 55 and Component.addFocusListener(java.awt.event.FocusListener)>Component.addFocusListener(java.awt.event.FocusListener) 55 .

The problem this class solves is that a TreeSelectionEvent might trigger expensive operations (e.g. loading detailed information for the newly selected tree node from a database). If the user "scrolls down" by pressing the down arrow for a long time, the expensive operation is performed for each visited node. This Listener blocks all TreeSelectionEvents while any key is pressed. Only when a key is released is the most recent event passed to the actual event handler.


Field Summary
private  javax.swing.event.TreeSelectionEvent blockedEvent
           
private  boolean blockNotification
           
 
Constructor Summary
private Gui4jTree.Gui4jTreeSelectionListener()
           
 
Method Summary
private  void block()
           
 void focusGained(java.awt.event.FocusEvent e)
          This method is called when a component gains the keyboard focus.
 void focusLost(java.awt.event.FocusEvent e)
          This method is invoked when a component loses the keyboard focus.
 void keyPressed(java.awt.event.KeyEvent e)
          This method is called when a key is pressed.
 void keyReleased(java.awt.event.KeyEvent e)
          This method is called when a key is released.
 void keyTyped(java.awt.event.KeyEvent e)
          This method is called when a key is typed.
abstract  void selectionChanged(javax.swing.event.TreeSelectionEvent e)
          Subclasses must override this method instead of the usual TreeSelectionListener.valueChanged(javax.swing.event.TreeSelectionEvent)>TreeSelectionListener.valueChanged(javax.swing.event.TreeSelectionEvent) 55 .
private  void unblock()
           
 void valueChanged(javax.swing.event.TreeSelectionEvent e)
          Subclasses should not override this method (as is done with a normal TreeSelectionListener) but selectionChanged(TreeSelectionEvent) 55 instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blockNotification

private boolean blockNotification

blockedEvent

private javax.swing.event.TreeSelectionEvent blockedEvent
Constructor Detail

Gui4jTree.Gui4jTreeSelectionListener

private Gui4jTree.Gui4jTreeSelectionListener()
Method Detail

block

private void block()

unblock

private void unblock()

selectionChanged

public abstract void selectionChanged(javax.swing.event.TreeSelectionEvent e)
Subclasses must override this method instead of the usual TreeSelectionListener.valueChanged(javax.swing.event.TreeSelectionEvent)>TreeSelectionListener.valueChanged(javax.swing.event.TreeSelectionEvent) 55 .


valueChanged

public final void valueChanged(javax.swing.event.TreeSelectionEvent e)
Subclasses should not override this method (as is done with a normal TreeSelectionListener) but selectionChanged(TreeSelectionEvent) 55 instead.

Specified by:
valueChanged in interface javax.swing.event.TreeSelectionListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Description copied from interface: java.awt.event.KeyListener
This method is called when a key is pressed.

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

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Description copied from interface: java.awt.event.KeyListener
This method is called when a key is released.

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

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Description copied from interface: java.awt.event.KeyListener
This method is called when a key is typed. A key is considered typed when it and all modifiers have been pressed and released, mapping to a single virtual key.

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

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Description copied from interface: java.awt.event.FocusListener
This method is called when a component gains the keyboard focus.

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

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Description copied from interface: java.awt.event.FocusListener
This method is invoked when a component loses the keyboard focus.

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