001: /*
002: * WindowTitleOptionsPanel.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 workbench.gui.components.WbCheckBoxLabel;
015: import workbench.gui.components.WbTraversalPolicy;
016: import workbench.gui.components.WbTraversalPolicy;
017: import workbench.resource.ResourceMgr;
018: import workbench.resource.Settings;
019:
020: /**
021: *
022: * @author support@sql-workbench.net
023: */
024: public class WindowTitleOptionsPanel extends javax.swing.JPanel
025: implements workbench.interfaces.Restoreable {
026:
027: public WindowTitleOptionsPanel() {
028: initComponents();
029: // It is important to add these in the correct order
030: // which is defined by the numeric values from Settings.SHOW_NO_FILENAME
031: // SHOW_FILENAME and SHOW_FULL_PATH
032: this .windowTitleComboBox.addItem(ResourceMgr
033: .getString("TxtShowNone"));
034: this .windowTitleComboBox.addItem(ResourceMgr
035: .getString("TxtShowName"));
036: this .windowTitleComboBox.addItem(ResourceMgr
037: .getString("TxtShowPath"));
038:
039: WbTraversalPolicy policy = new WbTraversalPolicy();
040: policy.addComponent(productAtEnd);
041: policy.addComponent(showProfileGroup);
042: policy.addComponent(showWorkspace);
043: policy.addComponent(windowTitleComboBox);
044: policy.setDefaultComponent(productAtEnd);
045:
046: this .encloseChar.insertItemAt(ResourceMgr
047: .getString("TxtNothingItem"), 0);
048: this .setFocusTraversalPolicy(policy);
049: this .setFocusCycleRoot(false);
050: this .restoreSettings();
051: }
052:
053: public void restoreSettings() {
054: int type = Settings.getInstance()
055: .getShowFilenameInWindowTitle();
056: if (type >= Settings.SHOW_NO_FILENAME
057: && type <= Settings.SHOW_FULL_PATH) {
058: this .windowTitleComboBox.setSelectedIndex(type);
059: }
060: this .showProfileGroup.setSelected(Settings.getInstance()
061: .getShowProfileGroupInWindowTitle());
062: this .showWorkspace.setSelected(Settings.getInstance()
063: .getShowWorkspaceInWindowTitle());
064: this .productAtEnd.setSelected(Settings.getInstance()
065: .getShowProductNameAtEnd());
066: String enclose = Settings.getInstance().getTitleGroupBracket();
067: if (enclose == null) {
068: encloseChar.setSelectedIndex(0);
069: } else {
070: int count = encloseChar.getItemCount();
071: for (int i = 1; i < count; i++) {
072: String item = (String) encloseChar.getItemAt(i);
073: if (item.startsWith(enclose.trim())) {
074: encloseChar.setSelectedIndex(i);
075: break;
076: }
077: }
078: }
079: this .encloseChar.setEnabled(this .showProfileGroup.isSelected());
080: this .titleGroupSep.setText(Settings.getInstance()
081: .getTitleGroupSeparator());
082: }
083:
084: public void saveSettings() {
085: Settings set = Settings.getInstance();
086: set.setShowFilenameInWindowTitle(this .windowTitleComboBox
087: .getSelectedIndex());
088: set.setShowProfileGroupInWindowTitle(showProfileGroup
089: .isSelected());
090: set.setShowWorkspaceInWindowTitle(showWorkspace.isSelected());
091: set.setShowProductNameAtEnd(productAtEnd.isSelected());
092: set.setTitleGroupSeparator(titleGroupSep.getText());
093: int index = this .encloseChar.getSelectedIndex();
094: if (index == 0) {
095: Settings.getInstance().setTitleGroupBracket(null);
096: } else {
097: String bracket = (String) this .encloseChar
098: .getSelectedItem();
099: Settings.getInstance().setTitleGroupBracket(
100: bracket.substring(0, 1));
101: }
102: }
103:
104: /** This method is called from within the constructor to
105: * initialize the form.
106: * WARNING: Do NOT modify this code. The content of this method is
107: * always regenerated by the Form Editor.
108: */
109: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
110: private void initComponents() {
111: java.awt.GridBagConstraints gridBagConstraints;
112:
113: productAtEndLabel = new WbCheckBoxLabel();
114: productAtEnd = new javax.swing.JCheckBox();
115: showProfileGroupLabel = new WbCheckBoxLabel();
116: showProfileGroup = new javax.swing.JCheckBox();
117: showWorkspaceLabel = new WbCheckBoxLabel();
118: showWorkspace = new javax.swing.JCheckBox();
119: windowTitleLabel = new javax.swing.JLabel();
120: windowTitleComboBox = new javax.swing.JComboBox();
121: encloseCharLabel = new javax.swing.JLabel();
122: encloseChar = new javax.swing.JComboBox();
123: jPanel1 = new javax.swing.JPanel();
124: titleGroupSepLabel = new javax.swing.JLabel();
125: titleGroupSep = new javax.swing.JTextField();
126:
127: setLayout(new java.awt.GridBagLayout());
128:
129: productAtEndLabel.setLabelFor(productAtEnd);
130: productAtEndLabel.setText(ResourceMgr
131: .getString("LblShowProductAtEnd"));
132: productAtEndLabel.setToolTipText(ResourceMgr
133: .getDescription("LblShowProductAtEnd"));
134: gridBagConstraints = new java.awt.GridBagConstraints();
135: gridBagConstraints.gridx = 0;
136: gridBagConstraints.gridy = 0;
137: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
138: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
139: gridBagConstraints.insets = new java.awt.Insets(6, 12, 2, 0);
140: add(productAtEndLabel, gridBagConstraints);
141:
142: productAtEnd.setText(" ");
143: productAtEnd.setBorder(javax.swing.BorderFactory
144: .createEmptyBorder(0, 0, 0, 0));
145: productAtEnd.setMargin(new java.awt.Insets(0, 0, 0, 0));
146: gridBagConstraints = new java.awt.GridBagConstraints();
147: gridBagConstraints.gridx = 1;
148: gridBagConstraints.gridy = 0;
149: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
151: gridBagConstraints.insets = new java.awt.Insets(5, 10, 2, 11);
152: add(productAtEnd, gridBagConstraints);
153:
154: showProfileGroupLabel.setLabelFor(showProfileGroup);
155: showProfileGroupLabel.setText(ResourceMgr
156: .getString("LblShowProfileGroup"));
157: showProfileGroupLabel.setToolTipText(ResourceMgr
158: .getDescription("LblShowProfileGroup"));
159: gridBagConstraints = new java.awt.GridBagConstraints();
160: gridBagConstraints.gridx = 0;
161: gridBagConstraints.gridy = 2;
162: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
163: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
164: gridBagConstraints.insets = new java.awt.Insets(7, 12, 2, 0);
165: add(showProfileGroupLabel, gridBagConstraints);
166:
167: showProfileGroup.setText("");
168: showProfileGroup.setBorder(null);
169: showProfileGroup
170: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
171: showProfileGroup
172: .setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
173: showProfileGroup.setIconTextGap(5);
174: showProfileGroup
175: .addChangeListener(new javax.swing.event.ChangeListener() {
176: public void stateChanged(
177: javax.swing.event.ChangeEvent evt) {
178: showProfileGroupStateChanged(evt);
179: }
180: });
181: gridBagConstraints = new java.awt.GridBagConstraints();
182: gridBagConstraints.gridx = 1;
183: gridBagConstraints.gridy = 2;
184: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
185: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
186: gridBagConstraints.weightx = 1.0;
187: gridBagConstraints.insets = new java.awt.Insets(6, 10, 2, 11);
188: add(showProfileGroup, gridBagConstraints);
189:
190: showWorkspaceLabel.setLabelFor(showWorkspace);
191: showWorkspaceLabel.setText(ResourceMgr
192: .getString("LblShowWorkspace"));
193: showWorkspaceLabel.setToolTipText(ResourceMgr
194: .getDescription("LblShowWorkspace"));
195: gridBagConstraints = new java.awt.GridBagConstraints();
196: gridBagConstraints.gridx = 0;
197: gridBagConstraints.gridy = 1;
198: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
199: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
200: gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
201: add(showWorkspaceLabel, gridBagConstraints);
202:
203: showWorkspace.setText("");
204: showWorkspace.setBorder(null);
205: showWorkspace
206: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
207: showWorkspace
208: .setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
209: showWorkspace.setIconTextGap(5);
210: gridBagConstraints = new java.awt.GridBagConstraints();
211: gridBagConstraints.gridx = 1;
212: gridBagConstraints.gridy = 1;
213: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
214: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
215: gridBagConstraints.weightx = 1.0;
216: gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 11);
217: add(showWorkspace, gridBagConstraints);
218:
219: windowTitleLabel.setLabelFor(windowTitleComboBox);
220: windowTitleLabel.setText(ResourceMgr
221: .getString("LblShowEditorInfo"));
222: windowTitleLabel.setToolTipText(ResourceMgr
223: .getDescription("LblShowEditorInfo"));
224: gridBagConstraints = new java.awt.GridBagConstraints();
225: gridBagConstraints.gridx = 0;
226: gridBagConstraints.gridy = 5;
227: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
228: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
229: gridBagConstraints.insets = new java.awt.Insets(7, 12, 0, 0);
230: add(windowTitleLabel, gridBagConstraints);
231:
232: gridBagConstraints = new java.awt.GridBagConstraints();
233: gridBagConstraints.gridx = 1;
234: gridBagConstraints.gridy = 5;
235: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
236: gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 11);
237: add(windowTitleComboBox, gridBagConstraints);
238:
239: encloseCharLabel.setText(ResourceMgr
240: .getString("LblEncloseGroupChar"));
241: encloseCharLabel.setToolTipText(ResourceMgr
242: .getDescription("LblEncloseGroupChar"));
243: gridBagConstraints = new java.awt.GridBagConstraints();
244: gridBagConstraints.gridx = 0;
245: gridBagConstraints.gridy = 3;
246: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
247: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
248: gridBagConstraints.insets = new java.awt.Insets(7, 12, 2, 0);
249: add(encloseCharLabel, gridBagConstraints);
250:
251: encloseChar.setModel(new javax.swing.DefaultComboBoxModel(
252: new String[] { "( )", "{ }", "[ ]", "< >" }));
253: encloseChar.setToolTipText(ResourceMgr
254: .getDescription("LblEncloseGroupChar"));
255: gridBagConstraints = new java.awt.GridBagConstraints();
256: gridBagConstraints.gridx = 1;
257: gridBagConstraints.gridy = 3;
258: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
259: gridBagConstraints.insets = new java.awt.Insets(4, 10, 0, 11);
260: add(encloseChar, gridBagConstraints);
261: gridBagConstraints = new java.awt.GridBagConstraints();
262: gridBagConstraints.gridx = 0;
263: gridBagConstraints.gridy = 7;
264: gridBagConstraints.weighty = 1.0;
265: add(jPanel1, gridBagConstraints);
266:
267: titleGroupSepLabel.setText(ResourceMgr
268: .getString("LblGroupSeparator"));
269: titleGroupSepLabel.setToolTipText(ResourceMgr
270: .getDescription("LblGroupSeparator"));
271: gridBagConstraints = new java.awt.GridBagConstraints();
272: gridBagConstraints.gridx = 0;
273: gridBagConstraints.gridy = 4;
274: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
275: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
276: gridBagConstraints.insets = new java.awt.Insets(7, 12, 2, 0);
277: add(titleGroupSepLabel, gridBagConstraints);
278:
279: titleGroupSep.setColumns(5);
280: titleGroupSep.setToolTipText(ResourceMgr
281: .getDescription("LblGroupSeparator"));
282: gridBagConstraints = new java.awt.GridBagConstraints();
283: gridBagConstraints.gridx = 1;
284: gridBagConstraints.gridy = 4;
285: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
286: gridBagConstraints.insets = new java.awt.Insets(6, 10, 2, 11);
287: add(titleGroupSep, gridBagConstraints);
288: }// </editor-fold>//GEN-END:initComponents
289:
290: private void showProfileGroupStateChanged(
291: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_showProfileGroupStateChanged
292: this .encloseChar.setEnabled(this .showProfileGroup.isSelected());
293: }//GEN-LAST:event_showProfileGroupStateChanged
294:
295: // Variables declaration - do not modify//GEN-BEGIN:variables
296: private javax.swing.JComboBox encloseChar;
297: private javax.swing.JLabel encloseCharLabel;
298: private javax.swing.JPanel jPanel1;
299: private javax.swing.JCheckBox productAtEnd;
300: private javax.swing.JLabel productAtEndLabel;
301: private javax.swing.JCheckBox showProfileGroup;
302: private javax.swing.JLabel showProfileGroupLabel;
303: private javax.swing.JCheckBox showWorkspace;
304: private javax.swing.JLabel showWorkspaceLabel;
305: private javax.swing.JTextField titleGroupSep;
306: private javax.swing.JLabel titleGroupSepLabel;
307: private javax.swing.JComboBox windowTitleComboBox;
308: private javax.swing.JLabel windowTitleLabel;
309: // End of variables declaration//GEN-END:variables
310:
311: }
|