01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.util;
19:
20: import java.util.List;
21: import java.util.Vector;
22:
23: import javax.swing.Box;
24: import javax.swing.JToolBar;
25:
26: public class OptionalToolBar extends JToolBar {
27:
28: private List actionGroups = new Vector();
29:
30: private List actionBundles = new Vector();
31:
32: boolean hasGlue = false;
33:
34: public void addActionGroup(ActionGroup actionGroup) {
35: actionGroups.add(actionGroup.getName());
36: }
37:
38: public void addActionGroupName(String name) {
39: actionGroups.add(name);
40: }
41:
42: public boolean hasActionGroup(ActionGroup actionGroup) {
43: return actionGroups.contains(actionGroup.getName());
44: }
45:
46: public void addActionBundle(ActionBundle actionBundle) {
47: actionBundles.add(actionBundle.getName());
48: }
49:
50: public void addActionBundleName(String name) {
51: actionBundles.add(name);
52: }
53:
54: public boolean hasActionBundle(ActionBundle actionBundle) {
55: return actionBundles.contains(actionBundle.getName());
56: }
57:
58: public void removeAll() {
59: hasGlue = false;
60: super .removeAll();
61: }
62:
63: public void validate() {
64: if (!hasGlue) {
65: // This is a little ugly, but necessary to make the toolbar extend
66: // to the full width.
67: // This hack relies on the MenuAndToolbarComposer to always remove
68: // all icons before
69: // readding them.
70: add(Box.createHorizontalGlue());
71: // The strut is to prevent an ugly little blue line when the toolbar
72: // is empty.
73: // Instead, we get something that actually looks like an empty
74: // toolbar.
75: add(Box.createVerticalStrut(28));
76: hasGlue = true;
77: }
78: super.validate();
79: }
80: }
|