001: /*
002: * DelimiterDefinitionPanel.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.components;
013:
014: import java.beans.PropertyChangeEvent;
015: import java.beans.PropertyChangeEvent;
016: import java.beans.PropertyChangeListener;
017: import java.beans.PropertyChangeListener;
018: import java.beans.PropertyChangeListener;
019: import javax.swing.JPanel;
020: import workbench.resource.ResourceMgr;
021: import workbench.sql.DelimiterDefinition;
022:
023: /**
024: *
025: * @author support@sql-workbench.net
026: */
027: public class DelimiterDefinitionPanel extends JPanel implements
028: PropertyChangeListener {
029: private DelimiterDefinition delimiter;
030: private StringPropertyEditor delimitTextField;
031: private BooleanPropertyEditor singleLineCheckBox;
032: public static final String PROP_DELIM = "delimiter";
033: public static final String PROP_SLD = "singleLine";
034: private boolean updating = false;
035:
036: public DelimiterDefinitionPanel() {
037: initComponents();
038: this .delimitTextField.setImmediateUpdate(true);
039: this .singleLineCheckBox.setImmediateUpdate(true);
040: }
041:
042: public void setDelimiter(DelimiterDefinition delim) {
043: try {
044: updating = true;
045:
046: delimitTextField.removePropertyChangeListener(PROP_DELIM,
047: this );
048: singleLineCheckBox.removePropertyChangeListener(PROP_SLD,
049: this );
050:
051: if (delim != null) {
052: this .delimiter = delim;
053: } else {
054: this .delimiter = new DelimiterDefinition();
055: }
056:
057: this .delimitTextField.setSourceObject(null, PROP_DELIM);
058: this .singleLineCheckBox.setSourceObject(null, PROP_SLD);
059:
060: this .delimitTextField
061: .setText(this .delimiter.getDelimiter());
062: this .singleLineCheckBox.setSelected(this .delimiter
063: .isSingleLine());
064:
065: this .delimitTextField
066: .setSourceObject(delimiter, PROP_DELIM);
067: this .singleLineCheckBox
068: .setSourceObject(delimiter, PROP_SLD);
069: } finally {
070: updating = false;
071: }
072:
073: delimitTextField.addPropertyChangeListener(PROP_DELIM, this );
074: singleLineCheckBox.addPropertyChangeListener(PROP_SLD, this );
075: }
076:
077: public DelimiterDefinition getDelimiter() {
078: return this .delimiter;
079: }
080:
081: public javax.swing.JTextField getTextField() {
082: return this .delimitTextField;
083: }
084:
085: public javax.swing.JCheckBox getCheckBox() {
086: return this .singleLineCheckBox;
087: }
088:
089: private void initComponents() {
090: java.awt.GridBagConstraints gridBagConstraints;
091:
092: delimitTextField = new StringPropertyEditor();
093: singleLineCheckBox = new BooleanPropertyEditor();
094:
095: setLayout(new java.awt.GridBagLayout());
096:
097: //delimitTextField.setMinimumSize(new java.awt.Dimension(72, 20));
098: delimitTextField.setName("delimiter");
099: gridBagConstraints = new java.awt.GridBagConstraints();
100: gridBagConstraints.gridx = 0;
101: gridBagConstraints.gridy = 0;
102: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
103: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
104: gridBagConstraints.weightx = 0.5;
105: add(delimitTextField, gridBagConstraints);
106:
107: singleLineCheckBox.setText(ResourceMgr
108: .getString("LblDelimSingleLine"));
109: singleLineCheckBox.setToolTipText(ResourceMgr
110: .getDescription("LblDelimSingleLine"));
111: singleLineCheckBox.setBorder(javax.swing.BorderFactory
112: .createEmptyBorder(0, 0, 0, 0));
113: singleLineCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
114: gridBagConstraints = new java.awt.GridBagConstraints();
115: gridBagConstraints.gridx = 1;
116: gridBagConstraints.gridy = 0;
117: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
118: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
119: gridBagConstraints.weightx = 0.5;
120: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
121: add(singleLineCheckBox, gridBagConstraints);
122: }
123:
124: public void propertyChange(PropertyChangeEvent evt) {
125: if (updating)
126: return;
127: if (evt.getSource() == this.delimitTextField
128: || evt.getSource() == this.singleLineCheckBox) {
129: if (evt.getPropertyName().equals(PROP_DELIM)
130: || evt.getPropertyName().equals(PROP_SLD)) {
131: firePropertyChange(evt.getPropertyName(), evt
132: .getOldValue(), evt.getNewValue());
133: }
134: }
135: }
136:
137: }
|