Gridarta Editor
StackLayout.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /* Downloaded 02 nov 2004 from
21  * http://www.softbear.com/java/mktview/StackLayout.java
22  */
23 
24 package net.sf.gridarta.gui.dialog.plugin;
25 
26 import java.awt.Component;
27 import java.awt.Container;
28 import java.awt.Dimension;
29 import java.awt.Insets;
30 import java.awt.LayoutManager;
31 
37 public class StackLayout implements LayoutManager {
38 
42  private final int vGap;
43 
48  public StackLayout(final int vGap) {
49  this.vGap = vGap;
50  }
51 
52  @Override
53  public void addLayoutComponent(final String name, final Component comp) {
54  }
55 
56  @Override
57  public Dimension preferredLayoutSize(final Container parent) {
58  final Insets insets = parent.getInsets();
59  final int componentCount = parent.getComponentCount();
60  int w = 0;
61  int h = 0;
62 
63  for (int i = 0; i < componentCount; i++) {
64  final Component comp = parent.getComponent(i);
65  final Dimension d = comp.getPreferredSize();
66  if (w < d.width) {
67  w = d.width;
68  }
69  h += d.height;
70  if (i != 0) {
71  h += vGap;
72  }
73  }
74  return new Dimension(insets.left + insets.right + w, insets.top + insets.bottom + h);
75  }
76 
77  @Override
78  public void layoutContainer(final Container parent) {
79  final Insets insets = parent.getInsets();
80  final int x = insets.left;
81  int y = insets.top;
82  final int w = preferredLayoutSize(parent).width;
83 
84  final int componentCount = parent.getComponentCount();
85  for (int i = 0; i < componentCount; ++i) {
86  final Component comp = parent.getComponent(i);
87  final Dimension d = comp.getPreferredSize();
88  comp.setBounds(x, y, w, d.height);
89  y += d.height + vGap;
90  }
91  }
92 
93  @Override
94  public Dimension minimumLayoutSize(final Container parent) {
95  return preferredLayoutSize(parent);
96  }
97 
98  @Override
99  public void removeLayoutComponent(final Component comp) {
100  }
101 
102 }
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.gui.dialog.plugin.StackLayout.vGap
final int vGap
The vertical gap between components in pixels.
Definition: StackLayout.java:42
net.sf.gridarta.gui.dialog.plugin.StackLayout.removeLayoutComponent
void removeLayoutComponent(final Component comp)
Definition: StackLayout.java:99
net.sf.gridarta.gui.dialog.plugin.StackLayout.StackLayout
StackLayout(final int vGap)
Creates a new instance.
Definition: StackLayout.java:48
net.sf.gridarta.gui.dialog.plugin.StackLayout.preferredLayoutSize
Dimension preferredLayoutSize(final Container parent)
Definition: StackLayout.java:57
net.sf.gridarta.gui.dialog.plugin.StackLayout.minimumLayoutSize
Dimension minimumLayoutSize(final Container parent)
Definition: StackLayout.java:94
net.sf.gridarta.gui.dialog.plugin.StackLayout
A layoutManager which stacks components one on top of the other, regardless of their size.
Definition: StackLayout.java:37
net.sf.gridarta.gui.dialog.plugin.StackLayout.layoutContainer
void layoutContainer(final Container parent)
Definition: StackLayout.java:78
net.sf.gridarta.gui.dialog.plugin.StackLayout.addLayoutComponent
void addLayoutComponent(final String name, final Component comp)
Definition: StackLayout.java:53