01: /*
02: * SQLeonardo :: java database frontend
03: * Copyright (C) 2004 nickyb@users.sourceforge.net
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or (at your option) any later version.
09: *
10: * This program 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
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: *
19: */
20:
21: package nickyb.sqleonardo.environment;
22:
23: import java.util.Hashtable;
24:
25: import nickyb.sqleonardo.querybuilder.QueryBuilder;
26:
27: public class Preferences {
28: /* BAD */
29: public static void loadDefaults() {
30: if (Application.session.mount(Application.ENTRY_PREFERENCES)
31: .size() == 0) {
32: Application.session.mount(Application.ENTRY_PREFERENCES)
33: .add(new Hashtable());
34:
35: set("window.height", new Integer(600));
36: set("window.width", new Integer(800));
37:
38: set("explorer.navigator.datasources.name.width",
39: new Integer(30));
40: set("explorer.navigator.datasources.url.width",
41: new Integer(250));
42: set("explorer.navigator.datasources.status.width",
43: new Integer(30));
44: }
45:
46: QueryBuilder.autoJoin = getBoolean("querybuilder.auto-join",
47: true);
48: QueryBuilder.autoAlias = getBoolean("querybuilder.auto-alias",
49: true);
50: QueryBuilder.useAlwaysQuote = getBoolean(
51: "querybuilder.use-quote", true);
52: QueryBuilder.loadObjectsAtOnce = getBoolean(
53: "querybuilder.load-objects-at-once", true);
54: QueryBuilder.selectAllColumns = getBoolean(
55: "querybuilder.select-all-columns", true);
56: }
57:
58: private static Hashtable get() {
59: return (Hashtable) Application.session.mount(
60: Application.ENTRY_PREFERENCES).get(0);
61: }
62:
63: public static void set(String key, Object value) {
64: get().put(key, value);
65: }
66:
67: public static boolean getBoolean(String key) {
68: return ((Boolean) get().get(key)).booleanValue();
69: }
70:
71: public static boolean getBoolean(String key, boolean defaultValue) {
72: if (!get().containsKey(key))
73: set(key, new Boolean(defaultValue));
74:
75: return getBoolean(key);
76: }
77:
78: public static int getInteger(String key) {
79: return ((Integer) get().get(key)).intValue();
80: }
81:
82: public static int getInteger(String key, int defaultValue) {
83: if (!get().containsKey(key))
84: set(key, new Integer(defaultValue));
85:
86: return getInteger(key);
87: }
88:
89: public static String getString(String key) {
90: return get().get(key).toString();
91: }
92:
93: public static String getString(String key, String defaultValue) {
94: if (!get().containsKey(key))
95: set(key, defaultValue);
96:
97: return getString(key);
98: }
99: }
|