From 46dbce888e7c3eff8969f1ddbe22e144410b67f4 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 07 Jul 2019 10:20:06 -0400
Subject: [PATCH] Put back serial IDs for cone and torus.

---
 ObjEditor.java |  269 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 202 insertions(+), 67 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index c8ad401..5d7d1bb 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.
@@ -207,7 +210,7 @@
         
         objEditor.ctrlPanel.remove(namePanel);
         
-        if (!GroupEditor.allparams)
+        if (!allparams)
             return;
         
 //        objEditor.ctrlPanel.remove(liveCB);
@@ -306,7 +309,7 @@
         //localCopy.parent = null;
 
         frame = new JFrame();
-                frame.setUndecorated(true);
+                frame.setUndecorated(false);
         objEditor = this;
         this.callee = callee;
 
@@ -337,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");
@@ -374,7 +382,7 @@
         }
 
         newItem.addActionListener(this);
-        loadItem.addActionListener(this);
+        openItem.addActionListener(this);
         saveItem.addActionListener(this);
         saveAsItem.addActionListener(this);
         exportAsItem.addActionListener(this);
@@ -397,6 +405,11 @@
 //                    }
 //                    
 //                    materialFlushed = true;
+//                }
+//                if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit"))
+//                {
+//                    if (listUI.size() == 0)
+//                        EditSelection(false);
 //                }
 
                 refreshContents(false); // To refresh Info tab
@@ -436,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());
@@ -448,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));
@@ -679,8 +699,8 @@
         }
     }
 
-static GraphicsDevice device = GraphicsEnvironment
-        .getLocalGraphicsEnvironment().getScreenDevices()[0];
+//static GraphicsDevice device = GraphicsEnvironment
+//        .getLocalGraphicsEnvironment().getScreenDevices()[0];
 
     Rectangle keeprect;
         cRadio radio;
@@ -701,10 +721,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);
@@ -712,22 +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()
         {
+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);
@@ -737,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;
@@ -752,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();
@@ -765,6 +813,7 @@
                     radio.layout.doClick();
                     //frame.setVisible(true);
                 }
+            frame.validate();
         }
 
     private JTextPane createTextPane()
@@ -1097,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);
@@ -1115,15 +1164,15 @@
         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)");
 
         if (Globals.ADVANCED)
         {
@@ -1439,13 +1488,16 @@
         //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
         //tmp.setName("Edit");
         objectPanel.add(materialPanel);
-        objectPanel.add(toolboxPanel);
 //        JPanel north = new JPanel(new BorderLayout());
 //        north.setName("Edit");
 //        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;
@@ -1454,7 +1506,7 @@
         aConstraints.gridy += 1;
         aConstraints.gridwidth = 1;
         mainPanel.add(objectPanel, aConstraints);
-         */
+        */
 
         scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
                 VERTICAL_SCROLLBAR_AS_NEEDED,
@@ -1553,9 +1605,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");
@@ -1574,12 +1626,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()
@@ -1666,24 +1719,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);
@@ -1733,6 +1768,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());
         
@@ -1784,6 +1825,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());
         
@@ -1791,35 +1844,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);
         
@@ -1926,8 +1979,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"))
@@ -2653,6 +2707,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)
@@ -2836,6 +2891,7 @@
             }
         }
     }
+    
     cFileSystemPane FSPane;
 
     void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
@@ -2889,6 +2945,7 @@
                 }
             }
         }
+        
         freezematerial = false;
     }
 
@@ -3007,12 +3064,17 @@
 //                }
 
         /**/
-        if (deselect)
+        if (deselect || child == null)
         {
             //group.deselectAll();
             //freeze = true;
             GetTree().clearSelection();
             //freeze = false;
+            
+            if (child == null)
+            {
+                return;
+            }
         }
 
         //group.addSelectee(child);
@@ -3336,9 +3398,9 @@
         {
             Close();
             //return true;
-        } else if (source == loadItem)
+        } else if (source == openItem)
         {
-            load();
+            Open();
             //return true;
         } else if (source == newItem)
         {
@@ -3363,6 +3425,10 @@
         {
             generatePOV();
             //return true;
+        } else if (event.getSource() == archiveItem)
+        {
+            cTools.Archive(frame);
+            return;
         } else if (source == zBufferItem)
         {
             try
@@ -3504,6 +3570,28 @@
     
     public void Save()
     {
+        // Default reduces the probability of heuristics errors.
+        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();
@@ -3513,20 +3601,37 @@
         
         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;
+            tab.graphs[tab.undoindex++] = compress;
+        }
+
+        copy.RestoreBigData(hashtable);
+
         //assert(hashtable.isEmpty());
         
         for (int i = tab.undoindex; i < tab.graphs.length; i++)
         {
+            tab.user[i] = false;
             tab.graphs[i] = null;
         }
 
+        SetUndoStates();
+        
         // test save
         if (false)
         {
@@ -3545,10 +3650,14 @@
                 e.printStackTrace();
             }
         }
+        
+        return !thesame;
     }
 
     void CopyChanged(Object3D obj)
     {
+        SetUndoStates();
+        
         boolean temp = CameraPane.SWITCH;
         CameraPane.SWITCH = false;
         
@@ -3588,7 +3697,18 @@
         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");
         
@@ -3597,18 +3717,27 @@
         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()
@@ -3624,6 +3753,9 @@
         tab.undoindex += 1;
 
         CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+        
+        if (!tab.user[tab.undoindex])
+            tab.graphs[tab.undoindex] = null;
     }
 
         void ImportGFD()
@@ -4648,7 +4780,7 @@
         }
     }
 
-    void load() // throws ClassNotFoundException
+    void Open() // throws ClassNotFoundException
     {
         if (Grafreed.standAlone)
         {
@@ -4765,6 +4897,8 @@
             String filename = browser.getFile();
             if (filename != null && filename.length() > 0)
             {
+                if (!filename.endsWith(".gfd"))
+                    filename += ".gfd";
                 lastname = browser.getDirectory() + filename;
                 save();
             }
@@ -4931,7 +5065,7 @@
     MenuBar menuBar;
     Menu fileMenu;
     MenuItem newItem;
-    MenuItem loadItem;
+    MenuItem openItem;
     MenuItem saveItem;
     MenuItem saveAsItem;
     MenuItem exportAsItem;
@@ -4954,6 +5088,7 @@
     CheckboxMenuItem toggleSwitchItem;
     CheckboxMenuItem toggleRootItem;
     CheckboxMenuItem animationItem;
+    MenuItem archiveItem;
     CheckboxMenuItem toggleHandleItem;
     CheckboxMenuItem togglePaintItem;
     JSplitPane mainPanel;

--
Gitblit v1.6.2