View Javadoc

1   package org.wcb.autohome.util.ui;
2   
3   import org.wcb.autohome.AutoHomeAdminSession;
4   import org.wcb.autohome.MonitorPanel;
5   import org.wcb.autohome.interfaces.I18nConstants;
6   
7   import javax.swing.*;
8   import java.awt.event.ActionListener;
9   import java.awt.event.ActionEvent;
10  
11  /***
12   * Copyright (C) 1999  Walter Bogaardt
13   *
14   * This library is free software; you can redistribute it and/or
15   * modify it under the terms of the GNU Lesser General Public
16   * License as published by the Free Software Foundation; either
17   * version 2 of the License, or (at your option) any later version.
18   *
19   * This library is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22   * Lesser General Public License for more details.
23   *
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this library; if not, write to the Free Software
26   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
27   *
28   * Project: Alice X10 Home Automation
29   * Filename:  $Id: MonitorTablePopup.java,v 1.4 2004/07/22 03:06:50 wbogaardt Exp $<BR>
30   * Abstract: Used to display pop up box when user right clicks to give some options to
31   * take when adding or deleting items.
32   *
33   * $Log: MonitorTablePopup.java,v $
34   * Revision 1.4  2004/07/22 03:06:50  wbogaardt
35   * removed deprecated method calls.
36   *
37   * Revision 1.3  2004/02/27 01:29:53  wbogaardt
38   * modified classes so they conform to Checkstyle format in readability
39   *
40   * Revision 1.2  2004/01/19 22:35:38  wbogaardt
41   * added fixes to runing events and emails so they work and added a testing of a monitored event through
42   * the table popup on a right mouse click.
43   *
44   * Revision 1.1  2004/01/18 17:39:12  wbogaardt
45   * added table pop up menu actions
46   *
47   */
48  public class MonitorTablePopup extends JPopupMenu implements ActionListener {
49  
50      private JMenuItem jmiSave, jmiDelete;
51      private JMenuItem jmiRunAction = new JMenuItem("Run");
52      private MonitorPanel mpReference;
53  
54      /***
55       * Sets the pop up menue on a particular table or component.
56       * @param mp Monitoring panel table
57       */
58      public MonitorTablePopup(MonitorPanel mp) {
59          this.mpReference = mp;
60          this.setMenus();
61          this.setVisible(false);
62      }
63  
64      /***
65       * This setsup the menu items on the pop up menu.
66       */
67      private void setMenus() {
68          jmiSave = new JMenuItem(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.SAVE_MENU));
69          jmiDelete = new JMenuItem(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.DELETE_MENU),
70                  AutoHomeAdminSession.DELETE_ROW_ICON);
71          add(jmiSave);
72          add(jmiDelete);
73          add(jmiRunAction);
74          jmiSave.addActionListener(this);
75          jmiDelete.addActionListener(this);
76          jmiRunAction.addActionListener(this);
77          setVisible(true);
78      }
79  
80      /***
81       * Perform the action on the selected menu item, which is save, delete or run an action
82       * @param e Menu selected event.
83       */
84      public void actionPerformed(ActionEvent e) {
85          Object src = e.getSource();
86          if (src == jmiSave)
87          {
88              saveModule();
89          }
90          if (src == jmiDelete)
91          {
92              deleteModule();
93          }
94          if (src == jmiRunAction)
95          {
96              this.mpReference.runEvent();
97          }
98      }
99  
100     /***
101      * Send the save command to the application
102      */
103     private void saveModule() {
104         this.mpReference.saveAllData();
105     }
106 
107     /***
108      * Send the delete command to the main panel and delete the selected row.
109      */
110     private void deleteModule() {
111         this.mpReference.deleteRow();
112     }
113 }