001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.directory;
019:
020: import java.awt.Dimension;
021:
022: import javax.swing.ButtonGroup;
023: import javax.swing.JDialog;
024: import javax.swing.JLabel;
025: import javax.swing.JOptionPane;
026: import javax.swing.JPanel;
027: import javax.swing.JRadioButton;
028: import javax.swing.JTextField;
029: import javax.swing.border.TitledBorder;
030:
031: import de.finix.contelligent.client.ContelligentClient;
032: import de.finix.contelligent.client.i18n.Resources;
033: import de.finix.contelligent.client.util.TableLayout;
034:
035: public class FindOptionPane extends JOptionPane {
036: private final static int VERTICAL_GAP = 5;
037:
038: private JTextField searchField, pathField;
039:
040: private JRadioButton searchAll = new JRadioButton(Resources
041: .getLocalString("search_all"));
042:
043: private JRadioButton searchSubtree = new JRadioButton(Resources
044: .getLocalString("search_subtree"));
045:
046: public boolean searchAll() {
047: return searchAll.isSelected();
048: }
049:
050: public String getSearchText() {
051: return searchField.getText();
052: }
053:
054: public String getPath() {
055: return pathField.getText();
056: }
057:
058: public int showFindDialog(String searchTerm, String path,
059: boolean nameSearch) {
060: if (path == null) {
061: path = "";
062: searchAll.setSelected(true);
063: } else {
064: searchSubtree.setSelected(true);
065: }
066: searchField = new JTextField(searchTerm);
067: pathField = new JTextField(path);
068: JPanel findPane = new JPanel(new TableLayout(new double[][] {
069: { TableLayout.FILL },
070: { TableLayout.PREFERRED, TableLayout.PREFERRED,
071: TableLayout.FILL } }));
072: JLabel searchLabel;
073: if (nameSearch) {
074: searchLabel = new JLabel(Resources.getLocalString("name"));
075: } else {
076: searchLabel = new JLabel(Resources
077: .getLocalString("search_text"));
078: }
079: findPane.add(searchLabel, "0,0");
080: findPane.add(searchField, "0,1");
081: ButtonGroup group = new ButtonGroup();
082: group.add(searchAll);
083: group.add(searchSubtree);
084: JPanel buttonPanel = new JPanel(new TableLayout(new double[][] {
085: { TableLayout.PREFERRED, TableLayout.FILL },
086: { TableLayout.PREFERRED, TableLayout.PREFERRED } }));
087: buttonPanel.setBorder(new TitledBorder(Resources
088: .getLocalString("search_scope")));
089: buttonPanel.add(searchAll, "0,0");
090: buttonPanel.add(searchSubtree, "0,1");
091: buttonPanel.add(pathField, "1,1");
092: findPane.add(buttonPanel, "0,2");
093: setMessage(findPane);
094: setMessageType(QUESTION_MESSAGE);
095: setOptionType(JOptionPane.OK_CANCEL_OPTION);
096:
097: JDialog dialog;
098: if (nameSearch) {
099: dialog = createDialog(ContelligentClient.getActiveFrame(),
100: Resources.getLocalString("find_name"));
101: } else {
102: dialog = createDialog(ContelligentClient.getActiveFrame(),
103: Resources.getLocalString("find"));
104: }
105: dialog.setSize(new Dimension(500, 200));
106: dialog.setVisible(true);
107: if (getValue() instanceof Integer) {
108: return ((Integer) getValue()).intValue();
109: }
110: return CANCEL_OPTION;
111: }
112: }
|