01: /*
02: * Swing Explorer. Tool for developers exploring Java/Swing-based application internals.
03: * Copyright (C) 2008, Maxim Zakharenkov
04: *
05: * This program is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU General Public License as published by
07: * the Free Software Foundation; either version 2 of the License, or
08: * (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License along
16: * with this program; if not, write to the Free Software Foundation, Inc.,
17: * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18: *
19: * $Header: /cvs/swingexplorer/src/org/swingexplorer/RichToolbar.java,v 1.2 2008/02/06 08:36:09 maxz1 Exp $
20: */
21: package org.swingexplorer;
22:
23: import java.beans.PropertyChangeListener;
24:
25: import javax.swing.AbstractButton;
26: import javax.swing.Action;
27: import javax.swing.Icon;
28: import javax.swing.JButton;
29: import javax.swing.JToolBar;
30:
31: /**
32: *
33: * @author Maxim Zakharenkov
34: */
35: public class RichToolbar extends JToolBar {
36:
37: public AbstractButton addActionEx(Action a) {
38: String text = a != null ? (String) a.getValue(Action.NAME)
39: : null;
40: Icon icon = a != null ? (Icon) a.getValue(Action.SMALL_ICON)
41: : null;
42: boolean enabled = a != null ? a.isEnabled() : true;
43: String tooltip = a != null ? (String) a
44: .getValue(Action.SHORT_DESCRIPTION) : null;
45:
46: AbstractButton b;
47:
48: if (a instanceof RichToggleAction) {
49: b = new RichToggleButton((RichToggleAction) a);
50: b.setText("");
51: } else {
52: b = new JButton(text, icon) {
53: protected PropertyChangeListener createActionPropertyChangeListener(
54: Action a) {
55: PropertyChangeListener pcl = createActionChangeListener(this );
56: if (pcl == null) {
57: pcl = super
58: .createActionPropertyChangeListener(a);
59: }
60: return pcl;
61: }
62: };
63: }
64:
65: if (icon != null) {
66: b.putClientProperty("hideActionText", Boolean.TRUE);
67: }
68: b.setHorizontalTextPosition(JButton.CENTER);
69: b.setVerticalTextPosition(JButton.BOTTOM);
70: b.setEnabled(enabled);
71: b.setToolTipText(tooltip);
72:
73: b.setAction(a);
74: add(b);
75: return null;
76: }
77: }
78:
79: /*
80: * $Log: RichToolbar.java,v $
81: * Revision 1.2 2008/02/06 08:36:09 maxz1
82: * Changed license header
83: *
84: * Revision 1.1 2007/06/27 19:41:38 maxz1
85: * new
86: *
87: */
|