1 /*
2 * $HeadURL: https://mindtreeinsight.svn.sourceforge.net/svnroot/mindtreeinsight/insight/insight-ui/trunk/src/main/java/com/mindtree/techworks/insight/gui/widgets/InsightToolbarButton.java $
3 * $Date: 2007-12-16 05:20:57 -0700 (Sun, 16 Dec 2007) $
4 * $Revision: 30 $
5 * $Author: bindul $
6 *
7 * Copyright (c) 2005 MindTree Consulting Ltd.
8 *
9 * This file is part of Insight.
10 *
11 * Insight is free software: you can redistribute it and/or modify it under the
12 * terms of the GNU General Public License as published by the Free Software
13 * Foundation, either version 3 of the License, or (at your option) any later
14 * version.
15 *
16 * Insight is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * Insight. If not, see <http://www.gnu.org/licenses/>.
23 */
24 package com.mindtree.techworks.insight.gui.widgets;
25
26 import java.awt.event.ActionListener;
27 import java.net.URL;
28
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31
32 import com.mindtree.techworks.insight.Controller;
33 import com.mindtree.techworks.insight.gui.action.IAction;
34
35 /**
36 *
37 * The <code>InsightToolbarButton</code> class represents all toolbar
38 * button instances in Insight. It contains specific behavior for enabling
39 * and disabling, registering with the Controller for data related
40 * call-back.
41 *
42 * @see com.mindtree.techworks.insight.Controller
43 * @see com.mindtree.techworks.insight.gui.action.IAction
44 * @see com.mindtree.techworks.insight.gui.Presentation
45 *
46 * @author Regunath B
47 * @version 1.0, 05/03/11
48 */
49
50 public class InsightToolbarButton extends JButton implements IAction {
51
52 /**
53 * Used for object serialization
54 */
55 private static final long serialVersionUID = 1L;
56
57 /**
58 * The type of this IAction
59 */
60 private int type;
61
62 /**
63 * The Controller instance for this IAction
64 */
65 private Controller controller;
66
67 /**
68 * Constructor for this class
69 * @param type the valid type of this InsightToolbarButton as defined in IAction
70 * @param name null or the name of the button
71 * @param imageName relative file path to the image for the JButton
72 * @param toolTip tooltip text for the JButton
73 * @param actionListener ActionListener instance that processes ActionEvent generated on this JButton
74 * @see IAction
75 */
76 public InsightToolbarButton (int type, String name, String imageName,
77 String toolTip, ActionListener actionListener) {
78 this.type = type;
79 if (name != null) {
80 this.setName(name);
81 }
82 this.setIcon(new ImageIcon(imageName));
83 this.setToolTipText(toolTip);
84 this.addActionListener(actionListener);
85 }
86
87 /**
88 * Constructor for this class
89 * @param type the valid type of this InsightToolbarButton as defined in IAction
90 * @param name null or the name of the button
91 * @param imageUrl URL to retrieve the image
92 * @param toolTip tooltip text for the JButton
93 * @param actionListener ActionListener instance that processes ActionEvent generated on this JButton
94 * @see IAction
95 */
96 public InsightToolbarButton (int type, String name, URL imageUrl,
97 String toolTip, ActionListener actionListener) {
98 this.type = type;
99 if (name != null) {
100 this.setName(name);
101 }
102 this.setIcon(new ImageIcon(imageUrl));
103 this.setToolTipText(toolTip);
104 this.addActionListener(actionListener);
105 }
106
107 /**
108 * Constructor for this class
109 * @param type the valid type of this InsightToolbarButton as defined in IAction
110 * @param name null or the name of the button
111 * @param image The image
112 * @param toolTip tooltip text for the JButton
113 * @param actionListener ActionListener instance that processes ActionEvent generated on this JButton
114 * @see IAction
115 */
116 public InsightToolbarButton (int type, String name, ImageIcon imageIcon,
117 String toolTip, ActionListener actionListener) {
118 this.type = type;
119 if (name != null) {
120 this.setName(name);
121 }
122 this.setIcon(imageIcon);
123 this.setToolTipText(toolTip);
124 this.addActionListener(actionListener);
125 }
126
127 /**
128 * @return Returns the type.
129 */
130 public int getType() {
131 return type;
132 }
133
134 /**
135 * @return Returns the controller.
136 */
137 public Controller getController() {
138 return controller;
139 }
140
141 /**
142 * @param controller The controller to set.
143 */
144 public void setController(Controller controller) {
145 this.controller = controller;
146 this.controller.registerAction(this);
147 }
148
149 /**
150 * Sets the icon of this button to the specified image and the tooltip
151 * to the specified string
152 * @param iconName the image name
153 * @param toolTip the tooltip text
154 */
155 public void setIconAndToolTip(String iconName, String toolTip) {
156 this.setIcon(new ImageIcon(iconName));
157 this.setToolTipText(toolTip);
158 }
159
160 /**
161 * Sets the icon of this button to the specified image and the tooltip
162 * to the specified string
163 * @param imageIcon The image icon
164 * @param toolTip the tooltip text
165 */
166 public void setIconAndToolTip(ImageIcon imageIcon, String toolTip) {
167 this.setIcon(imageIcon);
168 this.setToolTipText(toolTip);
169 }
170
171 }