From 914255f70cf047897212839cbf3a6722703f4457 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 24 Jun 2019 13:19:16 -0400
Subject: [PATCH] Fix manip window + new icons.

---
 ObjEditor.java       |   55 ++++++++++
 icons/redo.png       |    0 
 icons/add-128.png    |    0 
 Camera.java          |    2 
 icons/fullscreen.png |    0 
 icons/fit.png        |    0 
 Mocap.java           |    1 
 icons/step.png       |    0 
 CameraPane.java      |   13 +-
 Globals.java         |    2 
 icons/light-bulb.png |    0 
 icons/runfast.png    |    0 
 GroupEditor.java     |   84 +++++++++-------
 cFileSystemPane.java |    2 
 icons/down_arrow.png |    0 
 Object3D.java        |   39 ++++++-
 cButton.java         |   21 ++++
 cCheckBox.java       |   41 ++++++--
 icons/run.png        |    0 
 icons/track.png      |    0 
 icons/undo.png       |    0 
 21 files changed, 200 insertions(+), 60 deletions(-)

diff --git a/Camera.java b/Camera.java
index f5243d4..be4d200 100644
--- a/Camera.java
+++ b/Camera.java
@@ -20,7 +20,7 @@
         //<-2.2,0.7,-2> and pointed it at <-0.61,0.3,-0.6>
     //    location = LA.newVector(2,0.7,-2);
     //    lookAt = new cVector(0.6,0.3,-0.6);
-        location = LA.newVector(3,2,2);
+        location = LA.newVector(6,4,4);
         lookAt = new cVector(0.0,0.5,0);
         direction = new cVector();
         toParent = LA.newMatrix();
diff --git a/CameraPane.java b/CameraPane.java
index 7afdef6..c1f5c9b 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -11459,7 +11459,7 @@
 
     static boolean zoomonce = false;
     
-    void CreateSelectedPoint()
+    static void CreateSelectedPoint()
     {
         if (selectedpoint == null)
         {
@@ -14377,7 +14377,8 @@
                 info.camera = renderCamera;
                 info.x = x;
                 info.y = y;
-                object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
+                object.manipWindow.copy
+                        .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
             } else
             {
                 if (x < startX)
@@ -14541,9 +14542,9 @@
         ci.camera = renderCamera;
         if (!isRenderer)
         {
-            ObjEditor editWindow = object.editWindow;
-            Object3D copy = editWindow.copy;
-            if (copy.doEditClick(ci, 0))
+            //ObjEditor editWindow = object.editWindow;
+            //Object3D copy = editWindow.copy;
+            if (object.doEditClick(ci, 0))
             {
                 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
             } else
@@ -16622,6 +16623,8 @@
 //                System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
 //                System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
                 
+                CreateSelectedPoint();
+                
                 // Will fit the mesh !!!
                 selectedpoint.toParent[0][0] = 0.0001;
                 selectedpoint.toParent[1][1] = 0.0001;
diff --git a/Globals.java b/Globals.java
index 3489016..4eca159 100644
--- a/Globals.java
+++ b/Globals.java
@@ -10,6 +10,8 @@
         public static boolean COMPUTESHADOWWHENLIVE = true;
         public static boolean RENDERSHADOW = true;
         
+        public static boolean SAVEONMAKE = false; // problems when auto-save (works with manual save)
+        
         public static boolean MOUSEDRAGGED = false;
     
         // Hold on calculation when moving camera
diff --git a/GroupEditor.java b/GroupEditor.java
index 33acfd4..cce9b1b 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -580,43 +580,43 @@
                 //minButton.setToolTipText("Minimize window");
 		//minButton.addActionListener(this);
                 
-		oe.toolbarPanel.add(maxButton = new cButton("\u271A", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		oe.toolbarPanel.add(maxButton = GetButton("icons/add-128.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 maxButton.setToolTipText("Maximize window");
 		maxButton.addActionListener(this);
                 
-		oe.toolbarPanel.add(fullButton = new cButton("\u2b1c", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		oe.toolbarPanel.add(fullButton = GetButton("icons/fullscreen.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 fullButton.setToolTipText("Full-screen window");
 		fullButton.addActionListener(this);
                 
-		oe.toolbarPanel.add(undoButton = new cButton("\u21a9", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		oe.toolbarPanel.add(undoButton = GetButton("icons/undo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 undoButton.setToolTipText("Undo changes");
 		undoButton.addActionListener(this);
                 
-		oe.toolbarPanel.add(redoButton = new cButton("\u21aa", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		oe.toolbarPanel.add(redoButton = GetButton("icons/redo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 redoButton.setToolTipText("Redo changes");
 		redoButton.addActionListener(this);
                 
-		oe.toolbarPanel.add(saveButton = new cButton("\u21e3", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		oe.toolbarPanel.add(saveButton = GetButton("icons/down_arrow.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 saveButton.setToolTipText("Save changes");
 		saveButton.addActionListener(this);
                 
-                oe.toolbarPanel.add(liveCB = new cCheckBox("Live", Globals.isLIVE())); //, oe.aConstraints);
+                oe.toolbarPanel.add(liveCB = GetCheckBox("icons/run.png", Globals.isLIVE())); //, oe.aConstraints);
                 liveCB.setToolTipText("Enable animation");
                                 liveCB.addItemListener(this);
 
-		oe.toolbarPanel.add(oneStepButton = new cButton("\u29f4", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                oneStepButton.setToolTipText("Animate one step forward");
-		oneStepButton.addActionListener(this);
-                
-                oe.toolbarPanel.add(fastCB = new cCheckBox("Fast", CameraPane.FAST)); //, constraints);
+                oe.toolbarPanel.add(fastCB = GetCheckBox("icons/runfast.png", CameraPane.FAST)); //, constraints);
                 fastCB.setToolTipText("Fast mode");
                                 fastCB.addItemListener(this);
                                 
-                oe.toolbarPanel.add(trackCB = new cCheckBox(":", CameraPane.TRACK)); //, oe.aConstraints);
+		oe.toolbarPanel.add(oneStepButton = GetButton("icons/step.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                oneStepButton.setToolTipText("Animate one step forward");
+		oneStepButton.addActionListener(this);
+                
+                oe.toolbarPanel.add(trackCB = GetCheckBox("icons/track.png", CameraPane.TRACK)); //, oe.aConstraints);
                 trackCB.setToolTipText("Enable tracking");
                                 trackCB.addItemListener(this);
 
-		oe.toolbarPanel.add(screenfitButton = new cButton("@", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		oe.toolbarPanel.add(screenfitButton = GetButton("icons/fit.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 screenfitButton.setToolTipText("Screen fit");
 		screenfitButton.addActionListener(this);
 
@@ -630,8 +630,8 @@
                         snapobjectButton.setToolTipText("Snap Object");
                 }
 
-		oe.toolbarPanel.add(flashSelectionButton = new cButton("?", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                flashSelectionButton.setToolTipText("Show selection");
+		oe.toolbarPanel.add(flashSelectionButton = GetButton("icons/light-bulb.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                flashSelectionButton.setToolTipText("Highlight selection");
 		flashSelectionButton.addActionListener(this);
                 
 		oe.toolbarPanel.add(new JSeparator(SwingConstants.VERTICAL));
@@ -815,6 +815,10 @@
                 shadowCB.setToolTipText("Compute shadows when live");
                                 shadowCB.addItemListener(this);
 
+                panel.add(autosaveCB = new cCheckBox("Auto-save", Globals.SAVEONMAKE)); //, constraints);
+                autosaveCB.setToolTipText("Auto-save on structure change");
+                                autosaveCB.addItemListener(this);
+
             if (Globals.ADVANCED)
             {
                 panel.add(lookAtCB = new cCheckBox("Target", CameraPane.LOOKAT)); //, constraints);
@@ -864,25 +868,26 @@
             /*DropTarget dropTarget =*/ new DropTarget(oe.cameraView, this);
         }
 
-        JCheckBox liveCB;
-        JCheckBox supportCB;
-        JCheckBox localCB;
-        JCheckBox crowdCB;
-        JCheckBox smoothCB;
-        JCheckBox fastCB;
-        JCheckBox slowCB;
-        JCheckBox boxCB;
-        JCheckBox zoomBoxCB;
-        JCheckBox trackCB;
-        JCheckBox smoothfocusCB;
+        cCheckBox liveCB;
+        cCheckBox supportCB;
+        cCheckBox localCB;
+        cCheckBox crowdCB;
+        cCheckBox smoothCB;
+        cCheckBox fastCB;
+        cCheckBox slowCB;
+        cCheckBox boxCB;
+        cCheckBox zoomBoxCB;
+        cCheckBox trackCB;
+        cCheckBox smoothfocusCB;
 //        JCheckBox speakerMocapCB;
-        JCheckBox speakerCameraCB;
-        JCheckBox speakerFocusCB;
-        JCheckBox debugCB;
+        cCheckBox speakerCameraCB;
+        cCheckBox speakerFocusCB;
+        cCheckBox debugCB;
         
-        JCheckBox oeilCB;
-        JCheckBox shadowCB;
-        JCheckBox lookAtCB;
+        cCheckBox oeilCB;
+        cCheckBox shadowCB;
+        cCheckBox autosaveCB;
+        cCheckBox lookAtCB;
         
 //        static int COLOR = 1;
 //        static int MATERIAL = 2;
@@ -890,9 +895,9 @@
         
         int dropAttributes = Object3D.COLOR | Object3D.MATERIAL;
         
-        JCheckBox colorCB;
-        JCheckBox materialCB;
-        JCheckBox textureCB;
+        cCheckBox colorCB;
+        cCheckBox materialCB;
+        cCheckBox textureCB;
         
         public void itemStateChanged(ItemEvent e)
         {
@@ -988,6 +993,10 @@
             else if(e.getSource() == shadowCB)
             {
                 Globals.COMPUTESHADOWWHENLIVE ^= true;
+            }
+            else if(e.getSource() == autosaveCB)
+            {
+                Globals.SAVEONMAKE ^= true;
             }
             else if(e.getSource() == lookAtCB)
             {
@@ -3159,7 +3168,8 @@
                                 buttonGroup.remove(ab);
                                 radioPanel.remove(ab);
                                 
-                                ab.GetObject().editWindow = null;
+                                //ab.GetObject().editWindow = null;
+                                ab.GetObject().manipWindow = null;
                             //    ab.GetObject().objectUI = null; // ?????????
                                 
                                 ((cRadio)radioPanel.getComponent(radioPanel.getComponentCount() - 1)).doClick();
@@ -3273,6 +3283,7 @@
                     
 // fix "+" issue
                     //group.editWindow = this;
+                    group.manipWindow = this;
                     
                     /*
                     currentLayout = radio.layout;
@@ -4595,6 +4606,7 @@
                 
 		if (cut)
 		{
+        if (Globals.SAVEONMAKE)
                     Save();
 			//int indices[] = jList.getSelectedIndices();
 			//for (int i = indices.length - 1; i >= 0; i--)
diff --git a/Mocap.java b/Mocap.java
index 438e46a..545c82e 100644
--- a/Mocap.java
+++ b/Mocap.java
@@ -501,6 +501,7 @@
         centroid.z = matrix[3][2];
 //        this.getCentroid(centroid, true);
         
+        CameraPane.CreateSelectedPoint();
         CameraPane.debugpointG.name = "";
         CameraPane.debugpointG.toParent[3][0] = mocaporigin.x;
         CameraPane.debugpointG.toParent[3][1] = mocaporigin.y;
diff --git a/ObjEditor.java b/ObjEditor.java
index 9fcd4b1..a1683f8 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.*;
@@ -37,6 +38,52 @@
     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);
+        }
+    }
+
+    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
     
@@ -3408,6 +3455,8 @@
     
     public void Save()
     {
+        System.err.println("Save");
+        
         cRadio tab = GetCurrentTab();
         
         boolean temp = CameraPane.SWITCH;
@@ -3492,6 +3541,8 @@
     
     public void Undo()
     {
+        System.err.println("Undo");
+        
         cRadio tab = GetCurrentTab();
         
         if (tab.undoindex == 0)
@@ -4170,7 +4221,8 @@
 
     void makeSomething(Object3D thing, boolean resetmodel) // deselect)
     {
-        Save();
+        if (Globals.SAVEONMAKE)
+            Save();
         //Tween.set(thing, 0).target(1).start(tweenManager);
         //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
 //            if (thing instanceof GenericJointDemo)
@@ -4479,6 +4531,7 @@
         
         if (readobj != null)
         {
+        if (Globals.SAVEONMAKE)
             Save();
             try
             {
diff --git a/Object3D.java b/Object3D.java
index 45bb2a6..c2b61ec 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -181,7 +181,7 @@
             return;
         }
 
-        Object3D o = new Object3D();
+        Object3D o = new Object3D("copy of " + this.name);
 
         hashtable.put(GetUUID(), o);
 
@@ -219,16 +219,23 @@
         if (!hashtable.containsKey(GetUUID()))
             return;
 
+        if (blockloop)
+            return;
+
+        blockloop = true;
+
         Object3D o = hashtable.get(GetUUID());
 
         RestoreBigData(o);
 
-        hashtable.remove(GetUUID());
+        //hashtable.remove(GetUUID());
 
         for (int i=0; i<Size(); i++)
         {
             get(i).RestoreBigData(hashtable);
         }
+        
+        blockloop = false;
     }
 
     void RestoreBigData(Object3D o)
@@ -2433,6 +2440,14 @@
         {
             editWindow.refreshContents();
         }
+        else
+        {
+            if (manipWindow != null)
+            {
+                manipWindow.refreshContents();
+            }
+        }
+                
     //if (parent != null)
     //parent.refreshEditWindow();
     }
@@ -4963,6 +4978,14 @@
         }
     }
     
+    ObjEditor GetWindow()
+    {
+        if (editWindow != null)
+            return editWindow;
+        
+        return manipWindow;
+    }
+    
     cTreePath Select(int indexcount, boolean deselect)
     {
         if (hide || dontselect)
@@ -4999,10 +5022,11 @@
                 if (leaf != null)
                 {
                     cTreePath tp = new cTreePath(this, leaf);
-                    if (editWindow != null)
+                    ObjEditor window = GetWindow();
+                    if (window != null)
                     {
                         //System.out.println("editWindow = " + editWindow + " vs " + this);
-                        editWindow.Select(tp, deselect, true);
+                        window.Select(tp, deselect, true);
                     }
 
                     return tp;
@@ -5028,9 +5052,10 @@
                 if (leaf != null)
                 {
                     cTreePath tp = new cTreePath(this, leaf);
-                    if (editWindow != null)
+                    ObjEditor window = GetWindow();
+                    if (window != null)
                     {
-                        editWindow.Select(tp, deselect, true);
+                        window.Select(tp, deselect, true);
                     }
 
                     return tp;
@@ -7967,6 +7992,8 @@
     }
     
     transient ObjEditor editWindow;
+    transient ObjEditor manipWindow;
+    
     transient ObjectUI objectUI;
     public static int povDepth = 0;
     private static cVector tbMin = new cVector();
diff --git a/cButton.java b/cButton.java
index fb1d9a3..6755475 100644
--- a/cButton.java
+++ b/cButton.java
@@ -21,4 +21,25 @@
                 //setBorder(null); //new javax.swing.border.EmptyBorder(0,0,0,0));
         }
     }
+    
+    cButton(javax.swing.ImageIcon icon, boolean border)
+    {
+        super(icon);
+        
+        setMargin(new java.awt.Insets(1, 1, 1, 1));
+        
+//result = new JButton( icon );
+//result.setBorderPainted( false );
+//result.setContentAreaFilled( false );
+//
+//width = icon.getIconWidth();
+//height = icon.getIconHeight();
+//result.setPreferredSize( new Dimension( width, height ) );
+        if (border)
+                setBorder(new javax.swing.border.EtchedBorder());
+        else
+        {
+                //setBorder(null); //new javax.swing.border.EmptyBorder(0,0,0,0));
+        }
+    }
 }
diff --git a/cCheckBox.java b/cCheckBox.java
index bf26b8b..8135140 100644
--- a/cCheckBox.java
+++ b/cCheckBox.java
@@ -1,19 +1,40 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
 
-/**
- *
- * @author nbriere
- */
+import javax.swing.ImageIcon;
+
 public class cCheckBox extends javax.swing.JCheckBox
 {
     cCheckBox(String name, boolean enabled)
     {
         super(name, enabled);
-        
-        setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
+
+        setBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0));
         //setBorder(new javax.swing.border.EtchedBorder());
     }
+
+    cCheckBox(ImageIcon icon, boolean enabled)
+    {
+        super("", enabled);
+
+        this.image = icon.getImage();
+        iconWidth = icon.getIconWidth();
+
+        setBorder(new javax.swing.border.EmptyBorder(8, 0, 8, 24)); // top, left, bottom, right
+        //setBorder(new javax.swing.border.EtchedBorder());
+    }
+    
+    private java.awt.Image image;
+    private int iconWidth;
+
+    @Override
+    protected void paintComponent(java.awt.Graphics g)
+    {
+        super.paintComponent(g);
+        if (image != null)
+        {
+            //if (getWidth() > image.getWidth(null) + 8)
+            {
+                g.drawImage(image, 18, 6, this);
+            }
+        }
+    }
 }
diff --git a/cFileSystemPane.java b/cFileSystemPane.java
index da2f91f..56bc5ea 100644
--- a/cFileSystemPane.java
+++ b/cFileSystemPane.java
@@ -26,7 +26,7 @@
     JCheckBox stripCB;
     JCheckBox genUVCB;
 
-    JCheckBox mergeAttributesCB;
+    cCheckBox mergeAttributesCB;
     
     cFileSystemPane(iCallBack o)
     {
diff --git a/icons/add-128.png b/icons/add-128.png
new file mode 100644
index 0000000..5e24f1e
--- /dev/null
+++ b/icons/add-128.png
Binary files differ
diff --git a/icons/down_arrow.png b/icons/down_arrow.png
new file mode 100644
index 0000000..05a8b44
--- /dev/null
+++ b/icons/down_arrow.png
Binary files differ
diff --git a/icons/fit.png b/icons/fit.png
new file mode 100644
index 0000000..c387053
--- /dev/null
+++ b/icons/fit.png
Binary files differ
diff --git a/icons/fullscreen.png b/icons/fullscreen.png
new file mode 100644
index 0000000..0048e0b
--- /dev/null
+++ b/icons/fullscreen.png
Binary files differ
diff --git a/icons/light-bulb.png b/icons/light-bulb.png
new file mode 100644
index 0000000..601268e
--- /dev/null
+++ b/icons/light-bulb.png
Binary files differ
diff --git a/icons/redo.png b/icons/redo.png
new file mode 100644
index 0000000..603a4b8
--- /dev/null
+++ b/icons/redo.png
Binary files differ
diff --git a/icons/run.png b/icons/run.png
new file mode 100644
index 0000000..8d43124
--- /dev/null
+++ b/icons/run.png
Binary files differ
diff --git a/icons/runfast.png b/icons/runfast.png
new file mode 100644
index 0000000..1a25c05
--- /dev/null
+++ b/icons/runfast.png
Binary files differ
diff --git a/icons/step.png b/icons/step.png
new file mode 100644
index 0000000..7ec1f2c
--- /dev/null
+++ b/icons/step.png
Binary files differ
diff --git a/icons/track.png b/icons/track.png
new file mode 100644
index 0000000..59f9b49
--- /dev/null
+++ b/icons/track.png
Binary files differ
diff --git a/icons/undo.png b/icons/undo.png
new file mode 100644
index 0000000..5fbe678
--- /dev/null
+++ b/icons/undo.png
Binary files differ

--
Gitblit v1.6.2