bibliothek.gui.dock.station.screen.magnet
Class MagnetController

java.lang.Object
  extended by bibliothek.gui.dock.station.screen.magnet.MagnetController

public class MagnetController
extends Object

Each ScreenDockStation uses one MagnetController to calculate attractions between its children. The MagnetController makes use of a MagnetStrategy and of several AttractorStrategys to modify the location and size of the currently moved ScreenDockWindow.
ScreenDockWindows have to call start(ScreenDockWindow) when they start moving or resizing.

Author:
Benjamin Sigg

Constructor Summary
MagnetController(ScreenDockStation station)
          Creates a new MagnetController.
 
Method Summary
 int distance(ScreenDockWindow windowA, MagnetRequest.Side sideA, ScreenDockWindow windowB, MagnetRequest.Side sideB, boolean initialBoundaries)
          Calculates the distance between sideA of windowA to sideB of windowB.
 ScreenDockWindow[] getAttracted(ScreenDockWindow window)
          Gets all the ScreenDockWindows of the station that are attracted to window.
 AttractorStrategy.Attraction getAttraction(Dockable moved, Dockable fixed)
          Tells whether fixed and moved attract each other.
 AttractorStrategy getAttractorStrategy()
          Gets the currently used AttractorStrategy.
 DockController getController()
          Gets the DockController that is currently used by this MagnetController.
 ScreenDockWindow getCurrent()
          Gets the window that is currently moved.
 ScreenDockStation getStation()
          Gets the ScreenDockStation which is using this MagnetController.
 AttractorStrategy.Attraction getStickiness(Dockable moved, Dockable fixed)
          Tells whether fixed and moved stick to each other.
 MagnetStrategy getStrategy()
          Gets the MagnetStrategy that is currently used by this controller.
 int getValue(Rectangle rectangle, MagnetRequest.Side side)
          Gets the location of the side side of rectangle.
 int getValue(ScreenDockWindow window, MagnetRequest.Side side, boolean initialBoundaries)
          Gets the location of the side side of window.
 ScreenDockWindow[] getWindows()
          Gets an array containing all the ScreenDockWindows that are currently shown by the station.
 boolean intersectHorizontally(ScreenDockWindow windowA, ScreenDockWindow windowB, boolean initialBoundaries)
          Tells whether the y coordinate and the height of windowA and windowB are such that they have at least one pixel at the same height.
 boolean intersectVertically(ScreenDockWindow windowA, ScreenDockWindow windowB, boolean initialBoundaries)
          Tells whether the x coordinate and the width of windowA and windowB are such that they have at least one pixel at the same width.
 void setAttractorStrategy(AttractorStrategy strategy)
          Sets the AttractorStrategy to use.
 void setController(DockController controller)
          Sets the DockController which is to be used by this MagnetController.
 void setStrategy(MagnetStrategy strategy)
          Sets the MagnetStrategy that is to be used by this controller.
 MagnetizedOperation start(ScreenDockWindow window)
          Starts a move or resize operation that involves window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MagnetController

public MagnetController(ScreenDockStation station)
Creates a new MagnetController.

Parameters:
station - the station using this controller, not null
Method Detail

setController

@FrameworkOnly
public void setController(DockController controller)
Sets the DockController which is to be used by this MagnetController.

Parameters:
controller - the controller to use or null

getController

public DockController getController()
Gets the DockController that is currently used by this MagnetController.

Returns:
the controller, can be null

getStation

public ScreenDockStation getStation()
Gets the ScreenDockStation which is using this MagnetController.

Returns:
the owner of this controller, never null

start

public MagnetizedOperation start(ScreenDockWindow window)
Starts a move or resize operation that involves window. Only one operation can be running at the same time.

Parameters:
window - the window which is moved or resized
Returns:
a callback that is to be informed whenever window further changes position or size

getAttraction

public AttractorStrategy.Attraction getAttraction(Dockable moved,
                                                  Dockable fixed)
Tells whether fixed and moved attract each other.

Parameters:
moved - the dockable that has moved
fixed - the dockable that has not moved
Returns:
the attraction, the strongest result from all currently registered AttractorStrategys

getStickiness

public AttractorStrategy.Attraction getStickiness(Dockable moved,
                                                  Dockable fixed)
Tells whether fixed and moved stick to each other.

Parameters:
moved - the dockable that has moved
fixed - the dockable that has not moved
Returns:
the attraction, the strongest result from all currently registered AttractorStrategys

getCurrent

public ScreenDockWindow getCurrent()
Gets the window that is currently moved.

Returns:
the currently reshaped window, may be null

getWindows

public ScreenDockWindow[] getWindows()
Gets an array containing all the ScreenDockWindows that are currently shown by the station.

Returns:
all the windows

getAttracted

public ScreenDockWindow[] getAttracted(ScreenDockWindow window)
Gets all the ScreenDockWindows of the station that are attracted to window.

Parameters:
window - the window that has moved and whose partners are searched
Returns:
all the partner windows, may be empty, is never null, does not contain window

distance

public int distance(ScreenDockWindow windowA,
                    MagnetRequest.Side sideA,
                    ScreenDockWindow windowB,
                    MagnetRequest.Side sideB,
                    boolean initialBoundaries)
Calculates the distance between sideA of windowA to sideB of windowB. If either window is the current window, then its base boundaries are used instead of its current boundaires.

Parameters:
windowA - the first window
sideA - the side of the window to check
windowB - the second window
sideB - the side of the second window to check
initialBoundaries - if true, then the initial boundaries of window is used
Returns:
the horizontall or vertical distance between the two sides, always a number greater or equal to 0
Throws:
IllegalArgumentException - if sideA and sideB are neither equal nor opposite

intersectHorizontally

public boolean intersectHorizontally(ScreenDockWindow windowA,
                                     ScreenDockWindow windowB,
                                     boolean initialBoundaries)
Tells whether the y coordinate and the height of windowA and windowB are such that they have at least one pixel at the same height.

Parameters:
windowA - the first window
windowB - the second window
initialBoundaries - if true, then the initial boundaries of window is used
Returns:
true if both windows have at least one pixel on the same height

intersectVertically

public boolean intersectVertically(ScreenDockWindow windowA,
                                   ScreenDockWindow windowB,
                                   boolean initialBoundaries)
Tells whether the x coordinate and the width of windowA and windowB are such that they have at least one pixel at the same width.

Parameters:
windowA - the first window
windowB - the second window
initialBoundaries - if true, then the initial boundaries of window is used
Returns:
true if both windows have at least one pixel on the same width

getValue

public int getValue(ScreenDockWindow window,
                    MagnetRequest.Side side,
                    boolean initialBoundaries)
Gets the location of the side side of window. If window is the current window, then its base boundaries are used to calculate the coordinates, otherwise ScreenDockWindow.getWindowBounds() is used.

Parameters:
window - some window
side - the side to read
initialBoundaries - if true, then the initial boundaries of window is used
Returns:
the x or y coordinate of side

getValue

public int getValue(Rectangle rectangle,
                    MagnetRequest.Side side)
Gets the location of the side side of rectangle.

Parameters:
rectangle - some rectangle
side - the side to read
Returns:
the x or y coordinate of side

getStrategy

public MagnetStrategy getStrategy()
Gets the MagnetStrategy that is currently used by this controller.

Returns:
the current strategy, null if no DockController is set

setStrategy

public void setStrategy(MagnetStrategy strategy)
Sets the MagnetStrategy that is to be used by this controller.

Parameters:
strategy - the strategy, a value of null reinstalles the default strategy

getAttractorStrategy

public AttractorStrategy getAttractorStrategy()
Gets the currently used AttractorStrategy.

Returns:
the strategy defining which two Dockables attract each other

setAttractorStrategy

public void setAttractorStrategy(AttractorStrategy strategy)
Sets the AttractorStrategy to use.

Parameters:
strategy - the strategy, a value of null reinstalles the default strategy