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 * Filename: $Id: AutoHomeSession.java,v 1.43 2004/02/28 06:06:28 wbogaardt Exp $
21 * Abstract: Centralized backend for various components to send events to
22 * Serial port output.
23 */
24
25
26 import java.net.MalformedURLException;
27 import java.rmi.Naming;
28 import java.rmi.NotBoundException;
29 import java.rmi.RemoteException;
30 import java.rmi.RMISecurityManager;
31 import java.util.*;
32
33 import org.wcb.autohome.exceptions.HomeException;
34 import org.wcb.autohome.factories.HAGateway;
35 import org.wcb.autohome.factories.DeviceFactory;
36 import org.wcb.autohome.interfaces.*;
37 import org.wcb.autohome.implementations.EmailHeaderBean;
38 import org.wcb.autohome.implementations.SerialPortBean;
39 import org.wcb.autohome.model.MonitorTableModel;
40 import org.wcb.common.UIDefaultsLoader;
41
42 /***
43 *This class is a base class that holds most of the common methods
44 *that are accessed either via the command line daemon or the gui.
45 *Most of the functions handled through this class are for communications
46 *between the interface layer and the serial port, although all of the real
47 *process handled on the serial port end is done by the HAGateway object.
48 *
49 *@author Walter Bogaardt
50 *@version 1.0
51 */
52 public class AutoHomeSession implements org.wcb.autohome.interfaces.X10DeviceConstants {
53
54 /***
55 * The Current File name loaded into the application.
56 */
57 public static String CURRENT_FILENAME;
58 protected IDeviceRemote deviceFactory;
59 protected IHAGateway gateway;
60
61 /***
62 * Load the HAGateway and DeviceFactory based on the 'client.server' property.
63 * @param props Properties file with key value pair
64 * @deprecated
65 */
66 protected void loadServices(UIDefaultsLoader props) {
67 try
68 {
69 if (!(props.getProperty(RMI_HOST)).equals("") && !(props.getProperty(RMI_HOST)).startsWith(LOCALHOST))
70 {
71 if (System.getSecurityManager() == null)
72 {
73 System.out.print("Setting up security manager . . .");
74 System.setSecurityManager(new RMISecurityManager());
75 System.out.println("Security Enabled!");
76 }
77 try
78 {
79 System.out.print("Connecting to FileServer . . .");
80 deviceFactory = new DeviceFactory();
81 System.out.println("Connected!");
82 System.out.print("Connectiong to HA Gateway server . . .");
83 gateway = (IHAGateway) Naming
84 .lookup("rmi://" + props.getProperty(RMI_HOST) + "/GatewayServer");
85 System.out.println("Connected!");
86 }
87 catch (MalformedURLException murle)
88 {
89 System.err.println();
90 System.err.println("MalformedURLExcption: ");
91 System.err.println(murle);
92 loadStandAloneService(USER_HOME);
93 }
94 catch (NotBoundException nb)
95 {
96 System.err.println();
97 System.err.println("NotBoundException: ");
98 System.err.println(nb);
99 loadStandAloneService(USER_HOME);
100 }
101 catch (Exception err)
102 {
103 System.err.println();
104 System.err.println("Exception: ");
105 System.err.println(err);
106 loadStandAloneService(USER_HOME);
107 }
108 }
109 else
110 {
111 loadStandAloneService(USER_HOME);
112 }
113 }
114 catch (Exception err)
115 {
116 loadStandAloneService(USER_HOME);
117 }
118 }
119
120 /***
121 * Starts up all the services for the Alice gui or web
122 * application. The passed in directory is the location
123 * where the ini and config files can be found. If no
124 * config or ini files are found then they will be created
125 * in the indicated directory.
126 * @param sDirectory Directory string path where the ini files can be found.
127 */
128 protected void loadStandAloneService(String sDirectory) {
129
130 try
131 {
132 System.out.print("Connecting to local HAGateway . . .");
133 gateway = new HAGateway(sDirectory);
134 System.out.println("Connected!");
135 System.out.print("Connecting to local FileServer . . .");
136 deviceFactory = new DeviceFactory();
137 System.out.println("Connected!");
138 }
139 catch (RemoteException err)
140 {
141 err.printStackTrace();
142 }
143 }
144
145 /***
146 * Get internationalization resources.
147 * @return Resource for i18n;
148 */
149 public ResourceBundle getI18n()
150 {
151 Locale currentLocal = new Locale("en", "US");
152 ResourceBundle rbInternationalization = ResourceBundle.getBundle("org.wcb.plugins.AliceResource", currentLocal);
153 try
154 {
155 rbInternationalization = gateway.getI18n();
156 }
157 catch (RemoteException re)
158 {
159
160 }
161 return rbInternationalization;
162 }
163
164 /***
165 * Gets the last saved country value for internationalization.
166 *
167 * @return defaults to US
168 */
169 public String getCountry()
170 {
171 try
172 {
173 return gateway.getLocal().getCountry();
174 }
175 catch (RemoteException re)
176 {
177 return "US";
178 }
179 }
180
181 /***
182 * allows setting of country for internationalization
183 * 1 is dutch, 2 is german, 3 is GB english, default is US english
184 * @param iCountry Country code
185 */
186 public void setCountry(int iCountry)
187 {
188 try
189 {
190 switch(iCountry)
191 {
192 case 1:
193 gateway.setLocal(new Locale("nl", "NL"));
194 break;
195 case 2:
196 gateway.setLocal(new Locale("de", "DE"));
197 break;
198 case 3:
199 gateway.setLocal(new Locale("en", "GB"));
200 break;
201 default:
202 gateway.setLocal(new Locale("en", "US"));
203 break;
204 }
205 }
206 catch (RemoteException re)
207 {
208 }
209 }
210 /********************** FOR IHAGATEWAY INTERFACE *********************/
211 /***
212 * Calls the HAGateway class, which uses the java comm api
213 * to enumerate through the serial and parallel ports on the
214 * operating system.
215 * @return Vector of strings of all the operating systems serial ports.
216 */
217 public Vector getAvailablePorts() {
218 try
219 {
220 return gateway.getAvailablePorts();
221 }
222 catch (RemoteException err)
223 {
224 }
225 Vector returnVec = new Vector();
226 returnVec.addElement("NO PORTS FOUND");
227 return returnVec;
228 }
229
230 /***
231 * returns a boolean based on if
232 * the selected port has been activated
233 * or shutdown by the user/application.
234 * @return a false indicates X10 interface is not connected.
235 */
236 public boolean isX10GatwayConnected() {
237 try
238 {
239 return gateway.isPortActive();
240 }
241 catch (RemoteException err)
242 {
243 return false;
244 }
245 }
246
247 /***
248 * This closes the port that had been
249 * opend by the user to the CM11A or CM17A interface module
250 * @throws HomeException Caught exception but needs to be reported to user.
251 */
252 public void closeSerialPort() throws HomeException
253 {
254 try
255 {
256 gateway.closeSerialPort();
257 }
258 catch (RemoteException err)
259 {
260 }
261 catch (HomeException er)
262 {
263 throw new HomeException(er.toString());
264 }
265 }
266
267 /***
268 * Starts the events daemon which runs the
269 * events of times and on off for various modules.
270 * @return succes running events
271 */
272 public boolean runEventsDaemon() {
273 try
274 {
275 return gateway.runEventsDaemon(this.loadAllAliceEvents());
276 }
277 catch (RemoteException err)
278 {
279 return false;
280 }
281 }
282
283 /***
284 * Stops the events daemon which is the table
285 * of on off and devices and times table.
286 */
287 public void stopEventsDaemon() {
288 try
289 {
290 gateway.stopEventsDaemon();
291 }
292 catch (RemoteException err)
293 {
294 }
295 }
296
297 /***
298 * Checks if the events daemon is already running
299 * @return true if daemon is running
300 */
301 public boolean isEventDaemonRunning() {
302 try
303 {
304 return gateway.isEventDaemonRunning();
305 }
306 catch (RemoteException err)
307 {
308 return false;
309 }
310 }
311
312 /***
313 * Gets the x10 interfae type, which is either a CM11A or
314 * CM17A serial port device. The return value should be
315 * one of the following:
316 * 1 - CM11A
317 * 2 - CM17A
318 * @return a 1 or 2, which indicates the x10 gatway type.
319 */
320 public int getX10GatewayType() {
321 try
322 {
323 return gateway.getInterfaceType();
324 }
325 catch (RemoteException err)
326 {
327 return CM17A_TRANSMITTER;
328 }
329 }
330
331 /***
332 * This is either the CM11A or CM17A devices identified as
333 * X10DeviceConstants.CM11A_TRANSMITTER = 1
334 * or X10DeviceConstants.CM17A_TRANSMITER = 2
335 * @param iType should be a 1 or 2.
336 */
337 public void setInterfaceType(int iType) {
338 try
339 {
340 gateway.setInterfaceType(iType);
341 }
342 catch (RemoteException err)
343 {
344 }
345 }
346
347 /***
348 * Retrieves the CM11A's current battery usage. The value is is
349 * initialized after a call to updateStatus();
350 * The returned value is the number of minutes.
351 * @return minutes
352 */
353 public int getCM11ABatteryUsage() {
354 try
355 {
356 return gateway.getBatteryUsage();
357 }
358 catch (RemoteException err)
359 {
360 return 0;
361 }
362 }
363
364 /***
365 * This controls the appliance modules for only On/Off events
366 * The commands are either
367 * X10DeviceConstants.OFF_ACTION = 0
368 * X10DeviceConstants.ON_ACTION = 1
369 *
370 * @param x10module Module that the command is being sent.
371 * @param iCmd Numeric value of command to send this is either a 0 or 1.
372 * @throws HomeException Caught exception but needs to be reported to user.
373 */
374 public void sendCommandToX10Module(IX10Module x10module, int iCmd)
375 throws HomeException
376 {
377 try
378 {
379 gateway.deviceCommands(x10module, iCmd);
380 }
381 catch (RemoteException err)
382 {
383 }
384 catch (HomeException er)
385 {
386 throw new HomeException("Invalid command sent.");
387 }
388 }
389
390 /***
391 * These are commands that can be sent to the entire
392 * house code in a particular section regardless if it is an appliance or light module.
393 * This is separate from sendCommandToHouse which affects the entire house.
394 * @param cHouseCode the house code value 'A' through 'P'
395 * @param iCmnd 0 is all lights off, 1 all lights on, 2 all x10 devices off.
396 * @throws HomeException Caught exception but needs to be reported to user.
397 */
398 public void sendCommandToSection(char cHouseCode, int iCmnd)
399 throws HomeException
400 {
401 if (this.getX10GatewayType() == CM11A_TRANSMITTER)
402 {
403 try
404 {
405 gateway.allCommandToSection(cHouseCode, iCmnd);
406 }
407 catch (RemoteException err)
408 {
409 }
410 catch (HomeException er)
411 {
412 throw new HomeException(er.toString());
413 }
414 }
415 else
416 {
417 throw new HomeException("Not a CM11A gateway.");
418 }
419 }
420
421 /***
422 * Indicates that the user either wants the CM11A to autorecover
423 * upon detecting a power failure. If it is set to true, when the
424 * CM11A detects a power failure signal the command to set the clock will
425 * be sent. if set to false, it is up to another device to set the clock
426 * via a call to setCM11AClock before the CM11A can be used.
427 * @param bValue true indicates to recover the CM11A device.
428 */
429 public void recoverCM11A(boolean bValue) {
430 try
431 {
432 gateway.recoverCM11A(bValue);
433 }
434 catch (RemoteException err)
435 {
436 }
437 }
438
439 /***
440 * This returns the value of the HASConfig file
441 * which indicates that the user wants to or does not want
442 * to auto recover the CM11A on a power failure.
443 * @return true indicates auto recover mode.
444 */
445 public boolean isAutoRecoverCM11A() {
446 try
447 {
448 return gateway.isAutoRecoverCM11A();
449 }
450 catch (RemoteException err)
451 {
452 return false;
453 }
454 }
455
456 /***
457 * Update the Status of the CM11A device
458 */
459 public void updateCM11AStatus() {
460 try
461 {
462 gateway.updateCM11AStatus();
463 }
464 catch (RemoteException err)
465 {
466 }
467 }
468
469 /***
470 * Get the current date that the CM11A thinks it is.
471 * @return Current date on the CM11A
472 */
473 public GregorianCalendar getCM11ADate() {
474 try
475 {
476 return (GregorianCalendar) gateway.getCM11ADate();
477 }
478 catch (RemoteException err)
479 {
480 }
481 return new GregorianCalendar();
482 }
483
484 /***
485 * allows the user to set or send commands to set the CM11A clock settings
486 * This command needs the hours,minutes, seconds, month, day , day of week,
487 * house code character value, whether to reset the battery timer,
488 * clear the CM11A from monitoring the house, or purge the macro timer.
489 * @param calendar Calendar date and time to send to the CM11A
490 * @param houseCode The house code which should be A
491 * @param batteryTimer Reset the battery timer use True
492 * @param clrMonitored Clear monitored macros use True
493 * @param purgeTimer Purge timed macros use True.
494 * @throws HomeException Caught exception but needs to be reported to user.
495 */
496 public void setCM11AClock(Calendar calendar, char houseCode,
497 boolean batteryTimer, boolean clrMonitored,
498 boolean purgeTimer)
499 throws HomeException
500 {
501 try
502 {
503 gateway.setClock(calendar, houseCode, batteryTimer, clrMonitored, purgeTimer);
504 }
505 catch (RemoteException err)
506 {
507 }
508 catch (HomeException er)
509 {
510 throw new HomeException("Unable to set clock org.wcb.autohome.AutoHomeSession" + er);
511 }
512 }
513
514 /***
515 * Based on the user's select it will set the port to
516 * the string variable that is sent. This first detects
517 * if a current port is open and closes it then it will
518 * intiate connection to the user selected port.
519 * @param iDeviceType either a 1 for CM11A or 2 for CM17A.
520 * @throws HomeException Caught exception but needs to be reported to user.
521 */
522 public void connectPortToDevice(int iDeviceType)
523 throws HomeException
524 {
525 try
526 {
527 gateway.connectPortToX10Gateway(getSerialPort(), iDeviceType);
528 }
529 catch (RemoteException err)
530 {
531 }
532 catch (HomeException he)
533 {
534 throw new HomeException(he.toString());
535 }
536 }
537
538 /***
539 * Sets the serial port to the passed in string value.
540 * In windows environment this would be the string of
541 * COM1 or COM2. For Unix based it would be something like
542 * /dev/ttys0 or /dev/ttys1.
543 *
544 * @param sPortName SerialPortBean representation of the port and values
545 */
546 public void setSerialPort(SerialPortBean sPortName) {
547 try
548 {
549 gateway.setSerialPort(sPortName);
550 }
551 catch (RemoteException err)
552 {
553 showMessage("Failed to set up serial port");
554 }
555 }
556
557 /***
558 * Returns the string name of the serial port.
559 * @return defaults to null value.
560 */
561 public SerialPortBean getSerialPort() {
562 try
563 {
564 return gateway.getSerialPort();
565 }
566 catch (RemoteException err)
567 {
568 return null;
569 }
570 }
571
572 /***
573 * Gets the Swing ui look and feel for the user.
574 * The default return is the Swing METAL look and feel.
575 * @return Java Metal Look and feel.
576 */
577 public String getLookAndFeel() {
578 try
579 {
580 return gateway.getLookAndFeel();
581 }
582 catch (RemoteException err)
583 {
584 return METAL;
585 }
586 }
587
588 /***
589 * Sets the look and feel from the user selected option and
590 * saves this to the HAConfig.ini file for subsequent reload of the application.
591 *
592 * @param sLF Class package name of the look and feel.
593 */
594 public void setLookAndFeel(String sLF) {
595 try
596 {
597 gateway.setLookAndFeel(sLF);
598 }
599 catch (RemoteException err)
600 {
601 }
602 }
603
604 /***
605 * This allows the getting of email configruations from the
606 * HASConfig.ini file in a single object bean.
607 * @return Single object of configuration file settings
608 */
609 public EmailHeaderBean getEmailInformation() {
610 try
611 {
612 return gateway.getEmailInformation();
613 }
614 catch (RemoteException re)
615 {
616 }
617 return new EmailHeaderBean(null, null, null);
618 }
619
620 /***
621 * This sets the configuration files settings from a
622 * bean object.
623 * @param bean contains information to be stored in HASConfig.ini file.
624 */
625 public void setEmailInformation(EmailHeaderBean bean) {
626 try
627 {
628 gateway.setEmailInformation(bean);
629 }
630 catch (RemoteException re)
631 {
632 }
633 }
634
635 /***
636 * This controls the lights for only for dim and brighten events
637 * @param x10Evt x10 module
638 * @param cmnd Either 0 for dim 1 for brighten
639 * @param iPercentage percentation to change between 1 and 100.
640 * @throws HomeException Caught exception but needs to be reported to user.
641 */
642 public void lampIntensity(IX10Module x10Evt, int cmnd, int iPercentage)
643 throws HomeException
644 {
645 try
646 {
647 gateway.lampIntensity(x10Evt, cmnd, iPercentage);
648 }
649 catch (RemoteException err)
650 {
651 }
652 }
653
654
655
656
657
658 /***
659 * Saves the server file settings, which are the serial port information,
660 * email information, and look and feel for the swing gui.
661 */
662 public void saveServerFile() {
663 try
664 {
665 gateway.saveServerProperty();
666 }
667 catch (RemoteException err)
668 {
669 }
670 }
671
672 /***
673 * The User may opt to want to automatically connect the
674 * serial port to the X10 gateway on subsequent start up of the
675 * application.
676 * @param bVal True sets automatic connect to serial port
677 */
678 public void connectSerialOnStartup(boolean bVal)
679 {
680 try
681 {
682 gateway.connectSerialOnStartup(bVal);
683 }
684 catch (RemoteException err)
685 {
686 }
687 }
688
689 /***
690 * This allows the user to enable the speech engine
691 * or disable it if it gets irratating when listening to messages.
692 * @param bValue true enables speech false disables.
693 */
694 public void enableSpeechEngine(boolean bValue)
695 {
696 try
697 {
698 gateway.enableSpeechEngine(bValue);
699 }
700 catch (RemoteException err)
701 {
702 }
703 }
704
705 /***
706 * After reading in jhome.prop if initial.on.start indicates
707 * true then return a true to have the application automatically
708 * connect serial port up.
709 * @return true indicates automatically connect to serial port.
710 */
711 public boolean connectToSerialPortOnStartup()
712 {
713 try
714 {
715 return gateway.getConnectSerialOnStartup();
716 }
717 catch (RemoteException err)
718 {
719 return false;
720 }
721 }
722
723 /***
724 * Returns a true if the speech engine is enabled by the
725 * user other wise it returns false.
726 * @return true speech is enabled.
727 */
728 public boolean isSpeechEnabled() {
729 try
730 {
731 return gateway.isSpeechEnabled();
732 }
733 catch (RemoteException err)
734 {
735 return false;
736 }
737 }
738
739
740 /***
741 * This builds the macro trigger events
742 * for both the timer type triggers and for the
743 * macro module initiators. For CM11A type computer interfaces.
744 *
745 * @param bClear true value clears all macros from the interface before uploading.
746 * @throws HomeException - Either remote exception or unable to build a macro trigger
747 */
748 public void buildTriggerMacros(boolean bClear) throws HomeException {
749 try
750 {
751 if (bClear)
752 {
753 clearMacroEventsFromCM11A();
754 clearTimerMacrosFromCM11A();
755 }
756 gateway.sendMacrosToInterface(this.loadCM11AMacroTriggers());
757 }
758 catch (RemoteException err)
759 {
760 }
761 }
762
763 /***
764 * Clears only the timer event driven macros
765 * from the CM11A.
766 * @throws HomeException Caught exception but needs to be reported to user.
767 */
768 public void clearTimerMacrosFromCM11A() throws HomeException {
769 try
770 {
771 gateway.clearTimerMacros();
772 }
773 catch (RemoteException err)
774 {
775 }
776 }
777
778 /***
779 * Clears only the event driven macros
780 * from the CM11A.
781 * @throws HomeException Caught exception but needs to be reported to user.
782 */
783 public void clearMacroEventsFromCM11A() throws HomeException {
784 try
785 {
786 gateway.clearMacroEvents();
787 }
788 catch (RemoteException err)
789 {
790 }
791 }
792
793 /***
794 * Enables monitoring of the CM11A device.
795 * @return true indicates can monitor port false indicates cannot.
796 */
797 public boolean monitorCM11A() {
798 try
799 {
800 return gateway.monitorCM11A();
801 }
802 catch (RemoteException re)
803 {
804 }
805 return false;
806 }
807
808 /***
809 * Disables the monitoring of the CM11A device.
810 * @return true indicates can disable monitor to port false indicates cannot.
811 */
812 public boolean disableMonitorCM11A() {
813 try
814 {
815 return gateway.disableMonitorCM11A();
816 }
817 catch (RemoteException re)
818 {
819 }
820 return false;
821 }
822
823 /***
824 * This allows the gateway to have reference to the monitor table
825 * modle so that when the user decides to monitor the table
826 * object events and the table can update each other.
827 * @param mModel The monitoring table model
828 */
829 public void setMonitorModel(MonitorTableModel mModel) {
830 try
831 {
832 gateway.setMonitorModel(mModel);
833 }
834 catch (RemoteException re)
835 {
836 }
837 }
838
839
840 /***
841 * Save the IMacro to the file system in memory.
842 * @param mac Macro to save in the file system.
843 */
844 public void saveMacro(IMacro mac) {
845 deviceFactory.saveMacro(mac);
846 }
847
848 /***
849 * Removes the indicated macro from the file system.
850 * @param mac Macro to be removed
851 */
852 public void deleteMacro(IMacro mac) {
853 deviceFactory.deleteMacro(mac);
854 }
855
856 /***
857 * Loads from a file all the X10 devices that have been saved under
858 * the modules panel of the gui or website. The return will
859 * be a vector of IX10Module classes.
860 *
861 * @return Vector of IX10Module
862 */
863 public Vector loadAllX10Devices() {
864 return deviceFactory.readInX10Devices();
865 }
866
867 /***
868 * Saves to a file all the X10 devices added or modified in the modules
869 * tab of the gui or web interface.
870 *
871 * @param vX10Devices Vector of IX10Module
872 */
873 public void saveAllX10Devices(Vector vX10Devices) {
874 deviceFactory.writeX10Devices(vX10Devices);
875 }
876
877 /***
878 * Loads from file all the IX10Events, which are specific to
879 * the Alice system. These events are run by an events daemon to
880 * fire off actions such as turn x10 device A1 on or off at a certain time and date.
881 *
882 * @return Vector of IX10Events objects
883 */
884 public Vector loadAllAliceEvents() {
885 return deviceFactory.readInX10Events();
886 }
887
888 /***
889 * Saves to a file all the IX10Events, which are specific to
890 * the Alice system.
891 *
892 * @param vEvents Vector of IX10Events
893 */
894 public void saveAllAliceEvents(Vector vEvents) {
895 deviceFactory.writeX10Events(vEvents);
896 }
897
898 /***
899 * Allows saving of monitor events panel to the file system
900 * @param vMonitors Vector of IX10MonitorEvents objects
901 */
902 public void saveAllAliceMonitors(Vector vMonitors) {
903 deviceFactory.writeAliceMonitors(vMonitors);
904 }
905
906 /***
907 * Gets a vector from the saved file settings all of the
908 * monitor events that the user wants to monitor
909 * @return Vector of IX10MonitorEvent objects
910 */
911 public Vector loadAllAliceMonitors() {
912 return deviceFactory.readInAliceMonitors();
913 }
914 /***
915 * Loads all the macros that have been stored in a file system.
916 * These macros do not come from the CMA11 module but may have been
917 * sent to it at a previous time.
918 * @return Vector of IMacro objects
919 */
920 public Vector loadAllCM11AMacros() {
921 return deviceFactory.readInX10Macros();
922 }
923
924 /***
925 * Saves to the file system all the IMacro objects.
926 * @param vMacros Vector of IMacro objects
927 */
928 public void saveAllCM11AMacros(Vector vMacros) {
929 deviceFactory.writeMacros(vMacros);
930 }
931
932 /***
933 * Loads from file all the macro triggers for a set macro.
934 * @return Vector of IMacroTrigger
935 */
936 public Vector loadCM11AMacroTriggers() {
937 return deviceFactory.loadMacroTriggers();
938 }
939
940 /***
941 * Saves a vector of IMacroTrigger objects to the file system.
942 *
943 * @param vMacroTrig Vector of IMacroTrigger
944 */
945 public void saveCM11AMacroTriggers(Vector vMacroTrig) {
946 deviceFactory.saveMacroTriggers(vMacroTrig);
947 }
948
949
950 /***
951 * Loads the serialized file of objects from the user's operating system.
952 * The passed in string should be the full path plus file name and extension.
953 * If the file is not found a default serialized object will be returned. This
954 * is so the application can assume that this is a new file or a new application.
955 *
956 * @param sfilename Full path and file name
957 */
958 public void loadX10File(String sfilename) {
959 CURRENT_FILENAME = sfilename;
960 deviceFactory.loadFile(sfilename);
961 }
962
963 /***
964 * Creates a new file and sets the current file name
965 * sets settings to default value.
966 * @param sfilename The file name for the new file.
967 */
968 public void createNewFile(String sfilename) {
969 CURRENT_FILENAME = sfilename;
970 deviceFactory.createNewFile();
971 }
972
973 /***
974 * Saves all of the module information to the user selected
975 * save to file this method is usually called from a
976 * save or save as command. This also writes the information
977 * to the diskdrive.
978 * @param sfileName Full path and file name
979 * @throws HomeException Caught exception but needs to be reported to user.
980 */
981 public void saveFile(String sfileName)throws HomeException {
982 CURRENT_FILENAME = sfileName;
983 if (deviceFactory.saveFile(sfileName))
984 {
985 showMessage("X10 file saved");
986 }
987 else
988 {
989 showMessage("X10 file not saved!");
990 }
991 }
992
993 /***
994 * simple method to print messages to gui or console
995 * This will also speak the message if the speech plugin
996 * has been loaded by the class loader.
997 * @param sMessages text message to print.
998 */
999 protected void showMessage(String sMessages) {
1000
1001 try
1002 {
1003 gateway.speakMessage(sMessages);
1004 }
1005 catch (RemoteException re)
1006 {
1007 System.out.println(sMessages);
1008 }
1009 }
1010 }