001: /*
002: * ToolBarButton.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 javax.swing.Action;
025: import javax.swing.ImageIcon;
026:
027: import java.io.Serializable;
028:
029: import org.underworldlabs.swing.actions.ActionBuilder;
030: import org.underworldlabs.swing.util.IconUtilities;
031:
032: /* ----------------------------------------------------------
033: * CVS NOTE: Changes to the CVS repository prior to the
034: * release of version 3.0.0beta1 has meant a
035: * resetting of CVS revision numbers.
036: * ----------------------------------------------------------
037: */
038:
039: /**
040: *
041: * @author Takis Diakoumis
042: * @version $Revision: 1.6 $
043: * @date $Date: 2006/09/06 09:30:38 $
044: */
045: public class ToolBarButton implements Serializable, Cloneable {
046:
047: private int id;
048: private Action action;
049: private String actionId;
050: private ImageIcon icon;
051: private boolean visible;
052: private int order;
053:
054: /** Defines a tool bar separator */
055: public static final int SEPARATOR_ID = 29;
056:
057: public ToolBarButton(int id) {
058: this .id = id;
059: }
060:
061: public ToolBarButton(int id, String actionId) {
062: this .id = id;
063: this .actionId = actionId;
064: action = ActionBuilder.get(actionId);
065: }
066:
067: public void setActionId(String actionId) {
068: this .actionId = actionId;
069: action = ActionBuilder.get(actionId);
070: }
071:
072: public String getActionId() {
073: return actionId;
074: }
075:
076: public boolean isSeparator() {
077: return id == SEPARATOR_ID;
078: }
079:
080: public int getOrder() {
081: return order;
082: }
083:
084: public void setOrder(int order) {
085: this .order = order;
086: }
087:
088: public void setVisible(boolean visible) {
089: this .visible = visible;
090: }
091:
092: public void invertSelected() {
093: visible = !visible;
094: }
095:
096: public boolean isVisible() {
097: return visible;
098: }
099:
100: public ImageIcon getIcon() {
101: if (icon == null) {
102: if (id == SEPARATOR_ID) {
103: icon = IconUtilities.loadDefaultIconResource(
104: "Blank16.gif", true);
105: } else {
106: if (action != null) {
107: icon = (ImageIcon) action
108: .getValue(Action.SMALL_ICON);
109: }
110: }
111: }
112:
113: return icon;
114: }
115:
116: public String getName() {
117: if (id == SEPARATOR_ID) {
118: return "- Separator -";
119: } else {
120: return (String) action.getValue(Action.NAME);
121: }
122: }
123:
124: public void setId(int id) {
125: this .id = id;
126: }
127:
128: public int getId() {
129: return id;
130: }
131:
132: public String toString() {
133: return getName();
134: }
135:
136: public Object clone() {
137: try {
138: ToolBarButton button = (ToolBarButton) super .clone();
139: return button;
140: } catch (CloneNotSupportedException e) {
141: throw new InternalError();
142: }
143: }
144:
145: }
|