From f1382bc839a74ef1d1534c61ea94e53cf54716df Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 23 Jun 2019 15:00:47 -0400
Subject: [PATCH] Edit panel

---
 ObjEditor.java |  202 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 162 insertions(+), 40 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index 2cb5163..9fcd4b1 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -36,6 +36,8 @@
     GroupEditor callee;
     JFrame frame;
     
+    static ObjEditor theFrame;
+    
     // SCRIPT
     
     transient JFrame textpanel = null;
@@ -168,7 +170,8 @@
 //        objEditor.ctrlPanel.remove(remarkButton);
         
         objEditor.ctrlPanel.remove(setupPanel);
-        objEditor.ctrlPanel.remove(commandsPanel);
+        objEditor.ctrlPanel.remove(setupPanel2);
+        objEditor.ctrlPanel.remove(objectCommandsPanel);
         objEditor.ctrlPanel.remove(pushPanel);
         //objEditor.ctrlPanel.remove(fillPanel);
         
@@ -243,6 +246,7 @@
         //localCopy.parent = null;
 
         frame = new JFrame();
+                frame.setUndecorated(true);
         objEditor = this;
         this.callee = callee;
 
@@ -278,7 +282,7 @@
         frame.setMenuBar(menuBar = new MenuBar());
         menuBar.add(fileMenu = new Menu("File"));
         fileMenu.add(newItem = new MenuItem("New"));
-        fileMenu.add(loadItem = new MenuItem("Load..."));
+        fileMenu.add(loadItem = new MenuItem("Open..."));
         
                 //oe.menuBar.add(menu = new Menu("Include"));
         Menu menu = new Menu("Import");
@@ -323,9 +327,18 @@
         toolbarPanel.setName("Toolbar");
         treePanel = new cGridBag();
         treePanel.setName("Tree");
+        
+        editPanel = new cGridBag().setVertical(true);
+        editPanel.setName("Edit");
+        
         ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
-        ctrlPanel.setName("Edit");
+        
+        editCommandsPanel = new cGridBag();
+        editPanel.add(editCommandsPanel);
+        editPanel.add(ctrlPanel);
+                
         materialPanel = new cGridBag().setVertical(true);
+        
         materialPanel.setName("Material");
         /*JTextPane*/
         infoarea = createTextPane();
@@ -419,10 +432,10 @@
             e.printStackTrace();
         }
         
-        String selection = infoarea.getText();
-        java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
-        java.awt.datatransfer.Clipboard clipboard = 
-                Toolkit.getDefaultToolkit().getSystemClipboard();
+//        String selection = infoarea.getText();
+//        java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
+//        java.awt.datatransfer.Clipboard clipboard = 
+//                Toolkit.getDefaultToolkit().getSystemClipboard();
         //clipboard.setContents(data, data);
     }
     
@@ -582,19 +595,89 @@
         }
     }
 
+static GraphicsDevice device = GraphicsEnvironment
+        .getLocalGraphicsEnvironment().getScreenDevices()[0];
+
+    Rectangle keeprect;
+        cRadio radio;
+        
+cButton keepButton;
+	cButton twoButton; // Full 3D
+	cButton sixButton;
+	cButton threeButton;
+	cButton sevenButton;
+	cButton fourButton; // full panel
+	cButton oneButton; // full XYZ
+        //cButton currentLayout;
+        
+        boolean maximized;
+    
+        void Minimize()
+        {
+            frame.setState(Frame.ICONIFIED);
+        }
+        
+        void Maximize()
+        {
+            if (maximized)
+            {
+                frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
+            }
+            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);
+//                frame.setState(Frame.MAXIMIZED_BOTH);
+            }
+            
+            maximized ^= true;
+        }
+        
         void ToggleFullScreen()
         {
                 if (CameraPane.FULLSCREEN)
                 {
-                    frame.getContentPane().remove(/*"Center",*/bigThree);
-                    framePanel.add(bigThree);
-                    frame.getContentPane().add(/*"Center",*/framePanel);
+                    device.setFullScreenWindow(null);
+                    //frame.setVisible(false);
+//                frame.removeNotify();
+//                frame.setUndecorated(false);
+//                frame.addNotify();
+                //frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
+                    
+// X                   frame.getContentPane().remove(/*"Center",*/bigThree);
+// X                   framePanel.add(bigThree);
+// X                   frame.getContentPane().add(/*"Center",*/framePanel);
+                    framePanel.setDividerLocation(1);
+                    
+                    //frame.setVisible(true);
+                    radio.layout = keepButton;
+                    //theFrame = null;
+                    keepButton = null;
+                    radio.layout.doClick();
+                    
                 } else
                 {
-                    frame.getContentPane().remove(/*"Center",*/framePanel);
-                    framePanel.remove(bigThree);
-                    frame.getContentPane().add(/*"Center",*/bigThree);
+                    keepButton = radio.layout;
+                    //keeprect = frame.getBounds();
+//                frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
+//                        frame.getToolkit().getScreenSize().height);
+                    //frame.setVisible(false);
+                    device.setFullScreenWindow(frame);
+//                frame.removeNotify();
+//                frame.setUndecorated(true);
+//                frame.addNotify();
+// X                   frame.getContentPane().remove(/*"Center",*/framePanel);
+// X                   framePanel.remove(bigThree);
+// X                   frame.getContentPane().add(/*"Center",*/bigThree);
+                    framePanel.setDividerLocation(0);
+
+                    radio.layout = twoButton;
+                    radio.layout.doClick();
+                    //frame.setVisible(true);
                 }
+                
                 cameraView.ToggleFullScreen();
         }
 
@@ -745,9 +828,13 @@
     JButton fasterButton;
     JButton remarkButton;
     
+    cGridBag editPanel;
+    cGridBag editCommandsPanel;
+    
     cGridBag namePanel;
     cGridBag setupPanel;
-    cGridBag commandsPanel;
+    cGridBag setupPanel2;
+    cGridBag objectCommandsPanel;
     cGridBag pushPanel;
     cGridBag fillPanel;
 
@@ -939,40 +1026,44 @@
         markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
         markCB.setToolTipText("Set the animation target transform");
         
-        rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
+            setupPanel2 = new cGridBag().setVertical(false);
+            
+        rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
         rewindCB.setToolTipText("Rewind animation");
         
-        randomCB = AddCheckBox(setupPanel, "Random", copy.random);
-        randomCB.setToolTipText("Option for switch node");
+        randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
+        randomCB.setToolTipText("Randomly Rewind or Go back and forth");
 
         if (Globals.ADVANCED)
         {
-                link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
+                link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
                 link2masterCB.setToolTipText("Attach to support");
-                speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
+                speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
                 speedupCB.setToolTipText("Option motion capture");
         }
         
         oe.ctrlPanel.add(setupPanel);
         oe.ctrlPanel.Return();
+        oe.ctrlPanel.add(setupPanel2);
+        oe.ctrlPanel.Return();
         
-            commandsPanel = new cGridBag().setVertical(false);
+            objectCommandsPanel = new cGridBag().setVertical(false);
         
-        resetButton = AddButton(commandsPanel, "Reset");
+        resetButton = AddButton(objectCommandsPanel, "Reset");
         resetButton.setToolTipText("Jump to frame zero");
-        stepButton = AddButton(commandsPanel, "Step");
+        stepButton = AddButton(objectCommandsPanel, "Step");
         stepButton.setToolTipText("Step one frame");
 //            resetAllButton = AddButton(oe, "Reset All");
 //            stepAllButton = AddButton(oe, "Step All");
 //            Return();
-        slowerButton = AddButton(commandsPanel, "Slow");
+        slowerButton = AddButton(objectCommandsPanel, "Slow");
         slowerButton.setToolTipText("Decrease animation speed");
-        fasterButton = AddButton(commandsPanel, "Fast");
+        fasterButton = AddButton(objectCommandsPanel, "Fast");
         fasterButton.setToolTipText("Increase animation speed");
-        remarkButton = AddButton(commandsPanel, "Remark");
+        remarkButton = AddButton(objectCommandsPanel, "Remark");
         remarkButton.setToolTipText("Set the current transform as the target");
 
-        oe.ctrlPanel.add(commandsPanel);
+        oe.ctrlPanel.add(objectCommandsPanel);
         oe.ctrlPanel.Return();
 
     pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH, 1.1); // To have the buttons
@@ -1178,8 +1269,11 @@
         //worldPanel.setName("World");
 	centralPanel = new cGridBag();
         centralPanel.preferredWidth = 20;
-	timelinePanel = new JPanel(new BorderLayout());
-        timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
+        
+        if (Globals.ADVANCED)
+        {
+            timelinePanel = new JPanel(new BorderLayout());
+            timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
 
         cameraPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cameraView, timelinePanel);
         cameraPanel.setContinuousLayout(true);
@@ -1188,7 +1282,10 @@
 //        cameraPanel.setDividerSize(9);
         cameraPanel.setResizeWeight(1.0);
         
+        }
+        
         centralPanel.add(cameraView);
+        centralPanel.setFocusable(true);
         //frame.setJMenuBar(timelineMenubar);
         //centralPanel.add(timelinePanel);
         
@@ -1255,7 +1352,7 @@
 //        north.setName("Edit");
 //        north.add(ctrlPanel, BorderLayout.NORTH);
 //        objectPanel.add(north);
-        objectPanel.add(ctrlPanel);
+        objectPanel.add(editPanel);
         objectPanel.add(infoPanel);
 
         /*
@@ -1386,6 +1483,8 @@
         frame.setSize(1280, 860);
         frame.setVisible(true);
 
+                    cameraView.requestFocusInWindow();
+                    
         gridPanel.setDividerLocation(1.0);
 
         frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
@@ -2072,19 +2171,19 @@
 
     void LoadObjFile(String fullname)
     {
-        /*
+        System.out.println("Loading " + fullname);
+        /**/
         //lastFilename = fullname;
         if(loadObjThread == null)
         {
-        loadObjThread = new LoadOBJThread();
-        loadObjThread.start();
+            loadObjThread = new LoadOBJThread();
+            loadObjThread.start();
         }
         
         loadObjThread.add(fullname);
-         */
+        /**/
 
-        System.out.println("Loading " + fullname);
-        makeSomething(new FileObject(fullname, true), true);
+        //makeSomething(new FileObject(fullname, true), true);
     }
 
     void LoadGFDFile(String fullname)
@@ -2927,7 +3026,7 @@
             return;
         } else if (event.getSource() == toggleSwitchItem)
         {
-            cameraView.ToggleRandom();
+            cameraView.ToggleSwitch();
             cameraView.repaint();
             return;
         } else if (event.getSource() == toggleHandleItem)
@@ -3214,7 +3313,7 @@
         objEditor.refreshContents();
     }
     
-    static public byte[] Compress(Object o)
+    static public byte[] Compress(Object3D o)
     {
         try
         {
@@ -3222,8 +3321,13 @@
             java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
             ObjectOutputStream out = new ObjectOutputStream(zstream);
 
+        Object3D parent = o.parent;
+        o.parent = null;
+        
             out.writeObject(o);
             
+        o.parent = parent;
+        
             out.flush();
 
             zstream.close();
@@ -3239,6 +3343,7 @@
 
     static public Object Uncompress(byte[] bytes)
     {
+        System.out.println("#bytes = " + bytes.length);
         try
         {
             ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
@@ -3305,12 +3410,17 @@
     {
         cRadio tab = GetCurrentTab();
         
+        boolean temp = CameraPane.SWITCH;
+        CameraPane.SWITCH = false;
+        
         copy.ExtractBigData(hashtable);
         
         //EditorFrame.m_MainFrame.requestFocusInWindow();
-        tab.graphs[tab.undoindex++] = (Object3D)clone(copy);
+        tab.graphs[tab.undoindex++] = Compress(copy);
 
         copy.RestoreBigData(hashtable);
+
+        CameraPane.SWITCH = temp;
         
         //assert(hashtable.isEmpty());
         
@@ -3341,6 +3451,9 @@
 
     void CopyChanged(Object3D obj)
     {
+        boolean temp = CameraPane.SWITCH;
+        CameraPane.SWITCH = false;
+        
         copy.ExtractBigData(hashtable);
         
         copy.clear();
@@ -3351,6 +3464,8 @@
         }
         
         copy.RestoreBigData(hashtable);
+        
+        CameraPane.SWITCH = temp;
         
         //assert(hashtable.isEmpty());
         
@@ -3393,7 +3508,7 @@
 
         tab.undoindex -= 1;
 
-        CopyChanged(tab.graphs[tab.undoindex]);
+        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
     }
 
     public void Redo()
@@ -3408,7 +3523,7 @@
 
         tab.undoindex += 1;
 
-        CopyChanged(tab.graphs[tab.undoindex]);
+        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
     }
 
         void ImportGFD()
@@ -4279,6 +4394,7 @@
 
         try
         {
+            // Try compressed version first.
             java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
             java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
             java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
@@ -4348,6 +4464,12 @@
 
     void LoadIt(Object obj)
     {
+        if (obj == null)
+        {
+            // Invalid file
+            return;
+        }
+        
         System.out.println("Loaded " + obj);
         //new Exception().printStackTrace();
         Object3D readobj = (Object3D) obj;

--
Gitblit v1.6.2