summaryrefslogtreecommitdiff
path: root/NET/worlds/console/StackedLayout.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/StackedLayout.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/StackedLayout.java')
-rw-r--r--NET/worlds/console/StackedLayout.java69
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;
+ }
+ }
+}