01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui.text;
19:
20: import javax.swing.JDialog;
21: import javax.swing.JLabel;
22: import javax.swing.JOptionPane;
23: import javax.swing.JTextField;
24:
25: import de.finix.contelligent.client.ContelligentClient;
26: import de.finix.contelligent.client.i18n.Resources;
27:
28: /**
29: * JDialog for simple replace in text.
30: */
31: public class ReplaceDialog extends JOptionPane {
32:
33: public final static int REPLACE_OPTION = 10;
34:
35: public final static int REPLACE_ALL_OPTION = 11;
36:
37: private final static String REPLACE = Resources
38: .getLocalString("replace");
39:
40: private final static String REPLACE_ALL = Resources
41: .getLocalString("replace_all");
42:
43: private final static String CANCEL = Resources
44: .getLocalString("cancel");
45:
46: private JTextField searchField = new JTextField(15);
47:
48: private JTextField replaceField = new JTextField(15);
49:
50: private boolean searchTextEditable;
51:
52: public ReplaceDialog(String searchText, String replaceText,
53: boolean searchTextEditable) {
54: searchField.setText(searchText);
55: replaceField.setText(replaceText);
56: searchField.setEditable(searchTextEditable);
57: this .searchTextEditable = searchTextEditable;
58: }
59:
60: public int showReplaceDialog() {
61: Object[] array = {
62: new JLabel(Resources.getLocalString("search_text")),
63: searchField,
64: new JLabel(Resources.getLocalString("replace_text")),
65: replaceField };
66:
67: setMessage(array);
68: setMessageType(QUESTION_MESSAGE);
69: setOptionType(JOptionPane.OK_CANCEL_OPTION);
70: setOptions(new String[] { REPLACE, REPLACE_ALL, CANCEL });
71:
72: JDialog dialog = createDialog(ContelligentClient
73: .getActiveFrame(), Resources.getLocalString("replace"));
74: if (!searchTextEditable) {
75: replaceField.requestFocus();
76: }
77: dialog.setVisible(true);
78: if (getValue() == REPLACE) {
79: return REPLACE_OPTION;
80: } else if (getValue() == REPLACE_ALL) {
81: return REPLACE_ALL_OPTION;
82: }
83: return CANCEL_OPTION;
84: }
85:
86: public String getSearchText() {
87: return searchField.getText();
88: }
89:
90: public String getReplaceText() {
91: return replaceField.getText();
92: }
93: }
|