1 package org.wcb.autohome.util;
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 java.util.Properties;
21
22 import org.wcb.autohome.interfaces.X10DeviceConstants;
23 import org.wcb.common.UIDefaultsLoader;
24
25 /***
26 * Project: Alice X10 Interface
27 *
28 * Filename: $Id: PropertyLoader.java,v 1.4 2003/12/31 00:08:12 wbogaardt Exp $
29 *
30 * Abstract: User default loader for UIManager
31 *
32 * @author wbogaardt
33 * @version $Id: PropertyLoader.java,v 1.4 2003/12/31 00:08:12 wbogaardt Exp $
34 */
35 public class PropertyLoader extends UIDefaultsLoader implements X10DeviceConstants{
36
37 private String userHome = System.getProperty("user.home");
38
39 public PropertyLoader()
40 {
41 this(DEFAULTFILENAME);
42 }
43
44 public PropertyLoader(String fileName)
45 {
46 this(fileName, null);
47 }
48
49 public PropertyLoader(String fileName, String directory)
50 {
51 if (directory != null) {
52 userHome = directory;
53 }
54 swingProperties = load(userHome, fileName);
55 }
56
57 /***
58 * Load the specified properties file. If the file does not exist, a
59 * default file will be created.
60 */
61 public Properties load(String directory, String file)
62 {
63 return super.load(directory,file);
64 }
65
66 public Properties getProperties(){
67 if(swingProperties == null)
68 {
69 swingProperties = load(userHome,DEFAULTFILENAME);
70 }
71 return swingProperties;
72 }
73
74
75
76 public void setProperty(String prop, Object value) {
77 swingProperties.put(prop,value);
78 }
79
80
81 /***
82 * Saves the setting in jhome.prop with the key
83 * initial.on.start with a string of true or false.
84 * @param bValue Boolean to be saved in property hash.
85 */
86 public void setInitialOnStart(boolean bValue){
87 if (bValue)
88 {
89 swingProperties.put(CONNECT_ON_START,TRUE);
90 }
91 if (!bValue)
92 {
93 swingProperties.put(CONNECT_ON_START,FALSE);
94 }
95 }
96
97 /***
98 * Reads the property value of initial.on.start for a value
99 * of true or false. A true indicates start the serial port connection.
100 *
101 * @return Boolean true or false from property file.
102 */
103 public boolean getInitialOnStart(){
104 String sStart = swingProperties.getProperty(CONNECT_ON_START);
105 if (sStart != null && sStart.startsWith(FALSE))
106 {
107 return true;
108 }
109 return false;
110 }
111 }