From 8558ae86e65457c512a26339d3660d79eee16ae6 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 09 Jun 2019 16:33:38 -0400
Subject: [PATCH] Multi-tab undo.

---
 ObjEditor.java |  139 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 139 insertions(+), 0 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index 1edfe37..422d126 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -1935,6 +1935,7 @@
             e2.printStackTrace();
         }
     }
+    
     LoadJMEThread loadThread;
 
     class LoadJMEThread extends Thread
@@ -1992,6 +1993,7 @@
             //LoadFile0(filename, converter);
         }
     }
+    
     LoadOBJThread loadObjThread;
 
     class LoadOBJThread extends Thread
@@ -3207,10 +3209,146 @@
         {
             copy.remove(1);
         }
+        
         ResetModel();
         objEditor.refreshContents();
     }
     
+    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;
+        }
+    }
+
+    cRadio GetCurrentTab()
+    {
+        cRadio ab;
+        for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
+        {
+            ab = (cRadio)e.nextElement();
+            if(ab.GetObject() == client)
+            {
+                return ab;
+            }
+        }
+        
+        return null;
+    }
+    
+    public void Save()
+    {
+        cRadio tab = GetCurrentTab();
+        
+        //EditorFrame.m_MainFrame.requestFocusInWindow();
+        tab.graphs[tab.undoindex++] = (Object3D)clone(copy);
+
+        for (int i = tab.undoindex; i < tab.graphs.length; i++)
+        {
+            tab.graphs[i] = null;
+        }
+
+        // test save
+        if (false)
+        {
+            try
+            {
+                FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
+                ObjectOutputStream p = new ObjectOutputStream(ostream);
+
+                p.writeObject(copy);
+                
+                p.flush();
+
+                ostream.close();
+            } catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    void CopyChanged(Object3D obj)
+    {
+        copy.clear();
+        
+        for (int i=0; i<obj.Size(); i++)
+        {
+            copy.add(obj.get(i));
+        }
+        
+        copy.Touch();
+        
+        ResetModel();
+        copy.HardTouch(); // recompile?
+        
+        cRadio ab;
+        for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
+        {
+            ab = (cRadio)e.nextElement();
+            Object3D test = copy.GetObject(ab.object.GetUUID());
+            //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
+            if (test != null)
+            {
+                test.editWindow = ab.object.editWindow;
+                ab.object = test;
+            }
+        }
+        
+        refreshContents();
+    }
+    
+    public void Undo()
+    {
+        cRadio tab = GetCurrentTab();
+        
+        if (tab.undoindex == 0)
+        {
+            java.awt.Toolkit.getDefaultToolkit().beep();
+            return;
+        }
+
+        if (tab.graphs[tab.undoindex] == null)
+        {
+            Save();
+            tab.undoindex -= 1;
+        }
+
+        tab.undoindex -= 1;
+
+        CopyChanged(tab.graphs[tab.undoindex]);
+    }
+
+    public void Redo()
+    {
+        cRadio tab = GetCurrentTab();
+        
+        if (tab.graphs[tab.undoindex + 1] == null)
+        {
+            java.awt.Toolkit.getDefaultToolkit().beep();
+            return;
+        }
+
+        tab.undoindex += 1;
+
+        CopyChanged(tab.graphs[tab.undoindex]);
+    }
+
         void ImportGFD()
         {
             FileDialog browser = new FileDialog(objEditor.frame, "Import GrafreeD", FileDialog.LOAD);
@@ -3855,6 +3993,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