ch.epfl.craft.maglib.magnet
Class DefaultMagnetLayout

java.lang.Object
  extended bych.epfl.craft.maglib.magnet.DefaultMagnetLayout
All Implemented Interfaces:
MagnetLayout, MagnetModelListener, java.lang.Runnable
Direct Known Subclasses:
CentralMagnetLayout

public class DefaultMagnetLayout
extends java.lang.Object
implements MagnetLayout, MagnetModelListener, java.lang.Runnable

This class will layout the nodes on the MagnetView it controls. It will choose the position of each node, and the which node is visible.

Version:
1.0
Author:
Jerome Caffaro

Field Summary
protected  java.awt.Rectangle boundsOfView
          the bounds of the main view in which the layout has to be done
protected  boolean continueupdating
           
protected  java.lang.Thread currentThread
          the current thread
protected  java.util.ArrayList listeners
          the listeners of the layout changes
protected  MagnetModel magnetModel
          the model that we layout
protected  int numberOfVisibleNodes
          the number of node that the layouter will set as visible
 
Constructor Summary
DefaultMagnetLayout()
           
 
Method Summary
 void addListener(MagnetLayoutListener listener)
          Adds a listener that will be notified when the layout has changed.
 int getNumberOfVisibleNodes()
          Returns the number of nodes simulatenously drawn by the view that this layouter controls.
 void modelHasChanged()
          Implementation of the MagnetModelListener interface.
 void removeListener(MagnetLayoutListener listener)
          Removes a listener.
 void run()
          Runs the layout algorithm.
 void setBounds(java.awt.Rectangle bounds)
          Sets the bounds of the main view.
 void setMagnetModel(MagnetModel newMagnetModel)
          Set the model that the layout is in charge of updating.
 void setNumberOfVisibleNodes(int numberOfVisibleNodes)
          Sets the number of visible nodes drawn by the view that this layouter controls
 void stopUpdatingPositions()
          Tells the receiver to stop updating the nodes positions in the model.
 void updatePositions(UpdateEvent event)
          Tells the receiver to update the nodes positions in the model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

magnetModel

protected MagnetModel magnetModel
the model that we layout


listeners

protected java.util.ArrayList listeners
the listeners of the layout changes


numberOfVisibleNodes

protected int numberOfVisibleNodes
the number of node that the layouter will set as visible


currentThread

protected java.lang.Thread currentThread
the current thread


boundsOfView

protected java.awt.Rectangle boundsOfView
the bounds of the main view in which the layout has to be done


continueupdating

protected boolean continueupdating
Constructor Detail

DefaultMagnetLayout

public DefaultMagnetLayout()
Method Detail

setMagnetModel

public void setMagnetModel(MagnetModel newMagnetModel)
Set the model that the layout is in charge of updating.

Specified by:
setMagnetModel in interface MagnetLayout
Parameters:
newMagnetModel - the model that will be updated by receiver.

updatePositions

public void updatePositions(UpdateEvent event)
Tells the receiver to update the nodes positions in the model. If model is null, does not do anything. The algorithm will begin updating the positions of the nodes, and stop only when the positions satisfy its constraints. The algorithm can also be stopped with the stopUpdatingPositions() method.

Specified by:
updatePositions in interface MagnetLayout
Parameters:
event - the associated event
See Also:
UpdateEvent

stopUpdatingPositions

public void stopUpdatingPositions()
Tells the receiver to stop updating the nodes positions in the model. If model is null, does not do anything.

Specified by:
stopUpdatingPositions in interface MagnetLayout
See Also:
run()

addListener

public void addListener(MagnetLayoutListener listener)
Adds a listener that will be notified when the layout has changed.

Specified by:
addListener in interface MagnetLayout
Parameters:
listener - the listener object to add

removeListener

public void removeListener(MagnetLayoutListener listener)
Removes a listener.

Specified by:
removeListener in interface MagnetLayout
Parameters:
listener - the listener object to remove

modelHasChanged

public void modelHasChanged()
Implementation of the MagnetModelListener interface. Called when the model has changed

Specified by:
modelHasChanged in interface MagnetModelListener

setNumberOfVisibleNodes

public void setNumberOfVisibleNodes(int numberOfVisibleNodes)
Sets the number of visible nodes drawn by the view that this layouter controls

Specified by:
setNumberOfVisibleNodes in interface MagnetLayout
Parameters:
numberOfVisibleNodes - the number of visible nodes.

getNumberOfVisibleNodes

public int getNumberOfVisibleNodes()
Returns the number of nodes simulatenously drawn by the view that this layouter controls.

Specified by:
getNumberOfVisibleNodes in interface MagnetLayout
Returns:
the number of visible nodes

setBounds

public void setBounds(java.awt.Rectangle bounds)
Sets the bounds of the main view. The algorithm can then be optimized for this rectangle

Specified by:
setBounds in interface MagnetLayout

run

public void run()
Runs the layout algorithm. Tells the receiver to update the nodes positions in the model. If model is null, does not do anything. The algorithm will begin updating the positions of the nodes, and stop only when the positions satisfy its constraints. The algorithm can also be stopped with the stopUpdatingPositions() method. Note to implementing classes. You can loop until continue updating is false, if necessary.

Specified by:
run in interface java.lang.Runnable


Copyright © CRAFT EPFL. All Rights Reserved.