Good morning, here is the example for the colors. It’s only using the Core library, but converting it to Common should not be a problem for you. Instead of using a “DefaultDockable” use a “DefaultSingleCDockable” and the method “extract” has to call “((CommonDockable)dockable).getDockable()” first.
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.JFrame;
import bibliothek.extension.gui.dock.theme.FlatTheme;
import bibliothek.gui.DockController;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.DefaultDockable;
import bibliothek.gui.dock.SplitDockStation;
import bibliothek.gui.dock.action.DefaultDockActionSource;
import bibliothek.gui.dock.action.LocationHint;
import bibliothek.gui.dock.action.SelectableDockAction;
import bibliothek.gui.dock.action.actions.SimpleSelectableAction;
import bibliothek.gui.dock.event.SelectableDockActionListener;
import bibliothek.gui.dock.station.split.SplitDockProperty;
import bibliothek.gui.dock.themes.color.TitleColor;
import bibliothek.gui.dock.util.Priority;
import bibliothek.gui.dock.util.color.ColorBridge;
import bibliothek.gui.dock.util.color.DockColor;
public class Dock48 {
/* This example shows how a Dockable and a ColorBridge can be combined to instantly change
* colors depending on the state of the Dockable */
public static void main( String[] args ){
JFrame frame = new JFrame();
DockController controller = new DockController();
controller.setRootWindow( frame );
controller.setTheme( new FlatTheme() );
SplitDockStation center = new SplitDockStation();
controller.add( center );
frame.add( center );
controller.getColors().publish( Priority.CLIENT, TitleColor.KIND_TITLE_COLOR, new CustomColorBridge() );
center.drop( new CustomDockable( "A" ) );
center.drop( new CustomDockable( "B" ), new SplitDockProperty( 0, 0, 1.0, 0.5 ));
center.drop( new CustomDockable( "C" ), new SplitDockProperty( 0, 0, 0.5, 0.5 ));
center.drop( new CustomDockable( "D" ), new SplitDockProperty( 0, 0.5, 0.5, 0.5 ));
frame.setBounds( 20, 20, 400, 400 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );
}
/* To be notified about changes of the state of our Dockables we create this listener interface */
private static interface CustomListener{
public void colorChanged( CustomDockable dockable );
}
/* And this is the action that will change the state of our Dockables */
private static class CustomAction extends SimpleSelectableAction.Check implements SelectableDockActionListener{
private CustomDockable dockable;
public CustomAction( CustomDockable dockable ){
this.dockable = dockable;
setText( "switch" );
addSelectableListener( this );
}
@Override
public void selectedChanged( SelectableDockAction action, Set<Dockable> dockables ){
dockable.setState( isSelected() );
}
}
/* And this is our Dockable with a "state", if the state changes the Dockable fires an event. */
private static class CustomDockable extends DefaultDockable{
private List<CustomListener> listeners = new ArrayList<CustomListener>();
private boolean state = false;
public CustomDockable( String title ){
setTitleText( title );
DefaultDockActionSource source = new DefaultDockActionSource( new LocationHint( LocationHint.DOCKABLE, LocationHint.LEFT ) );
source.add( new CustomAction( this ) );
setActionOffers( source );
}
public void addCustomListener( CustomListener listener ){
listeners.add( listener );
}
public void removeCustomListener( CustomListener listener ){
listeners.remove( listener );
}
public boolean isState(){
return state;
}
public void setState( boolean state ){
if( this.state != state ){
this.state = state;
for( CustomListener listener : listeners ){
listener.colorChanged( this );
}
}
}
}
/* Now the interesting part: this ColorBridge changes the colors of DockTitles according to the current state of
* a CustomDockable. */
private static class CustomColorBridge implements ColorBridge, CustomListener{
/* These are all the DockColors that are currently using a color, we only store the interesting ones - any
* color not associated with a CustomDockable is ignored. Please note that we always carefully ensure that
* no entry overrides another entry in these maps. */
private Map<CustomDockable, Map<String, List<DockColor>>> observers = new HashMap<CustomDockable, Map<String,List<DockColor>>>();
@Override
public void colorChanged( CustomDockable dockable ){
/* If the state of one of our Dockables changed, we search its DockColors and update them */
Map<String, List<DockColor>> map = observers.get( dockable );
if( map != null ){
for( Map.Entry<String, List<DockColor>> entry : map.entrySet() ){
for( DockColor uiValue : entry.getValue() ){
maybeSet( entry.getKey(), uiValue );
}
}
}
}
/* This methods stores "color" in a map, it returns "true" if this is the first time
* that "dockable" is using a color. */
private boolean add( CustomDockable dockable, String id, DockColor color ){
boolean result = false;
Map<String, List<DockColor>> map = observers.get( dockable );
if( map == null ){
result = true;
map = new HashMap<String, List<DockColor>>();
observers.put( dockable, map );
}
List<DockColor> list = map.get( id );
if( list == null ){
list = new ArrayList<DockColor>();
map.put( id, list );
}
list.add( color );
return result;
}
/* This method removes "color" from the care of this ColorBridge. The method returns
* "true" if "color" was the last DockColor "dockable" was using. */
private boolean remove( CustomDockable dockable, String id, DockColor color ){
boolean result = false;
Map<String,List<DockColor>> map = observers.get( dockable );
List<DockColor> list = map.get( id );
list.remove( color );
if( list.isEmpty() ){
map.remove( id );
if( map.isEmpty() ){
observers.remove( dockable );
result = true;
}
}
return result;
}
/* Given a DockColor tells which CustomDockable is associated with that DockColor */
private CustomDockable extract( DockColor uiValue ){
TitleColor color = (TitleColor)uiValue;
Dockable dockable = color.getTitle().getDockable();
if( dockable instanceof CustomDockable ){
return (CustomDockable)dockable;
}
return null;
}
/* Called when a DockColor starts requesting values. */
@Override
public void add( String id, DockColor uiValue ){
CustomDockable dockable = extract( uiValue );
if( dockable != null ){
if( add( dockable, id, uiValue )){
dockable.addCustomListener( this );
}
}
}
/* Called when a DockColor no longer requests values */
@Override
public void remove( String id, DockColor uiValue ){
CustomDockable dockable = extract( uiValue );
if( dockable != null ){
if( remove( dockable, id, uiValue )){
dockable.removeCustomListener( this );
}
}
}
/* Updates the current value of "uiValue" */
@Override
public void set( String id, Color value, DockColor uiValue ){
if( !maybeSet( id, uiValue )){
uiValue.set( value );
}
}
/* Replaces some colors of our choosing by other colors that depend on the
* current state of the CustomDockable that is associated with "uiValue" */
private boolean maybeSet( String id, DockColor uiValue ){
CustomDockable dockable = extract( uiValue );
if( dockable == null ){
return false;
}
if( dockable.isState() ){
if( id.equals( "title.active.left" )){
uiValue.set( Color.RED.brighter() );
return true;
}
else if( id.equals( "title.inactive.left" )){
uiValue.set( Color.ORANGE.brighter() );
return true;
}
else if( id.equals( "title.active.right" )){
uiValue.set( Color.RED.darker() );
return true;
}
else if( id.equals( "title.inactive.right" )){
uiValue.set( Color.ORANGE.darker() );
return true;
}
else{
return false;
}
}
else{
if( id.equals( "title.active.left" )){
uiValue.set( Color.BLUE.brighter() );
return true;
}
else if( id.equals( "title.inactive.left" )){
uiValue.set( Color.CYAN.brighter() );
return true;
}
else if( id.equals( "title.active.right" )){
uiValue.set( Color.BLUE.darker() );
return true;
}
else if( id.equals( "title.inactive.right" )){
uiValue.set( Color.CYAN.darker() );
return true;
}
else{
return false;
}
}
}
}
}