From 8f1afe25ea8fc8801aab66331c32a50859a758c2 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 12 Aug 2019 18:20:19 -0400
Subject: [PATCH] Fix version manager.

---
 GroupEditor.java |  210 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 131 insertions(+), 79 deletions(-)

diff --git a/GroupEditor.java b/GroupEditor.java
index 074be71..e09d28f 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -42,12 +42,12 @@
         });
     }
 
-    public void AddTextureButton(String f, final String t, cGridBag row)
+    public void AddTextureButton(String f, String c, final String t, int count, cGridBag row)
     {
         cButton textureButton;
-        final String path = "textures/" + f + "/"; // + t;
+        final String path = "textures/" + f + "/" + c + "/"; // + t;
         row.add(textureButton = GetButton(path + "icons/" + t, !Grafreed.NIMBUSLAF));
-        textureButton.setToolTipText(f + "s");
+        textureButton.setToolTipText(c + count);
         textureButton.addActionListener(new ActionListener()
         {
                 @Override
@@ -350,7 +350,23 @@
     
     public void ChangeTexture(String texture)
     {
-        cameraView.repaint();
+        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;
@@ -394,6 +410,8 @@
         {
             copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
+            
+            Save(true);
         }
         
 		if(ui)
@@ -625,11 +643,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);
@@ -877,6 +893,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.
@@ -900,35 +919,41 @@
         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)
+//        for (int i = 0; i < path.length; i++)
+//            System.out.print(path[i] + "/");
+//        System.out.println();
+        
+        if (//rowcount == 0 ||
+                path.length == 1)
         {
             currenttab = new cGridBag();
             added = false;
-            String tabname = String.valueOf((char)('A'+tabcount));
+            String tabname = path[0]; // String.valueOf((char)('A'+tabcount));
             currenttab.setName(tabname);
             rowcount = 1;
+            colcount = 0;
+            texturecount = 0;
         }
         
-        if (path.length > 1 && path[1].toLowerCase().endsWith(".jpg"))
+        if (path.length > 2 && path[2].toLowerCase().endsWith(".jpg"))
         {
             if (!added)
             {
                 added = true;
                 resourcecontainer.add(currenttab);
-                String tabname = String.valueOf((char)('A'+tabcount));
+                String tabname = path[0]; // String.valueOf((char)('A'+tabcount));
                 resourcecontainer.setToolTipTextAt(tabcount++, "Texture Group " + tabname);
             }
             
-            AddTextureButton(path[0], path[1], currenttab);
+            AddTextureButton(path[0], path[1], path[2], texturecount++, currenttab);
+            
             if (++colcount >= columns)
             {
                 colcount = 0;
@@ -949,7 +974,7 @@
     
         void CreateTexturePanel(cGridBag container)
         {
-            resourcecontainer = new JTabbedPane();
+            resourcecontainer = new JTabbedPane(JTabbedPane.LEFT);
             container.add(resourcecontainer);
             
             Grafreed.ParseResources("textures", this);
@@ -972,11 +997,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();
@@ -1009,10 +1029,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");
@@ -1057,14 +1116,14 @@
 		nextVersionButton.addActionListener(this);
                 nextVersionButton.setEnabled(false);
                 
-                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(liveCB = GetToggleButton("icons/run.png", Globals.isLIVE())); //, oe.aConstraints);
+                liveCB.setToolTipText("Enable animation");
+                                liveCB.addItemListener(this);
+
                 oe.toolbarPanel.add(fastCB = GetToggleButton("icons/runfast.png", CameraPane.FAST)); //, constraints);
                 fastCB.setToolTipText("Fast mode");
                                 fastCB.addItemListener(this);
@@ -1091,21 +1150,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");
@@ -1121,7 +1165,7 @@
                 
                 // 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);
@@ -1413,6 +1457,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.
@@ -1803,7 +1855,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() {
@@ -2696,6 +2753,18 @@
 		if (source == fullButton)
 		{
 			ToggleFullScreen();
+		} else
+		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)
 		{
@@ -3648,38 +3717,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();
                     
@@ -3865,6 +3903,7 @@
                 } else
 		if (source == rootButton)
 		{
+                    Replace();
                     Object3D obj;
                     for (Enumeration e = group.selection.elements(); e.hasMoreElements();)
                     {
@@ -4001,8 +4040,6 @@
                     
                     copy = group;
                     
-                    SetUndoStates();
-
                     //Globals.theRenderer.object = group;
                     if(!useclient)
                     {
@@ -4030,6 +4067,8 @@
                      */
                     radio.layout.doClick();
                     
+                    SetUndoStates();
+
                     ClearUnpinned();
                     
                     //Grafreed.Assert(group != null);
@@ -5264,6 +5303,19 @@
             flashSelectionButton.setEnabled(enabled);
             
             clearPanelButton.setEnabled(!listUI.isEmpty());
+            
+            boolean allComposites = true;
+            
+            for (Enumeration e = group.selection.elements(); e.hasMoreElements();)
+            {
+                    if (!(e.nextElement() instanceof Composite))
+                    {
+                        allComposites = false;
+                        break;
+                    }
+            }
+            
+            rootButton.setEnabled(allComposites);
         }
 
         void refreshContents(boolean cp)
@@ -5278,7 +5330,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

--
Gitblit v1.6.2