Normand Briere
2019-07-18 d7a17c35c443e2cb6c09eaa3cfeaf590a571faa1
ObjEditor.java
....@@ -282,6 +282,12 @@
282282 client = inClient;
283283 copy = client;
284284
285
+ if (copy.versions == null)
286
+ {
287
+ copy.versions = new byte[100][];
288
+ copy.versionindex = -1;
289
+ }
290
+
285291 // "this" is not called: SetupUI2(objEditor);
286292 }
287293
....@@ -295,6 +301,12 @@
295301 client = inClient;
296302 copy = client;
297303
304
+ if (copy.versions == null)
305
+ {
306
+ copy.versions = new byte[100][];
307
+ copy.versionindex = -1;
308
+ }
309
+
298310 SetupUI2(callee.GetEditor());
299311 }
300312
....@@ -327,6 +339,12 @@
327339 copy = localCopy;
328340 copy.editWindow = this;
329341
342
+ if (copy.versions == null)
343
+ {
344
+ copy.versions = new byte[100][];
345
+ copy.versionindex = -1;
346
+ }
347
+
330348 SetupMenu();
331349
332350 //SetupName(objEditor); // new
....@@ -815,6 +833,28 @@
815833 }
816834 frame.validate();
817835 }
836
+
837
+ private byte[] CompressCopy()
838
+ {
839
+ boolean temp = CameraPane.SWITCH;
840
+ CameraPane.SWITCH = false;
841
+
842
+ copy.ExtractBigData(versiontable);
843
+ // if (copy == client)
844
+
845
+ byte[] versions[] = copy.versions;
846
+ copy.versions = null;
847
+
848
+ byte[] compress = Compress(copy);
849
+
850
+ copy.versions = versions;
851
+
852
+ copy.RestoreBigData(versiontable);
853
+
854
+ CameraPane.SWITCH = temp;
855
+
856
+ return compress;
857
+ }
818858
819859 private JTextPane createTextPane()
820860 {
....@@ -3574,11 +3614,11 @@
35743614 return null;
35753615 }
35763616
3577
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35783617
35793618 public void Save()
35803619 {
3581
- Save(true);
3620
+ //Save(true);
3621
+ Replace();
35823622 }
35833623
35843624 private boolean Equal(byte[] compress, byte[] name)
....@@ -3597,25 +3637,20 @@
35973637 return true;
35983638 }
35993639
3640
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3641
+
36003642 public boolean Save(boolean user)
36013643 {
36023644 System.err.println("Save");
36033645
36043646 cRadio tab = GetCurrentTab();
36053647
3606
- boolean temp = CameraPane.SWITCH;
3607
- CameraPane.SWITCH = false;
3608
-
3609
- copy.ExtractBigData(hashtable);
3610
-
3611
- byte[] compress = Compress(copy);
3612
-
3613
- CameraPane.SWITCH = temp;
3648
+ byte[] compress = CompressCopy();
36143649
36153650 boolean thesame = false;
36163651
36173652 // Quick heuristic using length. Works only when stream is compressed.
3618
- if (tab.undoindex > 0 && tab.graphs[tab.undoindex-1] != null && Equal(compress, tab.graphs[tab.undoindex-1]))
3653
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
36193654 {
36203655 thesame = true;
36213656 }
....@@ -3623,23 +3658,23 @@
36233658 //EditorFrame.m_MainFrame.requestFocusInWindow();
36243659 if (!thesame)
36253660 {
3626
- //tab.user[tab.undoindex] = user;
3627
- boolean increment = tab.graphs[tab.undoindex] == null;
3661
+ //tab.user[tab.versionindex] = user;
3662
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
36283663
3629
- tab.graphs[tab.undoindex] = compress;
3664
+ copy.versions[++copy.versionindex] = compress;
36303665
3631
- if (increment)
3632
- tab.undoindex++;
3666
+ // if (increment)
3667
+ // tab.versionindex++;
36333668 }
36343669
3635
- copy.RestoreBigData(hashtable);
3670
+ //copy.RestoreBigData(versiontable);
36363671
36373672 //assert(hashtable.isEmpty());
36383673
3639
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3674
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
36403675 {
36413676 //tab.user[i] = false;
3642
- // tab.graphs[i] = null;
3677
+ copy.versions[i] = null;
36433678 }
36443679
36453680 SetUndoStates();
....@@ -3649,7 +3684,7 @@
36493684 {
36503685 try
36513686 {
3652
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3687
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
36533688 ObjectOutputStream p = new ObjectOutputStream(ostream);
36543689
36553690 p.writeObject(copy);
....@@ -3673,7 +3708,7 @@
36733708 boolean temp = CameraPane.SWITCH;
36743709 CameraPane.SWITCH = false;
36753710
3676
- copy.ExtractBigData(hashtable);
3711
+ copy.ExtractBigData(versiontable);
36773712
36783713 copy.clear();
36793714
....@@ -3682,7 +3717,7 @@
36823717 copy.add(obj.get(i));
36833718 }
36843719
3685
- copy.RestoreBigData(hashtable);
3720
+ copy.RestoreBigData(versiontable);
36863721
36873722 CameraPane.SWITCH = temp;
36883723
....@@ -3710,64 +3745,129 @@
37103745 }
37113746
37123747 cButton undoButton;
3748
+ cButton restoreButton;
3749
+ cButton replaceButton;
37133750 cButton redoButton;
37143751
3752
+ boolean muteSlider;
3753
+
3754
+ int VersionCount()
3755
+ {
3756
+ int count = 0;
3757
+
3758
+ for (int i = copy.versions.length; --i >= 0;)
3759
+ {
3760
+ if (copy.versions[i] != null)
3761
+ count++;
3762
+ }
3763
+
3764
+ return count;
3765
+ }
3766
+
37153767 void SetUndoStates()
37163768 {
37173769 cRadio tab = GetCurrentTab();
37183770
3719
- undoButton.setEnabled(tab.undoindex > 0);
3720
- redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3771
+ restoreButton.setEnabled(copy.versionindex != -1);
3772
+ replaceButton.setEnabled(copy.versionindex != -1);
3773
+
3774
+ undoButton.setEnabled(copy.versionindex > 0);
3775
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3776
+
3777
+ muteSlider = true;
3778
+ versionSlider.setMaximum(VersionCount() - 1);
3779
+ versionSlider.setInteger(copy.versionindex);
3780
+ muteSlider = false;
37213781 }
37223782
37233783 public boolean Undo()
37243784 {
3785
+ // Option?
3786
+ Replace();
3787
+
37253788 System.err.println("Undo");
37263789
37273790 cRadio tab = GetCurrentTab();
37283791
3729
- if (tab.undoindex == 0)
3792
+ if (copy.versionindex == 0)
37303793 {
37313794 java.awt.Toolkit.getDefaultToolkit().beep();
37323795 return false;
37333796 }
37343797
3735
- if (tab.graphs[tab.undoindex] == null) // || !tab.user[tab.undoindex])
3798
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3799
+// {
3800
+// if (Save(false))
3801
+// tab.versionindex -= 1;
3802
+// else
3803
+// {
3804
+// if (tab.versionindex <= 0)
3805
+// return false;
3806
+// else
3807
+// tab.versionindex -= 1;
3808
+// }
3809
+// }
3810
+
3811
+ copy.versionindex -= 1;
3812
+
3813
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3814
+
3815
+ return true;
3816
+ }
3817
+
3818
+ public boolean Restore()
3819
+ {
3820
+ System.err.println("Restore");
3821
+
3822
+ cRadio tab = GetCurrentTab();
3823
+
3824
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
37363825 {
3737
- if (Save(false))
3738
- tab.undoindex -= 1;
3739
- else
3740
- {
3741
- if (tab.undoindex <= 0)
3742
- return false;
3743
- else
3744
- tab.undoindex -= 1;
3745
- }
3826
+ java.awt.Toolkit.getDefaultToolkit().beep();
3827
+ return false;
37463828 }
37473829
3748
- tab.undoindex -= 1;
3830
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3831
+
3832
+ return true;
3833
+ }
37493834
3750
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3835
+ public boolean Replace()
3836
+ {
3837
+ System.err.println("Replace");
3838
+
3839
+ cRadio tab = GetCurrentTab();
3840
+
3841
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3842
+ {
3843
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3844
+ return false;
3845
+ }
3846
+
3847
+ copy.versions[copy.versionindex] = CompressCopy();
37513848
37523849 return true;
37533850 }
37543851
37553852 public void Redo()
37563853 {
3854
+ // Option?
3855
+ Replace();
3856
+
37573857 cRadio tab = GetCurrentTab();
37583858
3759
- if (tab.graphs[tab.undoindex + 1] == null)
3859
+ if (copy.versions[copy.versionindex + 1] == null)
37603860 {
37613861 java.awt.Toolkit.getDefaultToolkit().beep();
37623862 return;
37633863 }
37643864
3765
- tab.undoindex += 1;
3865
+ copy.versionindex += 1;
37663866
3767
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3867
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
37683868
3769
- //if (!tab.user[tab.undoindex])
3770
- // tab.graphs[tab.undoindex] = null;
3869
+ //if (!tab.user[tab.versionindex])
3870
+ // tab.graphs[tab.versionindex] = null;
37713871 }
37723872
37733873 void ImportGFD()
....@@ -4063,9 +4163,25 @@
40634163 //copy.Touch();
40644164 }
40654165
4166
+ cNumberSlider versionSlider;
4167
+
40664168 public void stateChanged(ChangeEvent e)
40674169 {
40684170 // assert(false);
4171
+ if (e.getSource() == versionSlider)
4172
+ {
4173
+ if (muteSlider)
4174
+ return;
4175
+
4176
+ int version = versionSlider.getInteger();
4177
+
4178
+ if (copy.versions[version] != null)
4179
+ {
4180
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4181
+ }
4182
+
4183
+ return;
4184
+ }
40694185
40704186 if (freezematerial)
40714187 {
....@@ -4414,7 +4530,7 @@
44144530
44154531 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
44164532 {
4417
- if (Globals.SAVEONMAKE) // && resetmodel)
4533
+ if (Globals.REPLACEONMAKE) // && resetmodel)
44184534 Save();
44194535 //Tween.set(thing, 0).target(1).start(tweenManager);
44204536 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4786,6 +4902,17 @@
47864902 c.addChild(csg);
47874903 }
47884904
4905
+ copy.versions = readobj.versions;
4906
+ copy.versionindex = readobj.versionindex;
4907
+
4908
+ if (copy.versions == null)
4909
+ {
4910
+ copy.versions = new byte[100][];
4911
+ copy.versionindex = -1;
4912
+ }
4913
+
4914
+ //? SetUndoStates();
4915
+
47894916 ResetModel();
47904917 copy.HardTouch(); // recompile?
47914918 refreshContents();