[Part 001-GEF指南] -复制剪切粘贴拷贝
程序员文章站
2022-06-01 22:16:05
...
复制:
Command:
public class CopyNodeCommand extends Command { private ArrayList<Node> list = new ArrayList<Node>(); public boolean addElement(Node node) { if (!list.contains(node)) { return list.add(node); } return false; } @Override public boolean canExecute() { if (list == null || list.isEmpty()) return false; Iterator<Node> it = list.iterator(); while (it.hasNext()) { if (!isCopyableNode(it.next())) return false; } return true; } @Override public void execute() { if (canExecute()) Clipboard.getDefault().s