001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.swing;
018:
019: import java.awt.Component;
020: import java.awt.Container;
021: import java.awt.Dimension;
022: import java.awt.Insets;
023: import java.awt.LayoutManager;
024:
025: /**
026: * ButtonAreaLayout. <br>
027: *
028: */
029: public final class ButtonAreaLayout implements LayoutManager {
030:
031: private int gap;
032:
033: public ButtonAreaLayout(int gap) {
034: this .gap = gap;
035: }
036:
037: public void addLayoutComponent(String string, Component comp) {
038: }
039:
040: public void layoutContainer(Container container) {
041: Insets insets = container.getInsets();
042: Component[] children = container.getComponents();
043:
044: // calculate the max width
045: int maxWidth = 0;
046: int maxHeight = 0;
047: int visibleCount = 0;
048: Dimension componentPreferredSize;
049:
050: for (int i = 0, c = children.length; i < c; i++) {
051: if (children[i].isVisible()) {
052: componentPreferredSize = children[i].getPreferredSize();
053: maxWidth = Math.max(maxWidth,
054: componentPreferredSize.width);
055: maxHeight = Math.max(maxHeight,
056: componentPreferredSize.height);
057: visibleCount++;
058: }
059: }
060:
061: int usedWidth = maxWidth * visibleCount + gap
062: * (visibleCount - 1);
063:
064: visibleCount = 0;
065: for (int i = 0, c = children.length; i < c; i++) {
066: if (children[i].isVisible()) {
067: children[i]
068: .setBounds(container.getWidth() - insets.right
069: - usedWidth + (maxWidth + gap)
070: * visibleCount, insets.top, maxWidth,
071: maxHeight);
072: visibleCount++;
073: }
074: }
075: }
076:
077: public Dimension minimumLayoutSize(Container c) {
078: return preferredLayoutSize(c);
079: }
080:
081: public Dimension preferredLayoutSize(Container container) {
082: Insets insets = container.getInsets();
083: Component[] children = container.getComponents();
084:
085: // calculate the max width
086: int maxWidth = 0;
087: int maxHeight = 0;
088: int visibleCount = 0;
089: Dimension componentPreferredSize;
090:
091: for (int i = 0, c = children.length; i < c; i++) {
092: if (children[i].isVisible()) {
093: componentPreferredSize = children[i].getPreferredSize();
094: maxWidth = Math.max(maxWidth,
095: componentPreferredSize.width);
096: maxHeight = Math.max(maxHeight,
097: componentPreferredSize.height);
098: visibleCount++;
099: }
100: }
101:
102: int usedWidth = maxWidth * visibleCount + gap
103: * (visibleCount - 1);
104:
105: return new Dimension(insets.left + usedWidth + insets.right,
106: insets.top + maxHeight + insets.bottom);
107: }
108:
109: public void removeLayoutComponent(Component c) {
110: }
111: }
|