@Override public void addDockActionSourceListener( DockActionSourceListener listener ){ if( listeners.isEmpty() && source != null ) source.addDockActionSourceListener( this.listener ); super.addDockActionSourceListener( listener ); }
/** * Gets the index of the child-source which contains <code>action</code>. * @param action the action for which is searched * @return the index of the source which contains the action or -1 */ protected int getSource( DockAction action ){ for( int i = 0, n = sources.size(); i<n; i++ ){ DockActionSource source = sources.get( i ); for( int j = 0, m = source.getDockActionCount(); j<m; j++ ){ if( source.getDockAction( j ) == action ) return i; } } return -1; }
public Iterator<DockAction> iterator(){ if( source == null ){ return new Iterator<DockAction>(){ public boolean hasNext(){ return false; } public DockAction next(){ return null; } public void remove(){ // ignore } }; } else{ return source.iterator(); } }
/** * Removes all listeners added by this listener. */ public void destroy(){ DockActionSource source = dockable.getGlobalActionOffers(); source.removeDockActionSourceListener( this ); actionsRemoved( source, 0, source.getDockActionCount()-1 ); }
/** * Creates a new observer * @param dockable the element whose actions will be managed */ public SourceObserver( Dockable dockable ){ this.dockable = dockable; DockActionSource source = dockable.getGlobalActionOffers(); actionsAdded( source, 0, source.getDockActionCount()-1 ); source.addDockActionSourceListener( this ); }
private void setSource( DockActionSource source ){ if( this.source != source ){ if( this.source != null ){ int size = getDockActionCount(); this.source.removeDockActionSourceListener( actionListener ); this.source = null; if( size > 0 ){ fireRemoved( 0, size-1 ); } } this.source = source; if( this.source != null ){ int size = getDockActionCount(); if( size > 0 ){ fireAdded( 0, size-1 ); } this.source.addDockActionSourceListener( actionListener ); } } }
@Override public void bind() { super.bind(); source.addDockActionSourceListener( sourceListener ); for( int i = 0, n = source.getDockActionCount(); i<n; i++ ){ DockAction action = source.getDockAction( i ); ActionItem item = new ActionItem(); item.action = action; actions.add( item ); MenuViewItem<JComponent> handler = handlerFor( action ); if( handler != null ){ item.handler = handler; item.bind(); item.action.bind( dockable ); handler.bind(); if( handler.getItem() != null ){ menu.add( handler.getItem() ); } } } }
@Override public int getDockActionCount(){ int count = source.getDockActionCount(); if( count > 0 ){ count++; } return count; }
@Override public DockAction getDockAction( int index ){ if( index == 0 ){ return separator; } else{ return source.getDockAction( index-1 ); } }
@Override public void removeDockActionSourceListener( DockActionSourceListener listener ){ boolean empty = listeners.isEmpty(); super.removeDockActionSourceListener( listener ); if( !empty && listeners.isEmpty() ){ for( DockActionSource source : sources ) source.removeDockActionSourceListener( this.listener ); } }
public LocationHint getLocationHint(){ if( source == null ) return LocationHint.UNKNOWN; else return source.getLocationHint(); }
private void setSource( DockActionSource source ){ if( this.source != source ){ if( this.source != null ){ int size = getDockActionCount(); this.source.removeDockActionSourceListener( actionListener ); this.source = null; if( size > 0 ){ fireRemoved( 0, size-1 ); } } this.source = source; if( this.source != null ){ int size = getDockActionCount(); if( size > 0 ){ fireAdded( 0, size-1 ); } this.source.addDockActionSourceListener( actionListener ); } } }
for( int i = 0, n = source.getDockActionCount(); i<n; i++ ){ DockAction sub = source.getDockAction( i ); add( i, sub ); source.addDockActionSourceListener( listener );
public int getDockActionCount(){ if( source == null ) return 0; else return source.getDockActionCount(); }
public void actionsAdded( DockActionSource source, int firstIndex, int lastIndex ){ for( int i = firstIndex; i <= lastIndex; i++ ) add( i, source.getDockAction( i )); }
@Override public void removeDockActionSourceListener( DockActionSourceListener listener ){ super.removeDockActionSourceListener( listener ); if( listeners.isEmpty() ){ source.removeDockActionSourceListener( this.listener ); actions = null; } }
/** * 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(); }
public LocationHint getLocationHint(){ if( source == null ) return LocationHint.UNKNOWN; else return source.getLocationHint(); }
private void rebuild(){ if( delegate != null ){ if( !listeners.isEmpty() ){ delegate.removeDockActionSourceListener( delegateListener ); } int size = getDockActionCount(); delegate = null; if( size > 0 ){ fireRemoved( 0, size-1 ); } } delegate = manager.getSharedActions( station ); if( delegate != null ){ if( !listeners.isEmpty() ){ delegate.addDockActionSourceListener( delegateListener ); } int size = getDockActionCount(); if( size > 0 ){ fireAdded( 0, size-1 ); } } } }