public Node( DockLayoutComposition composition, boolean collectLeafs ){ if( collectLeafs ){ leafs = new ArrayList<Node>(); } else{ leafs = null; } this.composition = composition; for( DockLayoutComposition child : composition.getChildren() ){ Node childNode = new Node( child, true ); children.add( childNode ); if( collectLeafs ){ if( childNode.isLeaf() ){ leafs.add( childNode ); } else{ leafs.addAll( childNode.leafs ); } } } }
/** * Closes up this node. If the location of a leaf changed, its previous location is set as successor. * Otherwise if the location of a child changed, set the new location and use the old location as successor. * Otherwise invalidate the leaf as its location will never be completed. * @see #prepare() */ public void finish(){ /* * If location of leaf changed: set old location as successor * If location of parent changed: set current location as successor and replace * If no location changed: leafs gets invalidated */ for( Node child : root.children ){ DockableProperty newParentLocation = child.validLocation(); for( Node leaf : child.leafs ){ leaf.finish( newParentLocation ); } for( Node grandchild : child.children ){ grandchild.finish( newParentLocation ); } } }
public void finish( DockableProperty newParentLocation ){ if( valid ){ DockableProperty newLeafLocation = validLocation(); if( newLeafLocation == null && newParentLocation != null ){ newLeafLocation = newParentLocation.copy(); } if( newLeafLocation != null ){ newLeafLocation.setSuccessor( oldLocation ); composition.getLayout().setLocation( newLeafLocation ); } else{ invalidate(); } } }
/** * Creates a new map * @param root the representation of this station */ public DefaultLocationEstimationMap( DockLayoutComposition root ){ this( new Node( root, false ) ); }
public void prepare(){ if( valid ){ oldLocation = composition.getLayout().getLocation(); for( Node child : children ){ child.prepare(); } } }
/** * Prepares this map for estimating locations. Preparation of the map means that all current locations * are stored and can be used for comparison when calling {@link #finish()}. */ public void prepare(){ root.prepare(); }