From bc829f47837b5a001f911542140b0b8e63c2bb0c Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 14 Jul 2019 19:47:03 -0400
Subject: [PATCH] Fix extract big data.

---
 ObjEditor.java |  448 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 358 insertions(+), 90 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index 9fcd4b1..b1bbdf6 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -4,6 +4,7 @@
 
 import java.awt.*;
 import java.awt.event.*;
+import java.awt.image.BufferedImage;
 import javax.swing.*;
 import javax.swing.event.*;
 import javax.swing.text.*;
@@ -13,6 +14,9 @@
 import javax.swing.plaf.metal.MetalLookAndFeel;
 //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;
 
@@ -37,6 +41,65 @@
     JFrame frame;
     
     static ObjEditor theFrame;
+    
+    cButton GetButton(String name, boolean border)
+    {
+        try
+        {
+            ImageIcon icon = GetIcon(name);
+            return new cButton(icon, border);
+        }
+        catch (Exception e)
+        {
+            return new cButton(name, border);
+        }
+    }
+
+    cToggleButton GetToggleButton(String name, boolean border)
+    {
+        try
+        {
+            ImageIcon icon = GetIcon(name);
+            return new cToggleButton(icon, border);
+        }
+        catch (Exception e)
+        {
+            return new cToggleButton(name, border);
+        }
+    }
+
+    cCheckBox GetCheckBox(String name, boolean border)
+    {
+        try
+        {
+            ImageIcon icon = GetIcon(name);
+            return new cCheckBox(icon, border);
+        }
+        catch (Exception e)
+        {
+            return new cCheckBox(name, border);
+        }
+    }
+
+    private ImageIcon GetIcon(String name) throws IOException
+    {
+        BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
+        
+        if (image.getWidth() != 24 && image.getHeight() != 24)
+        {
+            BufferedImage resized = new BufferedImage(24, 24, image.getType());
+            Graphics2D g = resized.createGraphics();
+            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+            //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+            g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
+            g.dispose();
+            
+            image = resized;
+        }
+        
+        javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
+        return icon;
+    }
     
     // SCRIPT
     
@@ -147,7 +210,7 @@
         
         objEditor.ctrlPanel.remove(namePanel);
         
-        if (!GroupEditor.allparams)
+        if (!allparams)
             return;
         
 //        objEditor.ctrlPanel.remove(liveCB);
@@ -246,7 +309,7 @@
         //localCopy.parent = null;
 
         frame = new JFrame();
-                frame.setUndecorated(true);
+                frame.setUndecorated(false);
         objEditor = this;
         this.callee = callee;
 
@@ -277,12 +340,17 @@
         return frame.action(event, obj);
     }
 
+    // Cannot work without static
+    static boolean allparams = true;
+
+    static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
+
     void SetupMenu()
     {
         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");
@@ -314,7 +382,7 @@
         }
 
         newItem.addActionListener(this);
-        loadItem.addActionListener(this);
+        openItem.addActionListener(this);
         saveItem.addActionListener(this);
         saveAsItem.addActionListener(this);
         exportAsItem.addActionListener(this);
@@ -323,6 +391,32 @@
         closeItem.addActionListener(this);
 
         objectPanel = new JTabbedPane();
+        
+        ChangeListener changeListener = new ChangeListener()
+        {
+            public void stateChanged(ChangeEvent changeEvent)
+            {
+//                if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed)
+//                {
+//                    if (latestObject != null)
+//                    {
+//                        refreshContents(true);
+//                        SetMaterial(latestObject);
+//                    }
+//                    
+//                    materialFlushed = true;
+//                }
+//                if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit"))
+//                {
+//                    if (listUI.size() == 0)
+//                        EditSelection(false);
+//                }
+
+                refreshContents(false); // To refresh Info tab
+            }
+        };
+        objectPanel.addChangeListener(changeListener);
+    
         toolbarPanel = new JPanel();
         toolbarPanel.setName("Toolbar");
         treePanel = new cGridBag();
@@ -337,9 +431,12 @@
         editPanel.add(editCommandsPanel);
         editPanel.add(ctrlPanel);
                 
-        materialPanel = new cGridBag().setVertical(true);
+        toolboxPanel = new cGridBag().setVertical(false);
+        toolboxPanel.setName("Toolbox");
         
+        materialPanel = new cGridBag().setVertical(true);
         materialPanel.setName("Material");
+        
         /*JTextPane*/
         infoarea = createTextPane();
         doc = infoarea.getStyledDocument();
@@ -352,7 +449,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());
@@ -364,7 +461,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));
@@ -595,8 +699,8 @@
         }
     }
 
-static GraphicsDevice device = GraphicsEnvironment
-        .getLocalGraphicsEnvironment().getScreenDevices()[0];
+//static GraphicsDevice device = GraphicsEnvironment
+//        .getLocalGraphicsEnvironment().getScreenDevices()[0];
 
     Rectangle keeprect;
         cRadio radio;
@@ -612,13 +716,24 @@
         
         boolean maximized;
     
+        cButton fullscreenLayout;
+
         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);
@@ -626,20 +741,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()
         {
-                if (CameraPane.FULLSCREEN)
+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);
@@ -649,7 +780,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;
@@ -664,7 +795,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();
@@ -673,12 +809,11 @@
 // X                   frame.getContentPane().add(/*"Center",*/bigThree);
                     framePanel.setDividerLocation(0);
 
-                    radio.layout = twoButton;
+                    radio.layout = fullscreenLayout;
                     radio.layout.doClick();
                     //frame.setVisible(true);
                 }
-                
-                cameraView.ToggleFullScreen();
+            frame.validate();
         }
 
     private JTextPane createTextPane()
@@ -819,7 +954,12 @@
     JCheckBox speedupCB;
     JCheckBox rewindCB;
     JCheckBox flipVCB;
+    
+    cCheckBox toggleTextureCB;
+    cCheckBox toggleSwitchCB;
+        
     JComboBox texresMenu;
+    
     JButton resetButton;
     JButton stepButton;
     JButton stepAllButton;
@@ -1006,12 +1146,12 @@
             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();
         
-        if (!GroupEditor.allparams)
+        if (!allparams)
             return;
 
             setupPanel = new cGridBag().setVertical(false);
@@ -1024,20 +1164,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");
         }
@@ -1353,7 +1494,11 @@
 //        north.add(ctrlPanel, BorderLayout.NORTH);
 //        objectPanel.add(north);
         objectPanel.add(editPanel);
-        objectPanel.add(infoPanel);
+        
+        //if (Globals.ADVANCED)
+            objectPanel.add(infoPanel);
+        
+        objectPanel.add(toolboxPanel);
 
         /*
         aConstraints.gridx = 0;
@@ -1362,7 +1507,7 @@
         aConstraints.gridy += 1;
         aConstraints.gridwidth = 1;
         mainPanel.add(objectPanel, aConstraints);
-         */
+        */
 
         scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
                 VERTICAL_SCROLLBAR_AS_NEEDED,
@@ -1379,9 +1524,7 @@
         JTabbedPane tabbedPane = new JTabbedPane();
         tabbedPane.add(scrollpane);
 
-        tabbedPane.add(FSPane = new cFileSystemPane(this));
-
-        optionsPanel = new cGridBag().setVertical(true);
+        optionsPanel = new cGridBag().setVertical(false);
 
         optionsPanel.setName("Options");
         
@@ -1389,6 +1532,8 @@
         
         tabbedPane.add(optionsPanel);
         
+        tabbedPane.add(FSPane = new cFileSystemPane(this));
+
         scenePanel.add(tabbedPane);
 
         /*
@@ -1461,9 +1606,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");
@@ -1481,11 +1626,14 @@
 //            aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
 
         frame.setSize(1280, 860);
-        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()
@@ -1572,24 +1720,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);
@@ -1639,6 +1769,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());
         
@@ -1690,6 +1826,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());
         
@@ -1697,35 +1845,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);
         
@@ -1832,8 +1980,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"))
@@ -2559,6 +2708,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)
@@ -2742,6 +2892,7 @@
             }
         }
     }
+    
     cFileSystemPane FSPane;
 
     void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
@@ -2795,11 +2946,14 @@
                 }
             }
         }
+        
         freezematerial = false;
     }
 
     void SetMaterial(Object3D object)
     {
+        latestObject = object;
+        
         cMaterial mat = object.material;
 
         if (mat == null)
@@ -2911,12 +3065,17 @@
 //                }
 
         /**/
-        if (deselect)
+        if (deselect || child == null)
         {
             //group.deselectAll();
             //freeze = true;
             GetTree().clearSelection();
             //freeze = false;
+            
+            if (child == null)
+            {
+                return;
+            }
         }
 
         //group.addSelectee(child);
@@ -2985,7 +3144,7 @@
             cameraView.ToggleDL();
             cameraView.repaint();
             return;
-        } else if (event.getSource() == toggleTextureItem)
+        } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
         {
             cameraView.ToggleTexture();
             // june 2013           copy.HardTouch();
@@ -3024,7 +3183,7 @@
             frame.validate();
 
             return;
-        } else if (event.getSource() == toggleSwitchItem)
+        } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
         {
             cameraView.ToggleSwitch();
             cameraView.repaint();
@@ -3240,9 +3399,9 @@
         {
             Close();
             //return true;
-        } else if (source == loadItem)
+        } else if (source == openItem)
         {
-            load();
+            Open();
             //return true;
         } else if (source == newItem)
         {
@@ -3267,6 +3426,10 @@
         {
             generatePOV();
             //return true;
+        } else if (event.getSource() == archiveItem)
+        {
+            cTools.Archive(frame);
+            return;
         } else if (source == zBufferItem)
         {
             try
@@ -3318,8 +3481,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;
@@ -3330,10 +3493,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);
@@ -3343,13 +3510,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;
@@ -3408,6 +3578,29 @@
     
     public void Save()
     {
+        Save(true);
+    }
+    
+    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;
+    }
+
+    public boolean Save(boolean user)
+    {
+        System.err.println("Save");
+        
         cRadio tab = GetCurrentTab();
         
         boolean temp = CameraPane.SWITCH;
@@ -3415,20 +3608,42 @@
         
         copy.ExtractBigData(hashtable);
         
-        //EditorFrame.m_MainFrame.requestFocusInWindow();
-        tab.graphs[tab.undoindex++] = Compress(copy);
-
-        copy.RestoreBigData(hashtable);
+        byte[] compress = Compress(copy);
 
         CameraPane.SWITCH = temp;
         
+        boolean thesame = false;
+        
+        // Quick heuristic using length. Works only when stream is compressed.
+        if (tab.undoindex > 0 && tab.graphs[tab.undoindex-1] != null && Equal(compress, tab.graphs[tab.undoindex-1]))
+        {
+            thesame = true;
+        }
+        
+        //EditorFrame.m_MainFrame.requestFocusInWindow();
+        if (!thesame)
+        {
+            //tab.user[tab.undoindex] = user;
+            boolean increment = tab.graphs[tab.undoindex] == null;
+            
+            tab.graphs[tab.undoindex] = compress;
+            
+            if (increment)
+                tab.undoindex++;
+        }
+
+        copy.RestoreBigData(hashtable);
+
         //assert(hashtable.isEmpty());
         
         for (int i = tab.undoindex; i < tab.graphs.length; i++)
         {
-            tab.graphs[i] = null;
+            //tab.user[i] = false;
+        //    tab.graphs[i] = null;
         }
 
+        SetUndoStates();
+        
         // test save
         if (false)
         {
@@ -3447,10 +3662,14 @@
                 e.printStackTrace();
             }
         }
+        
+        return !thesame;
     }
 
     void CopyChanged(Object3D obj)
     {
+        SetUndoStates();
+        
         boolean temp = CameraPane.SWITCH;
         CameraPane.SWITCH = false;
         
@@ -3490,25 +3709,47 @@
         refreshContents();
     }
     
-    public void Undo()
+    cButton undoButton;
+    cButton redoButton;
+        
+    void SetUndoStates()
     {
+        cRadio tab = GetCurrentTab();
+        
+        undoButton.setEnabled(tab.undoindex > 0);
+        redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
+    }
+    
+    public boolean Undo()
+    {
+        System.err.println("Undo");
+        
         cRadio tab = GetCurrentTab();
         
         if (tab.undoindex == 0)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
-            return;
+            return false;
         }
 
-        if (tab.graphs[tab.undoindex] == null)
+        if (tab.graphs[tab.undoindex] == null) // || !tab.user[tab.undoindex])
         {
-            Save();
-            tab.undoindex -= 1;
+            if (Save(false))
+                tab.undoindex -= 1;
+            else
+            {
+                if (tab.undoindex <= 0)
+                    return false;
+                else
+                    tab.undoindex -= 1;
+            }
         }
 
         tab.undoindex -= 1;
 
         CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+        
+        return true;
     }
 
     public void Redo()
@@ -3524,6 +3765,9 @@
         tab.undoindex += 1;
 
         CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+        
+        //if (!tab.user[tab.undoindex])
+        //    tab.graphs[tab.undoindex] = null;
     }
 
         void ImportGFD()
@@ -3675,7 +3919,7 @@
         assert false;
     }
 
-    void EditSelection()
+    void EditSelection(boolean newWindow)
     {
     }
 
@@ -4170,7 +4414,8 @@
 
     void makeSomething(Object3D thing, boolean resetmodel) // deselect)
     {
-        Save();
+        if (Globals.SAVEONMAKE) // && resetmodel)
+            Save();
         //Tween.set(thing, 0).target(1).start(tweenManager);
         //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
 //            if (thing instanceof GenericJointDemo)
@@ -4257,6 +4502,12 @@
         {
             ResetModel();
             Select(thing.GetTreePath(), true, false); // unselect... false);
+            
+        if (thing.Size() == 0)
+        {
+            //EditSelection(false);
+        }
+        
             refreshContents();
         }
 
@@ -4479,7 +4730,8 @@
         
         if (readobj != null)
         {
-            Save();
+        //if (Globals.SAVEONMAKE) // A new object cannot share meshes
+        //    Save();
             try
             {
                 //readobj.deepCopySelf(copy);
@@ -4540,7 +4792,7 @@
         }
     }
 
-    void load() // throws ClassNotFoundException
+    void Open() // throws ClassNotFoundException
     {
         if (Grafreed.standAlone)
         {
@@ -4657,6 +4909,8 @@
             String filename = browser.getFile();
             if (filename != null && filename.length() > 0)
             {
+                if (!filename.endsWith(".gfd"))
+                    filename += ".gfd";
                 lastname = browser.getDirectory() + filename;
                 save();
             }
@@ -4823,7 +5077,7 @@
     MenuBar menuBar;
     Menu fileMenu;
     MenuItem newItem;
-    MenuItem loadItem;
+    MenuItem openItem;
     MenuItem saveItem;
     MenuItem saveAsItem;
     MenuItem exportAsItem;
@@ -4846,22 +5100,36 @@
     CheckboxMenuItem toggleSwitchItem;
     CheckboxMenuItem toggleRootItem;
     CheckboxMenuItem animationItem;
+    MenuItem archiveItem;
     CheckboxMenuItem toggleHandleItem;
     CheckboxMenuItem togglePaintItem;
     JSplitPane mainPanel;
     JScrollPane scrollpane;
+    
     JPanel toolbarPanel;
+    
     cGridBag treePanel;
+    
     JPanel radioPanel;
     ButtonGroup buttonGroup;
-    cGridBag ctrlPanel;
+    
+    cGridBag toolboxPanel;
     cGridBag materialPanel;
+    cGridBag ctrlPanel;
+    
     JScrollPane infoPanel;
+    
     cGridBag optionsPanel;
+    
     JTabbedPane objectPanel;
+    boolean materialFlushed;
+    Object3D latestObject;
+    
     cGridBag XYZPanel;
+    
     JSplitPane gridPanel;
     JSplitPane bigPanel;
+    
     cGridBag bigThree;
     cGridBag scenePanel;
     cGridBag centralPanel;
@@ -4976,7 +5244,7 @@
     cNumberSlider fogField;
     JLabel opacityPowerLabel;
     cNumberSlider opacityPowerField;
-    JTree jTree;
+    cTree jTree;
     //ObjectUI parent;
     
     cNumberSlider normalpushField;

--
Gitblit v1.6.2