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 Toolbar extends Panel implements LayoutManager {
047: private Vector v = new Vector();
048:
049: public Toolbar() {
050: super ();
051: setLayout(this );
052: }
053:
054: public void add(int id, Component button) {
055: add(button);
056: while (v.size() <= id)
057: v.addElement("");
058: v.setElementAt(button, id);
059: }
060:
061: public boolean action(Event e, Object o) {
062: if (e.target instanceof SpeedButton) {
063: int id = v.indexOf(e.target);
064: getParent().postEvent(
065: new Event(this , e.ACTION_EVENT, Integer
066: .toString(id)));
067: return true;
068: }
069: return false;
070: }
071:
072: public Point location(int xx, int yy) {
073: return new Point(0, 0);
074: }
075:
076: public void addLayoutComponent(String name, Component comp) {
077: }
078:
079: public void removeLayoutComponent(Component comp) {
080: }
081:
082: public Dimension minimumLayoutSize(Container parent) {
083: return preferredLayoutSize(parent);
084: }
085:
086: public Dimension preferredLayoutSize(Container parent) {
087: int maxx = 0, maxy = 0, j;
088: Component[] v = getComponents();
089: for (j = 0; j < v.length; ++j) {
090: Component c = v[j];
091: Dimension d = c.preferredSize();
092: maxx += /* 1 + */d.width;
093: maxy = Math.max(maxy, d.height);
094: }
095: return new Dimension(maxx/*-1*/, maxy);
096: }
097:
098: public void layoutContainer(Container parent) {
099: int x, y, w, h, j;
100: Dimension real = parent.size();
101: Dimension want = preferredLayoutSize(parent);
102: Insets p_i = parent.insets();
103:
104: if (real.width == 0 || real.height == 0)
105: return;
106: // double cfx = (double)real.width/(double)want.width;
107:
108: x = p_i.left;
109: y = p_i.top;
110:
111: Component[] v = getComponents();
112: for (j = 0; j < v.length; ++j) {
113: Component c = v[j];
114: Dimension d = c.preferredSize();
115: w = d.width; //(int)((double)d.width * cfx);
116: h = real.height;
117:
118: c.resize(w, h);
119: c.move(x + p_i.left, y + p_i.top);
120: x += w /* + 1 */;
121: }
122: }
123:
124: public void setObjectsSize(Dimension d) {
125: int j;
126: for (j = 0; j < v.size(); ++j) {
127: Component c = (Component) v.elementAt(j);
128: if (c instanceof SpeedButton) {
129: SpeedButton cc = (SpeedButton) c;
130: cc.setImageSize(d);
131: }
132: }
133: }
134:
135: public int count() {
136: return v.size();
137: }
138:
139: public void setEnabled(int j, boolean state) {
140: Component c = (Component) v.elementAt(j);
141: if (state)
142: c.enable();
143: else
144: c.disable();
145: }
146: }
|