From 33504fc9a180903aace77613264550754fba5706 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Thu, 15 Aug 2019 12:03:58 -0400
Subject: [PATCH] Shadow RGB

---
 GroupEditor.java |  496 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 349 insertions(+), 147 deletions(-)

diff --git a/GroupEditor.java b/GroupEditor.java
index 0efe0b9..03991c3 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -16,6 +16,7 @@
 //import buoy.widget.BFileChooser;
 
 class GroupEditor extends ObjEditor implements //iParse, //iCallBack,
+        Grafreed.iResourceCallBack,
         ObjectUI,
         Runnable,
         ActionListener,
@@ -30,7 +31,7 @@
         final String path = "cubemaps/" + f + "-skyboxes/" + s;
         row.add(skyboxButton = GetButton(path + "/preview.jpg", !Grafreed.NIMBUSLAF));
         //row.add(skyboxButton = GetButton(path + "/negx.jpg", !Grafreed.NIMBUSLAF));
-        skyboxButton.setToolTipText(s);
+        skyboxButton.setToolTipText(s.equals("") ? "No background" : s);
         skyboxButton.addActionListener(new ActionListener()
         {
                 @Override
@@ -41,6 +42,22 @@
         });
     }
 
+    public void AddTextureButton(String f, String c, final String t, int count, cGridBag row)
+    {
+        cButton textureButton;
+        final String path = "textures/" + f + "/" + c + "/"; // + t;
+        row.add(textureButton = GetButton(path + "icons/" + t, !Grafreed.NIMBUSLAF));
+        textureButton.setToolTipText(c + count);
+        textureButton.addActionListener(new ActionListener()
+        {
+                @Override
+                public void actionPerformed(ActionEvent e)
+                {
+                    ChangeTexture(path + t);
+                }
+        });
+    }
+    
     public void AddSkyboxTab0(JTabbedPane skyboxpanel)
     {
         cGridBag tab0 = new cGridBag().setVertical(true);
@@ -56,7 +73,7 @@
         cGridBag row5 = new cGridBag();
         cGridBag row6 = new cGridBag();
         
-        AddSkyboxButton("default", "rgb", row0);
+        AddSkyboxButton("default", "", row0);
         //AddSkyboxButton("default", "cornell", row0);
         AddSkyboxButton("penguins", "dust", row0);
         AddSkyboxButton("penguins", "tropic", row0);
@@ -311,14 +328,56 @@
         }
     }
         
-    public void ChangeSkybox(String name)
+    public void ChangeSkybox(String skybox)
     {
-        //cameraView.envyoff = false;
-        group.skyboxname = name;
-        group.skyboxext = "jpg";
-        cameraView.repaint();
+        if (skybox.endsWith("/"))
+        {
+            group.skyboxname = null;
+            group.skyboxext = null;
+            cameraView.repaint();
+        }
+        else
+        {
+            //cameraView.envyoff = false;
+            group.skyboxname = skybox;
+            group.skyboxext = "jpg";
+            cameraView.repaint();
+        }
+    }
+
+    public void CreateSkyboxPanel(cGridBag skyboxPanel)
+    {
+        JTabbedPane skyboxpane = new JTabbedPane();
+        
+        AddSkyboxTab0(skyboxpane);
+        AddSkyboxTab1(skyboxpane);
+        AddSkyboxTab2(skyboxpane);
+        AddSkyboxTab3(skyboxpane);
+        
+        skyboxPanel.add(skyboxpane);
     }
     
+    public void ChangeTexture(String texture)
+    {
+        for (int i=0; i<group.selection.size(); i++)
+        {
+            Object3D obj = group.selection.get(i);
+            obj.SetPigmentTexture("@" + texture);
+        }
+       
+        refreshContents();
+    }
+
+    public void Show3DView()
+    {
+        // bug
+        //gridPanel.setDividerLocation(1.0);
+        //bigPanel.setDividerLocation(0.0);
+        bigThree.ClearUI();
+        bigThree.add(centralPanel);
+        bigThree.FlushUI();
+    }
+
     //ObjEditor objEditor;
 	public void closeUI2()
 	{
@@ -360,6 +419,8 @@
         {
             copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
+            
+            Save(true);
         }
         
 		if(ui)
@@ -479,32 +540,37 @@
 //		menu.add("-");
 		duplicateItem = oe.jTree.popup.add(new JMenuItem("Duplicate"));
 		duplicateItem.addActionListener(this);
-		cloneItem = menu.add(new MenuItem("Clone"));
+                
+		cloneItem = oe.jTree.popup.add(new JMenuItem("Clone"));
 		cloneItem.addActionListener(this);
-        if (Globals.ADVANCED)
+        //if (Globals.ADVANCED)
         {
 		cloneSupportItem = menu.add(new MenuItem("Clone (+supports)"));
 		cloneSupportItem.addActionListener(this);
         }
+                oe.jTree.popup.addSeparator();
 		menu.add("-");
-		cutItem = menu.add(new MenuItem("Cut"));
+		cutItem = oe.jTree.popup.add(new JMenuItem("Cut"));
 		cutItem.addActionListener(this);
-		copyItem = menu.add(new MenuItem("Copy"));
+		copyItem = oe.jTree.popup.add(new JMenuItem("Copy"));
 		copyItem.addActionListener(this);
 		pasteItem = menu.add(new MenuItem("Paste"));
 		pasteItem.addActionListener(this);
                 
-		menu.add("-");
-		pasteIntoItem = menu.add(new MenuItem("Paste into"));
+                oe.jTree.popup.addSeparator();
+		//menu.add("-");
+		pasteIntoItem = oe.jTree.popup.add(new JMenuItem("Paste into"));
 		pasteIntoItem.addActionListener(this);
-		pasteLinkItem = menu.add(new MenuItem("Paste link"));
+		pasteLinkItem = oe.jTree.popup.add(new JMenuItem("Paste link"));
 		pasteLinkItem.addActionListener(this);
-		pasteCloneItem = menu.add(new MenuItem("Paste clone"));
+		pasteCloneItem = oe.jTree.popup.add(new JMenuItem("Paste clone"));
 		pasteCloneItem.addActionListener(this);
-//		pasteExpandItem = menu.add(new MenuItem("Paste expand"));
+// CRASH	pasteExpandItem = oe.jTree.popup.add(new JMenuItem("Paste expand"));
 //		pasteExpandItem.addActionListener(this);
-		menu.add("-");
-		deleteItem = menu.add(new MenuItem("Delete"));
+		//menu.add("-");
+                oe.jTree.popup.addSeparator();
+                
+		deleteItem = oe.jTree.popup.add(new JMenuItem("Delete"));
 		deleteItem.addActionListener(this);
                 
         if (Globals.ADVANCED)
@@ -591,11 +657,9 @@
 		oe.cameraMenu.add(lookAtItem = new MenuItem("Set Interest"));
 		//cameraMenu.add(lookFromItem = new MenuItem("Look From Selection"));
 		//cameraMenu.add(switchViewItem = new MenuItem("Reverse View"));
-		editLeafItem = oe.cameraMenu.add(new MenuItem("Edit Leaf"));
 		oe.cameraMenu.add("-");
 		openWindowItem =  oe.cameraMenu.add(new MenuItem("Edit copy..."));
 		openWindowItem.addActionListener(this);
-		editLeafItem.addActionListener(this);
 		lookAtItem.addActionListener(this);
 		//lookFromItem.addActinoListener(this);
 		//switchViewItem.addActionListener(this);
@@ -657,7 +721,7 @@
 		hideItem = menu.add(new MenuItem("Hidden Group"));
 		hideItem.addActionListener(this);
         }
-		ungroupItem = menu.add(new MenuItem("Ungroup"));
+		ungroupItem = oe.jTree.popup.add(new JMenuItem("Ungroup"));
 		ungroupItem.addActionListener(this);
                 
 //		menu.add("-");
@@ -843,6 +907,9 @@
 		shareGeometriesItem.addActionListener(this);
 		mergeGeometriesItem = menu.add(new MenuItem("Merge Geometries"));
 		mergeGeometriesItem.addActionListener(this);
+		menu.add("-");
+		editLeafItem = menu.add(new MenuItem("Edit leaf..."));
+		editLeafItem.addActionListener(this);
         if (Globals.ADVANCED)
         {
             // Pretty much the same as duplicate and clone.
@@ -859,6 +926,74 @@
 		buildToolsMenu(menu);
 	}
 	
+        JTabbedPane resourcecontainer;
+        cGridBag currenttab;
+        //boolean added; // patch for jar
+                
+        int tabcount = 0;
+        int colcount = 0;
+        int rowcount = 0;
+        int texturecount = 0;
+        
+        int columns = 5;
+        int rows = 7;
+        
+    public void ResourceCallBack(String[] path)
+    {
+//        for (int i = 0; i < path.length; i++)
+//            System.out.print(path[i] + "/");
+//        System.out.println();
+        
+        if (//rowcount == 0 ||
+                path.length == 1 && !path[0].equals("") && !path[0].equals(".DS_Store"))
+        {
+            currenttab = new cGridBag();
+            String tabname = path[0]; // String.valueOf((char)('A'+tabcount));
+            currenttab.setName(tabname);
+            //added = false;
+            resourcecontainer.add(currenttab);
+            resourcecontainer.setToolTipTextAt(tabcount++, "Texture Group " + tabname);
+            rowcount = 1;
+            colcount = 0;
+            texturecount = 0;
+        }
+        
+        if (path.length > 2 && path[2].toLowerCase().endsWith(".jpg"))
+        {
+            //if (!added)
+            {
+                //added = true;
+                String tabname = path[0]; // String.valueOf((char)('A'+tabcount));
+                currenttab = (cGridBag)resourcecontainer.getComponentAt(resourcecontainer.indexOfTab(tabname));
+            }
+            
+            AddTextureButton(path[0], path[1], path[2], texturecount++, currenttab);
+            
+            if (++colcount >= columns)
+            {
+                colcount = 0;
+                currenttab.Return();
+                
+                if (rowcount++ >= rows)
+                {
+                    rowcount = 0;
+                }
+            }
+        }
+        else
+        {
+//            if (!path[path.length-1].equals("icons"))
+//                resourcecontainer.Return();
+        }
+    }
+    
+        void CreateTexturePanel(cGridBag container)
+        {
+            resourcecontainer = new JTabbedPane(JTabbedPane.LEFT);
+            container.add(resourcecontainer);
+            
+            Grafreed.ParseResources("textures", this);
+        }
         
 	void SetupUI2(ObjEditor oe)
 	{
@@ -877,11 +1012,6 @@
             //new Exception().printStackTrace();
                 
         oe.radioPanel = new JPanel(new GridBagLayout());
-	oe.aConstraints.weightx = 1;
-	oe.aConstraints.weighty = 0;
-		oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
-	oe.aConstraints.gridwidth = 100;
-	oe.aConstraints.gridheight = 1;
 //        oe.toolbarPanel.add(radioPanel); //, oe.aConstraints);
         
         oe.buttonGroup = new ButtonGroup();
@@ -914,10 +1044,49 @@
                 
                 if (Globals.ADVANCED)
                 {
-                    oe.toolbarPanel.add(maxButton = GetButton("icons/add-128.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                    maxButton.setToolTipText("Maximize window");
-                    maxButton.addActionListener(this);
+//                    oe.toolbarPanel.add(maxButton = GetButton("icons/add-128.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+//                    maxButton.setToolTipText("Maximize window");
+//                    maxButton.addActionListener(this);
                 }
+                
+                cButton gcButton;
+                
+//		oe.toolbarPanel.add(gcButton = GetButton("icons/trash.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+//                gcButton.setToolTipText("Garbage collect");
+//                gcButton.addActionListener(new ActionListener()
+//                {
+//                        public void actionPerformed(ActionEvent e)
+//                        {
+//                            System.gc();
+//                        }
+//                });
+                
+		oe.toolbarPanel.add(collapseButton = GetButton("icons/collapse.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                collapseButton.setToolTipText("Collapse toolbar");
+		collapseButton.addActionListener(this);
+                
+		oe.toolbarPanel.add(maximize3DButton = GetButton("", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                maximize3DButton.setToolTipText("Maximize 3D view");
+		maximize3DButton.addActionListener(this);
+                
+		oe.toolbarPanel.add(twoButton = GetButton("icons/cube.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                twoButton.setToolTipText("Show 3D view only");
+		twoButton.addActionListener(this);
+                this.fullscreenLayout = twoButton;
+                
+		oe.toolbarPanel.add(threeButton = GetButton("icons/controlsview.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                threeButton.setToolTipText("Show controls and 3D view");
+		threeButton.addActionListener(this);
+                if (Globals.ADVANCED)
+                {
+		oe.toolbarPanel.add(sixButton = GetButton("icons/viewcontrols.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                sixButton.setToolTipText("Show 3D view and controls");
+		sixButton.addActionListener(this);
+                }
+//		oe.toolbarPanel.add(sevenButton = new cButton("-|-|-", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+//                sevenButton.setToolTipText("3-column layout");
+//		sevenButton.addActionListener(this);
+                //
                 
 		oe.toolbarPanel.add(fullButton = GetButton("icons/fullscreen.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 fullButton.setToolTipText("Full-screen window");
@@ -931,41 +1100,45 @@
                 restoreCameraButton.setToolTipText("Restore viewpoint");
 		restoreCameraButton.addActionListener(this);
                 
-		copyOptionsPanel.add(saveButton = GetButton("icons/down_arrow.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                saveButton.setToolTipText("Duplicate current version");
-		saveButton.addActionListener(this);
+		copyOptionsPanel.add(saveVersionButton = GetButton("icons/down_arrow.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                saveVersionButton.setToolTipText("Duplicate current version");
+		saveVersionButton.addActionListener(this);
                                                 
-		copyOptionsPanel.add(undoButton = GetButton("icons/undo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                undoButton.setToolTipText("Previous version");
-		undoButton.addActionListener(this);
-                undoButton.setEnabled(false);
+		copyOptionsPanel.add(deleteVersionButton = GetButton("icons/trash.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                deleteVersionButton.setToolTipText("Delete current version");
+		deleteVersionButton.addActionListener(this);
+                                                
+		copyOptionsPanel.add(previousVersionButton = GetButton("icons/undo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                previousVersionButton.setToolTipText("Previous version");
+		previousVersionButton.addActionListener(this);
+                previousVersionButton.setEnabled(false);
                 
                 cGridBag updown = new cGridBag().setVertical(true);
 		updown.add(restoreButton = GetButton("icons/restore.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 restoreButton.setToolTipText("Undo (restore current version)");
 		restoreButton.addActionListener(this);
-                restoreButton.setEnabled(false);
+                //restoreButton.setEnabled(false);
                 
 		updown.add(replaceButton = GetButton("icons/replace.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 replaceButton.setToolTipText("Save (replace current version)");
 		replaceButton.addActionListener(this);
-                replaceButton.setEnabled(false);
+                //replaceButton.setEnabled(false);
                 
                 copyOptionsPanel.add(updown);
                 
-		copyOptionsPanel.add(redoButton = GetButton("icons/redo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                redoButton.setToolTipText("Next version");
-		redoButton.addActionListener(this);
-                redoButton.setEnabled(false);
+		copyOptionsPanel.add(nextVersionButton = GetButton("icons/redo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                nextVersionButton.setToolTipText("Next version");
+		nextVersionButton.addActionListener(this);
+                nextVersionButton.setEnabled(false);
+                
+		oe.toolbarPanel.add(oneStepButton = GetButton("icons/step.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                oneStepButton.setToolTipText("Animate one step forward");
+		oneStepButton.addActionListener(this);
                 
                 oe.toolbarPanel.add(liveCB = GetToggleButton("icons/run.png", Globals.isLIVE())); //, oe.aConstraints);
                 liveCB.setToolTipText("Enable animation");
                                 liveCB.addItemListener(this);
 
-		oe.toolbarPanel.add(oneStepButton = GetButton("icons/step.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                oneStepButton.setToolTipText("Animate one step forward");
-		oneStepButton.addActionListener(this);
-                
                 oe.toolbarPanel.add(fastCB = GetToggleButton("icons/runfast.png", CameraPane.FAST)); //, constraints);
                 fastCB.setToolTipText("Fast mode");
                                 fastCB.addItemListener(this);
@@ -992,21 +1165,6 @@
 
 		//oe.toolbarPanel.add(new JSeparator(SwingConstants.VERTICAL));
                 
-		oe.toolbarPanel.add(twoButton = GetButton("icons/cube.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                twoButton.setToolTipText("Show 3D view only");
-		twoButton.addActionListener(this);
-                this.fullscreenLayout = twoButton;
-                
-		oe.toolbarPanel.add(threeButton = GetButton("icons/controlsview.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                threeButton.setToolTipText("Show controls and 3D view");
-		threeButton.addActionListener(this);
-		oe.toolbarPanel.add(sixButton = GetButton("icons/viewcontrols.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                sixButton.setToolTipText("Show 3D view and controls");
-		sixButton.addActionListener(this);
-//		oe.toolbarPanel.add(sevenButton = new cButton("-|-|-", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-//                sevenButton.setToolTipText("3-column layout");
-//		sevenButton.addActionListener(this);
-                //
 
 		oe.toolbarPanel.add(rootButton = GetButton("icons/openwindow.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 rootButton.setToolTipText("Open selection in new tab");
@@ -1022,12 +1180,16 @@
                 
                 // INSERT
                 row1.add(gridButton = GetButton("icons/grid.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                gridButton.setToolTipText("Create grid");
+                gridButton.setToolTipText("Create ground");
                                 gridButton.addActionListener(this);
 
                 row1.add(boxButton = GetButton("icons/box.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 boxButton.setToolTipText("Create box");
                                 boxButton.addActionListener(this);
+
+                row1.add(superButton = GetButton("icons/super.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                superButton.setToolTipText("Create superellipsoid");
+                                superButton.addActionListener(this);
 
                 row1.add(sphereButton = GetButton("icons/sphere.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 sphereButton.setToolTipText("Create sphere");
@@ -1040,10 +1202,6 @@
                 row1.add(torusButton = GetButton("icons/torus.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 torusButton.setToolTipText("Create torus");
                                 torusButton.addActionListener(this);
-
-                row1.add(superButton = GetButton("icons/super.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                superButton.setToolTipText("Create superellipsoid");
-                                superButton.addActionListener(this);
 
                 if (Globals.ADVANCED)
                 {
@@ -1090,19 +1248,15 @@
 
                 oe.toolboxPanel.add(row2);
                 
-                // ENVYMAPS
-                cGridBag skyboxpane = new cGridBag();
-                skyboxpane.preferredHeight = 100;
+                cGridBag textures = new cGridBag();
                 
-                oe.toolboxPanel.add(skyboxpane);
+                CreateTexturePanel(textures);
                 
-                JTabbedPane skyboxpanel = new JTabbedPane();
-                skyboxpane.add(skyboxpanel);
+                oe.toolboxPanel.add(textures);
                 
-                AddSkyboxTab0(skyboxpanel);
-                AddSkyboxTab1(skyboxpanel);
-                AddSkyboxTab2(skyboxpanel);
-                AddSkyboxTab3(skyboxpanel);
+                textures.preferredHeight = 100;
+                
+                CreateSkyboxPanel(oe.skyboxPanel);
                 
                 // EDIT panel
 		editCommandsPanel.add(editButton = GetButton("icons/controls.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
@@ -1114,16 +1268,16 @@
 		uneditButton.addActionListener(this);
 
 		editCommandsPanel.add(allParamsButton = new JCheckBox("All", allparams)); //, oe.aConstraints);
-                allParamsButton.setToolTipText("Show all controle");
+                allParamsButton.setToolTipText("Show all controls");
 		allParamsButton.addActionListener(this);
 
 		editCommandsPanel.add(clearPanelButton = GetButton("icons/clear.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                clearPanelButton.setToolTipText("Clear edit panel");
+                clearPanelButton.setToolTipText("Clear all controls");
 		clearPanelButton.addActionListener(this);
 
-		editCommandsPanel.add(unselectButton = new cButton("U", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                unselectButton.setToolTipText("Unselect");
-		unselectButton.addActionListener(this);
+		//editCommandsPanel.add(unselectButton = new cButton("U", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                //unselectButton.setToolTipText("Unselect");
+		//unselectButton.addActionListener(this);
 
 		editCommandsPanel.add(flashSelectionButton = GetButton("icons/flash-light.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 flashSelectionButton.setToolTipText("Highlight selection");
@@ -1318,6 +1472,14 @@
 	
         void EditObject(Object3D obj)
         {
+            assert(obj instanceof Composite);
+            
+//            if (obj.versionlist == null)
+//            {
+//                obj.versionlist = new Object3D[100];
+//                obj.versionindex = -1;
+//            }
+            
             cRadio radioButton = new cRadio(obj.name);
             
             // June 2019. Patch to avoid bug with transparency.
@@ -1708,7 +1870,12 @@
   TreePath path;
 
   public TransferableTreePath(TreePath tp) {
-    path = tp;
+      Object[] objs = new Object[tp.getPathCount()];
+      for (int i=0; i<objs.length; i++)
+      {
+          objs[i] = ((Object3D)tp.getPathComponent(i)).GetUUID();
+      }
+    path = new TreePath(objs);
   }
 
   public synchronized DataFlavor[] getTransferDataFlavors() {
@@ -1998,7 +2165,11 @@
             shadow.material = new cMaterial(obj.material);
             shadow.material.diffuse = 0.0001f;
             shadow.material.specular = 0.0001f;
-            //shadow.projectedVertices[1].x = 300;
+            shadow.material.opacity = 0.75f;
+            
+            AllocProjectedVertices(shadow);
+        
+            shadow.projectedVertices[1].x = 300;
             
             makeSomething(shadow);
         }
@@ -2519,27 +2690,35 @@
 		} else
 		if (source == loopItem || source == loopButton)
 		{
+                    if (!group.selection.isEmpty())
+                    {
                         Composite csg = new GroupLeaf();
                         csg.count = 5;
-			group(csg);
                         Composite child = new cGroup("Branch");
                         csg.addChild(child);
                         child.addChild(csg);
+			group(csg);
+                    }
 		} else
 		if (source == doubleItem)
 		{
+                    if (!group.selection.isEmpty())
+                    {
                         Composite csg = new GroupLeaf("Fork");
                         csg.count = 5;
-			group(csg);
                         Composite child = new cGroup("Branch A");
                         csg.addChild(child);
                         child.addChild(csg);
                         child = new cGroup("Branch B");
                         csg.addChild(child);
                         child.addChild(csg);
+			group(csg);
+                    }
 		} else
 		if (source == tripleItem)
 		{
+                    if (!group.selection.isEmpty())
+                    {
                         Composite csg = new GroupLeaf("Trident");
                         csg.count = 4;
 			group(csg);
@@ -2552,6 +2731,7 @@
                         child = new cGroup();
                         csg.addChild(child);
                         child.addChild(csg);
+                    }
 		} else
 		if (source == computeAOItem)
 		{
@@ -2571,7 +2751,7 @@
 		if (source == invariantsItem)
 		{
                     System.out.println("Invariants:");
-                    Grafreed.grafreeD.universe.invariants();
+                    Grafreed.grafreed.universe.invariants();
 		} else
 		if (source == memoryItem)
 		{
@@ -2602,35 +2782,52 @@
 		{
 			ToggleFullScreen();
 		} else
-		if (source == undoButton)
+		if (source == collapseButton)
+		{
+                        this.expandedLayout = radio.layout;
+			CollapseToolbar();
+		} else
+		if (source == maximize3DButton)
+		{
+                        this.expandedLayout = radio.layout;
+                        radio.layout = twoButton;
+                        Show3DView();
+			CollapseToolbar();
+		} else
+		if (source == previousVersionButton)
 		{
                         // Go to previous version
 			//if (!Undo())
                             //java.awt.Toolkit.getDefaultToolkit().beep();
-			Undo();
+			PreviousVersion();
 		} else
 		if (source == restoreButton)
 		{
                         // Restore current version
 			Restore();
-        restoreButton.setEnabled(false);
+        //restoreButton.setEnabled(false);
 		} else
 		if (source == replaceButton)
 		{
                         // Overwrite current version
 			Replace();
-        replaceButton.setEnabled(false);
+        //replaceButton.setEnabled(false);
 		} else
-		if (source == redoButton)
+		if (source == nextVersionButton)
 		{
                         // Go to next version
-			Redo();
+			NextVersion();
 		} else
-		if (source == saveButton)
+		if (source == saveVersionButton)
 		{
                         // Save a new version
 			if (!Save(true))
                             java.awt.Toolkit.getDefaultToolkit().beep();
+		} else
+		if (source == deleteVersionButton)
+		{
+                        // Delete a new version
+                        DeleteVersion();
 		} else
 		if (source == oneStepButton)
 		{
@@ -2685,11 +2882,11 @@
 		} else
 		if (source == undoItem)
 		{
-			Undo();
+			PreviousVersion();
 		} else
 		if (source == redoItem)
 		{
-			Redo();
+			NextVersion();
 		} else
 		if (source == duplicateItem)
 		{
@@ -3170,22 +3367,34 @@
 		} else
 		if (source == ungroupItem || source == ungroupButton)
 		{
-                    boolean hasRoot = false;
+                    boolean canUngroup = true;
                     
                     for (int i=0; i<group.selection.size(); i++)
                     {
-                        if (group.selection.get(i) == group)
+                        Object3D selectedItem = group.selection.get(i);
+                        
+                        if (selectedItem.Size() == 0)
                         {
-                            hasRoot = true;
+                            // Cannot ungroup leaves
+                            canUngroup = false;
+                            break;
+                        }
+                                
+                        if (selectedItem == group)
+                        {
+                            // Cannot ungroup root
+                            canUngroup = false;
                             break;
                         }
                     }
 
-                    if (!hasRoot)
+                    if (canUngroup)
                     {
                         for (int i=0; i<group.selection.size(); i++)
                         {
-                            Ungroup(group.selection.get(i));
+                            Object3D selectedItem = group.selection.get(i);
+                            
+                            Ungroup(selectedItem);
                         }
 
                         ClearSelection(false);
@@ -3548,38 +3757,7 @@
                     if (CameraPane.FULLSCREEN)
                         fullscreenLayout = radio.layout;
                     
-                    // bug
-                    //gridPanel.setDividerLocation(1.0);
-                    //bigPanel.setDividerLocation(0.0);
-//                    bigThree.remove(scenePanel);
-//                    bigThree.remove(centralPanel);
-//                    bigThree.remove(XYZPanel);
-//                    aWindowConstraints.gridx = 0;
-//                    aWindowConstraints.gridy = 0;
-//                    aWindowConstraints.gridwidth = 1;
-//            //        aConstraints.gridheight = 3;
-//                    aWindowConstraints.fill = GridBagConstraints.VERTICAL;
-//                    aWindowConstraints.weightx = 0;
-//                    aWindowConstraints.weighty = 1;
-//                    //bigThree.add(jtp, aWindowConstraints);
-//                    aWindowConstraints.weightx = 1;
-//                    aWindowConstraints.gridwidth = 3;
-//            //        aConstraints.gridheight = 3;
-//                    aWindowConstraints.gridx = 1;
-//                    aWindowConstraints.fill = GridBagConstraints.BOTH;
-//                    bigThree.add(centralPanel, aWindowConstraints);
-//                    aWindowConstraints.weightx = 0;
-//                    aWindowConstraints.gridx = 4;
-//                    aWindowConstraints.gridwidth = 1;
-//            //        aConstraints.gridheight = 3;
-//                    aWindowConstraints.fill = GridBagConstraints.VERTICAL;
-//                    //bigThree.add(XYZPanel, aWindowConstraints);
-//                    scenePanel.setVisible(false);
-//                    centralPanel.setVisible(true);
-//                    XYZPanel.setVisible(false);
-                    bigThree.ClearUI();
-                    bigThree.add(centralPanel);
-                    bigThree.FlushUI();
+                    Show3DView();
                     
                     cameraView.requestFocusInWindow();
                     
@@ -3765,6 +3943,7 @@
                 } else
 		if (source == rootButton)
 		{
+                    Replace();
                     Object3D obj;
                     for (Enumeration e = group.selection.elements(); e.hasMoreElements();)
                     {
@@ -3901,8 +4080,6 @@
                     
                     copy = group;
                     
-                    SetUndoStates();
-
                     //Globals.theRenderer.object = group;
                     if(!useclient)
                     {
@@ -3930,6 +4107,18 @@
                      */
                     radio.layout.doClick();
                     
+                    assert(copy instanceof Composite);
+                    
+        if (copy.versionlist == null)
+        {
+            copy.versionlist = new Object3D[100];
+            copy.versionindex = -1;
+            
+            Save(true);
+        }
+        
+                    SetVersionStates();
+
                     ClearUnpinned();
                     
                     //Grafreed.Assert(group != null);
@@ -5160,15 +5349,29 @@
         {
             editButton.setEnabled(enabled);
             uneditButton.setEnabled(enabled);
-            unselectButton.setEnabled(enabled);
+            //unselectButton.setEnabled(enabled);
             flashSelectionButton.setEnabled(enabled);
             
             clearPanelButton.setEnabled(!listUI.isEmpty());
+            
+            boolean allComposites = true;
+            
+            if (group.selection != null)
+            for (Enumeration e = group.selection.elements(); e.hasMoreElements();)
+            {
+                    if (!(e.nextElement() instanceof Composite))
+                    {
+                        allComposites = false;
+                        break;
+                    }
+            }
+            
+            rootButton.setEnabled(allComposites);
         }
 
         void refreshContents(boolean cp)
         {
-            if (objectPanel.getSelectedIndex() == 2) // objectPanel.indexOfTab("Info"))
+            //if (objectPanel.getSelectedIndex() == 2) // objectPanel.indexOfTab("Info"))
             if (!Globals.MOUSEDRAGGED && group.selection != null) // && !Globals.TIMERRUNNING)
             {
                 objEditor.ClearInfo(); // .GetMaterial());
@@ -5178,7 +5381,7 @@
                     Object3D child = (Object3D) group.selection.get(i);
 
                     objEditor.AddInfo(child, this, true);
-    System.err.println("info : " + child.GetPath());
+//    System.err.println("info : " + child.GetPath());
                 }
 
                 objEditor.SetText(); // jan 2014
@@ -6004,7 +6207,6 @@
 	
 	cButton restoreCameraButton;
         
-	cButton saveButton;
 	cButton oneStepButton;
         
         cButton groupButton;
@@ -6062,11 +6264,11 @@
 	private MenuItem lookAtItem;
 	private MenuItem lookFromItem;
 	private MenuItem switchViewItem;
-	private MenuItem cutItem;
+	private JMenuItem cutItem;
 	private MenuItem undoItem;
 	private MenuItem redoItem;
 	private JMenuItem duplicateItem;
-	private MenuItem cloneItem;
+	private JMenuItem cloneItem;
 	private MenuItem cloneSupportItem;
 	private MenuItem overwriteGeoItem;
 	private MenuItem overwriteMatItem;
@@ -6087,13 +6289,13 @@
 	private MenuItem cloneGeometriesItem;
 	private MenuItem shareGeometriesItem;
 	private MenuItem mergeGeometriesItem;
-	private MenuItem copyItem;
+	private JMenuItem copyItem;
 	private MenuItem pasteItem;
-	private MenuItem pasteIntoItem;
-	private MenuItem pasteLinkItem;
-	private MenuItem pasteCloneItem;
-	private MenuItem pasteExpandItem;
-	private MenuItem deleteItem;
+	private JMenuItem pasteIntoItem;
+	private JMenuItem pasteLinkItem;
+	private JMenuItem pasteCloneItem;
+	private JMenuItem pasteExpandItem;
+	private JMenuItem deleteItem;
 	private MenuItem clearAllItem;
 	private MenuItem genUVItem;
 	private MenuItem genNormalsMESHItem;
@@ -6161,7 +6363,7 @@
 	private MenuItem switchTransfoItem;
 	private MenuItem morphItem;
 	private MenuItem linkerItem;
-	private MenuItem ungroupItem;
+	private JMenuItem ungroupItem;
 	private MenuItem editItem;
 	private MenuItem openWindowItem;
 	private MenuItem editLeafItem;

--
Gitblit v1.6.2