On Exit get dock sizes

Hello Beni,

I’ll use the sample code from this posting:

grid.add(  0,  0, 25, 75, create( "yellow", "Yellow", Color.YELLOW) );
grid.add(  0, 75, 25, 25, create( "green", "Green", Color.GREEN ) );
grid.add( 26,  0, 50, 100, cwArea );
grid.add( 75,  0, 25, 50, create( "blue", "Blue", Color.BLUE) );
grid.add( 75, 50, 25, 50, create( "red", "Red", Color.RED) );

ctcArea.getCenterArea().deploy(grid);

It creates 2 docks (DefaultSingleCDockable) on the far left, 2 docks (DefaultSingleCDockable) on the far right and a CWorkingArea in the middle.

So, when the user closes the application, I would like to know the width of the docks on the far left and far right. How do I get the width (don’t care about height) of a DefaultSingleCDockable? I cannot find any methods for the dockable.

Regards,
Roger

I would suggest looking at the “CLocation” of the Dockable, like in the example below. If you want the size in pixels, multiply the output with the size of the CContentArea on which the Dockables are shown.


import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.intern.CDockable;
import bibliothek.gui.dock.layout.DockableProperty;
import bibliothek.gui.dock.station.split.SplitDockPathProperty;

public class SizeExample {
	public static void main( String[] args ) {
		new SizeExample().checkAndPrint();
	}

	public void checkAndPrint() {
		CControl control = new CControl();
		CGrid grid = new CGrid( control );

		grid.add( 0, 0, 25, 75, create( "yellow" ) );
		grid.add( 0, 75, 25, 25, create( "green" ) );
		grid.add( 26, 0, 50, 100, create( "center" ) );
		grid.add( 75, 0, 25, 50, create( "blue" ) );
		grid.add( 75, 50, 25, 50, create( "red" ) );

		control.getContentArea().deploy( grid );

		for( int i = 0, n = control.getCDockableCount(); i < n; i++ ) {
			CDockable dockable = control.getCDockable( i );
			CLocation location = dockable.getBaseLocation();
			if( location != null ) {
				System.out.println( dockable );
				System.out.println( location );
				analze( location );
			}
		}
	}

	private void analze( CLocation location ) {
		DockableProperty property = location.findProperty();
		if( property instanceof SplitDockPathProperty ) {
			SplitDockPathProperty path = (SplitDockPathProperty) property;

			boolean left = true;
			boolean right = true;
			double width = 100.0;

			for( SplitDockPathProperty.Node node : path ) {
				switch( node.getLocation() ){
				case LEFT:
					right = false;
					width *= node.getSize();
					break;
				case RIGHT:
					left = false;
					width *= node.getSize();
				}
			}
			
			System.out.println( String.format( "left: %s, right: %s, width %f%%", left, right, width ) );
			System.out.println(  );
		}
	}

	private DefaultSingleCDockable create( String id ) {
		return new DefaultSingleCDockable( id, id );
	}
}

Hi Beni,

Thanks. That appears to do the trick.

Regards,
Roger