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

📄 listselectiondialog.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*====================================================================*\ListSelectionDialog.javaList selection dialog box class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program.  If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// IMPORTSimport gui.DashedBorder;import gui.GuiUtilities;import java.awt.Component;import java.awt.Dialog;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.Point;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.KeyStroke;import javax.swing.ListCellRenderer;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import util.KeyAction;//----------------------------------------------------------------------// LIST SELECTION DIALOG BOX CLASSclass ListSelectionDialog    extends JDialog    implements ActionListener, ListSelectionListener{//////////////////////////////////////////////////////////////////////////  Constants////////////////////////////////////////////////////////////////////////    private static final    int LIST_NUM_COLUMNS    = 72;    private static final    String  SELECT_ALL_STR              = "Select All";    private static final    String  DESELECT_ALL_STR            = "Deselect All";    private static final    String  SELECT_ALL_TOOL_TIP_STR     = "Select all items (Ctrl+A)";    private static final    String  DESELECT_ALL_TOOL_TIP_STR   = "Deselect all items (Ctrl+D)";    // Commands    private interface Command    {        String  SELECT_ALL      = "selectAll";        String  DESELECT_ALL    = "deselectAll";        String  ACCEPT          = "accept";        String  CLOSE           = "close";    }    private static final    KeyAction.CommandMap[]  KEY_COMMANDS    =    {        new KeyAction.CommandMap( KeyStroke.getKeyStroke( KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK ),                                  Command.SELECT_ALL ),        new KeyAction.CommandMap( KeyStroke.getKeyStroke( KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK ),                                  Command.DESELECT_ALL ),        new KeyAction.CommandMap( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ),                                  Command.CLOSE )    };//////////////////////////////////////////////////////////////////////////  Member classes : non-inner classes////////////////////////////////////////////////////////////////////////    // SELECTION LIST CELL RENDERER CLASS    private static class SelectionListCellRenderer        extends JLabel        implements ListCellRenderer    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private SelectionListCellRenderer( )        {            AppFont.MAIN.setFont( this );            setOpaque( true );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : ListCellRenderer interface    ////////////////////////////////////////////////////////////////////        public Component getListCellRendererComponent( JList   list,                                                       Object  value,                                                       int     index,                                                       boolean isSelected,                                                       boolean cellHasFocus )        {            setBackground( isSelected ? list.getSelectionBackground( ) : list.getBackground( ) );            setForeground( isSelected ? list.getSelectionForeground( ) : list.getForeground( ) );            setBorder( cellHasFocus ? BorderFactory.createCompoundBorder(                                                            new DashedBorder( 2.0f ),                                                            BorderFactory.createEmptyBorder( 0, 2, 0, 2 ) )                                    : BorderFactory.createEmptyBorder( 1, 3, 1, 3 ) );            setText( value.toString( ) );            return this;        }        //--------------------------------------------------------------    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Member classes : inner classes////////////////////////////////////////////////////////////////////////    // WINDOW EVENT HANDLER CLASS    private class WindowEventHandler        extends WindowAdapter    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private WindowEventHandler( )        {        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : overriding methods    ////////////////////////////////////////////////////////////////////        public void windowClosing( WindowEvent event )        {            doClose( );        }        //--------------------------------------------------------------    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    private ListSelectionDialog( Window   owner,                                 String   titleStr,                                 String   listLabelStr,                                 String[] listStrs )    {        super( owner, titleStr, Dialog.ModalityType.APPLICATION_MODAL );        init( owner, listLabelStr, listStrs );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class methods////////////////////////////////////////////////////////////////////////    public static ListSelectionDialog showDialog( Window   owner,                                                  String   titleStr,                                                  String   listLabelStr,                                                  String[] listStrs )    {        return new ListSelectionDialog( owner, titleStr, listLabelStr, listStrs );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : ActionListener interface////////////////////////////////////////////////////////////////////////    public void actionPerformed( ActionEvent event )    {        try        {            String command = event.getActionCommand( );            String methodName = AppConstants.COMMAND_METHOD_PREFIX +                                        command.substring( 0, 1 ).toUpperCase( ) + command.substring( 1 );            Util.getDeclaredMethod( getClass( ), methodName, false ).invoke( this );        }        catch ( Exception e )        {            e.printStackTrace( );        }    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : ListSelectionListener interface////////////////////////////////////////////////////////////////////////    public void valueChanged( ListSelectionEvent event )    {        if ( !event.getValueIsAdjusting( ) )            updateComponents( );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods////////////////////////////////////////////////////////////////////////    public boolean isAccepted( )    {        return accepted;    }    //------------------------------------------------------------------    public int[] getSelections( )    {        return list.getSelectedIndices( );    }    //------------------------------------------------------------------    private void init( Window   owner,                       String   listLabelStr,                       String[] listStrs )    {

⌨️ 快捷键说明

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