throw new IllegalArgumentException( "height < 0" ); if( isUnpack() ){ unpack( x, y, width, height ); Node<D> node = nodeAt( x, y, width, height ); int insert = 0; node.dockables = array( dockables.length ); node.dockables = array( oldDockables.length + dockables.length ); System.arraycopy( oldDockables, 0, node.dockables, 0, oldDockables.length );
/** * Tells whether the two nodes could be merged or not. * @param a the first node * @param b the second node * @return how likely the two nodes can be merged, a small result indicates * that merging would be a good idea. */ protected double diff( Node<D> a, Node<D> b ){ double x = Math.min( a.x, b.x ); double y = Math.min( a.y, b.y ); double w = Math.max( a.x + a.width, b.x + b.width ) - x; double h = Math.max( a.y + a.height, b.y + b.height ) - y; double sizeA = a.width * a.height; double sizeB = b.width * b.height; double size = w * h; double diff = (size - sizeA - sizeB) / size; for( Line line : lines ){ diff += penalty( x, y, w, h, line ); } return diff; }
/** * Gets all the dockables that were {@link #addDockable(double, double, double, double, Object...) added} * to this grid at location <code>x,y,width,height</code> * @param x the x-coordinate * @param y the y-coordinate * @param width the width, more than 0 * @param height the height, more than 0 * @return the dockables, <code>null</code> if there are no dockables at this location */ public D[] getDockables( double x, double y, double width, double height ){ Node<D> node = nodeAt( x, y, width, height ); if( node == null ){ return null; } D[] copy = array( node.dockables.length ); System.arraycopy( node.dockables, 0, copy, 0, copy.length ); return copy; }
/** * Unpacks any existing {@link DockStation} at location <code>x,y,width,height</code>. All children * of all {@link DockStation}s are removed and re-added as if {@link #addDockable(double, double, double, double, Object...)} * would have been called multiple times. * @param x the x-coordinate * @param y the y-coordinate * @param width the width, more than 0 * @param height the height, more than 0 */ public void unpack( double x, double y, double width, double height ){ Node<D> node = nodeAt( x, y, width, height ); if( node != null && node.dockables != null ){ List<D> copy = new ArrayList<D>(); for( D dockable : node.dockables ){ for( D unpacked : unpack( dockable )){ copy.add( unpacked ); } } D[] unpacked = copy.toArray( array( copy.size() )); node.dockables = unpacked; } }
/** * Fills the contents of this grid into <code>tree</code>. * @param tree the tree to fill */ protected void fillTree( SplitDockTree<D> tree ){ Node<D> root = tree(); if( root != null ){ SplitDockTree<D>.Key key = root.put( tree ); tree.root( key ); } }
addDockable( minx, miny, maxx-minx, maxy-miny, list );
Line line = bestFittingLine( x, y, w, h, false, split ); if( line == null ) node.divider = split; Line line = bestFittingLine( x, y, w, h, true, split); if( line == null ) node.divider = split;
/** * Unpacks any existing {@link DockStation} at location <code>x,y,width,height</code>. All children * of all {@link DockStation}s are removed and re-added as if {@link #addDockable(double, double, double, double, Object...)} * would have been called multiple times. * @param x the x-coordinate * @param y the y-coordinate * @param width the width, more than 0 * @param height the height, more than 0 */ public void unpack( double x, double y, double width, double height ){ Node<D> node = nodeAt( x, y, width, height ); if( node != null && node.dockables != null ){ List<D> copy = new ArrayList<D>(); for( D dockable : node.dockables ){ for( D unpacked : unpack( dockable )){ copy.add( unpacked ); } } D[] unpacked = copy.toArray( array( copy.size() )); node.dockables = unpacked; } }
/** * Gets all the dockables that were {@link #addDockable(double, double, double, double, Object...) added} * to this grid at location <code>x,y,width,height</code> * @param x the x-coordinate * @param y the y-coordinate * @param width the width, more than 0 * @param height the height, more than 0 * @return the dockables, <code>null</code> if there are no dockables at this location */ public D[] getDockables( double x, double y, double width, double height ){ Node<D> node = nodeAt( x, y, width, height ); if( node == null ){ return null; } D[] copy = array( node.dockables.length ); System.arraycopy( node.dockables, 0, copy, 0, copy.length ); return copy; }
/** * Fills the contents of this grid into <code>tree</code>. * @param tree the tree to fill */ protected void fillTree( SplitDockTree<D> tree ){ Node<D> root = tree(); if( root != null ){ SplitDockTree<D>.Key key = root.put( tree ); tree.root( key ); } }
addDockable( minx, miny, maxx-minx, maxy-miny, list );
Line line = bestFittingLine( x, y, w, h, false, split ); if( line == null ) node.divider = split; Line line = bestFittingLine( x, y, w, h, true, split); if( line == null ) node.divider = split;
throw new IllegalArgumentException( "height < 0" ); if( isUnpack() ){ unpack( x, y, width, height ); Node<D> node = nodeAt( x, y, width, height ); int insert = 0; node.dockables = array( dockables.length ); node.dockables = array( oldDockables.length + dockables.length ); System.arraycopy( oldDockables, 0, node.dockables, 0, oldDockables.length );
/** * Tells whether the two nodes could be merged or not. * @param a the first node * @param b the second node * @return how likely the two nodes can be merged, a small result indicates * that merging would be a good idea. */ protected double diff( Node<D> a, Node<D> b ){ double x = Math.min( a.x, b.x ); double y = Math.min( a.y, b.y ); double w = Math.max( a.x + a.width, b.x + b.width ) - x; double h = Math.max( a.y + a.height, b.y + b.height ) - y; double sizeA = a.width * a.height; double sizeB = b.width * b.height; double size = w * h; double diff = (size - sizeA - sizeB) / size; for( Line line : lines ){ diff += penalty( x, y, w, h, line ); } return diff; }