001: /*
002: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without modification,
005: * are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JETA Software nor the names of its contributors may
015: * be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
021: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
022: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
023: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
024: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
025: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: package com.jeta.forms.gui.form;
031:
032: import java.awt.Component;
033: import java.awt.Container;
034: import java.awt.Dimension;
035: import java.awt.Insets;
036: import java.awt.LayoutManager;
037:
038: /**
039: * This layout manager is used for JLayeredPanes. It simply makes all components
040: * in the container the width/height of the container. The top most components
041: * should not be opaque.
042: *
043: * @author Jeff Tassin
044: */
045: public class JETALayerLayout implements LayoutManager {
046: /**
047: * @param name
048: * @param comp
049: */
050: public void addLayoutComponent(String name, Component comp) {
051: }
052:
053: /**
054: * @param parent
055: */
056: public void layoutContainer(Container parent) {
057: Insets insets = parent.getInsets();
058: for (int index = 0; index < parent.getComponentCount(); index++) {
059: Component comp = parent.getComponent(index);
060: comp.setLocation(insets.left, insets.top);
061: comp.setSize(
062: parent.getWidth() - insets.left - insets.right,
063: parent.getHeight() - insets.top - insets.bottom);
064: }
065: }
066:
067: /**
068: * @param parent
069: * @return
070: */
071: public Dimension minimumLayoutSize(Container parent) {
072: Insets insets = parent.getInsets();
073: int min_width = 0;
074: int min_height = 0;
075: for (int index = 0; index < parent.getComponentCount(); index++) {
076: Component comp = parent.getComponent(index);
077: Dimension minsz = comp.getMinimumSize();
078: min_width = Math.max(minsz.width, min_width);
079: min_height = Math.max(minsz.height, min_height);
080: }
081: return new Dimension(min_width + insets.left + insets.right,
082: min_height + insets.top + insets.bottom);
083: }
084:
085: /**
086: * @param parent
087: * @return
088: */
089: public Dimension preferredLayoutSize(Container parent) {
090: Insets insets = parent.getInsets();
091: int width = 0;
092: int height = 0;
093: for (int index = 0; index < parent.getComponentCount(); index++) {
094: Component comp = parent.getComponent(index);
095: Dimension sz = comp.getPreferredSize();
096: width = Math.max(width, sz.width);
097: height = Math.max(height, sz.height);
098: }
099: return new Dimension(width + insets.left + insets.right, height
100: + insets.top + insets.bottom);
101: }
102:
103: /**
104: * @param comp
105: */
106: public void removeLayoutComponent(Component comp) {
107: }
108:
109: }
|