When I click the maximize button in the stackDockable layout, only the currently selected dockable is maximized. How can I maximize the entire stackDockable?
When I add a CButton to the title, how do I put a portion of the Button’s position to the right of the maximize/minimize button?
There is more than one way to change the order of the buttons.
Actions (a button is an Action) are collected in thematically organized DockActionSources. There is a source for the maximize/minimize/etc buttons, there is a source for the close button, there is a source for the clients custom actions. Sources are collected in CommonDockable.
In addition, DockStations and customizable ActionGuards may provide additional DockActionSources.
All these sources are collected, and forwarded to an ActionOffer. The ActionOffer combines all the actions, and creates one combined DockActionSource which is forwarded to the DockTitles and thus shown to the user.
Providing a new ActionGuard is a good way to introduce special actions. Like in the example below. Note the “special” button showing up on the very right side of the title.
package test;
import javax.swing.JFrame;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.action.ActionGuard;
import bibliothek.gui.dock.action.DockActionSource;
import bibliothek.gui.dock.action.LocationHint;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.action.CAction;
import bibliothek.gui.dock.common.action.CButton;
import bibliothek.gui.dock.common.intern.CDockable;
import bibliothek.gui.dock.common.intern.CommonDockable;
import bibliothek.gui.dock.common.intern.action.CActionSource;
public class CustomButtonLocationTest {
public static void main( String[] args ) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
CControl control = new CControl( frame );
frame.add( control.getContentArea() );
// register additional source of actions
control.getController().addActionGuard( new MoreActionsGuard() );
MoreActionsDockable dockable = new MoreActionsDockable( "id" );
dockable.setTitleText( "Title" );
dockable.setCloseable( true );
dockable.addAction( button( "normal" ) );
// now there is a special method for buttons that should be on the right side
dockable.addActionRight( button( "special" ) );
control.addDockable( dockable );
dockable.setVisible( true );
frame.setBounds( 50, 50, 1000, 1000 );
frame.setVisible( true );
}
private static CButton button( String name ) {
CButton button = new CButton();
button.setText( name );
button.setShowTextOnButtons( true );
return button;
}
// extracts the additional source of actions from MoreActionsDockable
private static class MoreActionsGuard implements ActionGuard {
@Override
public boolean react( Dockable dockable ) {
return toCDockable( dockable ) instanceof MoreActionsDockable;
}
@Override
public DockActionSource getSource( Dockable dockable ) {
return ((MoreActionsDockable) toCDockable( dockable )).moreActions;
}
private CDockable toCDockable( Dockable dockable ) {
if( dockable instanceof CommonDockable ) {
return ((CommonDockable) dockable).getDockable();
} else {
return null;
}
}
}
private static class MoreActionsDockable extends DefaultSingleCDockable {
// list of actions that should be on the right side of the title.
private CActionSource moreActions = new CActionSource( new LocationHint( LocationHint.DOCKABLE, LocationHint.RIGHT_OF_ALL ) );
public MoreActionsDockable( String id ) {
super( id );
}
public void addActionRight( CAction action ) {
moreActions.add( action );
}
}
}
The maximized and minimized icons are not in the same position, the maximized icon is behind the docking icon, and the minimized icon is actually in front of the docking icon. Can they make their position the same? I tried do this modification and didn’t find the right way.
You may reorder the actions by implementing your custom ActionOffer (an ActionOffer can completely override which actions are shown to the user. It may add, remove or order actions however it likes).