diff options
Diffstat (limited to 'NET/worlds/console/StackedLayout.java')
| -rw-r--r-- | NET/worlds/console/StackedLayout.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/NET/worlds/console/StackedLayout.java b/NET/worlds/console/StackedLayout.java new file mode 100644 index 0000000..2cbc840 --- /dev/null +++ b/NET/worlds/console/StackedLayout.java @@ -0,0 +1,69 @@ +package NET.worlds.console; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.LayoutManager; + +class StackedLayout implements LayoutManager { + public StackedLayout() { + } + + @Override + public void addLayoutComponent(String name, Component c) { + } + + @Override + public void removeLayoutComponent(Component c) { + } + + @Override + public Dimension preferredLayoutSize(Container target) { + Dimension size = new Dimension(0, 0); + int count = target.getComponentCount(); + + for (int i = 0; i < count; i++) { + Component m = target.getComponent(i); + Dimension d = m.getPreferredSize(); + size.width = Math.max(size.width, d.width); + size.height = size.height + d.height; + } + + Insets insets = target.getInsets(); + size.width = size.width + insets.left + insets.right; + size.height = size.height + insets.top + insets.bottom; + return size; + } + + @Override + public Dimension minimumLayoutSize(Container target) { + return this.preferredLayoutSize(target); + } + + @Override + public void layoutContainer(Container target) { + Insets insets = target.getInsets(); + Dimension size = target.getSize(); + int x = insets.left; + int y = insets.top; + int width = size.width - insets.left - insets.right; + int height = size.height - insets.top - insets.bottom; + int count = target.getComponentCount(); + + for (int i = 0; i < count; i++) { + Component c = target.getComponent(i); + 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); + c.setBounds(x, y, width, h); + height -= h; + y += h; + } + } +} |