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: StatusBar.java,v 1.8 2004/07/22 03:06:49 wbogaardt Exp $
21 * Abstract: Message bar for all panels
22 *
23 * $Log: StatusBar.java,v $
24 * Revision 1.8 2004/07/22 03:06:49 wbogaardt
25 * removed deprecated method calls.
26 *
27 * Revision 1.7 2004/02/25 21:38:32 wbogaardt
28 * added javadocs and fixed formating for checkstyle report
29 *
30 * Revision 1.6 2004/02/01 20:42:48 wbogaardt
31 * removed form panel reference and changed sizing of the split bars
32 *
33 * Revision 1.5 2003/12/22 20:51:29 wbogaardt
34 * refactored name assignments and formatted code for readability.
35 *
36 * Revision 1.4 2003/12/20 20:13:01 wbogaardt
37 * modified formating and some names for labels
38 *
39 * Revision 1.3 2003/12/12 01:34:28 wbogaardt
40 * fixed message interface was throwing stack overflow. Fixed display bug with Serial panel.
41 *
42 * Revision 1.2 2003/12/11 23:10:07 wbogaardt
43 * cleaned up exception handeling and logging of system.out messages
44 *
45 *
46 */
47
48 import javax.swing.SwingConstants;
49 import javax.swing.JTextArea;
50 import javax.swing.ImageIcon;
51 import javax.swing.JLabel;
52 import javax.swing.BorderFactory;
53 import javax.swing.JScrollPane;
54 import javax.swing.JPanel;
55 import java.util.StringTokenizer;
56 import java.util.Calendar;
57 import java.util.GregorianCalendar;
58 import java.awt.*;
59
60 import org.wcb.autohome.interfaces.MessageInterface;
61
62 /***
63 * Displays the status bar at the bottom of the swing application.
64 */
65 public class StatusBar extends JPanel implements MessageInterface, SwingConstants {
66
67 private JTextArea jtaPrintArea;
68 private ImageIcon iiConnectImage, iiDisconnectImage, iiSunriseImage, iiSunsetImage;
69 private JLabel jlConnectDisplay, jlSunrise, jlSunset;
70 private boolean bCM11A = false;
71
72 /***
73 * create the status bar and set up some components
74 */
75 public StatusBar() {
76 setupComponents();
77 printMessage("Finding last opened file");
78 }
79
80 /***
81 * Sets up the components
82 */
83 private void setupComponents() {
84 setLayout(new BorderLayout());
85 setBorder(BorderFactory.createTitledBorder
86 (BorderFactory.createLineBorder
87 (Color.yellow), "Status"));
88 jtaPrintArea = new JTextArea(3, 50);
89 iiConnectImage = AutoHomeAdminSession.INTERFACE_ON;
90 iiDisconnectImage = AutoHomeAdminSession.INTERFACE_OFF;
91 iiSunriseImage = AutoHomeAdminSession.SUNRISE;
92 iiSunsetImage = AutoHomeAdminSession.SUNSET;
93 jlSunrise = new JLabel("06:00", iiSunriseImage, CENTER);
94 jlSunset = new JLabel("17:00", iiSunsetImage, CENTER);
95 jlConnectDisplay = new JLabel(iiDisconnectImage);
96 JScrollPane js = new JScrollPane(jtaPrintArea);
97 add(js, BorderLayout.CENTER);
98 add(createStatusPanel(), BorderLayout.EAST);
99 }
100
101 /***
102 * This panel creates the icons to the right of
103 * the status bar.
104 * @return The icons panel.
105 */
106 private JPanel createStatusPanel() {
107 GridBagConstraints gridBagConstraints;
108 JPanel iconsPanel = new JPanel();
109 iconsPanel.setLayout(new GridBagLayout());
110 iconsPanel.add(jlConnectDisplay, new GridBagConstraints());
111
112 iconsPanel.add(jlSunrise, new GridBagConstraints());
113
114 gridBagConstraints = new GridBagConstraints();
115 gridBagConstraints.gridx = 1;
116 gridBagConstraints.gridy = 1;
117 iconsPanel.add(jlSunset, gridBagConstraints);
118
119 return iconsPanel;
120 }
121
122 /***
123 * This returns an instance of the MessageInterface
124 * that is used in this class to control the various
125 * messages.
126 * @return MessageInterface the messages to print to a console.
127 */
128 public MessageInterface getInterface() {
129 return this;
130 }
131
132 /***
133 * This method takes a string message and displays it
134 * in a text area. String messages are passed via
135 * the Message Interface.
136 * @param theMessage the message to print to the print area.
137 */
138 public void printMessage(String theMessage) {
139 GregorianCalendar currDate = new GregorianCalendar();
140 jtaPrintArea.append("[" + currDate.get(Calendar.HOUR) + ":" + currDate.get(Calendar.MINUTE) + ":"
141 + currDate.get(Calendar.SECOND) + "] ");
142 jtaPrintArea.append(theMessage + "\n");
143 }
144
145 /***
146 * This method takes a boolean value and displays
147 * an Icon label that denotes wether the interface
148 * is connected to the serial port or not.
149 * @param connected true shows a connected icon
150 */
151 public void interfaceConnected(boolean connected) {
152 if (connected)
153 {
154 jlConnectDisplay.setIcon(iiConnectImage);
155 }
156 else
157 {
158 jlConnectDisplay.setIcon(iiDisconnectImage);
159 }
160 }
161
162 /***
163 * Sets the sun rise time to a printable string
164 * @param timeString printable string of hh:mm A
165 */
166 public void setSunriseTime(String timeString) {
167 jlSunrise.setText(timeString);
168 }
169
170 /***
171 * Sets the sunset time to a printable string
172 * @param timeString printable string of hh:mm A
173 */
174 public void setSunsetTime(String timeString) {
175 jlSunset.setText(timeString);
176 }
177
178 /***
179 * Gets the sunrise time as a string.
180 * @return Sunrise time in HH:mm (24 hour format)
181 */
182 public String getSunriseTime() {
183 StringBuffer sunrise = new StringBuffer("");
184 String returnValue = null;
185 try
186 {
187 StringTokenizer hour = new StringTokenizer(jlSunrise.getText(), ":");
188 int hour24 = Integer.parseInt(hour.nextToken());
189 String minutes = hour.nextToken();
190 if (hour24 < 10)
191 {
192 sunrise.append("0" + hour24 + ":" + minutes);
193 }
194 returnValue = sunrise.toString();
195 }
196 catch (NumberFormatException err)
197 {
198 returnValue = "00:00";
199 }
200 return returnValue;
201 }
202
203 /***
204 * The sunset time in 24 hour format
205 * @return Sunsiet in HH:mm
206 */
207 public String getSunsetTime() {
208 return jlSunset.getText();
209 }
210
211 /***
212 * Boolean value if the serial port is connected to CM11A
213 * @return True if CM11A x10 interface
214 */
215 public boolean isGatewayCM11A()
216 {
217 return bCM11A;
218 }
219
220 /***
221 * If the the gateway is a CM11A set this to true.
222 * This way allows the Time panel to enable its display
223 * and allows the user to set time information for CM11A or CM12U gateways.
224 * @param bValue set the to true if the device connected is a CM11A interface
225 */
226 public void isGatewayCM11A(boolean bValue)
227 {
228 bCM11A = bValue;
229 }
230 }
231
232