diff options
Diffstat (limited to 'NET/worlds/console/QuantizedStackedLayout.java')
| -rw-r--r-- | NET/worlds/console/QuantizedStackedLayout.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/NET/worlds/console/QuantizedStackedLayout.java b/NET/worlds/console/QuantizedStackedLayout.java new file mode 100644 index 0000000..98f12f0 --- /dev/null +++ b/NET/worlds/console/QuantizedStackedLayout.java @@ -0,0 +1,63 @@ +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; + } + } +} |