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

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

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

    工作小驛

    Ninja!

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      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) 評論(0)  編輯  收藏 所屬分類: J2SE
    主站蜘蛛池模板: 亚洲精品第一国产综合野| 亚洲熟妇丰满多毛XXXX| 亚洲免费网站在线观看| **aaaaa毛片免费| 亚洲图片激情小说| 久草视频免费在线观看| 亚洲成人黄色网址| 无码免费午夜福利片在线| 亚洲色大成网站www久久九| 成人免费a级毛片| 亚洲AV无码AV男人的天堂不卡| 在线免费视频一区二区| 在线观看免费亚洲| 亚洲成网777777国产精品| 久久精品无码专区免费| 亚洲自偷自偷精品| 好爽…又高潮了免费毛片| 黄页网站在线视频免费| 国产日韩亚洲大尺度高清| 99在线观看免费视频| 亚洲精品天堂在线观看| 亚洲A丁香五香天堂网| 久久精品国产免费| 亚洲成a人片在线看| 亚洲A∨精品一区二区三区| 18禁在线无遮挡免费观看网站| 亚洲精品91在线| 国产在线观看免费完整版中文版| 国产黄片不卡免费| 亚洲第一永久在线观看| 午夜精品在线免费观看| 三级黄色免费观看| 亚洲国产精品无码久久久| 国产小视频在线观看免费| 一个人免费视频观看在线www| 亚洲AV无码一区二区三区在线| 国产在线不卡免费播放| 午夜无码A级毛片免费视频| 亚洲欧美日韩一区二区三区 | 18禁在线无遮挡免费观看网站| 亚洲伦理一二三四|