001: /*
002: * SQLeonardo :: java database frontend
003: * Copyright (C) 2004 nickyb@users.sourceforge.net
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: *
019: */
020:
021: package nickyb.sqleonardo.environment.mdi;
022:
023: import java.awt.GridLayout;
024: import java.util.Locale;
025:
026: import javax.swing.JCheckBox;
027: import javax.swing.JComboBox;
028: import javax.swing.JLabel;
029: import javax.swing.JMenuItem;
030: import javax.swing.JPanel;
031: import javax.swing.JSeparator;
032: import javax.swing.JTabbedPane;
033: import javax.swing.border.EmptyBorder;
034:
035: import nickyb.sqleonardo.common.gui.AbstractDialogConfirm;
036: import nickyb.sqleonardo.common.util.I18n;
037: import nickyb.sqleonardo.common.util.LocaleAdapter;
038: import nickyb.sqleonardo.environment.Application;
039: import nickyb.sqleonardo.environment.Preferences;
040: import nickyb.sqleonardo.querybuilder.QueryBuilder;
041:
042: public class DialogPreferences extends AbstractDialogConfirm {
043: private JCheckBox optQbAutoJoin;
044: private JCheckBox optQbAutoAlias;
045: private JCheckBox optQbUseQuote;
046: private JCheckBox optQbUseSchema;
047: private JCheckBox optQbLoadAtOnce;
048: private JCheckBox optQbSelectAll;
049:
050: private JLabel jLabelLanguage = new JLabel();
051: private JComboBox jComboBoxLanguage = new JComboBox();
052:
053: public DialogPreferences() {
054: super (Application.window, Application.PROGRAM + ".preferences",
055: 350, INITIAL_HEIGHT);
056:
057: JPanel pnlQB = new JPanel(new GridLayout(0, 1));
058: pnlQB.setBorder(new EmptyBorder(10, 5, 90, 5));
059:
060: pnlQB
061: .add(optQbAutoJoin = new JCheckBox(I18n
062: .getString("application.preferences.autoJoin",
063: "auto join"), Preferences.getBoolean(
064: "querybuilder.auto-join", true)));
065: pnlQB
066: .add(optQbAutoAlias = new JCheckBox(I18n.getString(
067: "application.preferences.autoAlias",
068: "auto alias"), Preferences.getBoolean(
069: "querybuilder.auto-alias", true)));
070: pnlQB.add(new JSeparator());
071: pnlQB.add(optQbUseQuote = new JCheckBox(I18n.getString(
072: "application.preferences.alwaysQuoteIdentifiers",
073: "always quote identifiers"), Preferences.getBoolean(
074: "querybuilder.use-quote", true)));
075: pnlQB.add(optQbUseSchema = new JCheckBox(I18n.getString(
076: "application.preferences.useSchemaName",
077: "use schema name in syntax definition"), Preferences
078: .getBoolean("querybuilder.use-schema", true)));
079: pnlQB.add(new JSeparator());
080: pnlQB
081: .add(optQbLoadAtOnce = new JCheckBox(I18n.getString(
082: "application.preferences.loadObjectsAtOnce",
083: "load table objects list at once"), Preferences
084: .getBoolean(
085: "querybuilder.load-objects-at-once",
086: true)));
087: pnlQB.add(optQbSelectAll = new JCheckBox(I18n.getString(
088: "application.preferences.selectAllColumns",
089: "aout select all colmuns"), Preferences.getBoolean(
090: "querybuilder.select-all-columns", true)));
091:
092: jLabelLanguage.setText(I18n.getString(
093: "application.preferences.language", "language"));
094:
095: // Add all the available languages...
096: java.util.List list = I18n.getListOfAvailLanguages();
097: list.add(0, Locale.getDefault());
098:
099: if (!Locale.getDefault().equals(Locale.ENGLISH)) {
100: list.add(1, Locale.ENGLISH);
101: }
102:
103: int selectedItem = 0;
104: for (int i = 0; i < list.size(); ++i) {
105: java.util.Locale loc = (java.util.Locale) list.get(i);
106: jComboBoxLanguage.addItem(new LocaleAdapter(loc));
107:
108: if (I18n.getCurrentLocale().toString().equals(
109: loc.toString())) {
110: selectedItem = i;
111: }
112: // else
113: // {
114: // System.out.println(I18n.getCurrentLocale().toString() + " != " + loc.toString());
115: // }
116: }
117: jComboBoxLanguage.setSelectedIndex(selectedItem);
118:
119: JPanel pnlGeneral = new JPanel(new GridLayout(0, 1));
120: pnlGeneral.setBorder(new EmptyBorder(10, 5, 215, 5));
121:
122: pnlGeneral.add(jLabelLanguage);
123: pnlGeneral.add(jComboBoxLanguage);
124:
125: JTabbedPane options = new JTabbedPane();
126: options.addTab("general", pnlGeneral);
127: options.addTab("query builder", pnlQB);
128:
129: getContentPane().add(options);
130: }
131:
132: protected void onOpen() {
133: Object[] items = Application.window.menubar.getMenu(
134: MDIMenubar.IDX_WINDOW).getMenuComponents();
135: for (int i = 0; i < items.length; i++) {
136: if (items[i] instanceof JMenuItem) {
137: String txt = ((JMenuItem) items[i]).getText();
138: if (txt.indexOf(" - QUERY : ") != -1) {
139: optQbAutoAlias.setEnabled(false);
140: optQbAutoJoin.setEnabled(false);
141: optQbUseQuote.setEnabled(false);
142: optQbUseSchema.setEnabled(false);
143: optQbLoadAtOnce.setEnabled(false);
144: optQbSelectAll.setEnabled(false);
145:
146: break;
147: }
148: }
149: }
150: }
151:
152: protected boolean onConfirm() {
153: QueryBuilder.autoJoin = optQbAutoJoin.isSelected();
154: QueryBuilder.autoAlias = optQbAutoAlias.isSelected();
155: QueryBuilder.useAlwaysQuote = optQbUseQuote.isSelected();
156: QueryBuilder.loadObjectsAtOnce = optQbLoadAtOnce.isSelected();
157: QueryBuilder.selectAllColumns = optQbSelectAll.isSelected();
158:
159: Preferences.set("querybuilder.auto-join", new Boolean(
160: optQbAutoJoin.isSelected()));
161: Preferences.set("querybuilder.auto-alias", new Boolean(
162: optQbAutoAlias.isSelected()));
163: Preferences.set("querybuilder.use-quote", new Boolean(
164: optQbUseQuote.isSelected()));
165: Preferences.set("querybuilder.use-schema", new Boolean(
166: optQbUseSchema.isSelected()));
167: Preferences.set("querybuilder.load-objects-at-once",
168: new Boolean(optQbLoadAtOnce.isSelected()));
169: Preferences.set("querybuilder.select-all-columns", new Boolean(
170: optQbSelectAll.isSelected()));
171:
172: if (jComboBoxLanguage.getSelectedIndex() >= 0) {
173: LocaleAdapter la = (LocaleAdapter) jComboBoxLanguage
174: .getSelectedItem();
175: I18n.setCurrentLocale(la.getLocale());
176: Preferences.set("app.locale", la.getLocale().toString());
177: }
178:
179: return true;
180: }
181: }
|