⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchdialog.java

📁 网站即时通讯系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.valhalla.jbother;import com.valhalla.gui.*;import org.jivesoftware.smack.PacketCollector;import org.jivesoftware.smack.SmackConfiguration;import org.jivesoftware.smack.filter.AndFilter;import org.jivesoftware.smack.filter.PacketFilter;import org.jivesoftware.smack.filter.PacketIDFilter;import org.jivesoftware.smack.filter.PacketTypeFilter;import org.jivesoftware.smack.packet.IQ;import org.jivesoftware.smack.packet.Packet;import com.valhalla.jbother.jabber.smack.*;import javax.swing.*;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.table.AbstractTableModel;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.*;/** * Created by luke on Apr 1, 2005 1:36:43 PM * * @author     synic * @created    April 14, 2005 *//** * dialog used in searching using Jabber Search (eg. Jabber User Directories) * exploits JEP-0055's 'jabber:iq:search' namespace * handles dynamic number of search fields * * @author     synic * @created    April 14, 2005 */public class SearchDialog extends JDialog{    private static String fId = "$Id$";    private String service;    private SearchDialog thisPointer = this;    private ResourceBundle resources = ResourceBundle.getBundle("JBotherBundle", Locale.getDefault());    // this will hold the mappings: <searchFieldName> -> textfield that contains it    private HashMap searchTextFields = new HashMap();    // all data for displaying the inside of this dialog is taken from here:    private Search search;    private JPanel container = new JPanel();    private JPanel inputPanel = new JPanel();    private JPanel resultsPanel = new JPanel();    private JButton closeButton = new JButton("Close");    private JTextArea instructionsArea = new JTextArea();    private JButton searchButton = new JButton("Search");    private JButton stopSearchButton = new JButton("Stop");    private JTable resultsTable = new JTable();    private SearchResultsTableModel resultsTableModel = new SearchResultsTableModel();    private JButton addContactButton = new JButton("Add contact");    private JButton userInfoButton = new JButton("User info");    private WaitDialog wait = new WaitDialog(this,null,"Gathering search information...");    // create panel with search fields    private JPanel searchFieldsPanel = new JPanel();    private GridBagLayout gridbag = new GridBagLayout();    private GridBagConstraints c = new GridBagConstraints();    private int selectedRow = -1;    /**     *Constructor for the SearchDialog object     *     * @param  service                Description of the Parameter     * @exception  HeadlessException  Description of the Exception     */    public SearchDialog(String service)        throws HeadlessException    {        super(BuddyList.getInstance().getContainerFrame(), "Search", true);        setModal(false);        setTitle(resources.getString("search") + ": " + service);        this.service = service;        thisPointer = this;        getRootPane().setDefaultButton(searchButton);        instructionsArea.setLineWrap(true);        instructionsArea.setWrapStyleWord(true);        initialize();        DialogTracker.addDialog(this, false, true);        collectInformation();    }    public void collectInformation()    {        wait.setVisible(true);        new Thread(new QuerySearch()).start();    }    /**     *  Description of the Class     *     * @author     synic     * @created    April 14, 2005     */    class QuerySearch implements Runnable    {        /**         *  Main processing method for the QuerySearch object         */        public void run()        {            if(querySearchService(service) == true)            {                SwingUtilities.invokeLater(                    new Runnable()                    {                        public void run()                        {                            instructionsArea.setText(search.getInstructions());                            Iterator iSearchFields = search.getSearchFields().keySet().iterator();                            while(iSearchFields.hasNext())                            {                                String searchFieldName = (String) iSearchFields.next();                                JLabel searchFieldNameLabel = new JLabel(capitalizeString(searchFieldName) + ": ");                                gridbag.setConstraints(searchFieldNameLabel, c);                                searchFieldsPanel.add(searchFieldNameLabel, c);                                c.gridx++;                                c.gridwidth = GridBagConstraints.REMAINDER;                                c.weightx = 1.0;                                c.fill = GridBagConstraints.HORIZONTAL;                                JTextField inputSearchField = new JTextField();                                inputSearchField.setColumns(15);                                searchTextFields.put(searchFieldName, inputSearchField);                                gridbag.setConstraints(inputSearchField, c);                                searchFieldsPanel.add(inputSearchField, c);                                c.gridx = 0;                                c.gridwidth = 1;                                c.weightx = 0;                                c.fill = GridBagConstraints.NONE;                                c.gridy++;                            }                            searchFieldsPanel.validate();                            searchFieldsPanel.repaint();                            wait.setVisible(false);                            setVisible(true);                            wait = new WaitDialog(thisPointer,null,"Searching...");                        }                    });            }        }    }    /**     * initialize the frame     */    private void initialize()    {        inputPanel = initializeInputPanel();        resultsPanel = initializeResultsPanel();        initializeListeners();        container.setLayout(new BorderLayout());        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, inputPanel, resultsPanel);        container.add(splitPane, BorderLayout.CENTER);        JPanel bottomButtonPanel = new JPanel(new BorderLayout());        bottomButtonPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 10));        bottomButtonPanel.add(closeButton, BorderLayout.EAST);        container.add(bottomButtonPanel, BorderLayout.SOUTH);        addContactButton.setEnabled(false);        userInfoButton.setEnabled(false);        setContentPane(container);        pack();        setLocationRelativeTo(null);    }    /**     * @return    JPanel containing instructions, search fields and start/stop searching buttons     */    private JPanel initializeInputPanel()    {        JPanel panel = new JPanel();        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));        panel.setBorder(BorderFactory.createTitledBorder(resources.getString("searchFields")));        // add text area with instructions        instructionsArea.setEditable(false);        instructionsArea.setBorder(BorderFactory.createEtchedBorder());        instructionsArea.setPreferredSize(new Dimension(300, 200));        panel.add(instructionsArea);        panel.add(Box.createVerticalStrut(5));        searchFieldsPanel.setLayout(gridbag);        c.gridx = 0;        c.gridy = 0;        c.gridwidth = 1;        c.gridheight = 1;        c.weightx = 0.0;        c.weighty = 0.0;        c.anchor = GridBagConstraints.NORTHWEST;        panel.add(searchFieldsPanel);        panel.add(Box.createVerticalStrut(5));        // create a panel with search/stop search buttons        JPanel buttonsPanel = new JPanel();        buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));        buttonsPanel.add(Box.createHorizontalGlue());        buttonsPanel.add(searchButton);        buttonsPanel.add(Box.createHorizontalStrut(10));        buttonsPanel.add(stopSearchButton);        buttonsPanel.add(Box.createHorizontalGlue());        panel.add(buttonsPanel);        panel.add(Box.createVerticalGlue());        JPanel ueberPanel = new JPanel(new BorderLayout());        ueberPanel.add(panel, BorderLayout.NORTH);        return ueberPanel;    }    /**     * @return    panel containing table with search results     */    private JPanel initializeResultsPanel()    {        JPanel panel = new JPanel(new BorderLayout());        panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));        // table        resultsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        ListSelectionModel rowSL = resultsTable.getSelectionModel();        rowSL.addListSelectionListener(            new ListSelectionListener()            {                public void valueChanged(ListSelectionEvent e)                {                    // ignora extra values                    if(e.getValueIsAdjusting())                    {                        return;                    }                    ListSelectionModel lsm = (ListSelectionModel) e.getSource();                    if(lsm.isSelectionEmpty())                    {                        // no rows selected                        selectedRow = -1;                        addContactButton.setEnabled(false);                        userInfoButton.setEnabled(false);                    }                    else                    {                        addContactButton.setEnabled(true);                        userInfoButton.setEnabled(true);                        selectedRow = lsm.getMinSelectionIndex();                    }                }            });        resultsTable.setModel(resultsTableModel);        JScrollPane scrollPane = new JScrollPane(resultsTable);        scrollPane.setBorder(BorderFactory.createTitledBorder("Search results"));        panel.add(scrollPane, BorderLayout.CENTER);        // buttons        JPanel buttonPanel = new JPanel();        buttonPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));        buttonPanel.add(Box.createHorizontalGlue());        buttonPanel.add(addContactButton);        buttonPanel.add(Box.createHorizontalStrut(5));        buttonPanel.add(userInfoButton);        panel.add(buttonPanel, BorderLayout.SOUTH);        return panel;    }    class SearchThread implements Runnable    {        public void run()        {            doSearch();        }    }    /**     * sets up action listeners for buttons     */    private void initializeListeners()    {        closeButton.addActionListener(            new ActionListener()            {                public void actionPerformed(ActionEvent e)                {                    dispose();                }            });        searchButton.addActionListener(            new ActionListener()            {                public void actionPerformed(ActionEvent e)                {                    wait.setVisible( true );                    new Thread( new SearchThread()).start();                }            });

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -