Import of Ekit 0.9h
[old-projects.git] / ekit / com / hexidec / ekit / component / SearchDialog.java
1 /*
2 GNU Lesser General Public License
3
4 SearchDialog
5 Copyright (C) 2000 Howard Kistler
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 package com.hexidec.ekit.component;
23
24 import java.awt.Frame;
25 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27 import java.beans.PropertyChangeEvent;
28 import java.beans.PropertyChangeListener;
29 import javax.swing.JCheckBox;
30 import javax.swing.JDialog;
31 import javax.swing.JOptionPane;
32 import javax.swing.JTextField;
33
34 import com.hexidec.util.Translatrix;
35
36 /** Class for providing a dialog that lets the user specify arguments for
37 * the Search Find/Replace functions
38 */
39 public class SearchDialog extends JDialog
40 {
41 private String inputFindTerm = (String)null;
42 private String inputReplaceTerm = (String)null;
43 private boolean bCaseSensitive = false;
44 private boolean bStartAtTop = false;
45 private boolean bReplaceAll = false;
46 private JOptionPane jOptionPane;
47
48 public SearchDialog(Frame parent, String title, boolean bModal, boolean bIsReplace, boolean bCaseSetting, boolean bTopSetting)
49 {
50 super(parent, title, bModal);
51 final boolean isReplaceDialog = bIsReplace;
52 final JTextField jtxfFindTerm = new JTextField(3);
53 final JTextField jtxfReplaceTerm = new JTextField(3);
54 final JCheckBox jchkCase = new JCheckBox(Translatrix.getTranslationString("SearchCaseSensitive"), bCaseSetting);
55 final JCheckBox jchkTop = new JCheckBox(Translatrix.getTranslationString("SearchStartAtTop"), bTopSetting);
56 final JCheckBox jchkAll = new JCheckBox(Translatrix.getTranslationString("SearchReplaceAll"), false);
57 final Object[] buttonLabels = { Translatrix.getTranslationString("DialogAccept"), Translatrix.getTranslationString("DialogCancel") };
58 if(bIsReplace)
59 {
60 Object[] panelContents = {
61 Translatrix.getTranslationString("SearchFind"),
62 jtxfFindTerm,
63 Translatrix.getTranslationString("SearchReplace"),
64 jtxfReplaceTerm,
65 jchkAll,
66 jchkCase,
67 jchkTop
68 };
69 jOptionPane = new JOptionPane(panelContents, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]);
70 }
71 else
72 {
73 Object[] panelContents = {
74 Translatrix.getTranslationString("SearchFind"),
75 jtxfFindTerm,
76 jchkCase,
77 jchkTop
78 };
79 jOptionPane = new JOptionPane(panelContents, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]);
80 }
81 setContentPane(jOptionPane);
82 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
83
84 addWindowListener(new WindowAdapter() {
85 public void windowClosing(WindowEvent we)
86 {
87 jOptionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
88 }
89 });
90
91 jOptionPane.addPropertyChangeListener(new PropertyChangeListener() {
92 public void propertyChange(PropertyChangeEvent e)
93 {
94 String prop = e.getPropertyName();
95 if(isVisible()
96 && (e.getSource() == jOptionPane)
97 && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY)))
98 {
99 Object value = jOptionPane.getValue();
100 if(value == JOptionPane.UNINITIALIZED_VALUE)
101 {
102 return;
103 }
104 jOptionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
105 if(value.equals(buttonLabels[0]))
106 {
107 inputFindTerm = jtxfFindTerm.getText();
108 bCaseSensitive = jchkCase.isSelected();
109 bStartAtTop = jchkTop.isSelected();
110 if(isReplaceDialog)
111 {
112 inputReplaceTerm = jtxfReplaceTerm.getText();
113 bReplaceAll = jchkAll.isSelected();
114 }
115 setVisible(false);
116 }
117 else
118 {
119 inputFindTerm = (String)null;
120 inputReplaceTerm = (String)null;
121 bCaseSensitive = false;
122 bStartAtTop = false;
123 bReplaceAll = false;
124 setVisible(false);
125 }
126 }
127 }
128 });
129 this.pack();
130 this.show();
131 jtxfFindTerm.requestFocus();
132 }
133
134 public String getFindTerm() { return inputFindTerm; }
135 public String getReplaceTerm() { return inputReplaceTerm; }
136 public boolean getCaseSensitive() { return bCaseSensitive; }
137 public boolean getStartAtTop() { return bStartAtTop; }
138 public boolean getReplaceAll() { return bReplaceAll; }
139 }
140