1 /*
2 * $HeadURL: $
3 * $Date: $
4 * $Revision: $
5 * $Author: $
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
28 import javax.swing.JMenuItem;
29
30 import com.mindtree.techworks.insight.Controller;
31 import com.mindtree.techworks.insight.gui.action.IAction;
32
33 /**
34 *
35 * The <code>InsightMenuItem</code> class represents all menu item
36 * instances in Insight. It contains specific behavior for enabling
37 * and disabling, registering with the Controller for data related
38 * call-back.
39 *
40 * @see com.mindtree.techworks.insight.Controller
41 * @see com.mindtree.techworks.insight.gui.action.IAction
42 * @see com.mindtree.techworks.insight.gui.Presentation
43 *
44 * @author Regunath B
45 * @version 1.0, 05/03/11
46 */
47 public class InsightMenuItem extends JMenuItem implements IAction {
48
49 /**
50 * Used for object serialization
51 */
52 private static final long serialVersionUID = 5926456181987356463L;
53
54 /**
55 * The type of this IAction
56 */
57 private int type;
58
59 /**
60 * The Controller instance for this IAction
61 */
62 private Controller controller;
63
64 /**
65 * Constructor for this class
66 * @param type the valid type of this Insight as defined in IAction
67 * @param name null or the name of the menu item
68 * @param displayText the text to be diplayed by this JMenuItem
69 * @param actionListener ActionListener instance that processes ActionEvent generated on this JMenuItem
70 * @see IAction
71 */
72 public InsightMenuItem (int type, String name, String displayText, ActionListener actionListener) {
73 super(displayText);
74 this.type = type;
75 if (name != null) {
76 this.setName(name);
77 }
78 this.addActionListener(actionListener);
79 }
80
81 /**
82 * @return Returns the type.
83 */
84 public int getType() {
85 return type;
86 }
87
88 /**
89 * @return Returns the controller.
90 */
91 public Controller getController() {
92 return controller;
93 }
94
95 /**
96 * @param controller The controller to set.
97 */
98 public void setController(Controller controller) {
99 this.controller = controller;
100 this.controller.registerAction(this);
101 }
102
103 }