From d7a17c35c443e2cb6c09eaa3cfeaf590a571faa1 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Wed, 17 Jul 2019 20:15:40 -0400
Subject: [PATCH] Version slider

---
 ObjEditor.java |  431 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 339 insertions(+), 92 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index d10d05b..6e1560f 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -15,6 +15,9 @@
 //import javax.swing.plaf.ColorUIResource;
 //import javax.swing.plaf.metal.DefaultMetalTheme;
 
+import javax.swing.plaf.basic.BasicSplitPaneDivider;
+import javax.swing.plaf.basic.BasicSplitPaneUI;
+
 //import javax.media.opengl.GLCanvas;
 
 import //weka.core.
@@ -279,6 +282,12 @@
         client = inClient;
         copy = client;
 
+        if (copy.versions == null)
+        {
+            copy.versions = new byte[100][];
+            copy.versionindex = -1;
+        }
+        
         // "this" is not called: SetupUI2(objEditor);
     }
 
@@ -292,6 +301,12 @@
         client = inClient;
         copy = client;
 
+        if (copy.versions == null)
+        {
+            copy.versions = new byte[100][];
+            copy.versionindex = -1;
+        }
+        
         SetupUI2(callee.GetEditor());
     }
 
@@ -306,7 +321,7 @@
         //localCopy.parent = null;
 
         frame = new JFrame();
-                frame.setUndecorated(true);
+                frame.setUndecorated(false);
         objEditor = this;
         this.callee = callee;
 
@@ -324,6 +339,12 @@
         copy = localCopy;
         copy.editWindow = this;
 
+        if (copy.versions == null)
+        {
+            copy.versions = new byte[100][];
+            copy.versionindex = -1;
+        }
+        
         SetupMenu();
 
         //SetupName(objEditor); // new
@@ -347,7 +368,7 @@
         frame.setMenuBar(menuBar = new MenuBar());
         menuBar.add(fileMenu = new Menu("File"));
         fileMenu.add(newItem = new MenuItem("New"));
-        fileMenu.add(loadItem = new MenuItem("Open..."));
+        fileMenu.add(openItem = new MenuItem("Open..."));
         
                 //oe.menuBar.add(menu = new Menu("Include"));
         Menu menu = new Menu("Import");
@@ -379,7 +400,7 @@
         }
 
         newItem.addActionListener(this);
-        loadItem.addActionListener(this);
+        openItem.addActionListener(this);
         saveItem.addActionListener(this);
         saveAsItem.addActionListener(this);
         exportAsItem.addActionListener(this);
@@ -446,7 +467,7 @@
 // TEXTAREA           infoarea.setLineWrap(true);
 // TEXTAREA           infoarea.setWrapStyleWord(true);
         infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
-        infoPanel.setPreferredSize(new Dimension(50, 200));
+        infoPanel.setPreferredSize(new Dimension(1, 1));
         infoPanel.setName("Info");
         //infoPanel.setLayout(new BorderLayout());
         //infoPanel.add(createTextPane());
@@ -458,7 +479,14 @@
         mainPanel.setDividerSize(9);
         mainPanel.setDividerLocation(0.5); //1.0);
         mainPanel.setResizeWeight(0.5);
-
+        
+//mainPanel.setDividerSize((int) (mainPanel.getDividerSize() * 1.5));
+    BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) mainPanel.getUI()).getDivider();
+    divider.setDividerSize(15);
+    divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!"));    
+    
+    mainPanel.setUI(new BasicSplitPaneUI());
+    
         //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
         //mainPanel.setLayout(new GridBagLayout());
         toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
@@ -689,8 +717,8 @@
         }
     }
 
-static GraphicsDevice device = GraphicsEnvironment
-        .getLocalGraphicsEnvironment().getScreenDevices()[0];
+//static GraphicsDevice device = GraphicsEnvironment
+//        .getLocalGraphicsEnvironment().getScreenDevices()[0];
 
     Rectangle keeprect;
         cRadio radio;
@@ -711,10 +739,19 @@
         void Minimize()
         {
             frame.setState(Frame.ICONIFIED);
+            frame.validate();
         }
         
+//        artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={}
+//        artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={}
+//        artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={}
         void Maximize()
         {
+            if (CameraPane.FULLSCREEN)
+            {
+                ToggleFullScreen();
+            }
+            
             if (maximized)
             {
                 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
@@ -722,22 +759,36 @@
             else
             {
                 keeprect = frame.getBounds();
-                Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
-                Dimension rect2 = frame.getToolkit().getScreenSize();
-                frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
+//                Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
+//                Dimension rect2 = frame.getToolkit().getScreenSize();
+//                frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
 //                frame.setState(Frame.MAXIMIZED_BOTH);
+                frame.setBounds(frame.getGraphicsConfiguration().getBounds());
             }
             
             maximized ^= true;
+            
+            frame.validate();
         }
+        
+	cButton minButton;
+	cButton maxButton;
+	cButton fullButton;
         
         void ToggleFullScreen()
         {
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
+
                 cameraView.ToggleFullScreen();
                 
                 if (!CameraPane.FULLSCREEN)
                 {
                     device.setFullScreenWindow(null);
+                    frame.dispose();
+                frame.setUndecorated(false);
+            frame.validate();
+                    frame.setVisible(true);
+                    
                     //frame.setVisible(false);
 //                frame.removeNotify();
 //                frame.setUndecorated(false);
@@ -747,7 +798,7 @@
 // X                   frame.getContentPane().remove(/*"Center",*/bigThree);
 // X                   framePanel.add(bigThree);
 // X                   frame.getContentPane().add(/*"Center",*/framePanel);
-                    framePanel.setDividerLocation(1);
+                    framePanel.setDividerLocation(46);
                     
                     //frame.setVisible(true);
                     radio.layout = keepButton;
@@ -762,7 +813,12 @@
 //                frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
 //                        frame.getToolkit().getScreenSize().height);
                     //frame.setVisible(false);
+                    
+            frame.dispose();
+                frame.setUndecorated(true);
                     device.setFullScreenWindow(frame);
+            frame.validate();
+                    frame.setVisible(true);
 //                frame.removeNotify();
 //                frame.setUndecorated(true);
 //                frame.addNotify();
@@ -775,7 +831,30 @@
                     radio.layout.doClick();
                     //frame.setVisible(true);
                 }
+            frame.validate();
         }
+
+    private byte[] CompressCopy()
+    {
+        boolean temp = CameraPane.SWITCH;
+        CameraPane.SWITCH = false;
+        
+        copy.ExtractBigData(versiontable);
+        // if (copy == client)
+        
+        byte[] versions[] = copy.versions;
+        copy.versions = null;
+        
+        byte[] compress = Compress(copy);
+        
+        copy.versions = versions;
+        
+        copy.RestoreBigData(versiontable);
+        
+        CameraPane.SWITCH = temp;
+        
+        return compress;
+    }
 
     private JTextPane createTextPane()
     {
@@ -1107,7 +1186,7 @@
             namePanel = new cGridBag();
             
         nameField = AddText(namePanel, copy.GetName());
-        namePanel.add(nameField);
+        namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
         oe.ctrlPanel.add(namePanel);
         
         oe.ctrlPanel.Return();
@@ -1125,20 +1204,21 @@
         hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
                 hideCB.setToolTipText("Hide object");
         markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
-        markCB.setToolTipText("Set the animation target transform");
+        markCB.setToolTipText("As animation target transform");
         
             setupPanel2 = new cGridBag().setVertical(false);
             
         rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
         rewindCB.setToolTipText("Rewind animation");
         
-        randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
-        randomCB.setToolTipText("Randomly Rewind or Go back and forth");
+        randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
+        randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
 
+        link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
+        link2masterCB.setToolTipText("Attach to support");
+        
         if (Globals.ADVANCED)
         {
-                link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
-                link2masterCB.setToolTipText("Attach to support");
                 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
                 speedupCB.setToolTipText("Option motion capture");
         }
@@ -1454,7 +1534,10 @@
 //        north.add(ctrlPanel, BorderLayout.NORTH);
 //        objectPanel.add(north);
         objectPanel.add(editPanel);
-        objectPanel.add(infoPanel);
+        
+        //if (Globals.ADVANCED)
+            objectPanel.add(infoPanel);
+        
         objectPanel.add(toolboxPanel);
 
         /*
@@ -1563,9 +1646,9 @@
 //		aConstraints.gridheight = 1;
 
         framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
-        framePanel.setContinuousLayout(true);
-        framePanel.setOneTouchExpandable(true);
-        framePanel.setDividerLocation(0.8);
+        framePanel.setContinuousLayout(false);
+        framePanel.setOneTouchExpandable(false);
+        //.setDividerLocation(0.8);
         //framePanel.setDividerSize(15);
         //framePanel.setResizeWeight(0.15);
         framePanel.setName("Frame");
@@ -1584,12 +1667,13 @@
 
         frame.setSize(1280, 860);
         
-        frame.validate();
-        frame.setVisible(true);
-
                     cameraView.requestFocusInWindow();
                     
         gridPanel.setDividerLocation(1.0);
+        
+        frame.validate();
+
+        frame.setVisible(true);
 
         frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
         frame.addWindowListener(new WindowAdapter()
@@ -1676,24 +1760,6 @@
                 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
         colorSection.add(texture);
 
-        cGridBag anisoU = new cGridBag();
-                anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
-                anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
-                anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
-        colorSection.add(anisoU);
-
-        cGridBag anisoV = new cGridBag();
-                anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
-                anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
-                anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
-        colorSection.add(anisoV);
-
-        cGridBag shadowbias = new cGridBag();
-                shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
-                shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
-                shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
-        colorSection.add(shadowbias);
-
         panel.add(new JSeparator());
         
         panel.add(colorSection);
@@ -1743,6 +1809,12 @@
                 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
         diffuseSection.add(fakedepth);
+
+        cGridBag shadowbias = new cGridBag();
+                shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
+                shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+                shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
+        diffuseSection.add(shadowbias);
 
         panel.add(new JSeparator());
         
@@ -1794,6 +1866,18 @@
 //		aConstraints.gridy += 1;
 //		aConstraints.gridwidth = 1;
 
+        cGridBag anisoU = new cGridBag();
+                anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
+                anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+                anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
+        specularSection.add(anisoU);
+
+        cGridBag anisoV = new cGridBag();
+                anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
+                anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+                anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
+        specularSection.add(anisoV);
+
 
         panel.add(new JSeparator());
         
@@ -1801,35 +1885,35 @@
         
         //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
         
-        cGridBag globalSection = new cGridBag().setVertical(true);
+        //cGridBag globalSection = new cGridBag().setVertical(true);
 
         cGridBag camera = new cGridBag();
                 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
                 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
-        globalSection.add(camera);
+        colorSection.add(camera);
 
         cGridBag ambient = new cGridBag();
                 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
                 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
-        globalSection.add(ambient);
+        colorSection.add(ambient);
 
         cGridBag backlit = new cGridBag();
                 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
                 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
-        globalSection.add(backlit);
+        colorSection.add(backlit);
 
         cGridBag opacity = new cGridBag();
                 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
                 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
-        globalSection.add(opacity);
+        colorSection.add(opacity);
 
-        panel.add(new JSeparator());
+        //panel.add(new JSeparator());
         
-        panel.add(globalSection);
+        //panel.add(globalSection);
         
         //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
         
@@ -1936,8 +2020,9 @@
             // 3D models
             if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
             {
-                lastConverter = new com.jmex.model.converters.MaxToJme();
-                LoadFile(filename, lastConverter);
+                //lastConverter = new com.jmex.model.converters.MaxToJme();
+                //LoadFile(filename, lastConverter);
+                LoadObjFile(filename); // New 3ds loader
                 continue;
             }
             if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
@@ -2663,6 +2748,7 @@
                 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
                 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
             }
+            
             //cJME.count++;
             //cJME.count %= 12;
             if (gc)
@@ -2846,6 +2932,7 @@
             }
         }
     }
+    
     cFileSystemPane FSPane;
 
     void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
@@ -2899,6 +2986,7 @@
                 }
             }
         }
+        
         freezematerial = false;
     }
 
@@ -3017,12 +3105,17 @@
 //                }
 
         /**/
-        if (deselect)
+        if (deselect || child == null)
         {
             //group.deselectAll();
             //freeze = true;
             GetTree().clearSelection();
             //freeze = false;
+            
+            if (child == null)
+            {
+                return;
+            }
         }
 
         //group.addSelectee(child);
@@ -3346,9 +3439,9 @@
         {
             Close();
             //return true;
-        } else if (source == loadItem)
+        } else if (source == openItem)
         {
-            load();
+            Open();
             //return true;
         } else if (source == newItem)
         {
@@ -3373,6 +3466,10 @@
         {
             generatePOV();
             //return true;
+        } else if (event.getSource() == archiveItem)
+        {
+            cTools.Archive(frame);
+            return;
         } else if (source == zBufferItem)
         {
             try
@@ -3424,8 +3521,8 @@
         try
         {
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
-            ObjectOutputStream out = new ObjectOutputStream(zstream);
+//            java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
+            ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
 
         Object3D parent = o.parent;
         o.parent = null;
@@ -3436,10 +3533,14 @@
         
             out.flush();
 
-            zstream.close();
+            baos //zstream
+                    .close();
             out.close();
             
-            return baos.toByteArray();
+            byte[] bytes = baos.toByteArray();
+            
+        System.out.println("save #bytes = " + bytes.length);
+            return bytes;
         } catch (Exception e)
         {
             System.err.println(e);
@@ -3449,13 +3550,16 @@
 
     static public Object Uncompress(byte[] bytes)
     {
-        System.out.println("#bytes = " + bytes.length);
+        System.out.println("restore #bytes = " + bytes.length);
         try
         {
             ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-            java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
-            ObjectInputStream in = new ObjectInputStream(istream);
+            //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
+            ObjectInputStream in = new ObjectInputStream(bais); // istream);
             Object obj = in.readObject();
+            
+            bais //istream
+                    .close();
             in.close();
             
             return obj;
@@ -3510,31 +3614,67 @@
         return null;
     }
     
-    java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
     
     public void Save()
+    {
+        //Save(true);
+        Replace();
+    }
+    
+    private boolean Equal(byte[] compress, byte[] name)
+    {
+        if (compress.length != name.length)
+        {
+            return false;
+        }
+        
+        for (int i=compress.length; --i>=0;)
+        {
+            if (compress[i] != name[i])
+                return false;
+        }
+        
+        return true;
+    }
+
+    java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
+    
+    public boolean Save(boolean user)
     {
         System.err.println("Save");
         
         cRadio tab = GetCurrentTab();
         
-        boolean temp = CameraPane.SWITCH;
-        CameraPane.SWITCH = false;
+        byte[] compress = CompressCopy();
         
-        copy.ExtractBigData(hashtable);
+        boolean thesame = false;
+        
+        // Quick heuristic using length. Works only when stream is compressed.
+        if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
+        {
+            thesame = true;
+        }
         
         //EditorFrame.m_MainFrame.requestFocusInWindow();
-        tab.graphs[tab.undoindex++] = Compress(copy);
+        if (!thesame)
+        {
+            //tab.user[tab.versionindex] = user;
+            //boolean increment = true; // tab.graphs[tab.versionindex] == null;
+            
+            copy.versions[++copy.versionindex] = compress;
+            
+            // if (increment)
+            //     tab.versionindex++;
+        }
 
-        copy.RestoreBigData(hashtable);
+        //copy.RestoreBigData(versiontable);
 
-        CameraPane.SWITCH = temp;
-        
         //assert(hashtable.isEmpty());
         
-        for (int i = tab.undoindex; i < tab.graphs.length; i++)
+        for (int i = copy.versionindex+1; i < copy.versions.length; i++)
         {
-            tab.graphs[i] = null;
+            //tab.user[i] = false;
+            copy.versions[i] = null;
         }
 
         SetUndoStates();
@@ -3544,7 +3684,7 @@
         {
             try
             {
-                FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
+                FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
                 ObjectOutputStream p = new ObjectOutputStream(ostream);
 
                 p.writeObject(copy);
@@ -3557,6 +3697,8 @@
                 e.printStackTrace();
             }
         }
+        
+        return !thesame;
     }
 
     void CopyChanged(Object3D obj)
@@ -3566,7 +3708,7 @@
         boolean temp = CameraPane.SWITCH;
         CameraPane.SWITCH = false;
         
-        copy.ExtractBigData(hashtable);
+        copy.ExtractBigData(versiontable);
         
         copy.clear();
         
@@ -3575,7 +3717,7 @@
             copy.add(obj.get(i));
         }
         
-        copy.RestoreBigData(hashtable);
+        copy.RestoreBigData(versiontable);
         
         CameraPane.SWITCH = temp;
         
@@ -3603,52 +3745,129 @@
     }
     
     cButton undoButton;
+    cButton restoreButton;
+    cButton replaceButton;
     cButton redoButton;
         
+    boolean muteSlider;
+    
+    int VersionCount()
+    {
+        int count = 0;
+        
+        for (int i = copy.versions.length; --i >= 0;)
+        {
+            if (copy.versions[i] != null)
+                count++;
+        }
+        
+        return count;
+    }
+    
     void SetUndoStates()
     {
         cRadio tab = GetCurrentTab();
         
-        undoButton.setEnabled(tab.undoindex > 0);
-        redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
+        restoreButton.setEnabled(copy.versionindex != -1);
+        replaceButton.setEnabled(copy.versionindex != -1);
+        
+        undoButton.setEnabled(copy.versionindex > 0);
+        redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
+        
+        muteSlider = true;
+        versionSlider.setMaximum(VersionCount() - 1);
+        versionSlider.setInteger(copy.versionindex);
+        muteSlider = false;
     }
     
-    public void Undo()
+    public boolean Undo()
     {
+        // Option?
+        Replace();
+        
         System.err.println("Undo");
         
         cRadio tab = GetCurrentTab();
         
-        if (tab.undoindex == 0)
+        if (copy.versionindex == 0)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
-            return;
+            return false;
         }
 
-        if (tab.graphs[tab.undoindex] == null)
+//        if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
+//        {
+//            if (Save(false))
+//                tab.versionindex -= 1;
+//            else
+//            {
+//                if (tab.versionindex <= 0)
+//                    return false;
+//                else
+//                    tab.versionindex -= 1;
+//            }
+//        }
+
+        copy.versionindex -= 1;
+
+        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        
+        return true;
+    }
+
+    public boolean Restore()
+    {
+        System.err.println("Restore");
+        
+        cRadio tab = GetCurrentTab();
+        
+        if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
         {
-            Save();
-            tab.undoindex -= 1;
+            java.awt.Toolkit.getDefaultToolkit().beep();
+            return false;
         }
 
-        tab.undoindex -= 1;
+        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        
+        return true;
+    }
 
-        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+    public boolean Replace()
+    {
+        System.err.println("Replace");
+        
+        cRadio tab = GetCurrentTab();
+        
+        if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
+        {
+            // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
+            return false;
+        }
+
+        copy.versions[copy.versionindex] = CompressCopy();
+        
+        return true;
     }
 
     public void Redo()
     {
+        // Option?
+        Replace();
+        
         cRadio tab = GetCurrentTab();
         
-        if (tab.graphs[tab.undoindex + 1] == null)
+        if (copy.versions[copy.versionindex + 1] == null)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
             return;
         }
 
-        tab.undoindex += 1;
+        copy.versionindex += 1;
 
-        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        
+        //if (!tab.user[tab.versionindex])
+        //    tab.graphs[tab.versionindex] = null;
     }
 
         void ImportGFD()
@@ -3944,9 +4163,25 @@
         //copy.Touch();
     }
 
+    cNumberSlider versionSlider;
+    
     public void stateChanged(ChangeEvent e)
     {
         //    assert(false);
+        if (e.getSource() == versionSlider)
+        {
+            if (muteSlider)
+                return;
+            
+            int version = versionSlider.getInteger();
+            
+            if (copy.versions[version] != null)
+            {
+                CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
+            }
+            
+            return;
+        }
 
         if (freezematerial)
         {
@@ -4295,7 +4530,7 @@
 
     void makeSomething(Object3D thing, boolean resetmodel) // deselect)
     {
-        if (Globals.SAVEONMAKE) // && resetmodel)
+        if (Globals.REPLACEONMAKE) // && resetmodel)
             Save();
         //Tween.set(thing, 0).target(1).start(tweenManager);
         //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
@@ -4611,8 +4846,8 @@
         
         if (readobj != null)
         {
-        if (Globals.SAVEONMAKE)
-            Save();
+        //if (Globals.SAVEONMAKE) // A new object cannot share meshes
+        //    Save();
             try
             {
                 //readobj.deepCopySelf(copy);
@@ -4667,13 +4902,24 @@
                 c.addChild(csg);
             }
 
+            copy.versions = readobj.versions;
+            copy.versionindex = readobj.versionindex;
+            
+        if (copy.versions == null)
+        {
+            copy.versions = new byte[100][];
+            copy.versionindex = -1;
+        }
+        
+            //? SetUndoStates();
+            
             ResetModel();
             copy.HardTouch(); // recompile?
             refreshContents();
         }
     }
 
-    void load() // throws ClassNotFoundException
+    void Open() // throws ClassNotFoundException
     {
         if (Grafreed.standAlone)
         {
@@ -4958,7 +5204,7 @@
     MenuBar menuBar;
     Menu fileMenu;
     MenuItem newItem;
-    MenuItem loadItem;
+    MenuItem openItem;
     MenuItem saveItem;
     MenuItem saveAsItem;
     MenuItem exportAsItem;
@@ -4981,6 +5227,7 @@
     CheckboxMenuItem toggleSwitchItem;
     CheckboxMenuItem toggleRootItem;
     CheckboxMenuItem animationItem;
+    MenuItem archiveItem;
     CheckboxMenuItem toggleHandleItem;
     CheckboxMenuItem togglePaintItem;
     JSplitPane mainPanel;

--
Gitblit v1.6.2