1 package org.wcb.autohome; 2 /*** 3 * Copyright (C) 1999 Walter Bogaardt 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 18 * 19 * Project: Home Automation Interface 20 * 21 * $Log: MacroPanel.java,v $ 22 * Revision 1.8 2004/02/25 21:38:32 wbogaardt 23 * added javadocs and fixed formating for checkstyle report 24 * 25 * Revision 1.7 2004/02/03 21:02:24 wbogaardt 26 * moved DeviceFactory away from rmi creation and simplified interface between gateway 27 * 28 * Revision 1.6 2004/01/16 19:50:14 wbogaardt 29 * refactored, fixed long standing bug with updating macro panels, add error notification to user for improper 30 * device codes 31 * 32 * Revision 1.5 2004/01/16 00:53:34 wbogaardt 33 * Fixed a very obscure bug with the Macro Panel that it didn't added new 34 * x10 devices to the drop down of available x10 device for the macro. Modified Macro triggers to change the 35 * events to integer verses strings cleaner this way. 36 * 37 * Revision 1.4 2003/12/30 01:10:25 wbogaardt 38 * updated panel information with internationalization 39 * 40 * Revision 1.3 2003/12/22 20:51:29 wbogaardt 41 * refactored name assignments and formatted code for readability. 42 * 43 * Revision 1.2 2003/10/09 23:55:21 wbogaardt 44 * code clean up of formating and adding revision history to comments 45 * 46 */ 47 48 import javax.swing.*; 49 50 import org.wcb.autohome.exceptions.HomeException; 51 import org.wcb.autohome.interfaces.I18nConstants; 52 import org.wcb.autohome.interfaces.RefreshInterface; 53 import org.wcb.autohome.interfaces.MessageInterface; 54 55 import java.awt.event.ActionListener; 56 import java.awt.event.ActionEvent; 57 58 /*** 59 * This displays the macro panels which contains controlling 60 * the CM11A through storable macros. 61 */ 62 public class MacroPanel extends JPanel implements RefreshInterface { 63 private MacroTriggerPanel macroTriggerPanel; 64 private MacroSequencePanel macroSequencePanel; 65 private JButton jbSendButton; 66 private MessageInterface msgInterface; 67 68 /*** 69 * Initialize the macro panel with the two panels on it. 70 */ 71 public MacroPanel() 72 { 73 msgInterface = AutoHomeAdminSession.getInstance().getMessageInterface(); 74 this.setupComponents(); 75 this.setupListener(); 76 } 77 78 /*** 79 * Sets up a panel with two tabbed panels on it, which 80 * are the Macro events panel and the macro trigger panel. 81 */ 82 public void setupComponents() 83 { 84 JTabbedPane jtabbed = new JTabbedPane(); 85 jbSendButton = new JButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.SEND_MACRO_LABEL)); 86 macroTriggerPanel = new MacroTriggerPanel(); 87 macroSequencePanel = new MacroSequencePanel(macroTriggerPanel.getInterface()); 88 jtabbed.add(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.EVENTS_PANEL), macroSequencePanel); 89 jtabbed.add(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.TRIGGER_PANEL), macroTriggerPanel); 90 add(jbSendButton); 91 add(jtabbed); 92 } 93 94 /*** 95 * This returns an instance of the MessageInterface 96 * that is used in this class to control the various 97 * messages. 98 * @return This classes refresh ability. 99 */ 100 public RefreshInterface getInterface() 101 { 102 return this; 103 } 104 105 /*** 106 * Refreshes the data in the different panels. 107 * Call the Macro panel because the macro panel 108 * then in turn calls the trigger panel. 109 */ 110 public void refresh() 111 { 112 macroSequencePanel.refresh(); 113 } 114 115 /*** 116 * this uses a class instants to call 117 * the CM11A device and set up the cmacros in the device. 118 */ 119 private void sendToCM11A() 120 { 121 int answer = JOptionPane.showConfirmDialog(null, "Do you want to clear all\n the Macros from the CM11A?"); 122 if (answer == JOptionPane.YES_OPTION) 123 { 124 try 125 { 126 AutoHomeAdminSession.getInstance().buildTriggerMacros(true); 127 } 128 catch (HomeException err) 129 { 130 this.log("Error clearing macros " + err); 131 } 132 } 133 try 134 { 135 AutoHomeAdminSession.getInstance().buildTriggerMacros(false); 136 } 137 catch (HomeException err) 138 { 139 JOptionPane.showMessageDialog(null, err.toString(), "Failed upload", JOptionPane.ERROR_MESSAGE); 140 } 141 } 142 143 /*** 144 * this sets up the action listener for the 145 * send command to the CM11A device. 146 */ 147 private void setupListener() { 148 ActionListener al = new ActionListener() { 149 public void actionPerformed(ActionEvent evt) { 150 Object src = evt.getSource(); 151 if (src == jbSendButton) 152 { 153 sendToCM11A(); 154 } 155 } 156 }; 157 jbSendButton.addActionListener(al); 158 } 159 160 /*** 161 * sends text information to the application statatus bar 162 * @param info String message to print to log interface. 163 */ 164 private void log (String info) 165 { 166 msgInterface.printMessage(info); 167 } 168 } 169