Normand Briere
2019-07-19 e79247ef52a0bbb3864d46bb1e2c716005b3ecf3
ObjEditor.java
....@@ -44,61 +44,47 @@
4444
4545 cButton GetButton(String name, boolean border)
4646 {
47
- try
48
- {
49
- ImageIcon icon = GetIcon(name);
50
- return new cButton(icon, border);
51
- }
52
- catch (Exception e)
53
- {
54
- return new cButton(name, border);
55
- }
47
+ ImageIcon icon = GetIcon(name);
48
+ return new cButton(icon, border);
5649 }
5750
5851 cToggleButton GetToggleButton(String name, boolean border)
5952 {
60
- try
61
- {
62
- ImageIcon icon = GetIcon(name);
63
- return new cToggleButton(icon, border);
64
- }
65
- catch (Exception e)
66
- {
67
- return new cToggleButton(name, border);
68
- }
53
+ ImageIcon icon = GetIcon(name);
54
+ return new cToggleButton(icon, border);
6955 }
7056
7157 cCheckBox GetCheckBox(String name, boolean border)
7258 {
59
+ ImageIcon icon = GetIcon(name);
60
+ return new cCheckBox(icon, border);
61
+ }
62
+
63
+ private ImageIcon GetIcon(String name)
64
+ {
7365 try
7466 {
75
- ImageIcon icon = GetIcon(name);
76
- return new cCheckBox(icon, border);
67
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
68
+
69
+ if (image.getWidth() != 24 && image.getHeight() != 24)
70
+ {
71
+ BufferedImage resized = new BufferedImage(24, 24, image.getType());
72
+ Graphics2D g = resized.createGraphics();
73
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
74
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
75
+ g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
76
+ g.dispose();
77
+
78
+ image = resized;
79
+ }
80
+
81
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
82
+ return icon;
7783 }
7884 catch (Exception e)
7985 {
80
- return new cCheckBox(name, border);
86
+ return null;
8187 }
82
- }
83
-
84
- private ImageIcon GetIcon(String name) throws IOException
85
- {
86
- BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
87
-
88
- if (image.getWidth() != 24 && image.getHeight() != 24)
89
- {
90
- BufferedImage resized = new BufferedImage(24, 24, image.getType());
91
- Graphics2D g = resized.createGraphics();
92
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
93
- //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
94
- g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
95
- g.dispose();
96
-
97
- image = resized;
98
- }
99
-
100
- javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
101
- return icon;
10288 }
10389
10490 // SCRIPT
....@@ -282,6 +268,12 @@
282268 client = inClient;
283269 copy = client;
284270
271
+ if (copy.versions == null)
272
+ {
273
+ copy.versions = new byte[100][];
274
+ copy.versionindex = -1;
275
+ }
276
+
285277 // "this" is not called: SetupUI2(objEditor);
286278 }
287279
....@@ -295,6 +287,12 @@
295287 client = inClient;
296288 copy = client;
297289
290
+ if (copy.versions == null)
291
+ {
292
+ copy.versions = new byte[100][];
293
+ copy.versionindex = -1;
294
+ }
295
+
298296 SetupUI2(callee.GetEditor());
299297 }
300298
....@@ -327,6 +325,12 @@
327325 copy = localCopy;
328326 copy.editWindow = this;
329327
328
+ if (copy.versions == null)
329
+ {
330
+ copy.versions = new byte[100][];
331
+ copy.versionindex = -1;
332
+ }
333
+
330334 SetupMenu();
331335
332336 //SetupName(objEditor); // new
....@@ -419,11 +423,12 @@
419423
420424 toolbarPanel = new JPanel();
421425 toolbarPanel.setName("Toolbar");
426
+
422427 treePanel = new cGridBag();
423428 treePanel.setName("Tree");
424429
425430 editPanel = new cGridBag().setVertical(true);
426
- editPanel.setName("Edit");
431
+ //editPanel.setName("Edit");
427432
428433 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
429434
....@@ -432,10 +437,10 @@
432437 editPanel.add(ctrlPanel);
433438
434439 toolboxPanel = new cGridBag().setVertical(false);
435
- toolboxPanel.setName("Toolbox");
440
+ //toolboxPanel.setName("Toolbox");
436441
437442 materialPanel = new cGridBag().setVertical(true);
438
- materialPanel.setName("Material");
443
+ //materialPanel.setName("Material");
439444
440445 /*JTextPane*/
441446 infoarea = createTextPane();
....@@ -443,6 +448,7 @@
443448
444449 infoarea.setEditable(true);
445450 SetText();
451
+
446452 // infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
447453 // infoarea.setOpaque(false);
448454 // //infoarea.setForeground(textcolor);
....@@ -450,7 +456,7 @@
450456 // TEXTAREA infoarea.setWrapStyleWord(true);
451457 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
452458 infoPanel.setPreferredSize(new Dimension(1, 1));
453
- infoPanel.setName("Info");
459
+ //infoPanel.setName("Info");
454460 //infoPanel.setLayout(new BorderLayout());
455461 //infoPanel.add(createTextPane());
456462
....@@ -816,6 +822,28 @@
816822 frame.validate();
817823 }
818824
825
+ private byte[] CompressCopy()
826
+ {
827
+ boolean temp = CameraPane.SWITCH;
828
+ CameraPane.SWITCH = false;
829
+
830
+ copy.ExtractBigData(versiontable);
831
+ // if (copy == client)
832
+
833
+ byte[] versions[] = copy.versions;
834
+ copy.versions = null;
835
+
836
+ byte[] compress = Compress(copy);
837
+
838
+ copy.versions = versions;
839
+
840
+ copy.RestoreBigData(versiontable);
841
+
842
+ CameraPane.SWITCH = temp;
843
+
844
+ return compress;
845
+ }
846
+
819847 private JTextPane createTextPane()
820848 {
821849 // TEXTAREA String[] initString =
....@@ -1174,10 +1202,11 @@
11741202 randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
11751203 randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11761204
1205
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1206
+ link2masterCB.setToolTipText("Attach to support");
1207
+
11771208 if (Globals.ADVANCED)
11781209 {
1179
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1180
- link2masterCB.setToolTipText("Attach to support");
11811210 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11821211 speedupCB.setToolTipText("Option motion capture");
11831212 }
....@@ -1451,6 +1480,7 @@
14511480 XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll);
14521481 XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll);
14531482 XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
1483
+ //XYZPanel.setName("XYZ");
14541484
14551485 /*
14561486 gridPanel = new JPanel(); //new BorderLayout());
....@@ -1488,16 +1518,23 @@
14881518 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14891519 //tmp.setName("Edit");
14901520 objectPanel.add(materialPanel);
1521
+ objectPanel.setIconAt(0, GetIcon("icons/material.png"));
14911522 // JPanel north = new JPanel(new BorderLayout());
14921523 // north.setName("Edit");
14931524 // north.add(ctrlPanel, BorderLayout.NORTH);
14941525 // objectPanel.add(north);
14951526 objectPanel.add(editPanel);
1527
+ objectPanel.setIconAt(1, GetIcon("icons/write.png"));
14961528
14971529 //if (Globals.ADVANCED)
14981530 objectPanel.add(infoPanel);
1531
+ objectPanel.setIconAt(2, GetIcon("icons/info.png"));
1532
+
1533
+ objectPanel.add(XYZPanel);
1534
+ objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
14991535
15001536 objectPanel.add(toolboxPanel);
1537
+ objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
15011538
15021539 /*
15031540 aConstraints.gridx = 0;
....@@ -1518,7 +1555,7 @@
15181555 scrollpane.addMouseWheelListener(this); // Default not fast enough
15191556
15201557 /*JTabbedPane*/ scenePanel = new cGridBag();
1521
- scenePanel.preferredWidth = 6;
1558
+ scenePanel.preferredWidth = 5;
15221559
15231560 JTabbedPane tabbedPane = new JTabbedPane();
15241561 tabbedPane.add(scrollpane);
....@@ -1596,7 +1633,7 @@
15961633 bigThree = new cGridBag();
15971634 bigThree.addComponent(scenePanel);
15981635 bigThree.addComponent(centralPanel);
1599
- bigThree.addComponent(XYZPanel);
1636
+ //bigThree.addComponent(XYZPanel);
16001637
16011638 // // SIDE EFFECT!!!
16021639 // aConstraints.gridx = 0;
....@@ -3480,8 +3517,8 @@
34803517 try
34813518 {
34823519 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3483
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3484
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3520
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3521
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34853522
34863523 Object3D parent = o.parent;
34873524 o.parent = null;
....@@ -3492,10 +3529,14 @@
34923529
34933530 out.flush();
34943531
3495
- zstream.close();
3532
+ baos //zstream
3533
+ .close();
34963534 out.close();
34973535
3498
- return baos.toByteArray();
3536
+ byte[] bytes = baos.toByteArray();
3537
+
3538
+ System.out.println("save #bytes = " + bytes.length);
3539
+ return bytes;
34993540 } catch (Exception e)
35003541 {
35013542 System.err.println(e);
....@@ -3505,13 +3546,16 @@
35053546
35063547 static public Object Uncompress(byte[] bytes)
35073548 {
3508
- System.out.println("#bytes = " + bytes.length);
3549
+ System.out.println("restore #bytes = " + bytes.length);
35093550 try
35103551 {
35113552 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3512
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3513
- ObjectInputStream in = new ObjectInputStream(istream);
3553
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3554
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
35143555 Object obj = in.readObject();
3556
+
3557
+ bais //istream
3558
+ .close();
35153559 in.close();
35163560
35173561 return obj;
....@@ -3566,12 +3610,11 @@
35663610 return null;
35673611 }
35683612
3569
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35703613
35713614 public void Save()
35723615 {
3573
- // Default reduces the probability of heuristics errors.
3574
- Save(true);
3616
+ //Save(true);
3617
+ Replace();
35753618 }
35763619
35773620 private boolean Equal(byte[] compress, byte[] name)
....@@ -3590,25 +3633,20 @@
35903633 return true;
35913634 }
35923635
3636
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3637
+
35933638 public boolean Save(boolean user)
35943639 {
35953640 System.err.println("Save");
35963641
35973642 cRadio tab = GetCurrentTab();
35983643
3599
- boolean temp = CameraPane.SWITCH;
3600
- CameraPane.SWITCH = false;
3601
-
3602
- copy.ExtractBigData(hashtable);
3603
-
3604
- byte[] compress = Compress(copy);
3605
-
3606
- CameraPane.SWITCH = temp;
3644
+ byte[] compress = CompressCopy();
36073645
36083646 boolean thesame = false;
36093647
36103648 // Quick heuristic using length. Works only when stream is compressed.
3611
- if (tab.undoindex > 0 && tab.graphs[tab.undoindex-1] != null && Equal(compress, tab.graphs[tab.undoindex-1]))
3649
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
36123650 {
36133651 thesame = true;
36143652 }
....@@ -3616,18 +3654,23 @@
36163654 //EditorFrame.m_MainFrame.requestFocusInWindow();
36173655 if (!thesame)
36183656 {
3619
- tab.user[tab.undoindex] = user;
3620
- tab.graphs[tab.undoindex++] = compress;
3657
+ //tab.user[tab.versionindex] = user;
3658
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3659
+
3660
+ copy.versions[++copy.versionindex] = compress;
3661
+
3662
+ // if (increment)
3663
+ // tab.versionindex++;
36213664 }
36223665
3623
- copy.RestoreBigData(hashtable);
3666
+ //copy.RestoreBigData(versiontable);
36243667
36253668 //assert(hashtable.isEmpty());
36263669
3627
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3670
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
36283671 {
3629
- tab.user[i] = false;
3630
- tab.graphs[i] = null;
3672
+ //tab.user[i] = false;
3673
+ copy.versions[i] = null;
36313674 }
36323675
36333676 SetUndoStates();
....@@ -3637,7 +3680,7 @@
36373680 {
36383681 try
36393682 {
3640
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3683
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
36413684 ObjectOutputStream p = new ObjectOutputStream(ostream);
36423685
36433686 p.writeObject(copy);
....@@ -3661,7 +3704,7 @@
36613704 boolean temp = CameraPane.SWITCH;
36623705 CameraPane.SWITCH = false;
36633706
3664
- copy.ExtractBigData(hashtable);
3707
+ copy.ExtractBigData(versiontable);
36653708
36663709 copy.clear();
36673710
....@@ -3670,7 +3713,7 @@
36703713 copy.add(obj.get(i));
36713714 }
36723715
3673
- copy.RestoreBigData(hashtable);
3716
+ copy.RestoreBigData(versiontable);
36743717
36753718 CameraPane.SWITCH = temp;
36763719
....@@ -3698,64 +3741,129 @@
36983741 }
36993742
37003743 cButton undoButton;
3744
+ cButton restoreButton;
3745
+ cButton replaceButton;
37013746 cButton redoButton;
37023747
3748
+ boolean muteSlider;
3749
+
3750
+ int VersionCount()
3751
+ {
3752
+ int count = 0;
3753
+
3754
+ for (int i = copy.versions.length; --i >= 0;)
3755
+ {
3756
+ if (copy.versions[i] != null)
3757
+ count++;
3758
+ }
3759
+
3760
+ return count;
3761
+ }
3762
+
37033763 void SetUndoStates()
37043764 {
37053765 cRadio tab = GetCurrentTab();
37063766
3707
- undoButton.setEnabled(tab.undoindex > 0);
3708
- redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3767
+ restoreButton.setEnabled(copy.versionindex != -1);
3768
+ replaceButton.setEnabled(copy.versionindex != -1);
3769
+
3770
+ undoButton.setEnabled(copy.versionindex > 0);
3771
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3772
+
3773
+ muteSlider = true;
3774
+ versionSlider.setMaximum(VersionCount() - 1);
3775
+ versionSlider.setInteger(copy.versionindex);
3776
+ muteSlider = false;
37093777 }
37103778
37113779 public boolean Undo()
37123780 {
3781
+ // Option?
3782
+ Replace();
3783
+
37133784 System.err.println("Undo");
37143785
37153786 cRadio tab = GetCurrentTab();
37163787
3717
- if (tab.undoindex == 0)
3788
+ if (copy.versionindex == 0)
37183789 {
37193790 java.awt.Toolkit.getDefaultToolkit().beep();
37203791 return false;
37213792 }
37223793
3723
- if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex])
3794
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3795
+// {
3796
+// if (Save(false))
3797
+// tab.versionindex -= 1;
3798
+// else
3799
+// {
3800
+// if (tab.versionindex <= 0)
3801
+// return false;
3802
+// else
3803
+// tab.versionindex -= 1;
3804
+// }
3805
+// }
3806
+
3807
+ copy.versionindex -= 1;
3808
+
3809
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3810
+
3811
+ return true;
3812
+ }
3813
+
3814
+ public boolean Restore()
3815
+ {
3816
+ System.err.println("Restore");
3817
+
3818
+ cRadio tab = GetCurrentTab();
3819
+
3820
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
37243821 {
3725
- if (Save(false))
3726
- tab.undoindex -= 1;
3727
- else
3728
- {
3729
- if (tab.undoindex <= 0)
3730
- return false;
3731
- else
3732
- tab.undoindex -= 1;
3733
- }
3822
+ java.awt.Toolkit.getDefaultToolkit().beep();
3823
+ return false;
37343824 }
37353825
3736
- tab.undoindex -= 1;
3826
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3827
+
3828
+ return true;
3829
+ }
37373830
3738
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3831
+ public boolean Replace()
3832
+ {
3833
+ System.err.println("Replace");
3834
+
3835
+ cRadio tab = GetCurrentTab();
3836
+
3837
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3838
+ {
3839
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3840
+ return false;
3841
+ }
3842
+
3843
+ copy.versions[copy.versionindex] = CompressCopy();
37393844
37403845 return true;
37413846 }
37423847
37433848 public void Redo()
37443849 {
3850
+ // Option?
3851
+ Replace();
3852
+
37453853 cRadio tab = GetCurrentTab();
37463854
3747
- if (tab.graphs[tab.undoindex + 1] == null)
3855
+ if (copy.versions[copy.versionindex + 1] == null)
37483856 {
37493857 java.awt.Toolkit.getDefaultToolkit().beep();
37503858 return;
37513859 }
37523860
3753
- tab.undoindex += 1;
3861
+ copy.versionindex += 1;
37543862
3755
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3863
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
37563864
3757
- if (!tab.user[tab.undoindex])
3758
- tab.graphs[tab.undoindex] = null;
3865
+ //if (!tab.user[tab.versionindex])
3866
+ // tab.graphs[tab.versionindex] = null;
37593867 }
37603868
37613869 void ImportGFD()
....@@ -4051,9 +4159,25 @@
40514159 //copy.Touch();
40524160 }
40534161
4162
+ cNumberSlider versionSlider;
4163
+
40544164 public void stateChanged(ChangeEvent e)
40554165 {
40564166 // assert(false);
4167
+ if (e.getSource() == versionSlider)
4168
+ {
4169
+ if (muteSlider)
4170
+ return;
4171
+
4172
+ int version = versionSlider.getInteger();
4173
+
4174
+ if (copy.versions[version] != null)
4175
+ {
4176
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4177
+ }
4178
+
4179
+ return;
4180
+ }
40574181
40584182 if (freezematerial)
40594183 {
....@@ -4402,7 +4526,7 @@
44024526
44034527 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
44044528 {
4405
- if (Globals.SAVEONMAKE) // && resetmodel)
4529
+ if (Globals.REPLACEONMAKE) // && resetmodel)
44064530 Save();
44074531 //Tween.set(thing, 0).target(1).start(tweenManager);
44084532 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4718,8 +4842,8 @@
47184842
47194843 if (readobj != null)
47204844 {
4721
- if (Globals.SAVEONMAKE)
4722
- Save();
4845
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4846
+ // Save();
47234847 try
47244848 {
47254849 //readobj.deepCopySelf(copy);
....@@ -4774,6 +4898,17 @@
47744898 c.addChild(csg);
47754899 }
47764900
4901
+ copy.versions = readobj.versions;
4902
+ copy.versionindex = readobj.versionindex;
4903
+
4904
+ if (copy.versions == null)
4905
+ {
4906
+ copy.versions = new byte[100][];
4907
+ copy.versionindex = -1;
4908
+ }
4909
+
4910
+ //? SetUndoStates();
4911
+
47774912 ResetModel();
47784913 copy.HardTouch(); // recompile?
47794914 refreshContents();