001: /**
002: * Caption: Zaval Java Resource Editor
003: * $Revision: 0.37 $
004: * $Date: 2002/03/28 9:24:42 $
005: *
006: * @author: Victor Krapivin
007: * @version: 1.3
008: *
009: * Zaval JRC Editor is a visual editor which allows you to manipulate
010: * localization strings for all Java based software with appropriate
011: * support embedded.
012: *
013: * For more info on this product read Zaval Java Resource Editor User's Guide
014: * (It comes within this package).
015: * The latest product version is always available from the product's homepage:
016: * http://www.zaval.org/products/jrc-editor/
017: * and from the SourceForge:
018: * http://sourceforge.net/projects/zaval0002/
019: *
020: * Contacts:
021: * Support : support@zaval.org
022: * Change Requests : change-request@zaval.org
023: * Feedback : feedback@zaval.org
024: * Other : info@zaval.org
025: *
026: * Copyright (C) 2001-2002 Zaval Creative Engineering Group (http://www.zaval.org)
027: *
028: * This program is free software; you can redistribute it and/or
029: * modify it under the terms of the GNU General Public License
030: * (version 2) as published by the Free Software Foundation.
031: *
032: * This program is distributed in the hope that it will be useful,
033: * but WITHOUT ANY WARRANTY; without even the implied warranty of
034: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
035: * GNU General Public License for more details.
036: *
037: * You should have received a copy of the GNU General Public License
038: * along with this program; if not, write to the Free Software
039: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
040: *
041: */package org.zaval.awt;
042:
043: import java.awt.*;
044: import java.util.*;
045:
046: public class FitLayout implements LayoutManager {
047: protected int gapX, gapY;
048: protected int gapW, gapH;
049:
050: public FitLayout() {
051: this (0, 0, 0, 0);
052: }
053:
054: public FitLayout(int gapX, int gapY, int gapW, int gapH) {
055: this .gapX = gapX;
056: this .gapY = gapY;
057: this .gapW = gapW;
058: this .gapH = gapH;
059: }
060:
061: public Point location(int xx, int yy) {
062: return new Point(0, 0);
063: }
064:
065: public void addLayoutComponent(String name, Component comp) {
066: }
067:
068: public void removeLayoutComponent(Component comp) {
069: }
070:
071: public Dimension preferredLayoutSize(Container parent) {
072: int i, wx = 0, wy = 0;
073: Component[] cc = parent.getComponents();
074: for (i = 0; i < cc.length; ++i) {
075: Dimension d2 = cc[i].preferredSize();
076: if (d2.width == 0 || d2.height == 0)
077: d2 = cc[i].size();
078: if (wx < d2.width)
079: wx = d2.width;
080: if (wy < d2.height)
081: wy = d2.height;
082: }
083: Insets is = parent.insets();
084: return new Dimension(wx + gapX + gapW/*+is.left+is.right*/, wy
085: + gapY + gapH/*+is.top+is.bottom*/);
086: }
087:
088: public Dimension minimumLayoutSize(Container parent) {
089: int i, wx = 0, wy = 0;
090: Component[] cc = parent.getComponents();
091: for (i = 0; i < cc.length; ++i) {
092: Dimension d2 = cc[i].minimumSize();
093: if (d2.width == 0 || d2.height == 0)
094: d2 = cc[i].size();
095: if (wx < d2.width)
096: wx = d2.width;
097: if (wy < d2.height)
098: wy = d2.height;
099: }
100: Insets is = parent.insets();
101: return new Dimension(wx + gapX + gapW/*+is.left+is.right*/, wy
102: + gapY + gapH/*+is.top+is.bottom*/);
103: }
104:
105: public void layoutContainer(Container parent) {
106: int i = 0, j = -1;
107: Rectangle r = parent.bounds();
108: Component[] c = parent.getComponents();
109: int gx = gapX, gy = gapY, gw = gapW, gh = gapH;
110:
111: Insets is = parent.insets();
112: for (i = 0; i < c.length; ++i) {
113: if (gapX == -1) {
114: Dimension v = c[i].preferredSize();
115: if (v.width > r.width)
116: v.width = r.width;
117: if (v.height > r.height)
118: v.height = r.height;
119: gx = gw = (r.width - v.width) / 2;
120: gy = gh = (r.height - v.height) / 2;
121: }
122:
123: c[i].move(gx + is.left, gy/* + is.top*/);
124: c[i].resize(r.width - gx - gw /*- is.right - is.left*/,
125: r.height - gy - gh /*- is.bottom- is.top*/);
126: if (c[i].isVisible())
127: if (j >= 0)
128: c[i].hide();
129: else
130: j = i;
131: }
132: }
133: }
|