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

📄 caretaker.cs

📁 c#设计模式随书源码 c#设计模式随书源码
💻 CS
字号:
using System;
using System.Collections ;
namespace Memento
{
	/// <summary>
	/// Summary description for CareTaker.
	/// </summary>
	public class CareTaker
	{
		private ArrayList drawings, undoList;
		private Memento mem;
		private VisRectangle[] draw_ings; //used only to make UML clearer
		public CareTaker(ArrayList dcol)
		{
			clear(dcol);
		}
		public void rememberPosition(VisRectangle vr) {
			mem = new Memento (vr);
			undoList.Add (mem);
		}
		public void clear(ArrayList drw) {
			drawings = drw;
			undoList = new ArrayList();
		}
		public void Add(int intg) {
			undoList.Add (intg);
		}
		public void removeDrawing() {
			drawings.RemoveAt (drawings.Count -1);
		}
		public void remove(Memento mem) {
			mem.restore ();
		}
		public void remove(int intg) {
			removeDrawing();
		}
		public void undo() {
			if(undoList.Count > 0) {
				int last = undoList.Count -1;
				object obj = undoList[last];
				try{
					Memento mem = (Memento)obj;
					remove(mem);
				}
				catch (Exception) {
					removeDrawing();
				}
				undoList.RemoveAt (last);
			}
		}
	}
}

⌨️ 快捷键说明

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