Ejemplo n.º 1
0
        /// <summary>
        /// Sets this <see cref="PhysicalWorkspace"/> with a previously created memento.
        /// </summary>
        /// <param name="memento">Memento to set.</param>
        /// <remarks>
        /// This method restores the state of a <see cref="PhysicalWorkspace"/> with
        /// a memento previously created by <see cref="CreateMemento"/>.
        /// </remarks>
        public virtual void SetMemento(object memento)
        {
            Platform.CheckForNullReference(memento, "memento");

            PhysicalWorkspaceMemento workspaceMemento = (PhysicalWorkspaceMemento)memento;

            //locked is not part of the memento.
            bool locked = Locked;

            SetLocked(false);

            this.ImageBoxes.Clear();

            for (int i = 0; i < workspaceMemento.ImageBoxes.Count; i++)
            {
                object    imageBoxMemento = workspaceMemento.ImageBoxMementos[i];
                IImageBox imageBox        = workspaceMemento.ImageBoxes[i];
                imageBox.SetMemento(imageBoxMemento);

                this.ImageBoxes.Add(imageBox);
            }

            _rows    = workspaceMemento.Rows;
            _columns = workspaceMemento.Columns;

            SetImageBoxGrid();

            //restore locked state.
            SetLocked(locked);

            OnLayoutCompleted();

            //The command in the command history should be drawable.
            //Draw();
        }
Ejemplo n.º 2
0
			private static void Execute(IImageBox imageBox, object unexplodeMemento)
			{
				MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox);
				memorableCommand.BeginState = imageBox.CreateMemento();

				IDisplaySet displaySet = imageBox.DisplaySet;
				IPresentationImage selectedImage;
				if (imageBox.SelectedTile != null)
					selectedImage = imageBox.SelectedTile.PresentationImage;
				else
					selectedImage = imageBox.TopLeftPresentationImage;

				imageBox.SetMemento(unexplodeMemento);

				//TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]).
				//This stuff with mementos is actually a hacky workaround.

				bool locked = imageBox.DisplaySetLocked;
				imageBox.DisplaySetLocked = false;
				imageBox.DisplaySet = displaySet;
				imageBox.DisplaySetLocked = locked;

				if (selectedImage != null)
					imageBox.TopLeftPresentationImage = selectedImage;

				imageBox.Draw();
                imageBox.SelectDefaultTile();

				memorableCommand.EndState = imageBox.CreateMemento();

				DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox);
				historyCommand.Name = SR.CommandExplodeTile;
				historyCommand.Enqueue(memorableCommand);
				imageBox.ParentPhysicalWorkspace.ImageViewer.CommandHistory.AddCommand(historyCommand);
			}
Ejemplo n.º 3
0
        private void ExplodeImageBox()
        {
            IImageBox imageBox = ImageViewer.SelectedImageBox;

            if (!CanExplodeImageBox(imageBox))
            {
                return;
            }

            IPhysicalWorkspace       workspace        = imageBox.ParentPhysicalWorkspace;
            MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace);

            memorableCommand.BeginState = workspace.CreateMemento();

            _imageBoxesObserver.SuppressChangedEvent = true;

            //set this here so checked will be correct.
            _unexplodeMemento = memorableCommand.BeginState;
            _oldImageBox      = imageBox;
            IDisplaySet        displaySet    = _oldImageBox.DisplaySet;
            IPresentationImage selectedImage = _oldImageBox.SelectedTile.PresentationImage;

            object imageBoxMemento = _oldImageBox.CreateMemento();

            workspace.SetImageBoxGrid(1, 1);
            IImageBox newImageBox = workspace.ImageBoxes[0];

            newImageBox.SetMemento(imageBoxMemento);

            //TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]).
            //This stuff with mementos is actually a hacky workaround.

            bool locked = newImageBox.DisplaySetLocked;

            newImageBox.DisplaySetLocked         = false;
            newImageBox.DisplaySet               = displaySet;
            newImageBox.TopLeftPresentationImage = selectedImage;
            newImageBox.DisplaySetLocked         = locked;

            _imageBoxesObserver.SuppressChangedEvent = false;

            workspace.Draw();
            workspace.SelectDefaultImageBox();

            memorableCommand.EndState = workspace.CreateMemento();
            DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace);

            historyCommand.Name = SR.CommandSurveyExplode;
            historyCommand.Enqueue(memorableCommand);
            base.ImageViewer.CommandHistory.AddCommand(historyCommand);

            OnCheckedChanged();
            UpdateEnabled();
        }
Ejemplo n.º 4
0
        private void ExplodeImageBoxes()
        {
            if (0 == imageBoxHistory.Count ||
                !CanExplodeImageBox(ImageViewer.SelectedImageBox))
            {
                return;
            }

            IPhysicalWorkspace       workspace        = ImageViewer.SelectedImageBox.ParentPhysicalWorkspace;
            MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(workspace);

            memorableCommand.BeginState = workspace.CreateMemento();

            _imageBoxesObserver.SuppressChangedEvent = true;

            //set this here so checked will be correct.
            _unexplodeMemento = memorableCommand.BeginState;
            List <IImageBox> explodeImageBoxes = new List <IImageBox>(imageBoxHistory.Skip(imageBoxHistory.Count - WorkspaceScreenCount()));

            explodeImageBoxes.Reverse();

            List <object> mementoList = new List <object>();

            foreach (IImageBox imageBox in explodeImageBoxes)
            {
                mementoList.Add(imageBox.CreateMemento());
            }

            workspace.SetImageBoxGrid(1, explodeImageBoxes.Count);
            int i = 0;

            foreach (IImageBox imageBox in explodeImageBoxes)
            {
                IImageBox newImageBox = workspace.ImageBoxes[i];
                oldImageBoxMap.Add(imageBox, newImageBox);
                newImageBox.SetMemento(mementoList[i]);
                i++;
            }

            _imageBoxesObserver.SuppressChangedEvent = false;

            workspace.Draw();
            workspace.SelectDefaultImageBox();

            memorableCommand.EndState = workspace.CreateMemento();
            DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(workspace);

            historyCommand.Name = SR.CommandSurveyExplode;
            historyCommand.Enqueue(memorableCommand);
            base.ImageViewer.CommandHistory.AddCommand(historyCommand);

            OnCheckedChanged();
            UpdateEnabled();
        }
Ejemplo n.º 5
0
            private static void Execute(IImageBox imageBox, object unexplodeMemento)
            {
                MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox);

                memorableCommand.BeginState = imageBox.CreateMemento();

                IDisplaySet        displaySet = imageBox.DisplaySet;
                IPresentationImage selectedImage;

                if (imageBox.SelectedTile != null)
                {
                    selectedImage = imageBox.SelectedTile.PresentationImage;
                }
                else
                {
                    selectedImage = imageBox.TopLeftPresentationImage;
                }

                imageBox.SetMemento(unexplodeMemento);

                //TODO (architecture): this wouldn't be necessary if we had a SetImageBoxGrid(imageBox[,]).
                //This stuff with mementos is actually a hacky workaround.

                bool locked = imageBox.DisplaySetLocked;

                imageBox.DisplaySetLocked = false;
                imageBox.DisplaySet       = displaySet;
                imageBox.DisplaySetLocked = locked;

                if (selectedImage != null)
                {
                    imageBox.TopLeftPresentationImage = selectedImage;
                }

                imageBox.Draw();
                imageBox.SelectDefaultTile();

                memorableCommand.EndState = imageBox.CreateMemento();

                DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox);

                historyCommand.Name = SR.CommandExplodeTile;
                historyCommand.Enqueue(memorableCommand);
                imageBox.ParentPhysicalWorkspace.ImageViewer.CommandHistory.AddCommand(historyCommand);
            }