001: /*
002: * ToolBarWrapper.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.toolbar;
023:
024: import java.util.Vector;
025:
026: /* ----------------------------------------------------------
027: * CVS NOTE: Changes to the CVS repository prior to the
028: * release of version 3.0.0beta1 has meant a
029: * resetting of CVS revision numbers.
030: * ----------------------------------------------------------
031: */
032:
033: /** <p>Wrapper class defining a tool bar, its buttons
034: * and its row and position within the tool bar area.
035: *
036: * @author Takis Diakoumis
037: * @version $Revision: 1.4 $
038: * @date $Date: 2006/05/14 06:56:07 $
039: */
040: public class ToolBarWrapper implements Cloneable {
041:
042: /** This tool bar's name */
043: private String name;
044:
045: /** Whether the tool bar is visible */
046: private boolean visible;
047:
048: /** This tool bar's buttons */
049: private Vector buttons;
050:
051: /** The tool bar's constraints */
052: private ToolBarConstraints constraints;
053:
054: public ToolBarWrapper() {
055: }
056:
057: public ToolBarWrapper(String name, boolean visible) {
058: this .name = name;
059: this .visible = visible;
060: }
061:
062: public ToolBarConstraints getConstraints() {
063: return constraints;
064: }
065:
066: public void setConstraints(ToolBarConstraints constraints) {
067: this .constraints = constraints;
068: }
069:
070: public boolean isVisible() {
071: return visible;
072: }
073:
074: public void addButton(ToolBarButton button) {
075: if (buttons == null) {
076: buttons = new Vector();
077: }
078: buttons.add(button);
079: }
080:
081: public void resetButtons(Vector _buttons) {
082: int size = _buttons.size();
083:
084: if (buttons != null) {
085: buttons.clear();
086: } else {
087: buttons = new Vector(size);
088: }
089:
090: for (int i = 0; i < size; i++) {
091: buttons
092: .add(((ToolBarButton) _buttons.elementAt(i))
093: .clone());
094: }
095:
096: }
097:
098: private int getVisibleButtonsCount(Vector _buttons) {
099: int count = 0;
100: ToolBarButton button = null;
101:
102: for (int i = 0, k = _buttons.size(); i < k; i++) {
103: button = (ToolBarButton) _buttons.elementAt(i);
104: if (button.isVisible()) {
105: count++;
106: }
107: }
108:
109: return count;
110: }
111:
112: public void setButtonsVector(Vector _buttons) {
113: constraints.setMinimumWidth(-1);
114: buttons = _buttons;
115: }
116:
117: public int getButtonCount() {
118: return buttons.size();
119: }
120:
121: public void setVisible(boolean _visible) {
122:
123: if (visible == _visible) {
124: return;
125: }
126: visible = _visible;
127:
128: if (visible) {
129: constraints.setRow(ToolBarProperties.getNextToolbarRow());
130: constraints.setPosition(0);
131: } else {
132: constraints.reset();
133: }
134:
135: }
136:
137: public void resetButtons() {
138: if (buttons != null && buttons.size() > 0) {
139: buttons.clear();
140: }
141: }
142:
143: public boolean hasButtons() {
144: return buttons != null && buttons.size() > 0;
145: }
146:
147: public Vector getButtonsVector() {
148: return buttons;
149: }
150:
151: public ToolBarButton[] getButtonsArray() {
152: if (buttons != null && buttons.size() > 0) {
153: return (ToolBarButton[]) buttons
154: .toArray(new ToolBarButton[] {});
155: } else {
156: return null;
157: }
158: }
159:
160: public void setName(String name) {
161: this .name = name;
162: }
163:
164: public String getName() {
165: return name;
166: }
167:
168: public Object clone() {
169: ToolBarWrapper tb = new ToolBarWrapper(name, visible);
170: tb.setConstraints((ToolBarConstraints) constraints.clone());
171:
172: if (buttons != null) {
173: tb.resetButtons((Vector) buttons.clone());
174: }
175: return tb;
176: }
177:
178: public String toString() {
179: return name;
180: }
181:
182: }
|