Exemplo n.º 1
0
        public static void Demo()
        {
            Originator o = new Originator()
            {
                State = "1"
            };
            CareTaker ct = new CareTaker();

            o.State = "2";
            ct.Add(o.Memento);

            o.State = "3";
            ct.Add(o.Memento);

            o.State = "4";
            Console.WriteLine("Current State " + o.State);

            o.Memento = ct.Get(0);
            Console.WriteLine("First State " + o.State);

            o.Memento = ct.Get(1);
            Console.WriteLine("Second State " + o.State);

            Console.Read();
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show(doc.content);

            caretaker.Add(doc.SaveMemento());

            doc.content = "1-Cambiando el contenido...";
            caretaker.Add(doc.SaveMemento());
            MessageBox.Show(doc.content);

            doc.content = "2-Cambiando el contenido... de nuevo...";
            caretaker.Add(doc.SaveMemento());
            MessageBox.Show(doc.content);

            doc.content = "3-Una vez más...";
            caretaker.Add(doc.SaveMemento());
            MessageBox.Show(doc.content);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Originator originator = new Originator();
            CareTaker  careTaker  = new CareTaker();

            originator.State = "State1";
            originator.State = "State2";

            originator.State = "State3";
            careTaker.Add(originator.SaveStateToMemento());
            originator.State = "State4";
            careTaker.Add(originator.SaveStateToMemento());

            Console.WriteLine(originator.GetStateFromMemento(careTaker.Get(0)));
            Console.WriteLine(originator.GetStateFromMemento(careTaker.Get(1)));

            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Originator originator = new Originator();
            CareTaker  careTaker  = new CareTaker();

            originator.State = "State #1";
            originator.State = "State #2";
            careTaker.Add(originator.SaveStateToMemento());
            originator.State = "State #3";
            careTaker.Add(originator.SaveStateToMemento());
            originator.State = "State #4";
            Console.WriteLine("Current State: " + originator.State);
            originator.GetStateFromMemento(careTaker.Get(0));
            Console.WriteLine("First saved State: " + originator.State);
            originator.GetStateFromMemento(careTaker.Get(1));
            Console.WriteLine("Second saved State: " + originator.State);
            Console.ReadKey();
        }
Exemplo n.º 5
0
        static void Main()
        {
            Originator originator = new Originator();
            CareTaker  careTaker  = new CareTaker();

            originator.SetState("State #1");
            originator.SetState("State #2");
            careTaker.Add(originator.SaveStateToMemento());

            originator.SetState("State #3");
            careTaker.Add(originator.SaveStateToMemento());

            originator.SetState("State #4");

            Console.WriteLine("Current State: " + originator.GetState());
            originator.GetStateFromMemento(careTaker.Get(0));

            Console.WriteLine("First saved State: " + originator.GetState());
            originator.GetStateFromMemento(careTaker.Get(1));
            Console.WriteLine("Second saved State: " + originator.GetState());
        }
Exemplo n.º 6
0
 //-----
 public void createRect(int x, int y)
 {
     unpick();                     //make sure no rectangle is selected
     if (startRect)                //if rect button is depressed
     {
         int count = drawings.Count;
         caretakr.Add(count);                     //Save previous drawing list size
         VisRectangle v = new VisRectangle(x, y); //create a rectangle
         drawings.Add(v);                         //add new element to list
         startRect = false;                       //done with this rectangle
         rect.setSelected(false);                 //unclick button
         canvas.Refresh();
     }
     else
     {
         pickRect(x, y);                   //if not pressed look for rect to select
     }
 }