001: /*
002: * ReplaceCriteriaPanel.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.awt.BorderLayout;
015: import java.awt.Component;
016: import java.awt.EventQueue;
017: import java.awt.GridLayout;
018:
019: import javax.swing.JCheckBox;
020: import javax.swing.JDialog;
021: import javax.swing.JLabel;
022: import javax.swing.JPanel;
023: import javax.swing.JTextField;
024:
025: import workbench.interfaces.Replaceable;
026: import workbench.resource.ResourceMgr;
027: import workbench.resource.Settings;
028:
029: /**
030: *
031: * @author support@sql-workbench.net
032: */
033: public class ReplaceCriteriaPanel extends JPanel {
034: private static final String PROP_KEY_CASE = "workbench.sql.replace.ignoreCase";
035: private JCheckBox ignoreCase;
036:
037: protected JTextField criteria;
038: private JTextField newValue;
039:
040: public ReplaceCriteriaPanel(Replaceable aClient) {
041: this (aClient, null);
042: }
043:
044: public ReplaceCriteriaPanel(Replaceable aClient, String initialValue) {
045: this .ignoreCase = new JCheckBox(ResourceMgr
046: .getString("LblSearchIgnoreCase"));
047: this .ignoreCase.setSelected(Settings.getInstance()
048: .getBoolProperty(PROP_KEY_CASE, true));
049:
050: JLabel label = new JLabel(ResourceMgr
051: .getString("LblSearchCriteria"));
052: this .criteria = new JTextField();
053: this .criteria.setColumns(40);
054: this .criteria.setText(initialValue);
055: if (initialValue != null) {
056: this .criteria.selectAll();
057: }
058: this .criteria
059: .addMouseListener(new TextComponentMouseListener());
060: JPanel searchPanel = new JPanel();
061: searchPanel.setLayout(new BorderLayout(5, 0));
062: searchPanel.add(label, BorderLayout.WEST);
063: searchPanel.add(this .criteria, BorderLayout.CENTER);
064:
065: label = new JLabel(ResourceMgr.getString("LblReplaceNewValue"));
066: this .newValue = new JTextField();
067: this .newValue.setColumns(40);
068: JPanel replacePanel = new JPanel();
069: replacePanel.setLayout(new BorderLayout(5, 0));
070: replacePanel.add(label, BorderLayout.WEST);
071: replacePanel.add(this .newValue, BorderLayout.CENTER);
072:
073: JPanel p = new JPanel();
074: p.setLayout(new GridLayout(2, 1));
075: p.add(searchPanel);
076: p.add(replacePanel);
077: this .setLayout(new BorderLayout());
078: this .add(p, BorderLayout.CENTER);
079: this .add(this .ignoreCase, BorderLayout.SOUTH);
080: }
081:
082: public String getCriteria() {
083: return this .criteria.getText();
084: }
085:
086: public boolean getIgnoreCase() {
087: return this .ignoreCase.isSelected();
088: }
089:
090: public void setSearchCriteria(String aValue) {
091: this .criteria.setText(aValue);
092: if (aValue != null) {
093: this .criteria.selectAll();
094: }
095: }
096:
097: public void setNewValue(String aValue) {
098: this .newValue.setText(aValue);
099: if (aValue != null) {
100: this .newValue.selectAll();
101: }
102: }
103:
104: public String getNewValue() {
105: return this .newValue.getText();
106: }
107:
108: public boolean showReplaceDialog(Component caller) {
109: EventQueue.invokeLater(new Runnable() {
110: public void run() {
111: criteria.grabFocus();
112: }
113: });
114: JDialog d = new JDialog();
115: d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
116: d.getContentPane().add(this , BorderLayout.CENTER);
117: d.setVisible(true);
118: return true;
119: }
120:
121: }
|