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

📄 keyaction.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
字号:
/*====================================================================*\KeyAction.javaKey action 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/>.\*====================================================================*/// PACKAGEpackage util;//----------------------------------------------------------------------// IMPORTSimport java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.JComponent;import javax.swing.KeyStroke;//----------------------------------------------------------------------// KEY ACTION CLASSpublic class KeyAction    extends AbstractAction{//////////////////////////////////////////////////////////////////////////  Member classes : non-inner classes////////////////////////////////////////////////////////////////////////    // COMMAND MAP CLASS    public static class CommandMap    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        public CommandMap( KeyStroke keyStroke,                           String    command )        {            this.keyStroke = keyStroke;            this.command = command;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        public  KeyStroke   keyStroke;        public  String      command;    }    //==================================================================    // ACTION MAP CLASS    public static class ActionMap    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        public ActionMap( KeyStroke keyStroke,                          Action    action )        {            this.keyStroke = keyStroke;            this.action = action;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        public  KeyStroke   keyStroke;        public  Action      action;    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    private KeyAction( String         command,                       ActionListener listener )    {        this.listener = listener;        putValue( Action.ACTION_COMMAND_KEY, command );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class methods////////////////////////////////////////////////////////////////////////    public static void create( JComponent component,                               int        condition,                               KeyStroke  keyStroke,                               Action     action )    {        String command = action.getValue( Action.ACTION_COMMAND_KEY ).toString( );        component.getInputMap( condition ).put( keyStroke, command );        component.getActionMap( ).put( command, action );    }    //------------------------------------------------------------------    public static void create( JComponent component,                               int        condition,                               ActionMap  actionMap )    {        create( component, condition, actionMap.keyStroke, actionMap.action );    }    //------------------------------------------------------------------    public static void create( JComponent  component,                               int         condition,                               ActionMap[] actionMaps )    {        for ( ActionMap actionMap : actionMaps )            create( component, condition, actionMap.keyStroke, actionMap.action );    }    //------------------------------------------------------------------    public static void create( JComponent     component,                               int            condition,                               KeyStroke      keyStroke,                               String         command,                               ActionListener listener )    {        create( component, condition, keyStroke, new KeyAction( command, listener ) );    }    //------------------------------------------------------------------    public static void create( JComponent     component,                               int            condition,                               CommandMap     commandMap,                               ActionListener listener )    {        create( component, condition, commandMap.keyStroke, commandMap.command, listener );    }    //------------------------------------------------------------------    public static void create( JComponent     component,                               int            condition,                               CommandMap[]   commandMaps,                               ActionListener listener )    {        for ( CommandMap commandMap : commandMaps )            create( component, condition, commandMap.keyStroke, commandMap.command, listener );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : ActionListener interface////////////////////////////////////////////////////////////////////////    public void actionPerformed( ActionEvent event )    {        event.setSource( null );        listener.actionPerformed( event );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance variables////////////////////////////////////////////////////////////////////////    private ActionListener  listener;}//----------------------------------------------------------------------

⌨️ 快捷键说明

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