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

📄 undoabledrawedit.java

📁 The Definitive Guide to Java Swing, Third Edition by John Zukowski (Author) 源码
💻 JAVA
字号:
import javax.swing.undo.*;
import java.awt.*;

public class UndoableDrawEdit extends AbstractUndoableEdit {
  UndoableDrawingPanel panel;
  Polygon polygon, savedPolygon;

  public UndoableDrawEdit(UndoableDrawingPanel panel) {
    this.panel = panel;
    polygon = panel.getPolygon();
  }

  public String getPresentationName() {
    return "Polygon of size " + polygon.npoints;
  }

  public void redo() throws CannotRedoException {
    super.redo();
    if (savedPolygon == null) {
      // Should never get here, as super() doesn't permit redoing
      throw new CannotRedoException();
    } else {
      panel.setPolygon(savedPolygon);
      savedPolygon = null;
    }
  }

  public void undo() throws CannotUndoException {
    super.undo();
    savedPolygon = panel.getPolygon();
    panel.setPolygon(polygon);
  }
}

⌨️ 快捷键说明

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