public static void SetTileLayout(IImageViewer imageViewer, int rows, int columns)
        {
            Platform.CheckForNullReference(imageViewer, "imageViewer");
            Platform.CheckArgumentRange(rows, 1, LayoutSettings.MaximumTileRows, "rows");
            Platform.CheckArgumentRange(columns, 1, LayoutSettings.MaximumTileColumns, "columns");

            IImageBox imageBox = imageViewer.PhysicalWorkspace.SelectedImageBox;

            if (imageBox == null || imageBox.ParentPhysicalWorkspace.Locked)
            {
                return;
            }

            var memorableCommand = new MemorableUndoableCommand(imageBox)
            {
                BeginState = imageBox.CreateMemento()
            };

            int index = imageBox.TopLeftPresentationImageIndex;

            imageBox.SetTileGrid(rows, columns);
            imageBox.TopLeftPresentationImageIndex = index;
            imageBox.Draw();
            imageBox.SelectDefaultTile();

            memorableCommand.EndState = imageBox.CreateMemento();

            var historyCommand = new DrawableUndoableCommand(imageBox)
            {
                Name = SR.CommandLayoutTiles
            };

            historyCommand.Enqueue(memorableCommand);
            imageViewer.CommandHistory.AddCommand(historyCommand);
        }
            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);
            }
        private void ExplodeSelectedTile(IImageBox imageBox)
        {
            MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox);

            memorableCommand.BeginState = imageBox.CreateMemento();

            //set this here so checked will be correct.
            object unexplodeMemento = memorableCommand.BeginState;

            _unexplodeCommands[imageBox] = new UnexplodeTileCommand(imageBox, unexplodeMemento, RemoveUnexplodeCommand);

            IDisplaySet        displaySet    = imageBox.DisplaySet;
            IPresentationImage selectedImage = imageBox.SelectedTile.PresentationImage;

            imageBox.SetTileGrid(1, 1);

            //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;

            imageBox.TopLeftPresentationImage = selectedImage;

            memorableCommand.EndState = imageBox.CreateMemento();

            DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox);

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

            imageBox.Draw();
            imageBox.SelectDefaultTile();
        }
			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);
			}
		private void ExplodeSelectedTile(IImageBox imageBox)
		{
			MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox);
			memorableCommand.BeginState = imageBox.CreateMemento();

			//set this here so checked will be correct.
			object unexplodeMemento = memorableCommand.BeginState;
			_unexplodeCommands[imageBox] = new UnexplodeTileCommand(imageBox, unexplodeMemento, RemoveUnexplodeCommand);
			
			IDisplaySet displaySet = imageBox.DisplaySet;
			IPresentationImage selectedImage = imageBox.SelectedTile.PresentationImage;
			imageBox.SetTileGrid(1, 1);

			//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;

			imageBox.TopLeftPresentationImage = selectedImage;

			memorableCommand.EndState = imageBox.CreateMemento();

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