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 ResizeLayout implements LayoutManager {
047: private int fix = -1;
048:
049: public ResizeLayout() {
050: }
051:
052: public Point location(int xx, int yy) {
053: return new Point(xx < fix ? 0 : 2, 0);
054: }
055:
056: public void setSeparator(int sef, Container parent) {
057: fix = sef;
058: layoutAll(parent);
059: }
060:
061: private void layoutAll(Container c) {
062: int i;
063: LayoutManager l = c.getLayout();
064: if (l != null)
065: l.layoutContainer(c);
066: Component[] o = c.getComponents();
067: c.repaint();
068:
069: for (i = 0; i < o.length; ++i)
070: if (o[i] instanceof Container)
071: layoutAll((Container) o[i]);
072: }
073:
074: // -----------------------------------
075:
076: public void addLayoutComponent(String name, Component comp) {
077: }
078:
079: public void removeLayoutComponent(Component comp) {
080: }
081:
082: public Dimension preferredLayoutSize(Container parent) {
083: int i;
084: Panel left = null, right = null;
085: Component[] obj = parent.getComponents();
086: for (i = 0; i < obj.length; ++i) {
087: if (obj[i] instanceof Panel) {
088: if (left == null)
089: left = (Panel) obj[i];
090: else if (right == null)
091: right = (Panel) obj[i];
092: else
093: break;
094: }
095: }
096:
097: Dimension d1 = left.preferredSize();
098: if (fix != -1)
099: d1.width = fix;
100: Dimension d2 = right.preferredSize();
101: return new Dimension(d1.width + d2.width + 5, Math.max(
102: d1.height, d2.height));
103: }
104:
105: public Dimension minimumLayoutSize(Container parent) {
106: int i;
107: Panel left = null, right = null;
108: Component[] obj = parent.getComponents();
109: for (i = 0; i < obj.length; ++i) {
110: if (obj[i] instanceof Panel) {
111: if (left == null)
112: left = (Panel) obj[i];
113: else if (right == null)
114: right = (Panel) obj[i];
115: else
116: break;
117: }
118: }
119:
120: Dimension d1 = left.minimumSize();
121: if (fix != -1)
122: d1.width = fix;
123: Dimension d2 = right.minimumSize();
124: return new Dimension(d1.width + d2.width + 5, Math.max(
125: d1.height, d2.height));
126: }
127:
128: public void layoutContainer(Container parent) {
129: int i;
130: Panel left = null, right = null;
131: Component rl = null;
132: Component[] obj = parent.getComponents();
133: for (i = 0; i < obj.length; ++i) {
134: if (obj[i] instanceof Panel) {
135: if (left == null)
136: left = (Panel) obj[i];
137: else if (right == null)
138: right = (Panel) obj[i];
139: else
140: break;
141: } else if (rl == null)
142: rl = obj[i];
143: }
144:
145: Rectangle r = parent.bounds();
146: int wx1 = fix == -1 ? left.preferredSize().width : fix;
147: int wx2 = r.width - wx1 - 15;
148: left.reshape(5, 5, wx1, r.height - 10);
149: right.reshape(10 + wx1, 5, wx2, r.height - 10);
150: rl.reshape(5 + wx1, 5, 5, r.height - 10);
151: }
152: }
|