gishur.gui2
Class InputHandler

java.lang.Object
  |
  +--gishur.gui2.DrawAtom
        |
        +--gishur.gui2.DrawObject
              |
              +--gishur.gui2.InputHandler
Direct Known Subclasses:
ContextHandler, EdgeInputHandler, MouseHandler, NodeInputHandler, TranslateHandler, ZoomHandler

public abstract class InputHandler
extends DrawObject

Base class for interactive DrawObjects that can process AWTEvents. Event processing with an InputHandler works in two ways: First, every InputHandler that is inserted to an InputLayer gets all events occuring at the drawing surface (usally a DisplayManager) - that is the use InputHandler are made for. Via the DrawObject.enableEvents(int), DrawObject.disableEvents(int) methods, it is possible to filter the events a InputHandler can get (this influences also the 'internal generated' DrawEvents). If a InputHandler consumes a consumable event, it will not be delivered to any other InputHandler same hierachy (other InputHandlers inserted to different InputLayer are not influenced by consumption). InputHandler can only get events, if they are enabled. The other way is to implement event listeners and register the InputHandler at the watched DisplayObject. In this case all enabled events of this DisplayObject were delivered to the InputHandler regardless of the enabled-state of the InputHandler or of the enabled events mask (so this method should only be used in a very restricted way).

Version:
1.0
Author:
Thomas Wolf

Fields inherited from class gishur.gui2.DrawAtom
BLOCK_REPAINT, MARK_RECALC, MARK_REPAINT, MARK_SIZE, REPAINT, UNBLOCK_REPAINT, USER_STATES_FIRST, USER_STATES_MASK
 
Constructor Summary
protected InputHandler(java.lang.String property_prefix)
          Constructs a new InputHandler which uses the given prefix for all properties.
 
Method Summary
 boolean acceptConsumed()
          Returns true, if this InputHandler accepts consumed InputEvents (per default the setting is false).
static boolean allButtons(java.awt.event.MouseEvent e, int buttonmask)
          Returns true, if the modifiers of the given MouseEvent contains all of the values of the given button mask.
 void disable()
          Disables this InputHandler.
protected  void dispatchModifyEvent(int id, int subtype, java.lang.Object target)
          Dispatches a new ModifyEvent.
 void enable()
          Enables this InputHandler.
 boolean enabled()
          Returns true, if the InputHandler is enabled and ready to receive AWTEvents, otherwise false.
protected  void filterEvent(java.awt.AWTEvent e)
          Filters events for this InputHandler and all of its members.
protected  void onConsumedEvent(java.awt.event.InputEvent e)
          Processes consumed InputEvents.
static boolean oneButton(java.awt.event.MouseEvent e, int buttonmask)
          Returns true, if the modifiers of the given MouseEvent contains one of the values of the given button mask.
protected  void preprocessEvent(int id, DrawAtom sender)
          Preprocesses the event specified via its id sent by the given source.
protected  void processActionEvent(java.awt.event.ActionEvent e)
          Processes action events.
protected  void processAdjustmentEvent(java.awt.event.AdjustmentEvent e)
          Processes adjustment events.
protected  void processComponentEvent(java.awt.event.ComponentEvent e)
          Processes component events (other than mouse, key, focus, paint or window events).
protected  void processContainerEvent(java.awt.event.ContainerEvent e)
          Processes container events.
protected  void processEvent(java.awt.AWTEvent e)
          Processes events delivered to this InputHandler.
protected  void processFocusEvent(java.awt.event.FocusEvent e)
          Processes focus events.
protected  void processItemEvent(java.awt.event.ItemEvent e)
          Processes item events.
protected  void processKeyEvent(java.awt.event.KeyEvent e)
          Processes key events.
protected  void processModifyEvent(ModifyEvent e)
          Processes modification events.
protected  void processMouseEvent(java.awt.event.MouseEvent e)
          Processes mouse events.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent e)
          Processes mouse motion events.
protected  void processPaintEvent(java.awt.event.PaintEvent e)
          Processes paint events.
protected  void processTextEvent(java.awt.event.TextEvent e)
          Processes text events.
protected  void processWindowEvent(java.awt.event.WindowEvent e)
          Processes window events.
protected  void recalculate(RenderContext context, PropertyStatusReader properties)
          Forces the DrawObject to recalculate its representation.
 void removeCursor()
          Removes the mouse cursor.
protected  void sendEvent(java.awt.AWTEvent e)
          Sends the given event to this InputHandler and to all of its members.
protected  boolean setAcceptConsumed(boolean cons)
          Sets the acceptance of consumed InputEvents (per default the setting is false).
 void setCursor(java.awt.Cursor cursor)
          Sets the mouse cursor to the given cursor.
 void setCursor(int cursor)
          Sets the mouse cursor to the given cursor.
 
Methods inherited from class gishur.gui2.DrawObject
addDrawDependency, addPainter, blockRepaint, checkState, checkStateCleared, child, clear, clearCache, clearState, dependency, dirty, disableEvents, draw, draw, enableEvents, ensureRecalculate, findPainter, firstPainter, fullscreen, hide, hide, insert, levelMask, levelUsed, locate, makeDirty, makeDirty, next, next, nextPainter, parent, prepeareRenderContext, prev, prev, processDrawEvent, propertyReader, recalculate, remove, removeDrawDependency, repaint, screenTransformation, setFullscreen, setPaintBeforeMembers, setScreenTransformation, setState, show, show, state, state, unblockRepaint, unblockRepaint, visible
 
Methods inherited from class gishur.gui2.DrawAtom
addProperties, collectHits, dispatchEvent, displayManager, drawComponent, getBounds, getLocalProperty, getProperty, getProperty, getRequiredProperty, processMessage, properties, removeProperty, sendEvent, sendMessage, setBounds, setPropertiesTo, setProperty, setProperty, setProperty, setProperty, toString, toString, toStringDetail, toTreeString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InputHandler

protected InputHandler(java.lang.String property_prefix)
Constructs a new InputHandler which uses the given prefix for all properties.
Parameters:
property_prefix - the prefix string used for all read properties
Method Detail

recalculate

protected void recalculate(RenderContext context,
                           PropertyStatusReader properties)
Forces the DrawObject to recalculate its representation. This method will only be called, if it became dirty via a call to the DrawObject.makeDirty(boolean) method or something has happened, that causes all DrawAtoms to recalculate their representation. This method should only be called by the render system.
Overrides:
recalculate in class DrawObject
Parameters:
context - the RenderContext to use
properties - the PropertyStatusReader to use for reading properties

enabled

public final boolean enabled()
Returns true, if the InputHandler is enabled and ready to receive AWTEvents, otherwise false.
Returns:
true, if the InputHandler is enabled, otherwise false.

enable

public final void enable()
Enables this InputHandler. Only enabled InputHandler can receive AWTEvents and post them to their members.

disable

public final void disable()
Disables this InputHandler. So it no longer receives AWTEvents, neither its members.

acceptConsumed

public final boolean acceptConsumed()
Returns true, if this InputHandler accepts consumed InputEvents (per default the setting is false).
Returns:
true, if accepts consumed InputEvents.

setAcceptConsumed

protected final boolean setAcceptConsumed(boolean cons)
Sets the acceptance of consumed InputEvents (per default the setting is false).
Parameters:
cons - if true, consumed InputEvents will be accepted.

oneButton

public static final boolean oneButton(java.awt.event.MouseEvent e,
                                      int buttonmask)
Returns true, if the modifiers of the given MouseEvent contains one of the values of the given button mask.
Parameters:
e - the MouseEvent with modifiers to test
buttonmask - a mask of mouse buttons to test
Returns:
true, if modifiers contains one of buttonmask

allButtons

public static final boolean allButtons(java.awt.event.MouseEvent e,
                                       int buttonmask)
Returns true, if the modifiers of the given MouseEvent contains all of the values of the given button mask.
Parameters:
e - the MouseEvent with modifiers to test
buttonmask - a mask of mouse buttons to test
Returns:
true, if modifiers contains all of buttonmask

setCursor

public void setCursor(java.awt.Cursor cursor)
Sets the mouse cursor to the given cursor.
Parameters:
cursor - the java.awt.Cursor to set

setCursor

public void setCursor(int cursor)
Sets the mouse cursor to the given cursor.
Parameters:
cursor - the cursor-id to set

removeCursor

public void removeCursor()
Removes the mouse cursor.

dispatchModifyEvent

protected void dispatchModifyEvent(int id,
                                   int subtype,
                                   java.lang.Object target)
Dispatches a new ModifyEvent. The ModifyEvent will have this InputHandler as source.
Parameters:
id - type of the event
subtype - sub-type of the event
target - target object that was modified

preprocessEvent

protected void preprocessEvent(int id,
                               DrawAtom sender)
Preprocesses the event specified via its id sent by the given source. This method will be called by events produced by the DrawAtom itself and by DrawAtom where this depends from. The method will be called before events are filtered out.
Overrides:
preprocessEvent in class DrawAtom
Parameters:
id - the event id
sender - the source of the event
See Also:
DrawEvent

sendEvent

protected final void sendEvent(java.awt.AWTEvent e)
Sends the given event to this InputHandler and to all of its members. This method should only be called by the filterEvent(java.awt.AWTEvent) method.
Parameters:
e - the event to send

onConsumedEvent

protected void onConsumedEvent(java.awt.event.InputEvent e)
Processes consumed InputEvents. In order to process the events further, call sendEvent(java.awt.AWTEvent).
Parameters:
e - consumed InputEvent.

filterEvent

protected void filterEvent(java.awt.AWTEvent e)
Filters events for this InputHandler and all of its members. This method should call sendEvent(java.awt.AWTEvent) in order to process events through this InputHandler and all of its members.
Parameters:
e - the source event. The event mask must be enabled in order to filter that type of events

processEvent

protected void processEvent(java.awt.AWTEvent e)
Processes events delivered to this InputHandler. By default this method calls the appropriate process<event type>Event method for the given class of event. The checking for enabled events will be done before the call of this method.
Overrides:
processEvent in class DrawObject
Parameters:
e - the event.
See Also:
DrawObject.processDrawEvent(gishur.gui2.event.DrawEvent), processModifyEvent(gishur.core.event.ModifyEvent), processMouseEvent(java.awt.event.MouseEvent), processMouseMotionEvent(java.awt.event.MouseEvent), processKeyEvent(java.awt.event.KeyEvent), processContainerEvent(java.awt.event.ContainerEvent), processFocusEvent(java.awt.event.FocusEvent), processPaintEvent(java.awt.event.PaintEvent), processWindowEvent(java.awt.event.WindowEvent), processComponentEvent(java.awt.event.ComponentEvent), processActionEvent(java.awt.event.ActionEvent), processAdjustmentEvent(java.awt.event.AdjustmentEvent), processItemEvent(java.awt.event.ItemEvent), processTextEvent(java.awt.event.TextEvent)

processModifyEvent

protected void processModifyEvent(ModifyEvent e)
Processes modification events. This implementation of the method calls the listener methods of If the given element is already consumed, this method does nothing. ModifyListener, if this implements this listener.
Parameters:
e - the event.

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent e)
Processes mouse events. This implementation of the method calls the listener methods of MouseListener, if this implements this listener. If the given element is already consumed, this method does nothing.
Parameters:
e - the event.

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent e)
Processes mouse motion events. This implementation of the method calls the listener methods of MouseMotionListener, if this implements this listener. If the given element is already consumed, this method does nothing.
Parameters:
e - the event.

processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent e)
Processes key events. This implementation of the method calls the listener methods of KeyListener, if this implements this listener. If the given element is already consumed, this method does nothing.
Parameters:
e - the event.

processContainerEvent

protected void processContainerEvent(java.awt.event.ContainerEvent e)
Processes container events. This implementation of the method calls the listener methods of ContainerListener, if this implements this listener.
Parameters:
e - the event.

processFocusEvent

protected void processFocusEvent(java.awt.event.FocusEvent e)
Processes focus events. This implementation of the method calls the listener methods of FocusListener, if this implements this listener.
Parameters:
e - the event.

processPaintEvent

protected void processPaintEvent(java.awt.event.PaintEvent e)
Processes paint events.
Parameters:
e - the event.

processWindowEvent

protected void processWindowEvent(java.awt.event.WindowEvent e)
Processes window events. This implementation of the method calls the listener methods of WindowListener, if this implements this listener.
Parameters:
e - the event.

processComponentEvent

protected void processComponentEvent(java.awt.event.ComponentEvent e)
Processes component events (other than mouse, key, focus, paint or window events). This implementation of the method calls the listener methods of ComponentListener, if this implements this listener.
Parameters:
e - the event.

processActionEvent

protected void processActionEvent(java.awt.event.ActionEvent e)
Processes action events. This implementation of the method calls the listener methods of ActionListener, if this implements this listener.
Parameters:
e - the event.

processAdjustmentEvent

protected void processAdjustmentEvent(java.awt.event.AdjustmentEvent e)
Processes adjustment events. This implementation of the method calls the listener methods of AdjustmentListener, if this implements this listener.
Parameters:
e - the event.

processItemEvent

protected void processItemEvent(java.awt.event.ItemEvent e)
Processes item events. This implementation of the method calls the listener methods of ItemListener, if this implements this listener.
Parameters:
e - the event.

processTextEvent

protected void processTextEvent(java.awt.event.TextEvent e)
Processes text events. This implementation of the method calls the listener methods of TextListener, if this implements this listener.
Parameters:
e - the event.