FileDocCategorySizeDatePackage
ListSearcherSimulator.javaAPI DocApache Lucene 1.93161Mon Feb 20 09:18:14 GMT 2006org.apache.lucene.swing.models

ListSearcherSimulator

public class ListSearcherSimulator extends Object
author
Jonathan Simon - jonathan_s_simon@yahoo.com

Fields Summary
Constructors Summary
public ListSearcherSimulator()

        JFrame frame = new JFrame();
        frame.setBounds(200,200, 400,250);

        JList list = new JList();
        JScrollPane scrollPane = new JScrollPane(list);

        final BaseListModel listModel = new BaseListModel(DataStore.getRestaurants());
        final ListSearcher listSearcher = new ListSearcher(listModel);

        list.setModel(listSearcher);

        final JTextField searchField = new JTextField();
        searchField.getDocument().addDocumentListener(
                new DocumentListener(){
                    public void changedUpdate(DocumentEvent e) {
                        listSearcher.search(searchField.getText().trim().toLowerCase());
                    }

                    public void insertUpdate(DocumentEvent e) {
                        listSearcher.search(searchField.getText().trim().toLowerCase());
                    }

                    public void removeUpdate(DocumentEvent e) {
                        listSearcher.search(searchField.getText().trim().toLowerCase());
                    }
                }
        );

        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(scrollPane, BorderLayout.CENTER);

        JPanel searchPanel = new JPanel();
        searchPanel.setLayout(new BorderLayout(10,10));
        searchPanel.add(searchField, BorderLayout.CENTER);
        searchPanel.add(new JLabel("Search: "), BorderLayout.WEST);

        JPanel topPanel = new JPanel(new BorderLayout());
        topPanel.add(searchPanel, BorderLayout.CENTER);
        topPanel.add(new JPanel(), BorderLayout.EAST);
        topPanel.add(new JPanel(), BorderLayout.WEST);
        topPanel.add(new JPanel(), BorderLayout.NORTH);
        topPanel.add(new JPanel(), BorderLayout.SOUTH);

        frame.getContentPane().add(topPanel, BorderLayout.NORTH);

        frame.setTitle("Lucene powered table searching");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.show();
    
Methods Summary
public static voidmain(java.lang.String[] args)

        new ListSearcherSimulator();