01: /*
02: * WbToolbar.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.awt.Container;
15: import javax.swing.Action;
16: import javax.swing.JButton;
17: import javax.swing.JToolBar;
18: import javax.swing.border.Border;
19: import javax.swing.border.CompoundBorder;
20: import javax.swing.border.CompoundBorder;
21: import javax.swing.border.EmptyBorder;
22: import javax.swing.border.EtchedBorder;
23: import workbench.gui.WbSwingUtilities;
24: import workbench.gui.actions.WbAction;
25:
26: /**
27: *
28: * @author support@sql-workbench.net
29: */
30: public class WbToolbar extends JToolBar {
31:
32: public WbToolbar() {
33: this .setFloatable(false);
34: this .setRollover(true);
35: this .setBorder(WbSwingUtilities.EMPTY_BORDER);
36: }
37:
38: public void addNotify() {
39: super .addNotify();
40: Container p = getParent();
41: if (p != null) {
42: this .setBackground(p.getBackground());
43: }
44: }
45:
46: public JButton add(Action a) {
47: JButton button;
48:
49: if (a instanceof WbAction) {
50: button = ((WbAction) a).getToolbarButton();
51: } else {
52: button = new WbToolbarButton(a);
53: }
54: this .add(button);
55: return button;
56: }
57:
58: public JButton add(WbAction a) {
59: return add(a, -1);
60: }
61:
62: public JButton add(WbAction a, int index) {
63: JButton button = a.getToolbarButton();
64: this .add(button, index);
65: return button;
66: }
67:
68: public void addSeparator() {
69: this .addSeparator(this .getComponentCount());
70: }
71:
72: public void addSeparator(int index) {
73: if (isRollover())
74: this .add(new WbToolbarSeparator(), index);
75: else
76: super .addSeparator();
77: }
78:
79: public void addDefaultBorder() {
80: Border b = new CompoundBorder(new EmptyBorder(1, 0, 1, 0),
81: new EtchedBorder());
82: this .setBorder(b);
83: this .setBorderPainted(true);
84: this .setRollover(true);
85: }
86: }
|