anundoablecomponent.java

来自「The Definitive Guide to Java Swing, Thir」· Java 代码 · 共 35 行

JAVA
35
字号
import javax.swing.undo.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;

public class AnUndoableComponent {
  UndoableEditSupport undoableEditSupport = new UndoableEditSupport(this);
  ActionListener actionListenerList = null;

  public void addActionListener(ActionListener actionListener) {
    actionListenerList = AWTEventMulticaster.add(actionListener, actionListenerList);
  }

  public void removeActionListener(ActionListener actionListener) {
    actionListenerList = AWTEventMulticaster.remove(actionListener, actionListenerList);
  }

  public void addUndoableEditListener(UndoableEditListener undoableEditListener) {
    undoableEditSupport.addUndoableEditListener(undoableEditListener);
  }

  public void removeUndoableEditListener(UndoableEditListener undoableEditListener) {
    undoableEditSupport.removeUndoableEditListener(undoableEditListener);
  }

  protected void fireActionPerformed(ActionEvent actionEvent) {
    if (actionListenerList != null) {
      actionListenerList.actionPerformed(actionEvent);
    }
    // Need to create your custom type of undoable operation
    undoableEditSupport.postEdit(new AbstractUndoableEdit());
  } 
}

⌨️ 快捷键说明

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