/** * Sets whether there are separators between the children of this * source or not. * @param separateSources <code>true</code> if children should be separated */ public void setSeparateSources( boolean separateSources ) { if( this.separateSources != separateSources ){ this.separateSources = separateSources; updateSeparators(); } }
/** * Counts how many {@link DockAction DockActions} are provided by the * source-children with index 0 (incl) to <code>index</code> (excl). * @param index the index of the first source that should not be counted * @param allowUpdate whether the {@link #updateSeparators()} can be called * by this method or not * @return the number of actions of the first <code>index</code> * child-sources. */ protected int getDockActionCountUntil( int index, boolean allowUpdate ){ if( allowUpdate && listeners.isEmpty() ) updateSeparators(); int sum = 0; for( int i = 0; i < index; i++ ) sum += sources.get( i ).getDockActionCount(); return sum; }
public DockAction getDockAction( int index ) { if( listeners.isEmpty() ) updateSeparators(); int sum = 0; for( int i = 0, n = sources.size(); i<n; i++ ){ int length = sources.get( i ).getDockActionCount(); if( sum <= index && index < sum + length ) return sources.get( i ).getDockAction( index - sum ); sum += length; } throw new ArrayIndexOutOfBoundsException(); }
@Override public void addDockActionSourceListener( DockActionSourceListener listener ){ boolean empty = listeners.isEmpty(); super.addDockActionSourceListener( listener ); if( empty && !listeners.isEmpty() ){ for( DockActionSource source : sources ) source.addDockActionSourceListener( this.listener ); updateSeparators(); } }
/** * Removes <code>source</code> from this {@link MultiDockActionSource}. * @param source the child to remove */ public void remove( DockActionSource source ){ int index = sources.indexOf( source ); if( index < 0 ) return; SeparatorSource separator = (SeparatorSource)sources.get( index+1 ); int actionIndex = getDockActionCountUntil( index, false ); int length = source.getDockActionCount(); sources.remove( index+1 ); sources.remove( index ); separators.remove( separator ); if( !listeners.isEmpty() ){ source.removeDockActionSourceListener( listener ); separator.removeDockActionSourceListener( listener ); } if( length > 0 ){ fireRemoved( actionIndex, index+length-1 ); } updateSeparators(); }
/** * Adds a source as child of this source. All {@link DockAction DockActions} * of <code>source</code> will be presented as actions of this source.<br> * Note: creating circles or adding a source more than once will lead to * unspecified behavior. * @param source the new child */ public void add( DockActionSource source ){ SeparatorSource separator = new SeparatorSource( source ); sources.add( source ); sources.add( separator ); separators.add( separator ); if( !listeners.isEmpty() ){ source.addDockActionSourceListener( listener ); separator.addDockActionSourceListener( listener ); } int index = getDockActionCountUntil( sources.size()-2, false ); int length = source.getDockActionCount(); if( length > 0 ) fireAdded( index, index+length-1 ); updateSeparators(); }