gecko-dev/grendel/search/SearchFrame.java

119 lines
3.6 KiB
Java
Raw Normal View History

1998-09-09 00:52:38 +00:00
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1997
* Netscape Communications Corporation. All Rights Reserved.
*
* Created: Will Scullin <scullin@netscape.com>, 9 Oct 1997.
*
* Contributors: Jeff Galyan <talisman@anamorphic.com>
1999-06-15 11:44:40 +00:00
* Edwin Woudt <edwin@woudt.nl>
1998-09-09 00:52:38 +00:00
*/
package grendel.search;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.Action;
import javax.swing.AbstractAction;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
1998-09-09 00:52:38 +00:00
//import netscape.orion.toolbars.BarLayout;
1998-09-09 00:52:38 +00:00
import grendel.ui.GeneralFrame;
public class SearchFrame extends GeneralFrame {
SearchPanel fSearchPanel;
JComponent fTargetPanel;
JComponent fActionPanel;
JButton fSearchButton;
JButton fCloseButton;
public SearchFrame() {
1999-06-15 11:44:40 +00:00
super("Search", "search");
1998-09-09 00:52:38 +00:00
fSearchPanel = new SearchPanel(new MailSearch());
getContentPane().add(fSearchPanel);
fActionPanel = new JPanel(new BoxLayout(this, BoxLayout.X_AXIS), true);
1998-09-09 00:52:38 +00:00
fActionPanel.setBorder(new EmptyBorder(5,5,5,5));
fActionPanel.add(new Canvas());
1998-09-09 00:52:38 +00:00
fCloseButton = new JButton("Close");
fCloseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent aEvent) {
dispose();
}
});
fActionPanel.add(fCloseButton);
1998-09-09 00:52:38 +00:00
fSearchButton = new JButton("Search");
fSearchButton.addActionListener(new SearchAction());
fActionPanel.add(fSearchButton);
1998-09-09 00:52:38 +00:00
fPanel.add(BorderLayout.SOUTH, fActionPanel);
fTargetPanel = new JPanel(new BoxLayout(this, BoxLayout.X_AXIS), true);
1998-09-09 00:52:38 +00:00
fTargetPanel.setBorder(new EmptyBorder(5,5,5,5));
fTargetPanel.add(new Canvas());
fTargetPanel.add(new JLabel("Search In: "));
fTargetPanel.add(fSearchPanel.getSearchable().getTargetComponent());
fTargetPanel.add(new Canvas());
1998-09-09 00:52:38 +00:00
fPanel.add(BorderLayout.NORTH, fTargetPanel);
getRootPane().registerKeyboardAction(new SearchAction(),
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
restoreBounds();
setVisible(true);
}
public void dispose() {
saveBounds();
super.dispose();
}
class SearchAction extends AbstractAction {
SearchAction() {
super("search");
}
public void actionPerformed(ActionEvent aEvent) {
ISearchable searchable = fSearchPanel.getSearchable();
searchable.search(fSearchPanel.getSearch());
ISearchResults results = searchable.getSearchResults();
Component c = searchable.getResultComponent(results);
if (c != null) {
new ResultsFrame(c);
}
}
}
}