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: import java.io.*;
046:
047: public class ScrollLayout implements LayoutManager {
048: protected Component hs, vs, stubb, center;
049:
050: public ScrollLayout() {
051: super ();
052: }
053:
054: public void addLayoutComponent(String s, Component c) {
055: if (s != null) {
056: if (s.equals("East"))
057: vs = c;
058: else if (s.equals("South"))
059: hs = c;
060: else if (s.equals("Center"))
061: center = c;
062: else if (s.equals("Stubb")) {
063: stubb = c;
064: stubb.resize(0, 0);
065: stubb.setBackground(Color.lightGray);
066: return;
067: }
068: }
069: }
070:
071: protected Insets getInsets(Container c) {
072: return c.insets();
073: }
074:
075: public void removeLayoutComponent(Component c) {
076: if (c == vs)
077: vs = null;
078: if (c == hs)
079: hs = null;
080: if (center == c)
081: center = null;
082: if (stubb == c)
083: stubb = null;
084: }
085:
086: public Dimension minimumLayoutSize(Container target) {
087: return preferredLayoutSize(target);
088: }
089:
090: public Dimension preferredLayoutSize(Container target) {
091: Dimension dim = new Dimension(0, 0);
092:
093: boolean hb = (hs != null && hs.isVisible());
094: boolean vb = (vs != null && vs.isVisible());
095:
096: if (vb) {
097: Dimension d = vs.preferredSize();
098: dim.width += d.width;
099: dim.height = Math.max(d.height, dim.height);
100: }
101:
102: if ((center != null) && center.isVisible()) {
103: Dimension d = center.preferredSize();
104: dim.width += d.width;
105: dim.height = Math.max(d.height, dim.height);
106: }
107:
108: if (hb) {
109: Dimension d = hs.preferredSize();
110: dim.width = Math.max(d.width, dim.width);
111: dim.height += d.height;
112: }
113:
114: Insets insets = getInsets(target);
115: dim.width += insets.left + insets.right;
116: dim.height += insets.top + insets.bottom;
117: return dim;
118: }
119:
120: public void layoutContainer(Container parent) {
121: Insets insets = getInsets(parent);
122: Rectangle target = parent.bounds();
123:
124: int top = insets.top;
125: int bottom = target.height - insets.bottom;
126: int left = insets.left;
127: int right = target.width - insets.right;
128: int s = ScrollController.SCROLL_SIZE;
129:
130: boolean hb = (hs != null && hs.isVisible());
131: boolean vb = (vs != null && vs.isVisible());
132:
133: if (hb)
134: bottom -= s;
135: if (vb)
136: right -= s;
137:
138: if (hb)
139: hs.reshape(left, bottom, right, s);
140:
141: if (vb)
142: vs.reshape(right, top, s, bottom);
143:
144: if ((center != null) && center.isVisible())
145: layoutCenter(parent, left, top, right - left, bottom - top);
146:
147: if (hb && vb) {
148: if (stubb != null)
149: stubb.reshape(right, bottom, s, s);
150: } else {
151: if (stubb != null)
152: stubb.resize(0, 0);
153: }
154: }
155:
156: public Dimension getAreaSize(Component c) {
157: Rectangle b = c.bounds();
158: Dimension d = new Dimension(b.width, b.height);
159:
160: if (hs.isVisible()) {
161: Rectangle r = hs.bounds();
162: if ((b.y + b.height) < r.y)
163: d.height += r.height;
164: }
165:
166: if (vs.isVisible()) {
167: Rectangle r = vs.bounds();
168: if ((b.x + b.width) < r.x)
169: d.width += r.width;
170: }
171:
172: return d;
173: }
174:
175: protected void layoutCenter(Container cont, int x, int y, int w,
176: int h) {
177: center.reshape(x, y, w, h);
178: }
179: }
|