|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.notuvy.gui.SimpleHandler
public abstract class SimpleHandler
This is a facility for handling a single, simple UI action. Very often, UI action handlers only need to perform simple behavior. For example, a key listener most often performs an action on 'key released' and ignores the initial 'key pressed'. This framework encapsulates that by defining a principle action for each type of handler and stubbing the functionality of others. A problem with generic Listeners is that if an exception or error happens in the body, it is in the UI thread. It may get swallowed or logged to an unexpected location (like System.err). Also there is no hook for handling. This fixes that by passing the logger and error message to the constructor. A hook method gets called in exception handling, which subclasses can override with additional functionality. There is also an overridable method that controls whether the error message is logged or not. Finally, there is built-in support for performing actions in a separate thread. This is important for Swing actions. Normally generic Listeners are executed in the Swing UI thread. In most cases, the action is short and simple and this is the desired behavior. But for long running actions, it may be desirable to free the Swing thread to continue with UI redrawing (for example, animating a progress bar). To handle this, a boolean flag is passed to the constructor indicating that the action is to be performed in the separate thread reserved for this class. Note that this should be done judiciously. In most cases, the Swing thread is the sufficient and desirable worker. User: murali Date: May 10, 2010 Time: 3:56:27 PM
Nested Class Summary | |
---|---|
static class |
SimpleHandler.Action
|
static class |
SimpleHandler.KeyRelease
|
static class |
SimpleHandler.WindowClosing
|
Constructor Summary | |
---|---|
protected |
SimpleHandler(org.apache.log4j.Logger pLogger,
String pMessage)
|
protected |
SimpleHandler(org.apache.log4j.Logger pLogger,
String pMessage,
boolean pSeparateThread)
|
Method Summary | |
---|---|
void |
actionPerformed(ActionEvent ae)
The entry point from the framework. |
boolean |
doLogError()
By default be verbose. |
ActionEvent |
getActionEvent()
|
KeyEvent |
getKeyEvent()
|
WindowEvent |
getWindowEvent()
|
void |
handleError()
A hook for additional error handling. |
void |
keyPressed(KeyEvent pKeyEvent)
|
void |
keyReleased(KeyEvent pKeyEvent)
|
void |
keyTyped(KeyEvent pKeyEvent)
|
protected abstract void |
principleAction()
This is the single action of the class. |
void |
run()
The work performed in the separate thread. |
void |
setWindowEvent(WindowEvent pWindowEvent)
|
void |
windowActivated(WindowEvent pWindowEvent)
|
void |
windowClosed(WindowEvent pWindowEvent)
|
void |
windowClosing(WindowEvent pWindowEvent)
|
void |
windowDeactivated(WindowEvent pWindowEvent)
|
void |
windowDeiconified(WindowEvent pWindowEvent)
|
void |
windowIconified(WindowEvent pWindowEvent)
|
void |
windowOpened(WindowEvent pWindowEvent)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected SimpleHandler(org.apache.log4j.Logger pLogger, String pMessage)
protected SimpleHandler(org.apache.log4j.Logger pLogger, String pMessage, boolean pSeparateThread)
Method Detail |
---|
public ActionEvent getActionEvent()
public KeyEvent getKeyEvent()
public WindowEvent getWindowEvent()
public void setWindowEvent(WindowEvent pWindowEvent)
public final void actionPerformed(ActionEvent ae)
actionPerformed
in interface ActionListener
ae
- The action event which will be stored as a member variable.public void keyTyped(KeyEvent pKeyEvent)
keyTyped
in interface KeyListener
public void keyPressed(KeyEvent pKeyEvent)
keyPressed
in interface KeyListener
public void keyReleased(KeyEvent pKeyEvent)
keyReleased
in interface KeyListener
public void windowOpened(WindowEvent pWindowEvent)
windowOpened
in interface WindowListener
public void windowClosed(WindowEvent pWindowEvent)
windowClosed
in interface WindowListener
public void windowIconified(WindowEvent pWindowEvent)
windowIconified
in interface WindowListener
public void windowDeiconified(WindowEvent pWindowEvent)
windowDeiconified
in interface WindowListener
public void windowActivated(WindowEvent pWindowEvent)
windowActivated
in interface WindowListener
public void windowDeactivated(WindowEvent pWindowEvent)
windowDeactivated
in interface WindowListener
public void windowClosing(WindowEvent pWindowEvent)
windowClosing
in interface WindowListener
public final void run()
run
in interface Runnable
protected abstract void principleAction()
public void handleError()
public boolean doLogError()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |