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

📄 resultlist.java

📁 编辑视频文件
💻 JAVA
字号:
/* * File:     ResultList.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.search.result.viewer;import mpi.search.result.model.Match;import mpi.search.result.model.ResultHandler;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import javax.swing.JList;import javax.swing.JMenuItem;import javax.swing.JPopupMenu;import javax.swing.ListSelectionModel;/** * $Id: ResultList.java,v 1.1 2007/03/09 09:42:17 klasal Exp $ * * @author $author$ * @version $Revision: 1.1 $ */public class ResultList extends JList implements MouseListener {    /** to choose an action which the resulthandler should perform */    private JPopupMenu actionsMenu;    /** handler that does something with selected match number */    private ResultHandler resultHandler;    /**     * Creates a new ResultList object.     */    public ResultList() {        this(null);    }    /**     * Creates a new ResultList object.     *     * @param resultHandler DOCUMENT ME!     */    public ResultList(ResultHandler resultHandler) {        super();        this.resultHandler = resultHandler;        setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        addMouseListener(this);    }    /**     * DOCUMENT ME!     *     * @param popupChoices DOCUMENT ME!     */    public void setPopupChoices(String[] popupChoices) {        if (popupChoices.length > 0) {            actionsMenu = new JPopupMenu();            ActionListener actionListener = new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        if (1 >= 0) {                            resultHandler.handleMatch((Match) getSelectedValue(),                                e.getActionCommand());                        }                    }                };            JMenuItem menuItem;            for (int i = 0; i < popupChoices.length; i++) {                menuItem = new JMenuItem(popupChoices[i]);                menuItem.addActionListener(actionListener);                actionsMenu.add(menuItem);            }        } else {            actionsMenu = null;        }    }    /**     *     *     * @param resultHandler DOCUMENT ME!     */    public void setResultHandler(ResultHandler resultHandler) {        this.resultHandler = resultHandler;    }    /**     * DOCUMENT ME!     *     * @param e DOCUMENT ME!     */    public void mouseClicked(MouseEvent e) {        if (e.getClickCount() > 1) {            // first registered action is considered default action            resultHandler.handleMatch((Match) getSelectedValue(),                ((JMenuItem) actionsMenu.getSubElements()[0]).getActionCommand());        }    }    /**     * DOCUMENT ME!     *     * @param e DOCUMENT ME!     */    public void mouseEntered(MouseEvent e) {    }    /**     * DOCUMENT ME!     *     * @param e DOCUMENT ME!     */    public void mouseExited(MouseEvent e) {    }    // on a pc this is the popup trigger method    public void mousePressed(MouseEvent e) {        if ((actionsMenu != null) && e.isPopupTrigger() &&                (getSelectedValue() != null)) {            showPopup(e);        }    }    // On the sun this is the popup trigger method    public void mouseReleased(MouseEvent e) {        if ((actionsMenu != null) && e.isPopupTrigger() &&                (getSelectedValue() != null)) {            showPopup(e);        }    }    private void showPopup(MouseEvent e) {        actionsMenu.show(ResultList.this, e.getX(), e.getY());        actionsMenu.setVisible(true);        requestFocus();    }}

⌨️ 快捷键说明

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