// start with the most "permissive" resize policy for each band
for (AbstractRibbonBand<?> band : selectedTask.getBands()) {
List<RibbonBandResizePolicy> policies = band
.getResizePolicies();
RibbonBandResizePolicy last = policies.get(0);
band.setCurrentResizePolicy(last);
}
int availableBandHeight = c.getHeight();
int availableWidth = c.getWidth();
if (selectedTask.getBandCount() > 0) {
RibbonBandResizeSequencingPolicy resizeSequencingPolicy = selectedTask
.getResizeSequencingPolicy();
resizeSequencingPolicy.reset();
AbstractRibbonBand<?> currToTakeFrom = resizeSequencingPolicy
.next();
while (true) {
// check whether all bands have the current resize
// policy as their last (most restrictive) registered policy
boolean noMore = true;
for (AbstractRibbonBand<?> band : selectedTask.getBands()) {
RibbonBandResizePolicy currentResizePolicy = band
.getCurrentResizePolicy();
List<RibbonBandResizePolicy> resizePolicies = band
.getResizePolicies();
if (currentResizePolicy != resizePolicies
.get(resizePolicies.size() - 1)) {
noMore = false;
break;
}
}
if (noMore)
break;
// get the current preferred width of the bands
int totalWidth = 0;
// System.out.println("Iteration");
for (AbstractRibbonBand<?> ribbonBand : selectedTask
.getBands()) {
RibbonBandResizePolicy currentResizePolicy = ribbonBand
.getCurrentResizePolicy();
Insets ribbonBandInsets = ribbonBand.getInsets();
AbstractBandControlPanel controlPanel = ribbonBand
.getControlPanel();
if (controlPanel == null) {
controlPanel = ribbonBand.getPopupRibbonBand()
.getControlPanel();
}
Insets controlPanelInsets = controlPanel.getInsets();
int controlPanelGap = controlPanel.getUI()
.getLayoutGap();
int ribbonBandHeight = availableBandHeight
- ribbonBandInsets.top
- ribbonBandInsets.bottom;
int availableHeight = ribbonBandHeight
- ribbonBand.getUI().getBandTitleHeight();
if (controlPanel != null) {
availableHeight = availableHeight
- controlPanelInsets.top
- controlPanelInsets.bottom;
}
int preferredWidth = currentResizePolicy
.getPreferredWidth(availableHeight,
controlPanelGap)
+ ribbonBandInsets.left
+ ribbonBandInsets.right;
totalWidth += preferredWidth + bandGap;
// System.out.println("\t"
// + ribbonBand.getTitle()
// + ":"
// + currentResizePolicy.getClass()
// .getSimpleName() + ":" + preferredWidth
// + " under " + availableHeight + " with "
// + controlPanel.getComponentCount()
// + " children");
}
// System.out.println("\t:Total:" + totalWidth + "("
// + availableWidth + ")");
// System.out.println("\n");
if (totalWidth < availableWidth)
break;
// try to take from the currently rotating band
List<RibbonBandResizePolicy> policies = currToTakeFrom
.getResizePolicies();
int currPolicyIndex = policies.indexOf(currToTakeFrom
.getCurrentResizePolicy());
if (currPolicyIndex == (policies.size() - 1)) {
// nothing to take
} else {
currToTakeFrom.setCurrentResizePolicy(policies
.get(currPolicyIndex + 1));
}
currToTakeFrom = resizeSequencingPolicy.next();
}
}
boolean ltr = c.getComponentOrientation().isLeftToRight();
x = ltr ? 1 : c.getWidth() - 1;
// System.out.println("Will get [" + availableWidth + "]:");
for (AbstractRibbonBand<?> ribbonBand : selectedTask.getBands()) {
Insets ribbonBandInsets = ribbonBand.getInsets();
RibbonBandResizePolicy currentResizePolicy = ribbonBand
.getCurrentResizePolicy();
AbstractBandControlPanel controlPanel = ribbonBand
.getControlPanel();
if (controlPanel == null) {
controlPanel = ribbonBand.getPopupRibbonBand()
.getControlPanel();
}
Insets controlPanelInsets = controlPanel.getInsets();
int controlPanelGap = controlPanel.getUI().getLayoutGap();
int ribbonBandHeight = availableBandHeight;
// - ribbonBandInsets.top - ribbonBandInsets.bottom;
int availableHeight = ribbonBandHeight - ribbonBandInsets.top
- ribbonBandInsets.bottom
- ribbonBand.getUI().getBandTitleHeight();
if (controlPanelInsets != null) {
availableHeight = availableHeight - controlPanelInsets.top
- controlPanelInsets.bottom;
}
int requiredBandWidth = currentResizePolicy.getPreferredWidth(
availableHeight, controlPanelGap)
+ ribbonBandInsets.left + ribbonBandInsets.right;
if (ltr) {
ribbonBand.setBounds(x, y, requiredBandWidth,