Posting my code (since the forum does not allow posts beyond 11000 chars, I may have to split this into multiple posts
) …
Here are the classes I have implemented.
LbSplitDockStationFactory creates SplitDockStation objects that use LbSplitLayoutManager.
public class LbSplitDockStationFactory extends SplitDockStationFactory
{
@Override
public SplitDockStation createStation()
{
SplitDockStation splitDockStation = new SplitDockStation();
splitDockStation.setSplitLayoutManager(new LbSplitLayoutManager());
splitDockStation.setDividerSize(1);
return splitDockStation;
}
}
LbSplitLayoutManager overrides the calculateDivider method.
public class LbSplitLayoutManager extends DefaultSplitLayoutManager
{
private static final double MINIMUM_ORIGINAL_SIZE = 0.25;
private static final Dimension cDefaultMinimumSize = new Dimension(10, 10);
//cache LbDockableSizeManager since it will be needed very often
LbDockableSizeManager _lbDockableSizeManager = null;
@Override
public void calculateDivider( SplitDockStation station,
PutInfo putInfo,
Leaf origin )
{
Dockable dockable = putInfo.getDockable();
if(origin != null)
{
super.calculateDivider(station, putInfo, origin);
}
// LbDockableSizeManager.getSize(dockable);
if(_lbDockableSizeManager == null)
{
_lbDockableSizeManager =
LbDockableSizeManager.getInstance(station.getController());
}
double percentSize = _lbDockableSizeManager.getOldSize(dockable);
if(percentSize == 0) //we do not have a stored size
{
super.calculateDivider(station, putInfo, origin);
}
else
{
SplitNode other = putInfo.getNode();
Dimension oldSize = dockable.getComponent().getSize();
int size = Math.min( oldSize.width, oldSize.height );
double divider = 0.5;
if( putInfo.getPut() == PutInfo.Put.TOP )
{
divider =
validateDivider(station,
percentSize,
cDefaultMinimumSize, //dockable.getComponent().getMinimumSize(),
cDefaultMinimumSize, //other.getMinimumSize(),
Orientation.VERTICAL,
other.getWidth(),
other.getHeight());
if( divider > 1 - MINIMUM_ORIGINAL_SIZE )
divider = 1 - MINIMUM_ORIGINAL_SIZE;
}
else if(putInfo.getPut() == PutInfo.Put.BOTTOM)
{
divider =
validateDivider(station,
1.0-percentSize,
cDefaultMinimumSize, //other.getMinimumSize(),
cDefaultMinimumSize, //dockable.getComponent().getMinimumSize(),
Orientation.VERTICAL,
other.getWidth(),
other.getHeight());
if( divider < MINIMUM_ORIGINAL_SIZE )
divider = MINIMUM_ORIGINAL_SIZE;
}
else if(putInfo.getPut() == PutInfo.Put.LEFT)
{
divider =
validateDivider(station,
percentSize,
cDefaultMinimumSize, //dockable.getComponent().getMinimumSize(),
cDefaultMinimumSize, //other.getMinimumSize(),
Orientation.HORIZONTAL,
other.getWidth(), other.getHeight() );
if( divider > 1 - MINIMUM_ORIGINAL_SIZE )
divider = 1 - MINIMUM_ORIGINAL_SIZE;
}
else if(putInfo.getPut() == PutInfo.Put.RIGHT)
{
divider =
validateDivider(station,
1.0-percentSize,
cDefaultMinimumSize, //other.getMinimumSize(),
cDefaultMinimumSize, //dockable.getComponent().getMinimumSize(),
Orientation.HORIZONTAL,
other.getWidth(),
other.getHeight() );
if( divider < MINIMUM_ORIGINAL_SIZE )
divider = MINIMUM_ORIGINAL_SIZE;
}
putInfo.setDivider(divider);
putInfo.setOldSize(size);
}
}
}
LbDockableSizeManager saves the size of a dockable when it is dragged.
–
Thanks & Regards
Parag