@@ -0,0 +1,2334 @@
+/*%0D%0A * Copyright (c) 2010 C%C3%A9lio Cidral Junior%0D%0A * %0D%0A *    Licensed under the Apache License, Version 2.0 (the %22License%22);%0D%0A *    you may not use this file except in compliance with the License.%0D%0A *    You may obtain a copy of the License at%0D%0A * %0D%0A *        http://www.apache.org/licenses/LICENSE-2.0%0D%0A * %0D%0A *    Unless required by applicable law or agreed to in writing, software%0D%0A *    distributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0A *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0A *    See the License for the specific language governing permissions and%0D%0A *    limitations under the License.%0D%0A */%0D%0A%0D%0Apackage org.tomighty.ui.layout;%0D%0A%0D%0Aimport java.awt.Component;%0D%0Aimport java.awt.Container;%0D%0Aimport java.awt.Dimension;%0D%0Aimport java.awt.Insets;%0D%0Aimport java.awt.LayoutManager;%0D%0A%0D%0Apublic class StackLayout implements LayoutManager %7B%0D%0A%09%0D%0A%09private int gap;%0D%0A%09%0D%0A%09public StackLayout() %7B%0D%0A%09%09this(0);%0D%0A%09%7D%0D%0A%09%0D%0A%09public StackLayout(int gap) %7B%0D%0A%09%09this.gap = gap;%0D%0A%09%7D%0D%0A%09%0D%0A%09@Override%0D%0A%09public void addLayoutComponent(String name, Component comp) %7B%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public void removeLayoutComponent(Component comp) %7B%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public Dimension preferredLayoutSize(Container parent) %7B%0D%0A%09%09int height = 0;%0D%0A%09%09int width = 0;%0D%0A%09%09Component%5B%5D components = parent.getComponents();%0D%0A%09%09for(int index = 0; index %3C components.length; index++) %7B%0D%0A%09%09%09Component child = components%5Bindex%5D;%0D%0A%09%09%09Dimension size = child.getPreferredSize();%0D%0A%09%09%09width = Math.max(width, size.width);%0D%0A%09%09%09height += size.height;%0D%0A%09%09%09if(index %3E 0) %7B%0D%0A%09%09%09%09height += gap;%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09Insets insets = parent.getInsets();%0D%0A%09%09width += insets.left + insets.right;%0D%0A%09%09height += insets.top + insets.bottom;%0D%0A%09%09return new Dimension(width, height);%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public Dimension minimumLayoutSize(Container parent) %7B%0D%0A%09%09return preferredLayoutSize(parent);%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public void layoutContainer(Container parent) %7B%0D%0A%09%09Insets insets = parent.getInsets();%0D%0A%09%09int x = insets.left;%0D%0A%09%09int y = insets.top;%0D%0A%09%09int width = parent.getWidth() - insets.left - insets.right;%0D%0A%09%09for(Component child : parent.getComponents()) %7B%0D%0A%09%09%09Dimension preferredSize = child.getPreferredSize();%0D%0A%09%09%09int height = preferredSize.height;%0D%0A%09%09%09child.setBounds(x, y, width, height);%0D%0A%09%09%09y += child.getPreferredSize().height + gap;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A

Create StackLayout that places components on top of each other