<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    工作小驛

    Ninja!

    BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
      103 Posts :: 0 Stories :: 36 Comments :: 0 Trackbacks
    import java.awt.event.ActionEvent;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.JEditorPane;
    import javax.swing.KeyStroke;
    import javax.swing.event.UndoableEditEvent;
    import javax.swing.event.UndoableEditListener;
    import javax.swing.text.JTextComponent;
    import javax.swing.undo.CannotRedoException;
    import javax.swing.undo.CannotUndoException;
    import javax.swing.undo.UndoManager;

    /**
    * UndoWrapper is responsible for adding undo and redo support to text components.
    * @author Antonio Vieiro (antonio@antonioshome.net), $Author: $
    * @version $Revision: $
    */
    public class UndoWrapper
    implements UndoableEditListener
    {
    private UndoManager undoManager;
    private UndoAction undoAction;
    private RedoAction redoAction;
    private JEditorPane textComponent;

    /**
    * Creates a new instance of UndoWrapper
    */
    public UndoWrapper( JEditorPane aComponent )
    {
    textComponent = aComponent;
    undoManager = new UndoManager();
    undoAction = new UndoAction();
    redoAction = new RedoAction();
    textComponent.getDocument().addUndoableEditListener( this );
    textComponent.getInputMap().put( (KeyStroke) undoAction.getValue(
    Action.ACCELERATOR_KEY), "undo" );
    textComponent.getInputMap().put( (KeyStroke) redoAction.getValue(
    Action.ACCELERATOR_KEY), "redo" );
    textComponent.getActionMap().put( "undo", undoAction );
    textComponent.getActionMap().put( "redo", redoAction );
    }

    public void undoableEditHappened(UndoableEditEvent e)
    {
    undoManager.addEdit( e.getEdit() );
    undoAction.updateUndoState();
    redoAction.updateRedoState();
    }

    /**
    * UndoAction is the Action responsible for handling the undo operation.
    */
    class UndoAction
    extends AbstractAction
    {
    public UndoAction()
    {
    super( "Cannot undo" ); // TODO: I18N
    setEnabled( false );
    putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl Z") );
    }

    public void actionPerformed(ActionEvent e)
    {
    try
    {
    undoManager.undo();
    }
    catch( CannotUndoException cue )
    {
    // TODO: Use logging?
    cue.printStackTrace( System.err );
    }
    updateUndoState();
    redoAction.updateRedoState();
    }

    void updateUndoState()
    {
    if ( undoManager.canUndo() )
    {
    setEnabled( true );
    putValue( Action.NAME, "Undo" ); // TODO I18N
    }
    else
    {
    setEnabled( false );
    putValue( Action.NAME, "Cannot undo" ); // TODO I18N
    }
    }
    }

    /**
    * RedoAction is the Action responsible for handling the redo operation.
    */
    class RedoAction
    extends AbstractAction
    {
    public RedoAction()
    {
    super( "Cannot redo" ); // TODO I18N
    setEnabled( false );
    putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl Y") );
    }
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    undoManager.redo();
    }
    catch( CannotRedoException cre )
    {
    // TODO: Use logging?
    cre.printStackTrace( System.err );
    }
    updateRedoState();
    undoAction.updateUndoState();
    }

    void updateRedoState()
    {
    if ( undoManager.canRedo() )
    {
    setEnabled( true );
    putValue( Action.NAME, "Redo" ); // TODO I18N
    }
    else
    {
    setEnabled( false );
    putValue( Action.NAME, "Cannot redo" ); // TODO I18N
    }
    }
    }

    UndoAction getUndoAction()
    {
    return undoAction;
    }

    RedoAction getRedoAction()
    {
    return redoAction;
    }
    }
        
    posted on 2007-08-14 12:15 王君 閱讀(468) 評(píng)論(0)  編輯  收藏 所屬分類: J2SE
    主站蜘蛛池模板: 亚洲91精品麻豆国产系列在线| 国产精品亚洲综合网站| 日韩a级毛片免费观看| 日韩精品视频在线观看免费| 亚洲国产精品一区二区久久hs| 成人免费福利视频| 日本视频免费观看| 亚洲精品免费在线| 国产高清在线免费| 免费国产污网站在线观看15| 亚洲av无码无线在线观看| 亚洲国产精华液网站w| 扒开双腿猛进入爽爽免费视频| 国产精品成人啪精品视频免费| 亚洲人成网站在线观看播放青青| 亚洲美日韩Av中文字幕无码久久久妻妇| 亚洲一区免费观看| 日韩在线一区二区三区免费视频| 亚洲日本香蕉视频| 亚洲欧洲中文日韩久久AV乱码| 亚洲精品视频免费在线观看| 一级做a爰片久久毛片免费看| 天堂亚洲国产中文在线| 亚洲AV无一区二区三区久久| 国产成人一区二区三区免费视频| 2021在线永久免费视频| 青青操在线免费观看| 亚洲成aⅴ人片久青草影院按摩| 久久精品国产精品亚洲精品| 又粗又大又猛又爽免费视频 | 亚洲日本久久久午夜精品| 亚洲精品乱码久久久久久自慰| 成人免费视频一区| 永久在线观看www免费视频| 中文字幕在线视频免费观看| 337p日本欧洲亚洲大胆人人| 2020国产精品亚洲综合网| 亚洲综合激情九月婷婷| 精品亚洲一区二区| 中文字幕亚洲无线码| 亚洲av日韩片在线观看|