001: /*
002: * Copyright (C) 2004 Giuseppe MANNA
003: *
004: * This file is part of FreeReportBuilder
005: *
006: * FreeReportBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package it.frb;
023:
024: import java.io.*;
025: import java.util.*;
026:
027: public class AppProp {
028: private static final String KEY_FONT_SIZE = "laf.FontSize";
029: private static final String KEY_LOOK_AND_FEEL = "laf.LookFeel";
030:
031: private static final String KEY_WND_X = "wnd.X";
032: private static final String KEY_WND_Y = "wnd.Y";
033: private static final String KEY_WND_WIDTH = "wnd.Width";
034: private static final String KEY_WND_HEIGHT = "wnd.Height";
035:
036: private static final String KEY_START_UPC = "app.StartUPC";
037: private static final String KEY_USE_MULTI_TRANS = "app.BDatabaseUseMultiTrans";
038: private static final String KEY_USE_RESULT_SET = "app.BUseResultSet";
039:
040: private static Properties properties = null;
041: private File file = null;
042:
043: public AppProp(File f) {
044: this .properties = new Properties();
045: this .file = f;
046:
047: try {
048: this .properties.load(new FileInputStream(f));
049: } catch (IOException exc) {
050: System.out.println();
051: }
052: }
053:
054: public String getLookAndFeel(String s) {
055: return getString(KEY_LOOK_AND_FEEL, s);
056: }
057:
058: public void setLookAndFeel(String s) {
059: set(KEY_LOOK_AND_FEEL, s);
060: save();
061: }
062:
063: public String getStartupUPC(String s) {
064: return getString(KEY_START_UPC, s);
065: }
066:
067: public void setStartupUPC(String s) {
068: set(KEY_START_UPC, s);
069: save();
070: }
071:
072: public boolean getUseMultiTransaction(boolean s) {
073: return getBoolean(KEY_USE_MULTI_TRANS, s);
074: }
075:
076: public void setUseMultiTransaction(boolean s) {
077: set(KEY_USE_MULTI_TRANS, s);
078: save();
079: }
080:
081: public boolean getUseResultSet(boolean s) {
082: return getBoolean(KEY_USE_RESULT_SET, s);
083: }
084:
085: public void setUseResultSet(boolean s) {
086: set(KEY_USE_RESULT_SET, s);
087: save();
088: }
089:
090: public int getFontSize(int n) {
091: return getInt(KEY_FONT_SIZE, n);
092: }
093:
094: public void setFontSize(int n) {
095: set(KEY_FONT_SIZE, n);
096: save();
097: }
098:
099: public int getWndX(int n) {
100: return getInt(KEY_WND_X, n);
101: }
102:
103: public void setWndX(int n) {
104: set(KEY_WND_X, n);
105: save();
106: }
107:
108: public int getWndY(int n) {
109: return getInt(KEY_WND_Y, n);
110: }
111:
112: public void setWndY(int n) {
113: set(KEY_WND_Y, n);
114: save();
115: }
116:
117: public int getWndWidth(int n) {
118: return getInt(KEY_WND_WIDTH, n);
119: }
120:
121: public void setWndWidth(int n) {
122: set(KEY_WND_WIDTH, n);
123: save();
124: }
125:
126: public int getWndHeight(int n) {
127: return getInt(KEY_WND_HEIGHT, n);
128: }
129:
130: public void setWndHeight(int n) {
131: set(KEY_WND_HEIGHT, n);
132: save();
133: }
134:
135: private String getString(String sKey, String sDefValue) {
136: return this .properties.getProperty(sKey, sDefValue);
137: }
138:
139: private boolean getBoolean(String sKey, boolean bDefValue) {
140: String s = this .properties.getProperty(sKey);
141:
142: return s == null ? bDefValue : s.equalsIgnoreCase("TRUE");
143: }
144:
145: private int getInt(String sKey, int nDefValue) {
146: String s = this .properties.getProperty(sKey);
147:
148: return (s == null || s.length() == 0) ? nDefValue : Integer
149: .parseInt(s);
150: }
151:
152: private void set(String sKey, String sValue) {
153: this .properties.setProperty(sKey, sValue);
154: }
155:
156: private void set(String sKey, boolean bValue) {
157: this .properties.setProperty(sKey, String.valueOf(bValue));
158: }
159:
160: private void set(String sKey, int nValue) {
161: this .properties.setProperty(sKey, String.valueOf(nValue));
162: }
163:
164: private void save() {
165: try {
166: FileOutputStream fos = new FileOutputStream(this .file);
167:
168: properties.store(fos, " "
169: + ConfigurationProperties.APPLICATION_NAME);
170:
171: fos.close();
172: } catch (Exception exc) {
173: System.out.println(exc.getMessage());
174: }
175: }
176: }
|