View Javadoc

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   */
20  import javax.swing.SwingConstants;
21  import javax.swing.JButton;
22  import javax.swing.JPanel;
23  import javax.swing.JToggleButton;
24  import javax.swing.JTextField;
25  import javax.swing.JSlider;
26  import javax.swing.JComboBox;
27  import javax.swing.ImageIcon;
28  import javax.swing.JOptionPane;
29  import javax.swing.JLabel;
30  import javax.swing.BorderFactory;
31  import java.awt.BorderLayout;
32  import java.awt.Color;
33  import javax.swing.BoxLayout;
34  import java.awt.event.ActionListener;
35  import java.awt.event.ActionEvent;
36  import java.util.Calendar;
37  import java.util.GregorianCalendar;
38  import java.text.SimpleDateFormat;
39  import java.text.ParseException;
40  
41  import org.wcb.autohome.util.Item;
42  import org.wcb.autohome.util.DeviceIDRenderer;
43  import org.wcb.autohome.interfaces.X10DeviceConstants;
44  import org.wcb.autohome.interfaces.IX10Events;
45  import org.wcb.autohome.interfaces.I18nConstants;
46  import org.wcb.autohome.interfaces.IX10Module;
47  import org.wcb.autohome.implementations.X10Events;
48  import org.wcb.autohome.implementations.X10Module;
49  import org.wcb.common.JTimeDialog;
50  /***
51   * * Project: Alice X10 Home Automation<BR>
52   * Filename:  $Id: EventsDetailPanel.java,v 1.26 2004/07/22 03:06:49 wbogaardt Exp $<BR>
53   * Abstract: Used to display detail information on the events panel and run the
54   *           events daemon
55   *
56   * $Log: EventsDetailPanel.java,v $
57   * Revision 1.26  2004/07/22 03:06:49  wbogaardt
58   * removed deprecated method calls.
59   *
60   * Revision 1.25  2004/02/28 06:06:28  wbogaardt
61   * *** empty log message ***
62   *
63   * Revision 1.24  2004/02/06 23:27:12  wbogaardt
64   * added clock label to internationalization, refactored menu bar from home center panel, fixed display of JTimeDialog so that it looks a bit better.
65   *
66   * Revision 1.23  2004/02/06 20:06:15  wbogaardt
67   * replaced ampm drop boxes with time buttons which launch a time panel move menu items around on main panel
68   *
69   * Revision 1.22  2004/02/05 14:31:50  wbogaardt
70   * modified to use time slider
71   *
72   * Revision 1.21  2004/02/01 19:31:52  wbogaardt
73   * removed form layout references
74   *
75   * Revision 1.20  2004/01/19 17:54:16  wbogaardt
76   * initial fixed monitor
77   *
78   * Revision 1.19  2004/01/17 07:21:15  wbogaardt
79   * added serialization to run events and allow monitoring of these events to the file system to reload later
80   *
81   * Revision 1.18  2004/01/16 19:50:14  wbogaardt
82   * refactored, fixed long standing bug with updating macro panels, add error notification to user
83   * for improper device codes
84   *
85   * Revision 1.17  2004/01/16 00:53:34  wbogaardt
86   * Fixed a very obscure bug with the Macro Panel that it didn't added new
87   * x10 devices to the drop down of available x10 device for the macro. Modified Macro triggers to change the events
88   * to integer verses strings cleaner this way.
89   *
90   * Revision 1.16  2004/01/15 21:05:17  wbogaardt
91   * major revamp of Modules and interfaces changes overall structure of how information is stored
92   *
93   * Revision 1.15  2003/12/30 21:20:16  wbogaardt
94   * added new file saving dialog to actually save files in .x10 extension.
95   *
96   * Revision 1.14  2003/12/30 18:47:40  wbogaardt
97   * made labels so they are internationlized and fixed layout of trigger panel
98   *
99   * Revision 1.13  2003/12/22 20:51:29  wbogaardt
100  * refactored name assignments and formatted code for readability.
101  *
102  * Revision 1.12  2003/12/20 21:32:38  wbogaardt
103  * enabled new file menu option and added functionality
104  *
105  * Revision 1.10  2003/12/20 06:16:00  wbogaardt
106  * moved most buttons text to i18n internationalization.
107  *
108  * Revision 1.9  2003/12/16 22:08:33  wbogaardt
109  * refactored events daemon handeling
110  *
111  * Revision 1.8  2003/12/12 23:17:33  wbogaardt
112  * javadoc comments refactored methods so they are more descriptive
113  *
114  * Revision 1.7  2003/12/11 23:10:07  wbogaardt
115  * cleaned up exception handeling and logging of system.out messages
116  *
117  * Revision 1.6  2003/10/10 22:35:33  wbogaardt
118  * fixed parsing of date information for am and pm values.
119  *
120  * Revision 1.5  2003/10/10 21:39:01  wbogaardt
121  * modified macro triggers to use calendar in stead of strings
122  *
123  * Revision 1.4  2003/10/10 18:39:09  wbogaardt
124  * changed date time information from a string to a calendar object
125  *
126  *
127  *@author wbogaardt
128  *@version 1.15
129  */
130 public class EventsDetailPanel extends JPanel implements SwingConstants, X10DeviceConstants {
131 
132     private JButton jbAdd, jbUpdate, jbDelete;
133     private JButton jbTime;
134     private JTimeDialog dialog;
135     private JButton okButton = new JButton("OK");
136     private JToggleButton jtbExecute;
137     private JToggleButton jtbSunday, jtbMonday, jtbTuesday, jtbWednesday, jtbThursday, jtbFriday, jtbSaturday;
138     private JTextField descriptionTf, startTf;
139     private JComboBox jcbStatus, jcbLightModuleAction, jcbInstalledModules;
140     private JSlider jsLightController;
141     private EventsPanel stepDad;
142     private ImageIcon imgIconDisableDate = AutoHomeAdminSession.DAYOFF;
143     private ImageIcon imgIconEnableDate = AutoHomeAdminSession.DAYON;
144     private String[] sEventsArray = {"Off", "ON", "LightControl",
145                                    "All Lights Off", "All Lights ON", "All Off"};
146     private IX10Events x10Events = null;
147     private static final SimpleDateFormat DATE_FORMAT_HMMA = new SimpleDateFormat("h:mm a");
148 
149     /***
150      * Creates the Events detail panel with a reference
151      * to the Main Events Panel.
152      * @param modPanel The main events panel with the table selection model.
153      */
154     public EventsDetailPanel(EventsPanel modPanel) {
155         stepDad = modPanel;
156         setupComponents();
157         setupListeners();
158     }
159 
160     /***
161      * Setup componets on this panel
162      */
163     private void setupComponents()
164     {
165         setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black),
166                 AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.DETAIL_LABEL)));
167         jsLightController = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);
168         jsLightController.setPaintLabels(true);
169         jsLightController.setMajorTickSpacing(20);
170         jcbLightModuleAction = new JComboBox();
171         jcbLightModuleAction.addItem("Dim");
172         jcbLightModuleAction.addItem("Brighten");
173         jsLightController.setEnabled(false);
174         jcbLightModuleAction.setEnabled(false);
175         startTf = new JTextField(6);
176         startTf.setEditable(false);
177         jbTime = new JButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.CLOCK_LABEL));
178         jtbSunday = new JToggleButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.SUN_BUTTON),
179                 imgIconDisableDate);
180         setupButton(jtbSunday);
181         jtbMonday = new JToggleButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.MON_BUTTON),
182                 imgIconDisableDate);
183         setupButton(jtbMonday);
184         jtbTuesday = new JToggleButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.TUE_BUTTON),
185                 imgIconDisableDate);
186         setupButton(jtbTuesday);
187         jtbWednesday = new JToggleButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.WED_BUTTON),
188                 imgIconDisableDate);
189         setupButton(jtbWednesday);
190         jtbThursday = new JToggleButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.THU_BUTTON),
191                 imgIconDisableDate);
192         setupButton(jtbThursday);
193         jtbFriday = new JToggleButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.FRI_BUTTON),
194                 imgIconDisableDate);
195         setupButton(jtbFriday);
196         jtbSaturday = new JToggleButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.SAT_BUTTON),
197                 imgIconDisableDate);
198         setupButton(jtbSaturday);
199         jbAdd = new JButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.ADD_BUTTON));
200         jbAdd.setToolTipText("Used to add new events");
201         jbUpdate = new JButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.UPDATE_BUTTON));
202         jbUpdate.setToolTipText("Update a currently selected event");
203         jbDelete = new JButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.DELETE_BUTTON));
204         jbDelete.setToolTipText("Delete a selected event");
205         jtbExecute = new JToggleButton(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.RUN_BUTTON),
206                 imgIconDisableDate);
207         jtbExecute.setToolTipText("Begin executing events");
208         jtbExecute.setSelected(AutoHomeAdminSession.getInstance().isEventDaemonRunning());
209         setupButton(jtbExecute);
210         jcbStatus = new JComboBox(sEventsArray);
211         descriptionTf = new JTextField(15);
212         jcbInstalledModules = new JComboBox();
213         updateDeviceID();
214 
215         JPanel execPanel = new JPanel();
216         execPanel.setLayout(new BoxLayout(execPanel, BoxLayout.Y_AXIS));
217         execPanel.add(jtbExecute);
218         add(BorderLayout.NORTH, this.createTopPanel());
219         add(BorderLayout.WEST, this.createWeeksPanel());
220         add(BorderLayout.EAST, execPanel);
221         add(BorderLayout.SOUTH, this.createLightControllerPanel());
222     }
223 
224     /***
225      * This panel creates the top description, add, delete, and update buttons
226      * as well as the time for the event and the modules.
227      * @return Completed panel of description details.
228      */
229     private JPanel createTopPanel() {
230          java.awt.GridBagConstraints gridBagConstraints;
231         JPanel jPanel2 = new javax.swing.JPanel();
232         jPanel2.setLayout(new java.awt.GridBagLayout());
233 
234         gridBagConstraints = new java.awt.GridBagConstraints();
235         gridBagConstraints.gridwidth = 2;
236         jPanel2.add(new JLabel(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.INSTALLED_MODULES_LABEL)), gridBagConstraints);
237 
238         gridBagConstraints = new java.awt.GridBagConstraints();
239         gridBagConstraints.gridx = 2;
240         gridBagConstraints.gridy = 0;
241         jPanel2.add(jcbInstalledModules, gridBagConstraints);
242 
243         gridBagConstraints = new java.awt.GridBagConstraints();
244         gridBagConstraints.gridx = 3;
245         gridBagConstraints.gridy = 0;
246         jPanel2.add(new JLabel(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.DESCRIPTION_LABEL)), gridBagConstraints);
247 
248         gridBagConstraints = new java.awt.GridBagConstraints();
249         gridBagConstraints.gridx = 4;
250         gridBagConstraints.gridy = 0;
251         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
252         jPanel2.add(descriptionTf, gridBagConstraints);
253 
254         gridBagConstraints = new java.awt.GridBagConstraints();
255         gridBagConstraints.gridx = 5;
256         gridBagConstraints.gridy = 0;
257         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
258         jPanel2.add(jbAdd, gridBagConstraints);
259 
260         gridBagConstraints = new java.awt.GridBagConstraints();
261         gridBagConstraints.gridx = 0;
262         gridBagConstraints.gridy = 1;
263         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
264         jPanel2.add(new JLabel(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.TIME_LABEL)), gridBagConstraints);
265 
266         gridBagConstraints = new java.awt.GridBagConstraints();
267         gridBagConstraints.gridx = 1;
268         gridBagConstraints.gridy = 1;
269         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
271         jPanel2.add(startTf, gridBagConstraints);
272 
273         gridBagConstraints = new java.awt.GridBagConstraints();
274         gridBagConstraints.gridx = 2;
275         gridBagConstraints.gridy = 1;
276         jPanel2.add(jbTime, gridBagConstraints);
277 
278         gridBagConstraints = new java.awt.GridBagConstraints();
279         gridBagConstraints.gridx = 3;
280         gridBagConstraints.gridy = 1;
281         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
282         jPanel2.add(new JLabel(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.ACTION_LABEL)), gridBagConstraints);
283 
284         gridBagConstraints = new java.awt.GridBagConstraints();
285         gridBagConstraints.gridx = 4;
286         gridBagConstraints.gridy = 1;
287         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
288         jPanel2.add(jcbStatus, gridBagConstraints);
289 
290         gridBagConstraints = new java.awt.GridBagConstraints();
291         gridBagConstraints.gridx = 5;
292         gridBagConstraints.gridy = 1;
293         jPanel2.add(jbUpdate, gridBagConstraints);
294 
295         gridBagConstraints = new java.awt.GridBagConstraints();
296         gridBagConstraints.gridx = 6;
297         gridBagConstraints.gridy = 1;
298         jPanel2.add(jbDelete, gridBagConstraints);
299         return jPanel2;
300     }
301 
302     /***
303      * This panel displays the toggle buttons for the various days of the week.
304      * @return Days of week panel
305      */
306     private JPanel createWeeksPanel() {
307         JPanel jpDaysOfWeek = new JPanel();
308         jpDaysOfWeek.add(new JLabel(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.WEEKDAY_LABEL)));
309         jpDaysOfWeek.add(jtbSunday);
310         jpDaysOfWeek.add(jtbMonday);
311         jpDaysOfWeek.add(jtbTuesday);
312         jpDaysOfWeek.add(jtbWednesday);
313         jpDaysOfWeek.add(jtbThursday);
314         jpDaysOfWeek.add(jtbFriday);
315         jpDaysOfWeek.add(jtbSaturday);
316         return jpDaysOfWeek;
317     }
318 
319     /***
320      * This creates the south panel which displays the light
321      * dim and brighten slider as well as other actions for light based modules.
322      * @return The light slider panel
323      */
324     private JPanel createLightControllerPanel() {
325         JPanel lightPanel = new JPanel();
326         lightPanel.setLayout(new BoxLayout(lightPanel, BoxLayout.X_AXIS));
327         lightPanel.add(new JLabel(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.LIGHT_LABEL)));
328         lightPanel.add(jcbLightModuleAction);
329         lightPanel.add(jsLightController);
330         return lightPanel;
331     }
332 
333     /***
334      * Pass in a toggle button and set its position
335      * text postion to center and top location.
336      * @param jtb the passed in toggle button to set information.
337      */
338     private void setupButton(JToggleButton jtb)
339     {
340         jtb.setSelectedIcon(imgIconEnableDate);
341         jtb.setVerticalTextPosition(TOP);
342         jtb.setHorizontalTextPosition(CENTER);
343     }
344 
345     /***
346      *Updates the drop down combo box with the list of available X10 modules
347      *added in the ModulePanel.  We wanted this information to updated to subsequent
348      *panels if we made changes to X10 devices so that they either become available
349      *or unavailable for either this panel or others.
350      */
351     public void updateDeviceID()
352     {
353         jcbInstalledModules = AutoHomeAdminSession.getInstance().setRenderedModules(jcbInstalledModules);
354         jcbInstalledModules.setRenderer(new DeviceIDRenderer());
355     }
356 
357     /***
358      * Updates this view with the selected row data
359      * in this case it is a vector. The information
360      * is appropriatly distributed to fill in the UI
361      * detail information for the user.
362      * @param detail The X10Events object interface to set components on panel to display its values.
363      */
364     public void updateView(IX10Events detail)
365     {
366         x10Events = detail;
367         IX10Module iEventModule = x10Events.getModule();
368         clearAllViews();
369         /* sets the detail icon Combo box to */
370         if (iEventModule.getType() == LAMP_MODULE_ON)
371         {
372             jsLightController.setEnabled(true);
373             jcbLightModuleAction.setEnabled(true);
374             setupLightComponets(detail.getAction());
375         }
376         if (iEventModule.getType() == APPLIANCE_MODULE_ON)
377         {
378             jsLightController.setEnabled(false);
379             jcbLightModuleAction.setEnabled(false);
380             jsLightController.setValue(0);
381         }
382         /* display the item Module ID */
383         for (int i = 0; i < jcbInstalledModules.getItemCount(); i++)
384         {
385             if (((jcbInstalledModules.getItemAt(i)).toString()).startsWith(iEventModule.getFullDeviceCode()))
386             {
387                 jcbInstalledModules.setSelectedIndex(i);
388             }
389         }
390         descriptionTf.setText(detail.getDescription());
391         /* set the checkbox value based on status */
392         if (detail.getAction().equalsIgnoreCase(sEventsArray[1]))
393         {
394             jcbStatus.setSelectedIndex(1);
395             jsLightController.setValue(100);
396             jcbLightModuleAction.setSelectedIndex(0);
397         }
398         if (detail.getAction().equalsIgnoreCase(sEventsArray[0]))
399         {
400             jcbStatus.setSelectedIndex(0);
401         }
402         if (detail.getAction().equalsIgnoreCase(sEventsArray[3]))
403         {
404             jcbStatus.setSelectedIndex(3);
405         }
406         if (detail.getAction().equalsIgnoreCase(sEventsArray[4]))
407         {
408             jcbStatus.setSelectedIndex(4);
409         }
410         if (detail.getAction().equalsIgnoreCase(sEventsArray[5]))
411         {
412             jcbStatus.setSelectedIndex(5);
413         }
414         /* set up toggle buttons on or off */
415         setupDaysofWeek(detail);
416         startTf.setText(DATE_FORMAT_HMMA.format(detail.getTime().getTime()));
417     }
418 
419     /***
420      * If the text indicates its a light then set
421      * the light slider bar to the value indicated.
422      */
423     private void setupLightComponets(String lightText)
424     {
425         if (lightText.startsWith("-"))
426         {
427             jcbLightModuleAction.setSelectedIndex(0);
428         }
429         if (lightText.startsWith("+"))
430         {
431             jcbLightModuleAction.setSelectedIndex(1);
432         }
433         try
434         {
435             jsLightController.setValue(Integer.parseInt(lightText.substring(1)));
436         }
437         catch (NumberFormatException err)
438         {
439             //default to the middle of the slider
440            jsLightController.setValue(50);
441         }
442         jcbStatus.setSelectedIndex(2);
443     }
444 
445     private void setupListeners()
446     {
447         ActionListener al = new ActionListener() {
448             public void actionPerformed(ActionEvent evt)
449             {
450                 Object src = evt.getSource();
451                 if (src == jbAdd)
452                 {
453                     if (checkIsLightDevice())
454                     {
455                         try
456                         {
457                             stepDad.addNewRow(saveDetailData());
458                             clearAllViews();
459                         }
460                         catch (Exception err)
461                         {
462                         }
463                     }
464                 }
465                 if (src == jbUpdate)
466                 {
467                     if (checkIsLightDevice())
468                     {
469                         try
470                         {
471                             stepDad.updateRow(saveDetailData());
472                         }
473                         catch (Exception err)
474                         {
475                         }
476                     }
477                 }
478                 if (src == jbDelete)
479                 {
480                     stepDad.deleteRow();
481                     clearAllViews();
482                 }
483 
484                 if (src == jtbExecute)
485                 {
486                     if (AutoHomeAdminSession.getInstance().isX10GatwayConnected())
487                     {
488                         if (jtbExecute.isSelected())
489                         {
490                             if (!AutoHomeAdminSession.getInstance().isEventDaemonRunning())
491                             {
492                                 stepDad.loadData();
493                                 AutoHomeAdminSession.getInstance().runEventsDaemon();
494                             }
495                         }
496                         if (!jtbExecute.isSelected())
497                         {
498                             if (AutoHomeAdminSession.getInstance().isEventDaemonRunning())
499                             {
500                                 AutoHomeAdminSession.getInstance().stopEventsDaemon();
501                             }
502                         }
503                     }
504                     else
505                     {
506                         showErrorMessage("ALICE is not currently connected\nto the X10 interface.");
507                         jtbExecute.setSelected(false);
508                     }
509                 }
510                 if (src == jbTime)
511                 {
512                     GregorianCalendar time = new GregorianCalendar();
513                     if (startTf.getText() != null)
514                     {
515                         try
516                         {
517                             time.setTime(DATE_FORMAT_HMMA.parse(startTf.getText()));
518                         }
519                         catch (ParseException pe)
520                         {
521                             //dialog will default to current time
522                         }
523                     }
524                     dialog = new JTimeDialog(null, time, okButton);
525                     dialog.setLocationRelativeTo(EventsDetailPanel.this);
526                     dialog.setVisible(true);
527                 }
528                 if (src == jcbStatus)
529                 {
530                     lightControllerCheck();
531                 }
532                 if (src == okButton)
533                 {
534                     startTf.setText(dialog.getTime());
535                     dialog.dispose();
536                 }
537 
538             }
539         };
540         okButton.addActionListener(al);
541         jbAdd.addActionListener(al);
542         jbUpdate.addActionListener(al);
543         jbDelete.addActionListener(al);
544         jtbExecute.addActionListener(al);
545         jcbStatus.addActionListener(al);
546         jbTime.addActionListener(al);
547     }
548 
549     /***
550      * Set all the toggle buttons to be unselected
551      */
552     private void clearAllViews()
553     {
554         jcbStatus.setSelectedIndex(0);
555         descriptionTf.setText("");
556         jtbSunday.setSelected(false);
557         jtbMonday.setSelected(false);
558         jtbTuesday.setSelected(false);
559         jtbWednesday.setSelected(false);
560         jtbThursday.setSelected(false);
561         jtbFriday.setSelected(false);
562         jtbSaturday.setSelected(false);
563         jtbExecute.setSelected(AutoHomeAdminSession.getInstance().isEventDaemonRunning());
564     }
565 
566     /***
567      * Toggle the day of week button down
568      * based on the string passed.
569      * example string is --TWTF-
570      */
571     private void setupDaysofWeek(IX10Events x10evt)
572     {
573         jtbSunday.setSelected(x10evt.getSunday());
574         jtbMonday.setSelected(x10evt.getMonday());
575         jtbTuesday.setSelected(x10evt.getTuesday());
576         jtbWednesday.setSelected(x10evt.getWednesday());
577         jtbThursday.setSelected(x10evt.getThursday());
578         jtbFriday.setSelected(x10evt.getFriday());
579         jtbSaturday.setSelected(x10evt.getSaturday());
580     }
581 
582     /***
583      * Enable or disable the light slider based on
584      * the module type selected.
585      */
586     private void lightControllerCheck()
587     {
588         Item selectItem = (Item) jcbInstalledModules.getSelectedItem();
589         if (selectItem.getType() == LAMP_MODULE_ON)
590         {
591             jsLightController.setEnabled(true);
592             jcbLightModuleAction.setEnabled(true);
593         }
594         if (selectItem.getType() == APPLIANCE_MODULE_ON)
595         {
596             jsLightController.setEnabled(false);
597             jcbLightModuleAction.setEnabled(false);
598             jsLightController.setValue(0);
599         }
600     }
601 
602     /***
603      * If a Toggle button had be selected then
604      * set its value to a day of the week otherwise
605      * put in a - to indicate that week was not selected.
606      * @param x10evt event Object to set the date values.
607      */
608     private void saveDaysOfWeek(X10Events x10evt)
609     {
610         x10evt.setSunday(jtbSunday.isSelected());
611         x10evt.setMonday(jtbMonday.isSelected());
612         x10evt.setTuesday(jtbTuesday.isSelected());
613         x10evt.setWednesday(jtbWednesday.isSelected());
614         x10evt.setThursday(jtbThursday.isSelected());
615         x10evt.setFriday(jtbFriday.isSelected());
616         x10evt.setSaturday(jtbSaturday.isSelected());
617     }
618 
619     /***
620      * With the information that the user entered
621      * create a new X10Events object and pass its
622      * interface.
623      * @return the X10Events object with all values set.
624      */
625     private IX10Events saveDetailData()
626     {
627         X10Events returnEvents = new X10Events(); // build a vector for return
628         Item type = (Item) jcbInstalledModules.getSelectedItem();
629         try
630         {
631             int i = Integer.parseInt((type.toString()).substring(1));
632             returnEvents.setDeviceModule(new X10Module(type.toString().charAt(0), i, "", "Event", type.getType()));
633         }
634         catch (NumberFormatException err)
635         {
636              returnEvents.setDeviceModule(new X10Module(type.toString().charAt(0), 1, "", "Event", type.getType()));
637         }
638         returnEvents.setDescription(descriptionTf.getText()); //description
639         /* set value to off or on regardless of the type */
640         if (jcbStatus.getSelectedIndex() == 0)
641         {
642             returnEvents.setAction(sEventsArray[0]);
643         }
644         if (jcbStatus.getSelectedIndex() == 1)
645         {
646             returnEvents.setAction(sEventsArray[1]);
647         }
648         /* if the item is a lamp and the value is Light Control then set it to the dim commands */
649         if (jcbLightModuleAction.getSelectedIndex() == 0 && jcbStatus.getSelectedIndex() == 2)
650         {
651             returnEvents.setAction("-" + jsLightController.getValue());
652         }
653         if (jcbLightModuleAction.getSelectedIndex() == 1 && jcbStatus.getSelectedIndex() == 2)
654         {
655             returnEvents.setAction("+" + jsLightController.getValue());
656         }
657         /* All commands */
658         if (jcbStatus.getSelectedIndex() == 3)
659         {
660             returnEvents.setAction(sEventsArray[3]);
661         }
662         if (jcbStatus.getSelectedIndex() == 4)
663         {
664             returnEvents.setAction(sEventsArray[4]);
665         }
666         if (jcbStatus.getSelectedIndex() == 5)
667         {
668             returnEvents.setAction(sEventsArray[5]);
669         }
670 
671         saveDaysOfWeek(returnEvents);
672         /* Time field to 24 hour clock format */
673         try
674         {
675             Calendar timestamp = new GregorianCalendar();
676 
677             timestamp.setTime(DATE_FORMAT_HMMA.parse(startTf.getText()));
678             returnEvents.setTime(timestamp);
679         }
680         catch (ParseException pe)
681         {
682             returnEvents.setTime(new GregorianCalendar()); //go with default time
683         }
684         return returnEvents;
685     }
686 
687 
688     /***
689      * Do a check on the item selected and if its an appliance
690      * module selected and they try to use light event commands
691      * then warn the user of this issue.
692      * @return false if it is not a light module.
693      */
694     private boolean checkIsLightDevice()
695     {
696         Item item = (Item) jcbInstalledModules.getSelectedItem();
697         if (item.getType() == APPLIANCE_MODULE_ON && (jcbStatus.getSelectedIndex() == 3 || jcbStatus.getSelectedIndex() == 4))
698         {
699             JOptionPane.showMessageDialog(null,
700                     "For appliance modules you cannot select\nlight action events.",
701                     "Error",
702                     JOptionPane.ERROR_MESSAGE);
703             return false;
704         }
705         return true;
706     }
707 
708     private void showErrorMessage(String errorString)
709     {
710         JOptionPane.showMessageDialog(null,
711                 errorString,
712                 "Failed Information",
713                 JOptionPane.ERROR_MESSAGE);
714     }
715 
716 }