Let’s start with 2, I think that is the easier question.
There is a method CDockable.setLocation, where you can use arguments like e.g. “CLocation.base().north( 0.25 )” (points to the top 25% of your application). But in your case I think it would be very hard to use this method because you can only move one Dockable at a time - which results in a really big puzzle to find out in which order to move the Dockabes.
So instead I would use the CGrid class. With the CGrid you can lay out all the Dockables at the same time. Beware however that the method “CContentArea.deploy” will remove any Dockables before applying “grid”. So any Dockable that is not added to “grid” will just disappear. In pseudo-code it would look somewhat like this:
CControl control = ...
// that is the helper-object we are going to fill up
CGrid grid = new CGrid();
int dc = wsControl.getCDockableCount();
for (int i = 0; i < dc; ++i) {
CDockable win = wsControl.getCDockable(i);
if (win instanceof DefaultSingleCDockable) {
DefaultSingleCDockable wSingle = ((DefaultSingleCDockable) win);
utMisc.debugOutput("Win #" + i + "=id:" + wSingle.getUniqueId() + ", Title=" + wSingle.getTitleText());
int windowType = xxxx; // let's say 0, 1, or 2
if( windowType = yyyy ){
// e.g. top. Assume "grid" has a size of 100/100, then we take up 75% horizontal, and 50% vertical space
grid.add( 0, 0, 75, 50, win );
}
else{
... // other location(s)
grid.add( ... );
}
}
else {
// don't forget to add other Dockables as well
grid.add( win, <appropriate location> );
}
// now replace any content of the default CContentArea with "grid".
control.getContentArea().deploy( grid );
… or as an application that really works. You certainly have to play a bit with the correct positions, but I think you understand what I suggest as solution?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
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.SingleCDockable;
import bibliothek.gui.dock.common.location.CMaximalExternalizedLocation;
import bibliothek.gui.dock.common.mode.ExtendedMode;
import bibliothek.gui.dock.layout.DockableProperty;
import bibliothek.gui.dock.station.split.SplitDockPathProperty;
import bibliothek.gui.dock.station.split.SplitDockPlaceholderProperty;
import bibliothek.gui.dock.station.split.SplitDockProperty;
public class Dock29 {
public static void main( String[] args ){
JFrame frame = new JFrame();
frame.setBounds( 20, 20, 500, 500 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
final CControl control = new CControl( frame );
final SingleCDockable red = create( "red", Color.RED );
final SingleCDockable green = create( "green", Color.GREEN );
final SingleCDockable blue = create( "blue", Color.BLUE );
JButton button = new JButton( "Reset" );
button.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent e ){
CGrid grid = new CGrid();
// put red and blue to the top left/bottom left
grid.add( 0, 0, 75, 50, red );
grid.add( 0, 50, 75, 50, blue );
// let green stay where it currently is
if( green.getExtendedMode() == ExtendedMode.MAXIMIZED ){
if( !(green.getBaseLocation() instanceof CMaximalExternalizedLocation) ){
// if in maximized mode and not free floating: demaximize
green.setExtendedMode( ExtendedMode.NORMALIZED );
}
}
if( green.getExtendedMode() == ExtendedMode.NORMALIZED ){
// fall back to Core and assume that green is a child of a SplitDockStation (not necessarily true,
// it could also be a StackDockStation. If that happens "property.getSuccessor" is not null, and the
// code below may not work properly anymore).
CLocation location = green.getBaseLocation();
DockableProperty property = location.findProperty();
if( property instanceof SplitDockPlaceholderProperty ){
property = ((SplitDockPlaceholderProperty)property).getBackup();
}
if( property instanceof SplitDockPathProperty ){
property = ((SplitDockPathProperty)property).toLocation();
}
if( property instanceof SplitDockProperty ){
SplitDockProperty rectangle = (SplitDockProperty)property;
grid.add( 100*rectangle.getX(), 100*rectangle.getY(), 100*rectangle.getWidth(), 100*rectangle.getHeight(), green );
}
else{
// backup plan if we guessed wrong about the type of "property"
grid.add( 75, 0, 25, 100, green );
}
}
control.getContentArea().deploy( grid );
}
});
CGrid grid = new CGrid( control );
grid.add( 0, 0, 75, 50, red );
grid.add( 0, 50, 75, 50, blue );
grid.add( 75, 0, 25, 100, green );
control.getContentArea().deploy( grid );
frame.add( control.getContentArea() );
frame.add( button, BorderLayout.SOUTH );
frame.setVisible( true );
}
public static DefaultSingleCDockable create( String title, Color color ){
JPanel panel = new JPanel();
panel.setOpaque(true);
panel.setBackground(color);
DefaultSingleCDockable singleDockable = new DefaultSingleCDockable(title, title, panel);
return singleDockable;
}
}