/** * Gets the elements that are represented by the leaf <code>key</code>. * @param key the leaf * @return the elements, can be <code>null</code> */ public D[] getDockables( Key key ){ if( !isDockable( key )) throw new IllegalArgumentException( "Not a Dockable" ); return key.asLeaf().dockables; }
/** * Gets the divider of the node <code>key</code>. * @param key the node * @return the divider, a number between 0 and 1 */ public double getDivider( Key key ){ if( !isNode( key )) throw new IllegalArgumentException( "Not a node" ); return key.asNode().divider; }
/** * Sets <code>key</code> as the root of the tree. The root must not have * a parent. * @param key the key which will be the root, <code>null</code> is not allowed. * @return <code>this</code> */ public SplitDockTree<D> root( Key key ){ if( key == null ) throw new IllegalArgumentException( "Key must not be null" ); if( key.getTree() != this ) throw new IllegalArgumentException( "Key is not created by this tree" ); if( key.parent != null ) throw new IllegalArgumentException( "Key has a parent, and can't be the root" ); this.root = key; return this; }
SplitDockTree<Dockable> tree = key.getTree(); if( dockables == null || dockables.length == 0 ){ Path[] placeholders = tree.getPlaceholders( key ); Placeholder leaf = createPlaceholder( key.getNodeId() ); leaf.setPlaceholders( placeholders ); leaf.setPlaceholderMap( tree.getPlaceholderMap( key )); leaf = createLeaf( key.getNodeId() ); linksToSet.put( leaf, dockables[0] ); CombinerSource source = new NodeCombinerSource( dockables[0], dockables[1], key.getTree().getPlaceholderMap( key ) ); CombinerTarget target = combiner.prepare( source, Enforcement.HARD ); removePlaceholderMap = true; if( dockables.length == 2 ){ leaf = createLeaf( key.getNodeId() ); linksToSet.put( leaf, combination ); Dockable selected = key.getTree().getSelected( key ); if( selected != null ) station.setFrontDockable( selected ); leaf = createLeaf( key.getNodeId() ); linksToSet.put( leaf, combination ); Dockable selected = key.getTree().getSelected( key ); if( selected != null ) station.setFrontDockable( selected );
SplitDockTree<PerspectiveDockable> tree = key.getTree(); if( tree.isDockable( key )){ PerspectiveDockable[] dockables = tree.getDockables( key ); return new Leaf( dockable, toSet( tree.getPlaceholders( key ) ), tree.getPlaceholderMap( key ), key.getNodeId() ); return new Node( orientation, tree.getDivider( key ), childA, childB, toSet( tree.getPlaceholders( key ) ), tree.getPlaceholderMap( key ), key.getNodeId() );
SplitDockTree<PerspectiveDockable> tree = key.getTree(); if( tree.isDockable( key )){ PerspectiveDockable[] dockables = tree.getDockables( key ); return new Leaf( dockable, toSet( tree.getPlaceholders( key ) ), tree.getPlaceholderMap( key ), key.getNodeId() ); return new Node( orientation, tree.getDivider( key ), childA, childB, toSet( tree.getPlaceholders( key ) ), tree.getPlaceholderMap( key ), key.getNodeId() );
@Override public void evolve( SplitDockTree<Dockable>.Key key, boolean checkValidity, Map<Leaf, Dockable> linksToSet ){ SplitDockTree<Dockable> tree = key.getTree(); setPlaceholders( tree.getPlaceholders( key ) ); setPlaceholderMap( tree.getPlaceholderMap( key ) ); if( tree.isHorizontal( key )){ orientation = SplitDockStation.Orientation.HORIZONTAL; setLeft( create( tree.getLeft( key ), checkValidity, linksToSet )); setRight( create( tree.getRight( key ), checkValidity, linksToSet )); setDivider( tree.getDivider( key )); } else{ orientation = SplitDockStation.Orientation.VERTICAL; setLeft( create( tree.getTop( key ), checkValidity, linksToSet )); setRight( create( tree.getBottom( key ), checkValidity, linksToSet )); setDivider( tree.getDivider( key )); } }
/** * Sets <code>key</code> as the root of the tree. The root must not have * a parent. * @param key the key which will be the root, <code>null</code> is not allowed. * @return <code>this</code> */ public SplitDockTree<D> root( Key key ){ if( key == null ) throw new IllegalArgumentException( "Key must not be null" ); if( key.getTree() != this ) throw new IllegalArgumentException( "Key is not created by this tree" ); if( key.parent != null ) throw new IllegalArgumentException( "Key has a parent, and can't be the root" ); this.root = key; return this; }
@Override public String toString(){ StringBuilder builder = new StringBuilder(); builder.append( getClass().getName() + "[root=\n" ); if( root == null ){ builder.append( "null" ); } else{ root.toString( builder, 1 ); } builder.append( "\n]" ); return builder.toString(); }
@Override public String toString(){ StringBuilder builder = new StringBuilder(); builder.append( getClass().getName() + "[root=\n" ); if( root == null ){ builder.append( "null" ); } else{ root.toString( builder, 1 ); } builder.append( "\n]" ); return builder.toString(); }
/** * Gets the left element of the node <code>key</code>. * @param key the node * @return the left element */ public Key getLeft( Key key ){ if( !isNode( key )) throw new IllegalArgumentException( "Not a node" ); return key.asNode().keyA; }
/** * Tells whether the node <code>key</code> represents a horizontal * or a vertical node. * @param key the node * @return <code>true</code> if the elements are laid out horizontally, * <code>false</code> if the are vertically */ public boolean isHorizontal( Key key ){ if( !isNode( key )) throw new IllegalArgumentException( "Not a node" ); return key.asNode().horizontal; }
/** * Gets the top element of the node <code>key</code>. * @param key the node * @return the top element */ public Key getTop( Key key ){ if( !isNode( key )) throw new IllegalArgumentException( "Not a node" ); return key.asNode().keyA; }
/** * Gets the left element of the node <code>key</code>. * @param key the node * @return the left element */ public Key getLeft( Key key ){ if( !isNode( key )) throw new IllegalArgumentException( "Not a node" ); return key.asNode().keyA; }
/** * Tells whether <code>key</code> represents a node or not. * @param key the key to test * @return <code>true</code> if <code>key</code> is a node */ public boolean isNode( Key key ){ return key.asNode() != null; }
/** * Tells whether <code>key</code> represents a leaf or not. * @param key the key to test * @return <code>true</code> if <code>key</code> is a leaf */ public boolean isDockable( Key key ){ return key.asLeaf() != null; }
/** * Tells whether <code>key</code> represents a leaf or not. * @param key the key to test * @return <code>true</code> if <code>key</code> is a leaf */ public boolean isDockable( Key key ){ return key.asLeaf() != null; }
/** * Gets the bottom element of the node <code>key</code>. * @param key the node * @return the bottom element */ public Key getBottom( Key key ){ if( !isNode( key )) throw new IllegalArgumentException( "Not a node" ); return key.asNode().keyB; }
/** * Tells whether the node <code>key</code> represents a horizontal * or a vertical node. * @param key the node * @return <code>true</code> if the elements are laid out horizontally, * <code>false</code> if the are vertically */ public boolean isHorizontal( Key key ){ if( !isNode( key )) throw new IllegalArgumentException( "Not a node" ); return key.asNode().horizontal; }