01: package org.apache.lucene.swing.models;
02:
03: /**
04: * Copyright 2005 The Apache Software Foundation
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import javax.swing.*;
20: import java.awt.*;
21: import java.awt.event.ActionListener;
22: import java.awt.event.ActionEvent;
23:
24: /**
25: * @author Jonathan Simon - jonathan_s_simon@yahoo.com
26: */
27: public class TableSearcherSimulator {
28:
29: public TableSearcherSimulator() {
30: JFrame frame = new JFrame();
31: frame.setBounds(200, 200, 400, 250);
32:
33: JTable table = new JTable();
34: final BaseTableModel tableModel = new BaseTableModel(DataStore
35: .getRestaurants());
36: final TableSearcher searchTableModel = new TableSearcher(
37: tableModel);
38:
39: table.setModel(searchTableModel);
40: JScrollPane scrollPane = new JScrollPane(table);
41:
42: final JTextField searchField = new JTextField();
43: JButton searchButton = new JButton("Go");
44:
45: ActionListener searchListener = new ActionListener() {
46: public void actionPerformed(ActionEvent e) {
47: searchTableModel.search(searchField.getText().trim()
48: .toLowerCase());
49: searchField.requestFocus();
50: }
51: };
52:
53: searchButton.addActionListener(searchListener);
54: searchField.addActionListener(searchListener);
55:
56: frame.getContentPane().setLayout(new BorderLayout());
57: frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
58:
59: JPanel searchPanel = new JPanel();
60: searchPanel.setLayout(new BorderLayout(10, 10));
61: searchPanel.add(searchField, BorderLayout.CENTER);
62: searchPanel.add(searchButton, BorderLayout.EAST);
63:
64: JPanel topPanel = new JPanel(new BorderLayout());
65: topPanel.add(searchPanel, BorderLayout.CENTER);
66: topPanel.add(new JPanel(), BorderLayout.EAST);
67: topPanel.add(new JPanel(), BorderLayout.WEST);
68: topPanel.add(new JPanel(), BorderLayout.NORTH);
69: topPanel.add(new JPanel(), BorderLayout.SOUTH);
70:
71: frame.getContentPane().add(topPanel, BorderLayout.NORTH);
72:
73: frame.setTitle("Lucene powered table searching");
74: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
75: frame.show();
76:
77: }
78:
79: public static void main(String[] args) {
80: new TableSearcherSimulator();
81: }
82:
83: }
|