001: /*
002: * ActionUtilities.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.actions;
023:
024: import java.awt.Insets;
025: import java.awt.event.ActionListener;
026: import java.util.Vector;
027: import javax.swing.Icon;
028: import javax.swing.JButton;
029: import javax.swing.JCheckBox;
030: import javax.swing.JComboBox;
031: import org.underworldlabs.swing.util.IconUtilities;
032:
033: /* ----------------------------------------------------------
034: * CVS NOTE: Changes to the CVS repository prior to the
035: * release of version 3.0.0beta1 has meant a
036: * resetting of CVS revision numbers.
037: * ----------------------------------------------------------
038: */
039:
040: /**
041: *
042: * @author Takis Diakoumis
043: * @version $Revision: 1.4 $
044: * @date $Date: 2006/05/14 06:56:07 $
045: */
046: public class ActionUtilities {
047:
048: private ActionUtilities() {
049: }
050:
051: public static JButton createButton(ActionListener actionListener,
052: Icon icon, String name, String command) {
053: JButton item = new JButton(name);
054: item.setActionCommand(command);
055:
056: if (icon != null) {
057: item.setIcon(icon);
058: }
059:
060: if (actionListener != null) {
061: item.addActionListener(actionListener);
062: }
063:
064: return item;
065: }
066:
067: public static JButton createButton(ActionListener actionListener,
068: String command, Icon icon, String toolTipText) {
069: JButton item = new JButton(icon);
070: item.setMargin(new Insets(1, 1, 1, 1));
071:
072: item.setToolTipText(toolTipText);
073: item.setActionCommand(command);
074:
075: if (actionListener != null) {
076: item.addActionListener(actionListener);
077: }
078:
079: return item;
080: }
081:
082: public static JButton createButton(ActionListener actionListener,
083: String icon, String toolTipText, String command) {
084:
085: JButton item = new JButton();
086: if (icon != null) {
087: item.setIcon(IconUtilities.loadIcon(icon));
088: item.setMargin(new Insets(1, 1, 1, 1));
089: }
090:
091: item.setToolTipText(toolTipText);
092: item.setActionCommand(command);
093:
094: if (actionListener != null) {
095: item.addActionListener(actionListener);
096: }
097:
098: return item;
099: }
100:
101: public static JButton createButton(String name, String icon,
102: String command, boolean iconOnly) {
103: JButton item = new JButton(name);
104: item.setToolTipText(name);
105: item.setActionCommand(command);
106:
107: if (icon != null) {
108: item.setIcon(IconUtilities.loadIcon(icon));
109: }
110:
111: if (iconOnly) {
112: item.setMargin(new Insets(1, 1, 1, 1));
113: item.setText(null);
114: }
115: return item;
116: }
117:
118: public static JButton createButton(ActionListener actionListener,
119: String name, String command) {
120: JButton item = new JButton(name);
121: item.setActionCommand(command);
122: item.addActionListener(actionListener);
123: return item;
124: }
125:
126: public static JButton createButton(String name, String command) {
127: JButton item = new JButton(name);
128: item.setActionCommand(command);
129: return item;
130: }
131:
132: public static JCheckBox createCheckBox(
133: ActionListener actionListener, String name, String command,
134: boolean selected) {
135: JCheckBox item = new JCheckBox(name, selected);
136: item.setActionCommand(command);
137:
138: if (actionListener != null) {
139: item.addActionListener(actionListener);
140: }
141:
142: return item;
143: }
144:
145: public static JCheckBox createCheckBox(
146: ActionListener actionListener, String name, String command) {
147: return createCheckBox(actionListener, name, command, false);
148: }
149:
150: public static JCheckBox createCheckBox(String name, String command,
151: boolean selected) {
152: return createCheckBox(null, name, command, selected);
153: }
154:
155: public static JCheckBox createCheckBox(String name, String command) {
156: return createCheckBox(null, name, command, false);
157: }
158:
159: public static JComboBox createComboBox(
160: ActionListener actionListener, String[] values,
161: String command) {
162: JComboBox combo = new JComboBox(values);
163: combo.setActionCommand(command);
164:
165: if (actionListener != null) {
166: combo.addActionListener(actionListener);
167: }
168:
169: return combo;
170: }
171:
172: public static JComboBox createComboBox(String[] values,
173: String command) {
174: return createComboBox(null, values, command);
175: }
176:
177: public static JComboBox createComboBox(
178: ActionListener actionListener, Vector values, String command) {
179: JComboBox combo = new JComboBox(values);
180: combo.setActionCommand(command);
181:
182: if (actionListener != null) {
183: combo.addActionListener(actionListener);
184: }
185:
186: return combo;
187: }
188:
189: public static JComboBox createComboBox(Vector values, String command) {
190: return createComboBox(null, values, command);
191: }
192:
193: }
|