From 79d0f9a45d36656051a77a7b0837aa0318f81ee5 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 09 Jun 2019 11:23:18 -0400
Subject: [PATCH] Undo/redo
---
ObjEditor.java | 103 ++++++++++++++++++++++++++++++++++
GroupEditor.java | 32 ++++++++--
2 files changed, 129 insertions(+), 6 deletions(-)
diff --git a/GroupEditor.java b/GroupEditor.java
index acdf1fc..5d4b4bf 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -154,6 +154,11 @@
oe.menuBar.add(menu = new Menu("Edit"));
//editItem = menu.add(new MenuItem("Edit"));
//editItem.addActionListener(this);
+ undoItem = menu.add(new MenuItem("Undo"));
+ undoItem.addActionListener(this);
+ redoItem = menu.add(new MenuItem("Redo"));
+ redoItem.addActionListener(this);
+ menu.add("-");
duplicateItem = menu.add(new MenuItem("Duplicate"));
duplicateItem.addActionListener(this);
cloneItem = menu.add(new MenuItem("Clone"));
@@ -197,7 +202,7 @@
//zBufferItem.addActionListener(this);
//cameraMenu.add(normalLensItem = new MenuItem("Normal Lens"));
//normalLensItem.addActionListener(this);
- cameraMenu.add(revertCameraItem = new MenuItem("Revert Camera"));
+ cameraMenu.add(revertCameraItem = new MenuItem("Restore Camera"));
revertCameraItem.addActionListener(this);
cameraMenu.add(toggleFullScreenItem = new CheckboxMenuItem("Full Screen"));
@@ -261,7 +266,7 @@
// animationItem.addItemListener(this);
// animationItem.setState(CameraPane.ANIMATION);
cameraMenu.add("-");
- cameraMenu.add(editCameraItem = new MenuItem("Freeze Camera"));
+ cameraMenu.add(editCameraItem = new MenuItem("Save Camera"));
editCameraItem.addActionListener(this);
if (Globals.ADVANCED)
@@ -2004,6 +2009,14 @@
if (source == cutItem || source == clearButton)
{
loadClipboard(true);
+ } else
+ if (source == undoItem)
+ {
+ Undo();
+ } else
+ if (source == redoItem)
+ {
+ Redo();
} else
if (source == duplicateItem)
{
@@ -4297,14 +4310,19 @@
objEditor.SetText(); // jan 2014
- if (flashIt && !Globals.isLIVE() && tps != null && tps.length > 0 && !(((Object3D) tps[0].getLastPathComponent()) instanceof Camera))
+ Object3D object = (Object3D) tps[0].getLastPathComponent();
+
+ if (flashIt && !Globals.isLIVE() && tps != null && tps.length > 0 && !(object instanceof Camera))
CameraPane.flash = true;
- if (tps != null && tps.length > 0 && ((Object3D) tps[0].getLastPathComponent()) instanceof Camera)
+ if (tps != null && tps.length > 0 && object instanceof Camera)
// a camera
{
- CameraPane.camerachangeframe = 0; // don't refuse it
- Globals.theRenderer.SetCamera((Camera) tps[0].getLastPathComponent());
+ if (object != Globals.theRenderer.LightCamera())
+ {
+ CameraPane.camerachangeframe = 0; // don't refuse it
+ Globals.theRenderer.SetCamera((Camera) tps[0].getLastPathComponent());
+ }
// Globals.theRenderer.renderCamera = Globals.theRenderer.manipCamera;
// Globals.theRenderer.eyeCamera = Globals.theRenderer.manipCamera;
}
@@ -5145,6 +5163,8 @@
private MenuItem lookFromItem;
private MenuItem switchItem;
private MenuItem cutItem;
+ private MenuItem undoItem;
+ private MenuItem redoItem;
private MenuItem duplicateItem;
private MenuItem cloneItem;
private MenuItem cloneSupportItem;
diff --git a/ObjEditor.java b/ObjEditor.java
index 1edfe37..05b548c 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -3207,10 +3207,112 @@
{
copy.remove(1);
}
+
ResetModel();
objEditor.refreshContents();
}
+ Object3D graphs[] = new Object3D[10000];
+ int undoindex = 0;
+
+ static public Object clone(Object o)
+ {
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(baos);
+
+ out.writeObject(o);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(bais);
+ Object obj = in.readObject();
+ in.close();
+ out.close();
+ return obj;
+ } catch (Exception e)
+ {
+ System.err.println(e);
+ return null;
+ }
+ }
+
+ public void Save()
+ {
+ if (true) return;
+
+ //EditorFrame.m_MainFrame.requestFocusInWindow();
+ graphs[undoindex++] = (Object3D)clone(copy);
+
+ for (int i = undoindex; i < graphs.length; i++)
+ {
+ graphs[i] = null;
+ }
+
+ // test save
+ if (false)
+ {
+ try
+ {
+ FileOutputStream ostream = new FileOutputStream("save" + undoindex);
+ ObjectOutputStream p = new ObjectOutputStream(ostream);
+
+ p.writeObject(copy);
+
+ p.flush();
+
+ ostream.close();
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void Undo()
+ {
+ if (undoindex == 0)
+ {
+ java.awt.Toolkit.getDefaultToolkit().beep();
+ return;
+ }
+
+ if (graphs[undoindex] == null)
+ {
+ Save();
+ undoindex -= 1;
+ }
+
+ undoindex -= 1;
+
+ copy = graphs[undoindex];
+
+ cameraView.object = copy;
+ copy.Touch();
+
+ ResetModel();
+ refreshContents();
+ }
+
+ public void Redo()
+ {
+ if (graphs[undoindex + 1] == null)
+ {
+ java.awt.Toolkit.getDefaultToolkit().beep();
+ return;
+ }
+
+ undoindex += 1;
+
+ copy = graphs[undoindex];
+
+ cameraView.object = copy;
+ copy.Touch();
+
+ ResetModel();
+ refreshContents();
+ }
+
void ImportGFD()
{
FileDialog browser = new FileDialog(objEditor.frame, "Import GrafreeD", FileDialog.LOAD);
@@ -3855,6 +3957,7 @@
void makeSomething(Object3D thing, boolean resetmodel) // deselect)
{
+ Save();
//Tween.set(thing, 0).target(1).start(tweenManager);
//Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
// if (thing instanceof GenericJointDemo)
--
Gitblit v1.6.2