package NET.worlds.console; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Insets; class QuantizedStackedLayout extends StackedLayout { ColorFiller m_filler; public QuantizedStackedLayout(ColorFiller filler) { this.m_filler = filler; } @Override public void layoutContainer(Container target) { int count = target.getComponentCount(); Insets insets = target.getInsets(); Dimension size = target.getSize(); int width = size.width - insets.left - insets.right; int height = size.height - insets.top - insets.bottom; int fillerHeight = 0; for (int i = 0; i < count; i++) { Component c = target.getComponent(i); if (c != this.m_filler) { int h = c.getPreferredSize().height; if (i == count - 1) { h = Math.max(h, height); } else { h = Math.min(h, height); } h = Math.max(0, h); height -= h; if (c instanceof QuantizedCanvas) { QuantizedCanvas qc = (QuantizedCanvas)c; fillerHeight += qc.getRemainder(h); } } } this.m_filler.setHeight(fillerHeight); int x = insets.left; int y = insets.top; height = size.height - insets.top - insets.bottom; for (int ix = 0; ix < count; ix++) { Component c = target.getComponent(ix); int hx = c.getPreferredSize().height; if (ix == count - 1) { hx = Math.max(hx, height); } else { hx = Math.min(hx, height); } hx = Math.max(0, hx); c.setBounds(x, y, width, hx); height -= hx; y += hx; } } }