001: /*
002: * GeneralOptionsPanel.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.settings;
013:
014: import java.util.Collection;
015: import javax.swing.DefaultComboBoxModel;
016: import javax.swing.JPanel;
017: import workbench.gui.components.WbCheckBoxLabel;
018: import workbench.log.LogMgr;
019: import workbench.resource.ResourceMgr;
020: import workbench.resource.Settings;
021: import workbench.util.StringUtil;
022: import workbench.util.WbLocale;
023:
024: /**
025: *
026: * @author support@sql-workbench.net
027: */
028: public class GeneralOptionsPanel extends JPanel implements
029: workbench.interfaces.Restoreable {
030:
031: /** Creates new form GeneralOptionsPanel */
032: public GeneralOptionsPanel() {
033: initComponents();
034: pdfReaderPath.setAllowMultiple(false);
035: standardFont.setAllowFontReset(true);
036: String[] updTypes = new String[] {
037: ResourceMgr.getString("LblUpdCheckNever"),
038: ResourceMgr.getString("LblUpdCheckDaily"),
039: ResourceMgr.getString("LblUpdCheck7"),
040: ResourceMgr.getString("LblUpdCheck14"),
041: ResourceMgr.getString("LblUpdCheck30") };
042: checkInterval.setModel(new DefaultComboBoxModel(updTypes));
043: }
044:
045: public void restoreSettings() {
046: msgLogFont.setSelectedFont(Settings.getInstance()
047: .getMsgLogFont());
048: standardFont.setSelectedFont(Settings.getInstance()
049: .getStandardFont());
050: pdfReaderPath.setFilename(Settings.getInstance()
051: .getPDFReaderPath());
052: logLevel.setSelectedItem(LogMgr.getLevel());
053: int days = Settings.getInstance().getUpdateCheckInterval();
054: if (days == 1) {
055: checkInterval.setSelectedIndex(1);
056: } else if (days == 7) {
057: checkInterval.setSelectedIndex(2);
058: } else if (days == 14) {
059: checkInterval.setSelectedIndex(3);
060: } else if (days == 30) {
061: checkInterval.setSelectedIndex(4);
062: } else {
063: checkInterval.setSelectedIndex(0);
064: }
065: languageDropDown.removeAllItems();
066: String currentLang = Settings.getInstance().getLanguage()
067: .getLanguage();
068:
069: Collection<WbLocale> locales = Settings.getInstance()
070: .getLanguages();
071: int index = 0;
072: int currentIndex = -1;
073: for (WbLocale l : locales) {
074: languageDropDown.addItem(l);
075: if (l.getLocale().getLanguage().equals(currentLang)) {
076: currentIndex = index;
077: }
078: index++;
079: }
080: if (currentIndex != -1) {
081: languageDropDown.setSelectedIndex(currentIndex);
082: }
083: }
084:
085: public void saveSettings() {
086: Settings set = Settings.getInstance();
087:
088: // General settings
089: set.setStandardFont(standardFont.getSelectedFont());
090: set.setUseEncryption(this .useEncryption.isSelected());
091: set.setMsgLogFont(msgLogFont.getSelectedFont());
092: set.setUseAnimatedIcon(this .enableAnimatedIcon.isSelected());
093: set.setQuoteChar(this .quoteCharField.getText().trim());
094: set.setConsolidateLogMsg(this .consolidateLog.isSelected());
095: set.setDefaultTextDelimiter(this .textDelimiterField.getText());
096: set.setPDFReaderPath(pdfReaderPath.getFilename());
097: int index = checkInterval.getSelectedIndex();
098: switch (index) {
099: case 0:
100: set.setUpdateCheckInterval(-1);
101: break;
102: case 1:
103: set.setUpdateCheckInterval(1);
104: break;
105: case 2:
106: set.setUpdateCheckInterval(7);
107: break;
108: case 3:
109: set.setUpdateCheckInterval(14);
110: break;
111: case 4:
112: set.setUpdateCheckInterval(30);
113: break;
114: default:
115: set.setUpdateCheckInterval(-1);
116: break;
117: }
118: String level = (String) logLevel.getSelectedItem();
119: LogMgr.setLevel(level);
120: set.setProperty("workbench.log.level", level);
121: WbLocale wl = (WbLocale) languageDropDown.getSelectedItem();
122: set.setLanguage(wl.getLocale());
123: }
124:
125: /** This method is called from within the constructor to
126: * initialize the form.
127: * WARNING: Do NOT modify this code. The content of this method is
128: * always regenerated by the Form Editor.
129: */
130: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
131: private void initComponents() {
132: java.awt.GridBagConstraints gridBagConstraints;
133:
134: useEncryptionLabel = new WbCheckBoxLabel();
135: useEncryption = new javax.swing.JCheckBox();
136: textDelimiterLabel = new javax.swing.JLabel();
137: textDelimiterField = new javax.swing.JTextField();
138: quoteCharLabel = new javax.swing.JLabel();
139: quoteCharField = new javax.swing.JTextField();
140: jPanel1 = new javax.swing.JPanel();
141: enableAnimatedIconLabel = new WbCheckBoxLabel();
142: enableAnimatedIcon = new javax.swing.JCheckBox();
143: consolidateLogLabel = new WbCheckBoxLabel();
144: consolidateLog = new javax.swing.JCheckBox();
145: msgFontLabel = new javax.swing.JLabel();
146: standardFontLabel = new javax.swing.JLabel();
147: msgLogFont = new workbench.gui.components.WbFontPicker();
148: standardFont = new workbench.gui.components.WbFontPicker();
149: pdfReaderPathLabel = new javax.swing.JLabel();
150: pdfReaderPath = new workbench.gui.components.WbFilePicker();
151: logLevelLabel = new javax.swing.JLabel();
152: logLevel = new javax.swing.JComboBox();
153: checkUpdatesLabel = new WbCheckBoxLabel();
154: checkInterval = new javax.swing.JComboBox();
155: langLabel = new javax.swing.JLabel();
156: languageDropDown = new javax.swing.JComboBox();
157:
158: setLayout(new java.awt.GridBagLayout());
159:
160: useEncryptionLabel.setLabelFor(useEncryption);
161: useEncryptionLabel.setText(ResourceMgr
162: .getString("LblUseEncryption"));
163: useEncryptionLabel.setToolTipText(ResourceMgr
164: .getDescription("LblUseEncryption"));
165: gridBagConstraints = new java.awt.GridBagConstraints();
166: gridBagConstraints.gridx = 0;
167: gridBagConstraints.gridy = 2;
168: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
169: gridBagConstraints.insets = new java.awt.Insets(7, 12, 0, 0);
170: add(useEncryptionLabel, gridBagConstraints);
171:
172: useEncryption.setFont(null);
173: useEncryption.setSelected(Settings.getInstance()
174: .getUseEncryption());
175: useEncryption.setText("");
176: useEncryption.setBorder(null);
177: useEncryption
178: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
179: useEncryption
180: .setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
181: useEncryption.setIconTextGap(5);
182: gridBagConstraints = new java.awt.GridBagConstraints();
183: gridBagConstraints.gridx = 1;
184: gridBagConstraints.gridy = 2;
185: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
186: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
187: gridBagConstraints.weightx = 1.0;
188: gridBagConstraints.insets = new java.awt.Insets(7, 10, 0, 11);
189: add(useEncryption, gridBagConstraints);
190:
191: textDelimiterLabel.setText(ResourceMgr
192: .getString("LblFieldDelimiter"));
193: textDelimiterLabel.setToolTipText(ResourceMgr
194: .getDescription("LblFieldDelimiter"));
195: gridBagConstraints = new java.awt.GridBagConstraints();
196: gridBagConstraints.gridx = 0;
197: gridBagConstraints.gridy = 13;
198: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
199: gridBagConstraints.insets = new java.awt.Insets(2, 12, 0, 0);
200: add(textDelimiterLabel, gridBagConstraints);
201:
202: textDelimiterField
203: .setHorizontalAlignment(javax.swing.JTextField.LEFT);
204: textDelimiterField.setText(Settings.getInstance()
205: .getDefaultTextDelimiter(true));
206: gridBagConstraints = new java.awt.GridBagConstraints();
207: gridBagConstraints.gridx = 1;
208: gridBagConstraints.gridy = 13;
209: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
210: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
211: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
212: gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 15);
213: add(textDelimiterField, gridBagConstraints);
214:
215: quoteCharLabel.setText(ResourceMgr.getString("LblQuoteChar"));
216: quoteCharLabel.setToolTipText(ResourceMgr
217: .getDescription("LblQuoteChar"));
218: gridBagConstraints = new java.awt.GridBagConstraints();
219: gridBagConstraints.gridx = 0;
220: gridBagConstraints.gridy = 14;
221: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
222: gridBagConstraints.insets = new java.awt.Insets(2, 12, 0, 0);
223: add(quoteCharLabel, gridBagConstraints);
224:
225: quoteCharField
226: .setHorizontalAlignment(javax.swing.JTextField.LEFT);
227: quoteCharField.setText(Settings.getInstance().getQuoteChar());
228: gridBagConstraints = new java.awt.GridBagConstraints();
229: gridBagConstraints.gridx = 1;
230: gridBagConstraints.gridy = 14;
231: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
232: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
233: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
234: gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 15);
235: add(quoteCharField, gridBagConstraints);
236: gridBagConstraints = new java.awt.GridBagConstraints();
237: gridBagConstraints.gridx = 0;
238: gridBagConstraints.gridy = 17;
239: gridBagConstraints.weighty = 1.0;
240: add(jPanel1, gridBagConstraints);
241:
242: enableAnimatedIconLabel.setLabelFor(enableAnimatedIcon);
243: enableAnimatedIconLabel.setText(ResourceMgr
244: .getString("LblEnableAnimatedIcon"));
245: enableAnimatedIconLabel.setToolTipText(ResourceMgr
246: .getDescription("LblEnableAnimatedIcon"));
247: gridBagConstraints = new java.awt.GridBagConstraints();
248: gridBagConstraints.gridx = 0;
249: gridBagConstraints.gridy = 5;
250: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
251: gridBagConstraints.insets = new java.awt.Insets(6, 12, 1, 0);
252: add(enableAnimatedIconLabel, gridBagConstraints);
253:
254: enableAnimatedIcon.setFont(null);
255: enableAnimatedIcon.setSelected(Settings.getInstance()
256: .getUseAnimatedIcon());
257: enableAnimatedIcon.setText("");
258: enableAnimatedIcon.setBorder(null);
259: enableAnimatedIcon
260: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
261: enableAnimatedIcon
262: .setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
263: enableAnimatedIcon.setIconTextGap(5);
264: gridBagConstraints = new java.awt.GridBagConstraints();
265: gridBagConstraints.gridx = 1;
266: gridBagConstraints.gridy = 5;
267: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
268: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
269: gridBagConstraints.weightx = 1.0;
270: gridBagConstraints.insets = new java.awt.Insets(4, 10, 1, 25);
271: add(enableAnimatedIcon, gridBagConstraints);
272:
273: consolidateLogLabel.setLabelFor(consolidateLog);
274: consolidateLogLabel.setText(ResourceMgr
275: .getString("LblConsolidateLog"));
276: consolidateLogLabel.setToolTipText(ResourceMgr
277: .getDescription("LblConsolidateLog"));
278: gridBagConstraints = new java.awt.GridBagConstraints();
279: gridBagConstraints.gridx = 0;
280: gridBagConstraints.gridy = 3;
281: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
282: gridBagConstraints.insets = new java.awt.Insets(8, 12, 1, 0);
283: add(consolidateLogLabel, gridBagConstraints);
284:
285: consolidateLog.setFont(null);
286: consolidateLog.setSelected(Settings.getInstance()
287: .getConsolidateLogMsg());
288: consolidateLog.setText("");
289: consolidateLog.setBorder(null);
290: consolidateLog
291: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
292: consolidateLog
293: .setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
294: consolidateLog.setIconTextGap(5);
295: gridBagConstraints = new java.awt.GridBagConstraints();
296: gridBagConstraints.gridx = 1;
297: gridBagConstraints.gridy = 3;
298: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
299: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
300: gridBagConstraints.weightx = 1.0;
301: gridBagConstraints.insets = new java.awt.Insets(8, 10, 1, 11);
302: add(consolidateLog, gridBagConstraints);
303:
304: msgFontLabel.setText(ResourceMgr.getString("LblMsgLogFont"));
305: msgFontLabel.setToolTipText(ResourceMgr
306: .getDescription("LblMsgLogFont"));
307: gridBagConstraints = new java.awt.GridBagConstraints();
308: gridBagConstraints.gridx = 0;
309: gridBagConstraints.gridy = 7;
310: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
311: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
312: gridBagConstraints.insets = new java.awt.Insets(4, 12, 0, 0);
313: add(msgFontLabel, gridBagConstraints);
314:
315: standardFontLabel.setText(ResourceMgr
316: .getString("LblStandardFont"));
317: standardFontLabel.setToolTipText(ResourceMgr
318: .getDescription("LblStandardFont"));
319: gridBagConstraints = new java.awt.GridBagConstraints();
320: gridBagConstraints.gridx = 0;
321: gridBagConstraints.gridy = 6;
322: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
323: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
324: gridBagConstraints.insets = new java.awt.Insets(8, 12, 0, 0);
325: add(standardFontLabel, gridBagConstraints);
326: gridBagConstraints = new java.awt.GridBagConstraints();
327: gridBagConstraints.gridx = 1;
328: gridBagConstraints.gridy = 7;
329: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
330: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
331: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
332: gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 15);
333: add(msgLogFont, gridBagConstraints);
334:
335: standardFont.setFont(standardFont.getFont());
336: gridBagConstraints = new java.awt.GridBagConstraints();
337: gridBagConstraints.gridx = 1;
338: gridBagConstraints.gridy = 6;
339: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
340: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
341: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
342: gridBagConstraints.insets = new java.awt.Insets(4, 10, 0, 15);
343: add(standardFont, gridBagConstraints);
344:
345: pdfReaderPathLabel.setText(ResourceMgr
346: .getString("LblReaderPath"));
347: pdfReaderPathLabel.setToolTipText(ResourceMgr
348: .getDescription("LblReaderPath"));
349: gridBagConstraints = new java.awt.GridBagConstraints();
350: gridBagConstraints.gridx = 0;
351: gridBagConstraints.gridy = 15;
352: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
353: gridBagConstraints.insets = new java.awt.Insets(4, 12, 0, 0);
354: add(pdfReaderPathLabel, gridBagConstraints);
355: gridBagConstraints = new java.awt.GridBagConstraints();
356: gridBagConstraints.gridx = 1;
357: gridBagConstraints.gridy = 15;
358: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
359: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
360: gridBagConstraints.insets = new java.awt.Insets(2, 10, 0, 15);
361: add(pdfReaderPath, gridBagConstraints);
362:
363: logLevelLabel.setText(ResourceMgr.getString("LblLogLevel"));
364: logLevelLabel.setToolTipText(ResourceMgr
365: .getDescription("LblLogLevel"));
366: gridBagConstraints = new java.awt.GridBagConstraints();
367: gridBagConstraints.gridx = 0;
368: gridBagConstraints.gridy = 16;
369: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
370: gridBagConstraints.insets = new java.awt.Insets(6, 12, 0, 0);
371: add(logLevelLabel, gridBagConstraints);
372:
373: logLevel.setModel(new javax.swing.DefaultComboBoxModel(
374: new String[] { "ERROR", "WARNING", "INFO", "DEBUG" }));
375: gridBagConstraints = new java.awt.GridBagConstraints();
376: gridBagConstraints.gridx = 1;
377: gridBagConstraints.gridy = 16;
378: gridBagConstraints.gridwidth = 2;
379: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
380: gridBagConstraints.insets = new java.awt.Insets(4, 10, 0, 0);
381: add(logLevel, gridBagConstraints);
382:
383: checkUpdatesLabel.setText(ResourceMgr
384: .getString("LblCheckForUpdate"));
385: checkUpdatesLabel.setToolTipText(ResourceMgr
386: .getDescription("LblCheckForUpdate"));
387: gridBagConstraints = new java.awt.GridBagConstraints();
388: gridBagConstraints.gridx = 0;
389: gridBagConstraints.gridy = 0;
390: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
391: gridBagConstraints.insets = new java.awt.Insets(9, 12, 0, 0);
392: add(checkUpdatesLabel, gridBagConstraints);
393:
394: checkInterval.setModel(new javax.swing.DefaultComboBoxModel(
395: new String[] { "never", "daily", "7 days", "14 days",
396: "30 days" }));
397: gridBagConstraints = new java.awt.GridBagConstraints();
398: gridBagConstraints.gridx = 1;
399: gridBagConstraints.gridy = 0;
400: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
401: gridBagConstraints.insets = new java.awt.Insets(7, 10, 0, 0);
402: add(checkInterval, gridBagConstraints);
403:
404: langLabel.setText(ResourceMgr.getString("LblLanguage"));
405: langLabel.setToolTipText(ResourceMgr
406: .getDescription("LblLanguage"));
407: gridBagConstraints = new java.awt.GridBagConstraints();
408: gridBagConstraints.gridx = 0;
409: gridBagConstraints.gridy = 1;
410: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
411: gridBagConstraints.insets = new java.awt.Insets(3, 12, 0, 0);
412: add(langLabel, gridBagConstraints);
413:
414: languageDropDown.setModel(new javax.swing.DefaultComboBoxModel(
415: new String[] { "English", "German" }));
416: languageDropDown.setToolTipText(ResourceMgr
417: .getDescription("LblLanguage"));
418: gridBagConstraints = new java.awt.GridBagConstraints();
419: gridBagConstraints.gridx = 1;
420: gridBagConstraints.gridy = 1;
421: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
422: gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 15);
423: add(languageDropDown, gridBagConstraints);
424: }// </editor-fold>//GEN-END:initComponents
425:
426: // Variables declaration - do not modify//GEN-BEGIN:variables
427: private javax.swing.JComboBox checkInterval;
428: private javax.swing.JLabel checkUpdatesLabel;
429: private javax.swing.JCheckBox consolidateLog;
430: private javax.swing.JLabel consolidateLogLabel;
431: private javax.swing.JCheckBox enableAnimatedIcon;
432: private javax.swing.JLabel enableAnimatedIconLabel;
433: private javax.swing.JPanel jPanel1;
434: private javax.swing.JLabel langLabel;
435: private javax.swing.JComboBox languageDropDown;
436: private javax.swing.JComboBox logLevel;
437: private javax.swing.JLabel logLevelLabel;
438: private javax.swing.JLabel msgFontLabel;
439: private workbench.gui.components.WbFontPicker msgLogFont;
440: private workbench.gui.components.WbFilePicker pdfReaderPath;
441: private javax.swing.JLabel pdfReaderPathLabel;
442: private javax.swing.JTextField quoteCharField;
443: private javax.swing.JLabel quoteCharLabel;
444: private workbench.gui.components.WbFontPicker standardFont;
445: private javax.swing.JLabel standardFontLabel;
446: private javax.swing.JTextField textDelimiterField;
447: private javax.swing.JLabel textDelimiterLabel;
448: private javax.swing.JCheckBox useEncryption;
449: private javax.swing.JLabel useEncryptionLabel;
450: // End of variables declaration//GEN-END:variables
451:
452: }
|