01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: StretchLayout.java,v 1.7 2005/02/16 11:28:12 jesper Exp $
23: package net.infonode.gui.layout;
24:
25: import java.awt.*;
26:
27: public class StretchLayout implements LayoutManager {
28: public static final StretchLayout BOTH = new StretchLayout();
29:
30: private boolean horizontal;
31: private boolean vertical;
32:
33: public StretchLayout() {
34: this (true, true);
35: }
36:
37: public StretchLayout(boolean horizontal, boolean vertical) {
38: this .horizontal = horizontal;
39: this .vertical = vertical;
40: }
41:
42: public void addLayoutComponent(String name, Component comp) {
43: }
44:
45: public void layoutContainer(Container parent) {
46: Dimension innerSize = LayoutUtil.getInteriorSize(parent);
47: Insets insets = parent.getInsets();
48: Component[] components = LayoutUtil.getVisibleChildren(parent);
49:
50: for (int i = 0; i < components.length; i++) {
51: Dimension size = new Dimension(horizontal ? innerSize.width
52: : components[i].getPreferredSize().width,
53: vertical ? innerSize.height : components[i]
54: .getPreferredSize().height);
55: components[i]
56: .setBounds(
57: (int) (insets.left + (innerSize.width - size.width)
58: * components[i].getAlignmentX()),
59: (int) (insets.top + (innerSize.height - size.height)
60: * components[i].getAlignmentY()),
61: size.width, size.height);
62: }
63: }
64:
65: public Dimension minimumLayoutSize(Container parent) {
66: return LayoutUtil.add(LayoutUtil.getMaxMinimumSize(LayoutUtil
67: .getVisibleChildren(parent)), parent.getInsets());
68: }
69:
70: public Dimension preferredLayoutSize(Container parent) {
71: return LayoutUtil.add(LayoutUtil.getMaxPreferredSize(LayoutUtil
72: .getVisibleChildren(parent)), parent.getInsets());
73: }
74:
75: public void removeLayoutComponent(Component comp) {
76: }
77: }
|