Spaces between dockables

Hi,

Would it be possible to get rid of the spaces that the toolbar introduces between the dockables? Here’s a picture of the flat theme with no toolbar:

http://tinypic.com/r/2qs420w/6

And here’s one with a toolbar:

http://tinypic.com/r/15pr2aq/6

I have highlighted with red the right space that I want to get rid of (and also the left and bottom space).

Another question: is it possible to change the color of the toolbar (the background, I mean, all the empty top space), like for example, to the same color of the toolbar’s buttons, instead of that dark gray?

Sebastian.

The empty space can be changed by using a custom “SpanFactory” (as in the example below). Right now the minimum size of the Component is 1/1, in version 1.1.2p4a it will be changed to 0/0, so the gap can really be hidden.

In version 1.1.2p4a the default color will be the usual JPanel-grey, but clients will be able to set a custom color by calling the ColorManager.


import java.awt.Color;

import javax.swing.JFrame;

import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.action.CButton;
import bibliothek.gui.dock.common.theme.ThemeMap;
import bibliothek.gui.dock.station.span.Span;
import bibliothek.gui.dock.station.span.SpanCallback;
import bibliothek.gui.dock.station.span.SpanFactory;
import bibliothek.gui.dock.station.span.SpanMode;
import bibliothek.gui.dock.themes.ThemeManager;
import bibliothek.gui.dock.toolbar.CToolbarContentArea;
import bibliothek.gui.dock.toolbar.CToolbarItem;
import bibliothek.gui.dock.util.Priority;
import bibliothek.gui.dock.util.color.ColorManager;

public class ToolbarGap {
	public static void main( String[] args ){
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		frame.setBounds( 20, 20, 400, 400 );
		
		CControl control = new CControl( frame );
		control.setTheme( ThemeMap.KEY_FLAT_THEME );
		
		// here we override the algorithm that usually tells how big the gaps should be
		ThemeManager themeManager = control.getController().getThemeManager();
		themeManager.setSpanFactory( ThemeManager.SPAN_FACTORY + ".toolbar.container", new CustomSpanFactory() );
		
		// this is how the color of the background changes. This piece of code will work with version 1.1.2p4a
		ColorManager colors = control.getController().getColors();
		colors.put( Priority.CLIENT, "toolbar.container.background", Color.GREEN );
		
		CToolbarContentArea area = new CToolbarContentArea( control, "area" );
		control.addStationContainer( area );
		frame.add( area );
		
		DefaultSingleCDockable dockable = new DefaultSingleCDockable( "a", "Aaaa" );
		control.addDockable( dockable );
		dockable.setVisible( true );
		
		CToolbarItem item = new CToolbarItem( "button" );
		item.setItem( new CButton() );
		item.setLocation( area.getNorthToolbar().getStationLocation() );
		control.addDockable( item );
		item.setVisible( true );
		
		frame.setVisible( true );
	}
	
	// A span describes the size of some (empty) space, in pixels. A span can change the size at any time. 
	private static class CustomSpanFactory implements SpanFactory{
		@Override
		public Span create( SpanCallback callback ){
			return new CustomSpan( callback );
		}
		
		private class CustomSpan implements Span{
			private SpanCallback callback;
			private SpanMode mode;
			
			public CustomSpan( SpanCallback callback ){
				this.callback = callback;
			}
			
			@Override
			public void mutate( SpanMode mode ){
				this.mode = mode;
				callback.resized();
			}

			@Override
			public void set( SpanMode mode ){
				this.mode = mode;
				callback.resized();
			}

			@Override
			public void configureSize( SpanMode mode, int size ){
				// ignore
			}

			@Override
			public int getSize(){
				if( mode == SpanMode.OPEN || mode == SpanMode.TEASING ){
					return 5;
				}
				else{
					return 0;
				}
			}			
		}
	}
}

It works great! Thank you!

Sebastian.