Download Implementierung eines Statechart-Editors mit layoutbasierten
Transcript
230
220
210
200
190
260
250
240
/**
*
}
targetMapping = new HashMap () ;
targetMapping . put ( cell , targetBounds ) ;
// recursion : root := aTa rget Mappi ng . keySet () . iterator () . next () ;
// All ancestors have to be moved , the parent has to be resized ,
then
// recursive : root := parent
addCells ( cell , targetBounds ) ;
startThread ( this ) ;
290
270
/**
* Not just simply enlarges the given graph cell . In addition to that
all
* ancestors have to be moved to a probably new position , then maybe the
* parent has to be resized . This resize has to be applied recursively !
* @param cell contains the current coordinates .
* @param targetBounds defines the target coordinates .
*/
public void e x p a n d C o m p o s i t e S t a t e ( final DefaultGraphCe ll cell ,
final Rectangle2D targetBounds ) {
280
}
targetMapping = new HashMap () ;
targetMapping . put ( cell , targetBounds ) ;
startThread ( this ) ;
/**
* Simply ensmalls the given graph cell .
* @param cell contains the current coordinates .
* @param targetBounds defines the target coordinates .
*/
public void c o l l a p s e C o m p o s i t e S t a t e ( final Def aultGraphCell cell ,
final Rectangle2D targetBounds ) {
}
* @see java . lang . Runnable # run ()
*/
public void run () {
while ( true ) { // TODO Just run on request !
try {
if ( isFull () ) {
consumeNext () . run () ;
} else {
final int sleepingTime = 30;
sleep ( sleepingTime ) ;
}
} catch ( I n t e r r u p t e d E x c e p t i o n e ) {
e . p ri n tS t ac k Tr a ce () ;
}
}
}
final Rectangle2D sourceBounds =
sourceGraph . g e t G r a p h L a y o u t C a c h e () . getMapping (
cell , false ) . getBounds () ;
if ( sourceBounds . getX () != targetBounds . getX ()
|| sourceBounds . getY () != targetBounds . getY () ) {
return ;
}
final double deltaWidth = targetBounds . getWidth ()
- sourceBounds . getWidth () ;
final double deltaHeight = targetBounds . getHeight ()
- sourceBounds . getHeight () ;
if ( deltaWidth < 0 && deltaHeight < 0) {
// move nodes only on expand ...
return ;
}
Rectangle2D parentBounds = null ;
if ( cell . getParent () != null ) {
parentBounds = sourceGraph . g e t G r a p h L a y o u t C a c h e ()
. getMapping ( cell . getParent () , false ) . getBounds () ;
}
// The ancestors and its childs have to be moved ...
final Object [] all = sourceGraph . getDescendants ( sourceGraph . getRoots
() ) ;
double m ax Par en tOv er lap X = 0;
double m ax Par en tOv er lap Y = 0;
for ( int i = 0; i < all . length ; i ++) {
if ( all [ i ] instanceof NodeCell
/**
* Is called by e x p a n d C o m p o s i t e S t a t e () and recursively . Checks the
* ancestors of the cell and the parent .
* @param cell the cell whose ancestors and parent have to be checked .
* @param targetBounds the cell ’ s target bounds .
*/
private void addCells ( final D efaultGraphCell cell ,
final Rectangle2D targetBounds ) {
* @param cell .
* @param testCell .
* @return .
*/
private static boolean i s A n c e s t o r O r C h i l d O f A n c e s t o r (
final Defaul tGraphCell cell , final DefaultGra phCell testCell ) {
if ( cell == testCell . getParent () ) {
return false ;
} else if ( cell . getParent () == testCell . getParent () ) {
return true ;
} else if ( testCell . getParent () == null ) {
return false ;
} else {
return i s A n c e s t o r O r C h i l d O f A n c e s t o r (
cell , ( Defa ultGraphCell ) testCell . getParent () ) ;
}
}
A.4. Der Quelltext
135