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 StatusBar extends Panel implements LayoutManager {
047: public static final int FULL = 1;
048:
049: private Insets insets = new Insets(2, 1, 0, -1);
050: private int hgap = 2;
051: private int fill = 0;
052:
053: public StatusBar() {
054: setLayout(this );
055: }
056:
057: public int getFill() {
058: return fill;
059: }
060:
061: public void setFill(int f) {
062: if (fill == f)
063: return;
064: fill = f;
065: invalidate();
066: }
067:
068: public void addLayoutComponent(String name, Component comp) {
069: }
070:
071: public void layoutContainer(Container parent) {
072: Dimension ds = parent.size();
073: Component[] cc = parent.getComponents();
074: int height = getActualHeight(parent);
075: int[] widths = getActualWidths(parent);
076:
077: int x = insets.left;
078: int y = insets.top;
079: for (int j = 0; j < cc.length; ++j) {
080: cc[j].move(x, y);
081: cc[j].resize(widths[j], height);
082: x += (widths[j] + hgap);
083: }
084: }
085:
086: public Dimension minimumLayoutSize(Container parent) {
087: return preferredLayoutSize(parent);
088: }
089:
090: public Dimension preferredLayoutSize(Container parent) {
091: int[] widths = getActualWidths(parent);
092: int height = getActualHeight(parent) + insets.top
093: + insets.bottom;
094: int width = insets.left + insets.right + hgap
095: * (widths.length - 1);
096: for (int i = 0; i < widths.length; i++)
097: width += widths[i];
098: return new Dimension(width, height);
099: }
100:
101: public void removeLayoutComponent(Component comp) {
102: }
103:
104: protected int getActualHeight(Container parent) {
105: Component[] cc = parent.getComponents();
106: int ah = 0;
107: for (int j = 0; j < cc.length; ++j) {
108: Dimension d = cc[j].preferredSize();
109: if (ah < d.height)
110: ah = d.height;
111: }
112: return ah;
113: }
114:
115: protected int[] getActualWidths(Container parent) {
116: Dimension ds = parent.size();
117: Component[] cc = parent.getComponents();
118: int aw = 0, j = 0;
119: int[] widths = new int[cc.length];
120: int xx = insets.left + hgap * (cc.length - 1);
121:
122: ds.width -= (insets.left + insets.right + hgap
123: * (cc.length - 1));
124: ds.height -= (insets.top + insets.bottom);
125:
126: for (j = 0; j < cc.length; ++j) {
127: Dimension d = cc[j].preferredSize();
128:
129: if (!(cc[j] instanceof StatusBarElement)) {
130: widths[j] = d.width;
131: aw += d.width;
132: continue;
133: }
134:
135: if (cc[j] instanceof StatusBarElement) {
136: StatusBarElement e = (StatusBarElement) cc[j];
137: if (e.getPercent() == 0) {
138: aw += d.width;
139: widths[j] = d.width;
140: }
141: }
142: }
143:
144: ds.width -= aw;
145: for (j = 0; j < cc.length; ++j) {
146: xx += widths[j];
147: if (cc[j] instanceof StatusBarElement) {
148: StatusBarElement e = (StatusBarElement) cc[j];
149: int perc = e.getPercent();
150: if (perc == 0)
151: continue;
152: widths[j] = (ds.width * perc) / 100;
153: }
154: }
155:
156: if (getFill() == FULL) {
157: xx -= widths[cc.length - 1];
158: widths[cc.length - 1] = ds.width - xx - insets.right;
159: }
160: return widths;
161: }
162: }
|