001: /*
002: * TextOptionsPanel.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.dialogs.dataimport;
013:
014: import javax.swing.JPanel;
015: import workbench.resource.ResourceMgr;
016: import workbench.resource.Settings;
017: import workbench.util.CharacterRange;
018: import workbench.util.StringUtil;
019:
020: /**
021: *
022: * @author support@sql-workbench.net
023: */
024: public class TextOptionsPanel extends JPanel implements
025: TextImportOptions {
026:
027: /** Creates new form TextoptionsPanel */
028: public TextOptionsPanel() {
029: initComponents();
030: }
031:
032: public void saveSettings() {
033: saveSettings("text");
034: }
035:
036: public void saveSettings(String key) {
037: Settings s = Settings.getInstance();
038: s.setProperty("workbench.import." + key + ".containsheader",
039: this .getContainsHeader());
040: s.setProperty("workbench.import." + key + ".decode", this
041: .getDecode());
042: s.setDelimiter("workbench.import." + key + ".fielddelimiter",
043: getTextDelimiter());
044: s.setProperty("workbench.import." + key + ".quotechar", this
045: .getTextQuoteChar());
046: s.setProperty("workbench.import." + key + ".decimalchar", this
047: .getDecimalChar());
048: }
049:
050: public void restoreSettings() {
051: restoreSettings("text");
052: }
053:
054: public void restoreSettings(String key) {
055: Settings s = Settings.getInstance();
056: this .setContainsHeader(s.getBoolProperty("workbench.import."
057: + key + ".containsheader", true));
058: this .setDecode(s.getBoolProperty("workbench.import." + key
059: + ".decode", false));
060: this .setTextQuoteChar(s.getProperty("workbench.import." + key
061: + ".quotechar", s.getQuoteChar()));
062: this .setTextDelimiter(s.getDelimiter("workbench.import." + key
063: + ".fielddelimiter", "\\t", true));
064: this .setDecimalChar(s.getProperty("workbench.import." + key
065: + ".decimalchar", "."));
066: }
067:
068: public boolean getDecode() {
069: return this .decode.isSelected();
070: }
071:
072: public void setDecode(boolean flag) {
073: this .decode.setSelected(flag);
074: }
075:
076: public boolean getContainsHeader() {
077: return this .headerIncluded.isSelected();
078: }
079:
080: public String getTextDelimiter() {
081: return this .delimiter.getText();
082: }
083:
084: public String getTextQuoteChar() {
085: return this .quoteChar.getText();
086: }
087:
088: public void disableHeaderSelection() {
089: this .headerIncluded.setEnabled(false);
090: }
091:
092: public void setContainsHeader(boolean flag) {
093: this .headerIncluded.setSelected(flag);
094: }
095:
096: public void setTextDelimiter(String delim) {
097: this .delimiter.setText(delim);
098: }
099:
100: public void setTextQuoteChar(String quote) {
101: this .quoteChar.setText(quote);
102: }
103:
104: public String getDecimalChar() {
105: String s = this .decimalCharTextField.getText();
106: if (s == null || s.trim().length() == 0)
107: return ".";
108: return s.trim();
109: }
110:
111: public void setDecimalChar(String s) {
112: this .decimalCharTextField.setText(s);
113: }
114:
115: /** This method is called from within the constructor to
116: * initialize the form.
117: * WARNING: Do NOT modify this code. The content of this method is
118: * always regenerated by the Form Editor.
119: */
120: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
121: private void initComponents() {
122: java.awt.GridBagConstraints gridBagConstraints;
123:
124: delimiterLabel = new javax.swing.JLabel();
125: delimiter = new javax.swing.JTextField();
126: headerIncluded = new javax.swing.JCheckBox();
127: quoteCharLabel = new javax.swing.JLabel();
128: quoteChar = new javax.swing.JTextField();
129: jPanel1 = new javax.swing.JPanel();
130: decode = new javax.swing.JCheckBox();
131: decimalCharLabel = new javax.swing.JLabel();
132: decimalCharTextField = new javax.swing.JTextField();
133:
134: setLayout(new java.awt.GridBagLayout());
135:
136: delimiterLabel.setText(ResourceMgr
137: .getString("LblFieldDelimiter"));
138: gridBagConstraints = new java.awt.GridBagConstraints();
139: gridBagConstraints.gridx = 0;
140: gridBagConstraints.gridy = 4;
141: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
142: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
143: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
144: add(delimiterLabel, gridBagConstraints);
145:
146: gridBagConstraints = new java.awt.GridBagConstraints();
147: gridBagConstraints.gridx = 0;
148: gridBagConstraints.gridy = 5;
149: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
151: gridBagConstraints.weightx = 1.0;
152: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
153: add(delimiter, gridBagConstraints);
154:
155: headerIncluded.setText(ResourceMgr
156: .getString("LblImportIncludeHeaders"));
157: headerIncluded.setToolTipText(ResourceMgr
158: .getDescription("LblImportIncludeHeaders"));
159: gridBagConstraints = new java.awt.GridBagConstraints();
160: gridBagConstraints.gridx = 0;
161: gridBagConstraints.gridy = 1;
162: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
163: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
164: add(headerIncluded, gridBagConstraints);
165:
166: quoteCharLabel.setText(ResourceMgr.getString("LblQuoteChar"));
167: gridBagConstraints = new java.awt.GridBagConstraints();
168: gridBagConstraints.gridx = 0;
169: gridBagConstraints.gridy = 6;
170: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
171: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
172: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
173: add(quoteCharLabel, gridBagConstraints);
174:
175: gridBagConstraints = new java.awt.GridBagConstraints();
176: gridBagConstraints.gridx = 0;
177: gridBagConstraints.gridy = 7;
178: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
180: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
181: add(quoteChar, gridBagConstraints);
182:
183: gridBagConstraints = new java.awt.GridBagConstraints();
184: gridBagConstraints.gridx = 0;
185: gridBagConstraints.gridy = 11;
186: gridBagConstraints.weighty = 1.0;
187: add(jPanel1, gridBagConstraints);
188:
189: decode.setText(ResourceMgr.getString("LblImportDecode"));
190: decode.setToolTipText(ResourceMgr
191: .getDescription("LblImportDecode"));
192: gridBagConstraints = new java.awt.GridBagConstraints();
193: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
194: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
195: add(decode, gridBagConstraints);
196:
197: decimalCharLabel.setText(ResourceMgr
198: .getString("LblImportDecimalChar"));
199: decimalCharLabel.setToolTipText(ResourceMgr
200: .getDescription("LblImportDecimalChar"));
201: gridBagConstraints = new java.awt.GridBagConstraints();
202: gridBagConstraints.gridx = 0;
203: gridBagConstraints.gridy = 2;
204: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
206: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
207: add(decimalCharLabel, gridBagConstraints);
208:
209: decimalCharTextField.setToolTipText(ResourceMgr
210: .getDescription("LblImportDecimalChar"));
211: gridBagConstraints = new java.awt.GridBagConstraints();
212: gridBagConstraints.gridx = 0;
213: gridBagConstraints.gridy = 3;
214: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
215: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
216: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
217: add(decimalCharTextField, gridBagConstraints);
218:
219: }
220:
221: // </editor-fold>//GEN-END:initComponents
222:
223: // Variables declaration - do not modify//GEN-BEGIN:variables
224: private javax.swing.JLabel decimalCharLabel;
225: private javax.swing.JTextField decimalCharTextField;
226: private javax.swing.JCheckBox decode;
227: private javax.swing.JTextField delimiter;
228: private javax.swing.JLabel delimiterLabel;
229: private javax.swing.JCheckBox headerIncluded;
230: private javax.swing.JPanel jPanel1;
231: private javax.swing.JTextField quoteChar;
232: private javax.swing.JLabel quoteCharLabel;
233: // End of variables declaration//GEN-END:variables
234:
235: }
|