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

📄 frametestedititemaction.java

📁 简单的java文本编辑器
💻 JAVA
字号:
/************************************************************************************** 类名: FrameTestEditItemAction                                                               *                                                                    * 功能: 此类为编辑器中“Edit"菜单中菜单项所注册的监听器类*        **************************************************************************************/package edit.com;import java.awt.event.ActionListener;import javax.swing.JMenuItem;import java.awt.event.ActionEvent;import javax.swing.JOptionPane;import javax.swing.undo.CannotUndoException;import java.awt.Component;import java.awt.Color;class FrameTestEditItemAction implements ActionListener {    private JMenuItem[] editItems;    private FrameTestState state;    private EditArea editArea;    private FrameTestTools tool;    private Component c;    private FrameTestDialogs dialogs;    public FrameTestEditItemAction( JMenuItem[] aEditItems ,                                    FrameTestState aState,                                    EditArea aEditArea,                                    FrameTestTools aTool,                                    Component c,                                    FrameTestDialogs aDialogs ) {        editItems = aEditItems;        state = aState;        editArea = aEditArea;        tool = aTool;        this.c = c;        dialogs = aDialogs;    }    public void actionPerformed( ActionEvent e ) {       if ( editItems[0].equals( ( JMenuItem )e.getSource() ) ) { //”undo“菜单项           if ( state.getUndoManager().canUndo() ) {              try {                  state.getUndoManager().undo();              }catch( CannotUndoException c ) {                  JOptionPane.showMessageDialog( this.c,                                                 "can`t undo" , "error" ,                                                 JOptionPane.ERROR_MESSAGE );                  c.printStackTrace();              }           }else{               JOptionPane.showMessageDialog( this.c ,                                              "can`t undo" , "error" ,                                              JOptionPane.ERROR_MESSAGE );               editItems[0].setEnabled( false );           }        }else if( editItems[1].equals( ( JMenuItem )e.getSource() ) ) { //”cut"菜单项            editArea.cut();        }else if( editItems[2].equals( ( JMenuItem )e.getSource() ) ) {//“copy"菜单项            editArea.copy();        }else if( editItems[3].equals( ( JMenuItem )e.getSource() ) ) {//”paste"菜单项            editArea.paste();        }else if( editItems[4].equals( ( JMenuItem )e.getSource() ) ) {//"delete"菜单项            editArea.replaceRange( "",                                   editArea.getSelectionStart(),                                   editArea.getSelectionEnd() );        }else if( editItems[5].equals( ( JMenuItem )e.getSource() ) ) {//“find"菜单项            dialogs.setFindBox( new Find() );            dialogs.getFindBox().setString( editArea.getText() );            if ( dialogs.getFindBox().showDialog( this.c , "FindDialog" ) ) {                tool.findText( state , editArea , dialogs.getFindBox() );            }        }else if( editItems[6].equals( ( JMenuItem )e.getSource() ) ) {//"replace"菜单项            int showFlag = 0;            dialogs.setReplaceBox( new Replace() );            dialogs.getReplaceBox().setString( editArea.getText() );            showFlag = dialogs.getReplaceBox().showDialog( this.c , "ReplaceDialog" );            if ( showFlag == 1 ) {                tool.replaceText( state, editArea, dialogs.getReplaceBox() );            }else if( showFlag == 2 ) {                tool.replaceAllText( editArea , dialogs.getReplaceBox() );            }        }else if( editItems[7].equals( ( JMenuItem )e.getSource() ) ) {//”goto"菜单项            int cartPosition = 0;            dialogs.setGotoBox( new Goto( editArea.getText() ,                                          editArea.getLineCount() ) );            if ( dialogs.getGotoBox().showDialog( this.c , "GotoDialog" ) ) {                cartPosition = dialogs.getGotoBox().getFindPosition();                editArea.setCaretPosition( cartPosition );            }        }else if( editItems[8].equals( ( JMenuItem )e.getSource() ) ) {//“selectAll"菜单项            editArea.setSelectionColor( Color.red );            editArea.selectAll();        }    }}

⌨️ 快捷键说明

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