bibliothek.gui.dock.control.focus
Class AbstractMouseFocusObserver

java.lang.Object
  extended by bibliothek.gui.dock.control.focus.AbstractMouseFocusObserver
All Implemented Interfaces:
MouseFocusObserver, DockRelocatorListener
Direct Known Subclasses:
DefaultMouseFocusObserver

public abstract class AbstractMouseFocusObserver
extends java.lang.Object
implements MouseFocusObserver, DockRelocatorListener

This abstract implementation of a MouseFocusObserver offers methods to handle FocusVetoListeners and registers itself as DockRelocatorListener. On a drop event this observer will automatically transfer the focus to the dropped Dockable.

Author:
Benjamin Sigg

Constructor Summary
AbstractMouseFocusObserver(DockController controller, ControllerSetupCollection setup)
          Creates a new FocusController.
 
Method Summary
 void cancel(DockController controller, Dockable dockable)
          Invoked when a drag and drop operation was initiated, but canceld.
protected  void check(java.awt.AWTEvent event)
          Lets check this controller whether the focus should change, or not.
protected  void check(java.awt.Component component, java.awt.AWTEvent event)
          Tries to find the Dockable which owns component and sets this Dockable to the focusedDockable.
protected  void check(java.awt.Component component, boolean ensureFocus, boolean requestFocusInWindow, java.awt.AWTEvent event)
          Tries to find the Dockable which owns component and sets this Dockable to the focusedDockable.
 void check(java.awt.event.MouseEvent event)
          This method may be called at any time by any component that received the MouseEvent event.
 void check(java.awt.event.MouseWheelEvent event)
          This method may be called at any time by any component that received the MouseWheelEvent event.
 void drag(DockController controller, Dockable dockable, DockStation station)
          Invoked when a drag and drop operation has been confirmed.
 void drop(DockController controller, Dockable dockable, DockStation station)
          Invoked after a Dockable was dropped.
 DockController getController()
          Gets the affected controller.
protected  DockElementRepresentative getDockable(java.awt.Component component, java.awt.AWTEvent event)
          Gets the top-dockable which has component or parent of component as base Component.
protected  void handleVeto(java.awt.AWTEvent event, FocusVetoListener.FocusVeto veto)
          Handles the veto that was given when trying to forward event.
 void init(DockController controller, Dockable dockable)
          Invoked when a drag and drop operation is initiated.
protected  boolean interact(java.awt.AWTEvent event)
          Tells whether this event should change the focus.
 void kill()
          Stops this FocusController.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMouseFocusObserver

public AbstractMouseFocusObserver(DockController controller,
                                  ControllerSetupCollection setup)
Creates a new FocusController.

Parameters:
controller - the controller which will be informed about focus-changes
setup - an observable informing this object when controller is set up.
Method Detail

kill

public void kill()
Stops this FocusController. This controller will remove all its listeners and become ready for the garbage collector.

Specified by:
kill in interface MouseFocusObserver

getController

public DockController getController()
Gets the affected controller.

Specified by:
getController in interface MouseFocusObserver
Returns:
the controller

check

public void check(java.awt.event.MouseEvent event)
Description copied from interface: MouseFocusObserver
This method may be called at any time by any component that received the MouseEvent event. This observer may transfer the focus because of this call.
If this application runs in a restricted environment than any DockStation of this framework will call this method.

Specified by:
check in interface MouseFocusObserver
Parameters:
event - the event to check

check

public void check(java.awt.event.MouseWheelEvent event)
Description copied from interface: MouseFocusObserver
This method may be called at any time by any component that received the MouseWheelEvent event. This observer may transfer the focus because of this call.
If this application runs in a restricted environment than any DockStation of this framework will call this method.

Specified by:
check in interface MouseFocusObserver
Parameters:
event - the event to check

check

protected void check(java.awt.AWTEvent event)
Lets check this controller whether the focus should change, or not. Clients invoking this method should first check whether event is allowed to change the focus or not. This check can be done through the method interact(AWTEvent).

Parameters:
event - The event to react on.
See Also:
interact(AWTEvent)

interact

protected boolean interact(java.awt.AWTEvent event)
Tells whether this event should change the focus.

Parameters:
event - the event
Returns:
true if the focus could be changed

handleVeto

protected void handleVeto(java.awt.AWTEvent event,
                          FocusVetoListener.FocusVeto veto)
Handles the veto that was given when trying to forward event. The default implementation calls InputEvent.consume() to get rid of the event.

Parameters:
event - the event to handle
veto - which veto was called by a FocusVetoListener

check

protected void check(java.awt.Component component,
                     java.awt.AWTEvent event)
Tries to find the Dockable which owns component and sets this Dockable to the focusedDockable. The method only succeeds if no veto-listener reacts.

Parameters:
component - the component whose dockable parent is to set focused
event - the event that causes this check

check

protected void check(java.awt.Component component,
                     boolean ensureFocus,
                     boolean requestFocusInWindow,
                     java.awt.AWTEvent event)
Tries to find the Dockable which owns component and sets this Dockable to the focusedDockable. The method only succeeds if no veto-listener reacts.

Parameters:
component - the component whose dockable parent is to set focused
ensureFocus - whether the DockController should ensure that the focus is set correctly or not.
requestFocusInWindow - whether Component.requestFocusInWindow() should be called or not
event - the event that causes this check

init

public void init(DockController controller,
                 Dockable dockable)
Description copied from interface: DockRelocatorListener
Invoked when a drag and drop operation is initiated. This method is called when the user made the gesture of dragging, but not yet of dropping.

Specified by:
init in interface DockRelocatorListener
Parameters:
controller - the origin of the event
dockable - the element that has been grabbed

cancel

public void cancel(DockController controller,
                   Dockable dockable)
Description copied from interface: DockRelocatorListener
Invoked when a drag and drop operation was initiated, but canceld. This method can be called any time after DockRelocatorListener.init(DockController, Dockable). was called.

Specified by:
cancel in interface DockRelocatorListener
Parameters:
controller - the origin of the event
dockable - the element that has been grabbed

drag

public void drag(DockController controller,
                 Dockable dockable,
                 DockStation station)
Description copied from interface: DockRelocatorListener
Invoked when a drag and drop operation has been confirmed. This method is called after the user made a drop-gesture, but before dockable is dragged from its old parent.

Specified by:
drag in interface DockRelocatorListener
Parameters:
controller - the origin of the event
dockable - the Dockable which was dragged
station - the future parent of dockable
See Also:
DockRelocatorListener.drop(DockController, Dockable, DockStation)

drop

public void drop(DockController controller,
                 Dockable dockable,
                 DockStation station)
Description copied from interface: DockRelocatorListener
Invoked after a Dockable was dropped.

Specified by:
drop in interface DockRelocatorListener
Parameters:
controller - the origin of the event
dockable - the Dockable which was dragged
station - the new parent of dockable
See Also:
DockRelocatorListener.drag(DockController, Dockable, DockStation)

getDockable

protected DockElementRepresentative getDockable(java.awt.Component component,
                                                java.awt.AWTEvent event)
Gets the top-dockable which has component or parent of component as base Component.

Parameters:
component - a Component
event - the event that causes this check
Returns:
a Dockable or null if nothing was found