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.util.*;
044: import java.awt.*;
045:
046: public class StatusBarPanel extends Panel implements LayoutManager {
047: private Vector elements = new Vector();
048:
049: public StatusBarPanel() {
050: setLayout(this );
051: }
052:
053: public void addStatusBarComponent(Component c, int p) {
054: StatusBarElement e = new StatusBarElement(c, p);
055: elements.addElement(e);
056: add(e);
057: }
058:
059: public void addLayoutComponent(String name, Component comp) {
060: }
061:
062: public void layoutContainer(Container parent) {
063: Dimension pd = preferredLayoutSize(parent);
064: Dimension d = parent.size();
065: int size = elements.size();
066: int width = d.width;
067: if (size > 1)
068: d.width -= (2 * (size - 1));
069:
070: int x = 0;
071: for (int i = 0; i < size; i++) {
072: StatusBarElement c = (StatusBarElement) elements
073: .elementAt(i);
074: Dimension ps = c.preferredSize();
075: if (i > 0)
076: x += 2;
077: int perc = c.getPercent();
078:
079: if (i == (size - 1))
080: ps.width = width - x;
081: else if (perc > 0)
082: ps.width = (d.width * perc) / 100;
083:
084: c.move(x, d.height - pd.height);
085: c.resize(ps.width, pd.height);
086: x += ps.width;
087: }
088: }
089:
090: public Dimension minimumLayoutSize(Container parent) {
091: return preferredLayoutSize(parent);
092: }
093:
094: public Dimension preferredLayoutSize(Container parent) {
095: Dimension d = new Dimension(0, 0);
096: Dimension pd = parent.size();
097: int size = elements.size();
098: if (size > 1)
099: pd.width -= (2 * (size - 1));
100:
101: for (int i = 0; i < size; i++) {
102: StatusBarElement c = (StatusBarElement) elements
103: .elementAt(i);
104: Dimension d1 = c.preferredSize();
105: int perc = c.getPercent();
106: if (perc > 0)
107: d1.width = (pd.width * perc) / 100;
108: d.width += d1.width;
109: if (d1.height > d.height)
110: d.height = d1.height;
111: }
112: return d;
113: }
114:
115: public void removeLayoutComponent(Component comp) {
116: }
117: }
|