Normand Briere
2019-08-01 29d5516687020263d3ae0454ce81879a3a450af0
ObjEditor.java
....@@ -41,64 +41,78 @@
4141 JFrame frame;
4242
4343 static ObjEditor theFrame;
44
+
45
+ public cGridBag GetSeparator()
46
+ {
47
+ cGridBag separator = new cGridBag();
48
+ separator.add(new JSeparator());
49
+ separator.preferredHeight = 5;
50
+ return separator;
51
+ }
4452
4553 cButton GetButton(String name, boolean border)
4654 {
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
- }
55
+ ImageIcon icon = GetIcon(name);
56
+ return new cButton(icon, border);
57
+ }
58
+
59
+ cLabel GetLabel(String name, boolean border)
60
+ {
61
+ //ImageIcon icon = GetIcon(name);
62
+ return new cLabel(GetImage(name), border);
5663 }
5764
5865 cToggleButton GetToggleButton(String name, boolean border)
5966 {
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
- }
67
+ ImageIcon icon = GetIcon(name);
68
+ return new cToggleButton(icon, border);
6969 }
7070
7171 cCheckBox GetCheckBox(String name, boolean border)
7272 {
73
+ ImageIcon icon = GetIcon(name);
74
+ return new cCheckBox(icon, border);
75
+ }
76
+
77
+ ImageIcon GetIcon(String name)
78
+ {
7379 try
7480 {
75
- ImageIcon icon = GetIcon(name);
76
- return new cCheckBox(icon, border);
81
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
82
+
83
+// if (image.getWidth() > 48 && image.getHeight() > 48)
84
+// {
85
+// BufferedImage resized = new BufferedImage(48, 48, image.getType());
86
+// Graphics2D g = resized.createGraphics();
87
+// g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
88
+// //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
89
+// g.drawImage(image, 0, 0, 48, 48, 0, 0, image.getWidth(), image.getHeight(), null);
90
+// g.dispose();
91
+//
92
+// image = resized;
93
+// }
94
+
95
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
96
+ return icon;
7797 }
7898 catch (Exception e)
7999 {
80
- return new cCheckBox(name, border);
100
+ return null;
81101 }
82102 }
83
-
84
- private ImageIcon GetIcon(String name) throws IOException
103
+
104
+ BufferedImage GetImage(String name)
85105 {
86
- BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
87
-
88
- if (image.getWidth() != 24 && image.getHeight() != 24)
106
+ try
89107 {
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;
108
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
109
+
110
+ return image;
98111 }
99
-
100
- javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
101
- return icon;
112
+ catch (Exception e)
113
+ {
114
+ return null;
115
+ }
102116 }
103117
104118 // SCRIPT
....@@ -282,6 +296,12 @@
282296 client = inClient;
283297 copy = client;
284298
299
+ if (copy.versions == null)
300
+ {
301
+ copy.versions = new byte[100][];
302
+ copy.versionindex = -1;
303
+ }
304
+
285305 // "this" is not called: SetupUI2(objEditor);
286306 }
287307
....@@ -295,6 +315,12 @@
295315 client = inClient;
296316 copy = client;
297317
318
+ if (copy.versions == null)
319
+ {
320
+ copy.versions = new byte[100][];
321
+ copy.versionindex = -1;
322
+ }
323
+
298324 SetupUI2(callee.GetEditor());
299325 }
300326
....@@ -327,6 +353,12 @@
327353 copy = localCopy;
328354 copy.editWindow = this;
329355
356
+ if (copy.versions == null)
357
+ {
358
+// copy.versions = new byte[100][];
359
+// copy.versionindex = -1;
360
+ }
361
+
330362 SetupMenu();
331363
332364 //SetupName(objEditor); // new
....@@ -419,11 +451,12 @@
419451
420452 toolbarPanel = new JPanel();
421453 toolbarPanel.setName("Toolbar");
454
+
422455 treePanel = new cGridBag();
423456 treePanel.setName("Tree");
424457
425458 editPanel = new cGridBag().setVertical(true);
426
- editPanel.setName("Edit");
459
+ //editPanel.setName("Edit");
427460
428461 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
429462
....@@ -431,11 +464,11 @@
431464 editPanel.add(editCommandsPanel);
432465 editPanel.add(ctrlPanel);
433466
434
- toolboxPanel = new cGridBag().setVertical(false);
435
- toolboxPanel.setName("Toolbox");
467
+ toolboxPanel = new cGridBag().setVertical(true);
468
+ //toolboxPanel.setName("Toolbox");
436469
437470 materialPanel = new cGridBag().setVertical(true);
438
- materialPanel.setName("Material");
471
+ //materialPanel.setName("Material");
439472
440473 /*JTextPane*/
441474 infoarea = createTextPane();
....@@ -443,6 +476,7 @@
443476
444477 infoarea.setEditable(true);
445478 SetText();
479
+
446480 // infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
447481 // infoarea.setOpaque(false);
448482 // //infoarea.setForeground(textcolor);
....@@ -450,7 +484,7 @@
450484 // TEXTAREA infoarea.setWrapStyleWord(true);
451485 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
452486 infoPanel.setPreferredSize(new Dimension(1, 1));
453
- infoPanel.setName("Info");
487
+ //infoPanel.setName("Info");
454488 //infoPanel.setLayout(new BorderLayout());
455489 //infoPanel.add(createTextPane());
456490
....@@ -816,6 +850,28 @@
816850 frame.validate();
817851 }
818852
853
+ private byte[] CompressCopy()
854
+ {
855
+ boolean temp = CameraPane.SWITCH;
856
+ CameraPane.SWITCH = false;
857
+
858
+ copy.ExtractBigData(versiontable);
859
+ // if (copy == client)
860
+
861
+ byte[] versions[] = copy.versions;
862
+ copy.versions = null;
863
+
864
+ byte[] compress = Compress(copy);
865
+
866
+ copy.versions = versions;
867
+
868
+ copy.RestoreBigData(versiontable);
869
+
870
+ CameraPane.SWITCH = temp;
871
+
872
+ return compress;
873
+ }
874
+
819875 private JTextPane createTextPane()
820876 {
821877 // TEXTAREA String[] initString =
....@@ -946,7 +1002,7 @@
9461002 // NumberSlider vDivsField;
9471003 // JCheckBox endcaps;
9481004 JCheckBox liveCB;
949
- JCheckBox selectCB;
1005
+ JCheckBox selectableCB;
9501006 JCheckBox hideCB;
9511007 JCheckBox link2masterCB;
9521008 JCheckBox markCB;
....@@ -1158,13 +1214,16 @@
11581214
11591215 liveCB = AddCheckBox(setupPanel, "Live", copy.live);
11601216 liveCB.setToolTipText("Animate object");
1161
- selectCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
1162
- selectCB.setToolTipText("Make object selectable");
1217
+ selectableCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
1218
+ selectableCB.setToolTipText("Make object selectable");
11631219 // Return();
1220
+
11641221 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
11651222 hideCB.setToolTipText("Hide object");
11661223 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
11671224 markCB.setToolTipText("As animation target transform");
1225
+
1226
+ ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
11681227
11691228 setupPanel2 = new cGridBag().setVertical(false);
11701229
....@@ -1174,10 +1233,11 @@
11741233 randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
11751234 randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11761235
1236
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1237
+ link2masterCB.setToolTipText("Attach to support");
1238
+
11771239 if (Globals.ADVANCED)
11781240 {
1179
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1180
- link2masterCB.setToolTipText("Attach to support");
11811241 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11821242 speedupCB.setToolTipText("Option motion capture");
11831243 }
....@@ -1451,6 +1511,7 @@
14511511 XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll);
14521512 XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll);
14531513 XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
1514
+ //XYZPanel.setName("XYZ");
14541515
14551516 /*
14561517 gridPanel = new JPanel(); //new BorderLayout());
....@@ -1488,16 +1549,29 @@
14881549 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14891550 //tmp.setName("Edit");
14901551 objectPanel.add(materialPanel);
1552
+ objectPanel.setIconAt(0, GetIcon("icons/material.png"));
1553
+ objectPanel.setToolTipTextAt(0, "Material panel");
1554
+
14911555 // JPanel north = new JPanel(new BorderLayout());
14921556 // north.setName("Edit");
14931557 // north.add(ctrlPanel, BorderLayout.NORTH);
14941558 // objectPanel.add(north);
14951559 objectPanel.add(editPanel);
1560
+ objectPanel.setIconAt(1, GetIcon("icons/write.png"));
1561
+ objectPanel.setToolTipTextAt(1, "Edit panel");
14961562
14971563 //if (Globals.ADVANCED)
14981564 objectPanel.add(infoPanel);
1565
+ objectPanel.setIconAt(2, GetIcon("icons/info.png"));
1566
+ objectPanel.setToolTipTextAt(2, "Info panel");
1567
+
1568
+ objectPanel.add(XYZPanel);
1569
+ objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
1570
+ objectPanel.setToolTipTextAt(3, "XYZ/RGB panel");
14991571
15001572 objectPanel.add(toolboxPanel);
1573
+ objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
1574
+ objectPanel.setToolTipTextAt(4, "Objects/backgrounds panel");
15011575
15021576 /*
15031577 aConstraints.gridx = 0;
....@@ -1518,7 +1592,7 @@
15181592 scrollpane.addMouseWheelListener(this); // Default not fast enough
15191593
15201594 /*JTabbedPane*/ scenePanel = new cGridBag();
1521
- scenePanel.preferredWidth = 6;
1595
+ scenePanel.preferredWidth = 5;
15221596
15231597 JTabbedPane tabbedPane = new JTabbedPane();
15241598 tabbedPane.add(scrollpane);
....@@ -1596,7 +1670,7 @@
15961670 bigThree = new cGridBag();
15971671 bigThree.addComponent(scenePanel);
15981672 bigThree.addComponent(centralPanel);
1599
- bigThree.addComponent(XYZPanel);
1673
+ //bigThree.addComponent(XYZPanel);
16001674
16011675 // // SIDE EFFECT!!!
16021676 // aConstraints.gridx = 0;
....@@ -1637,7 +1711,6 @@
16371711 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
16381712 frame.addWindowListener(new WindowAdapter()
16391713 {
1640
-
16411714 public void windowClosing(WindowEvent e)
16421715 {
16431716 Close();
....@@ -1699,27 +1772,48 @@
16991772 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17001773
17011774 cGridBag colorSection = new cGridBag().setVertical(true);
1775
+
1776
+ cGridBag huepanel = new cGridBag();
1777
+ cGridBag huelabel = new cGridBag();
1778
+ huelabel.add(GetLabel("icons/hue.png", false));
1779
+ huelabel.preferredWidth = 20;
1780
+ huepanel.add(new cGridBag()); // Label
1781
+ huepanel.add(huelabel); // Field/slider
1782
+
1783
+ huepanel.preferredHeight = 7;
1784
+
1785
+ colorSection.add(huepanel);
17021786
17031787 cGridBag color = new cGridBag();
1704
- color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints);
1705
- colorLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1706
- color.add(colorField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1788
+
1789
+ color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints);
1790
+ colorLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1791
+ color.add(colorField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
1792
+
17071793 //colorField.preferredWidth = 200;
17081794 colorSection.add(color);
17091795
17101796 cGridBag modulation = new cGridBag();
17111797 modulation.add(modulationLabel = new JLabel("Saturation")); // , aConstraints);
17121798 modulationLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1713
- modulation.add(modulationField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1799
+ modulation.add(modulationField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
17141800 colorSection.add(modulation);
17151801
1802
+ cGridBag opacity = new cGridBag();
1803
+ opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
1804
+ opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1805
+ opacity.add(opacityField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
1806
+ colorSection.add(opacity);
1807
+
1808
+ colorSection.add(GetSeparator());
1809
+
17161810 cGridBag texture = new cGridBag();
17171811 texture.add(textureLabel = new JLabel("Texture")); // , aConstraints);
17181812 textureLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17191813 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
17201814 colorSection.add(texture);
17211815
1722
- panel.add(new JSeparator());
1816
+ panel.add(GetSeparator());
17231817
17241818 panel.add(colorSection);
17251819
....@@ -1775,7 +1869,7 @@
17751869 shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17761870 diffuseSection.add(shadowbias);
17771871
1778
- panel.add(new JSeparator());
1872
+ panel.add(GetSeparator());
17791873
17801874 panel.add(diffuseSection);
17811875
....@@ -1838,7 +1932,7 @@
18381932 specularSection.add(anisoV);
18391933
18401934
1841
- panel.add(new JSeparator());
1935
+ panel.add(GetSeparator());
18421936
18431937 panel.add(specularSection);
18441938
....@@ -1863,12 +1957,6 @@
18631957 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18641958 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
18651959 colorSection.add(backlit);
1866
-
1867
- cGridBag opacity = new cGridBag();
1868
- opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
1869
- opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1870
- opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1871
- colorSection.add(opacity);
18721960
18731961 //panel.add(new JSeparator());
18741962
....@@ -1914,7 +2002,7 @@
19142002 opacityPower.add(opacityPowerField = new cNumberSlider(this, 0.0, 10 /*10 dec 2013*/)); // , aConstraints);
19152003 textureSection.add(opacityPower);
19162004
1917
- panel.add(new JSeparator());
2005
+ panel.add(GetSeparator());
19182006
19192007 panel.add(textureSection);
19202008
....@@ -3213,7 +3301,7 @@
32133301 {
32143302 copy.live ^= true;
32153303 return;
3216
- } else if (event.getSource() == selectCB)
3304
+ } else if (event.getSource() == selectableCB)
32173305 {
32183306 copy.dontselect ^= true;
32193307 return;
....@@ -3480,8 +3568,8 @@
34803568 try
34813569 {
34823570 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3483
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3484
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3571
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3572
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34853573
34863574 Object3D parent = o.parent;
34873575 o.parent = null;
....@@ -3492,10 +3580,14 @@
34923580
34933581 out.flush();
34943582
3495
- zstream.close();
3583
+ baos //zstream
3584
+ .close();
34963585 out.close();
34973586
3498
- return baos.toByteArray();
3587
+ byte[] bytes = baos.toByteArray();
3588
+
3589
+ System.out.println("save #bytes = " + bytes.length);
3590
+ return bytes;
34993591 } catch (Exception e)
35003592 {
35013593 System.err.println(e);
....@@ -3505,13 +3597,16 @@
35053597
35063598 static public Object Uncompress(byte[] bytes)
35073599 {
3508
- System.out.println("#bytes = " + bytes.length);
3600
+ System.out.println("restore #bytes = " + bytes.length);
35093601 try
35103602 {
35113603 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3512
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3513
- ObjectInputStream in = new ObjectInputStream(istream);
3604
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3605
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
35143606 Object obj = in.readObject();
3607
+
3608
+ bais //istream
3609
+ .close();
35153610 in.close();
35163611
35173612 return obj;
....@@ -3566,12 +3661,11 @@
35663661 return null;
35673662 }
35683663
3569
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35703664
35713665 public void Save()
35723666 {
3573
- // Default reduces the probability of heuristics errors.
3574
- Save(true);
3667
+ //Save(true);
3668
+ Replace();
35753669 }
35763670
35773671 private boolean Equal(byte[] compress, byte[] name)
....@@ -3590,25 +3684,20 @@
35903684 return true;
35913685 }
35923686
3687
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3688
+
35933689 public boolean Save(boolean user)
35943690 {
35953691 System.err.println("Save");
35963692
35973693 cRadio tab = GetCurrentTab();
35983694
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;
3695
+ byte[] compress = CompressCopy(); // Saved version. No need for "Replace".
36073696
36083697 boolean thesame = false;
36093698
36103699 // 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]))
3700
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
36123701 {
36133702 thesame = true;
36143703 }
....@@ -3616,18 +3705,23 @@
36163705 //EditorFrame.m_MainFrame.requestFocusInWindow();
36173706 if (!thesame)
36183707 {
3619
- tab.user[tab.undoindex] = user;
3620
- tab.graphs[tab.undoindex++] = compress;
3708
+ //tab.user[tab.versionindex] = user;
3709
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3710
+
3711
+ copy.versions[++copy.versionindex] = compress;
3712
+
3713
+ // if (increment)
3714
+ // tab.versionindex++;
36213715 }
36223716
3623
- copy.RestoreBigData(hashtable);
3717
+ //copy.RestoreBigData(versiontable);
36243718
36253719 //assert(hashtable.isEmpty());
36263720
3627
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3721
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
36283722 {
3629
- tab.user[i] = false;
3630
- tab.graphs[i] = null;
3723
+ //tab.user[i] = false;
3724
+ copy.versions[i] = null;
36313725 }
36323726
36333727 SetUndoStates();
....@@ -3637,7 +3731,7 @@
36373731 {
36383732 try
36393733 {
3640
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3734
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
36413735 ObjectOutputStream p = new ObjectOutputStream(ostream);
36423736
36433737 p.writeObject(copy);
....@@ -3661,16 +3755,19 @@
36613755 boolean temp = CameraPane.SWITCH;
36623756 CameraPane.SWITCH = false;
36633757
3664
- copy.ExtractBigData(hashtable);
3758
+ copy.ExtractBigData(versiontable);
36653759
36663760 copy.clear();
36673761
3762
+ copy.skyboxname = obj.skyboxname;
3763
+ copy.skyboxext = obj.skyboxext;
3764
+
36683765 for (int i=0; i<obj.Size(); i++)
36693766 {
36703767 copy.add(obj.get(i));
36713768 }
36723769
3673
- copy.RestoreBigData(hashtable);
3770
+ copy.RestoreBigData(versiontable);
36743771
36753772 CameraPane.SWITCH = temp;
36763773
....@@ -3698,64 +3795,129 @@
36983795 }
36993796
37003797 cButton undoButton;
3798
+ cButton restoreButton;
3799
+ cButton replaceButton;
37013800 cButton redoButton;
37023801
3802
+ boolean muteSlider;
3803
+
3804
+ int VersionCount()
3805
+ {
3806
+ int count = 0;
3807
+
3808
+ for (int i = copy.versions.length; --i >= 0;)
3809
+ {
3810
+ if (copy.versions[i] != null)
3811
+ count++;
3812
+ }
3813
+
3814
+ return count;
3815
+ }
3816
+
37033817 void SetUndoStates()
37043818 {
37053819 cRadio tab = GetCurrentTab();
37063820
3707
- undoButton.setEnabled(tab.undoindex > 0);
3708
- redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3821
+ restoreButton.setEnabled(copy.versionindex != -1);
3822
+ replaceButton.setEnabled(copy.versionindex != -1);
3823
+
3824
+ undoButton.setEnabled(copy.versionindex > 0);
3825
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3826
+
3827
+ muteSlider = true;
3828
+ versionSlider.setMaximum(VersionCount() - 1);
3829
+ versionSlider.setInteger(copy.versionindex);
3830
+ muteSlider = false;
37093831 }
37103832
37113833 public boolean Undo()
37123834 {
3835
+ // Option?
3836
+ Replace();
3837
+
37133838 System.err.println("Undo");
37143839
37153840 cRadio tab = GetCurrentTab();
37163841
3717
- if (tab.undoindex == 0)
3842
+ if (copy.versionindex == 0)
37183843 {
37193844 java.awt.Toolkit.getDefaultToolkit().beep();
37203845 return false;
37213846 }
37223847
3723
- if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex])
3848
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3849
+// {
3850
+// if (Save(false))
3851
+// tab.versionindex -= 1;
3852
+// else
3853
+// {
3854
+// if (tab.versionindex <= 0)
3855
+// return false;
3856
+// else
3857
+// tab.versionindex -= 1;
3858
+// }
3859
+// }
3860
+
3861
+ copy.versionindex -= 1;
3862
+
3863
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3864
+
3865
+ return true;
3866
+ }
3867
+
3868
+ public boolean Restore()
3869
+ {
3870
+ System.err.println("Restore");
3871
+
3872
+ cRadio tab = GetCurrentTab();
3873
+
3874
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
37243875 {
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
- }
3876
+ java.awt.Toolkit.getDefaultToolkit().beep();
3877
+ return false;
37343878 }
37353879
3736
- tab.undoindex -= 1;
3880
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3881
+
3882
+ return true;
3883
+ }
37373884
3738
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3885
+ public boolean Replace()
3886
+ {
3887
+ System.err.println("Replace");
3888
+
3889
+ cRadio tab = GetCurrentTab();
3890
+
3891
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3892
+ {
3893
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3894
+ return false;
3895
+ }
3896
+
3897
+ copy.versions[copy.versionindex] = CompressCopy();
37393898
37403899 return true;
37413900 }
37423901
37433902 public void Redo()
37443903 {
3904
+ // Option?
3905
+ Replace();
3906
+
37453907 cRadio tab = GetCurrentTab();
37463908
3747
- if (tab.graphs[tab.undoindex + 1] == null)
3909
+ if (copy.versions[copy.versionindex + 1] == null)
37483910 {
37493911 java.awt.Toolkit.getDefaultToolkit().beep();
37503912 return;
37513913 }
37523914
3753
- tab.undoindex += 1;
3915
+ copy.versionindex += 1;
37543916
3755
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3917
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
37563918
3757
- if (!tab.user[tab.undoindex])
3758
- tab.graphs[tab.undoindex] = null;
3919
+ //if (!tab.user[tab.versionindex])
3920
+ // tab.graphs[tab.versionindex] = null;
37593921 }
37603922
37613923 void ImportGFD()
....@@ -4051,9 +4213,25 @@
40514213 //copy.Touch();
40524214 }
40534215
4216
+ cNumberSlider versionSlider;
4217
+
40544218 public void stateChanged(ChangeEvent e)
40554219 {
40564220 // assert(false);
4221
+ if (e.getSource() == versionSlider)
4222
+ {
4223
+ if (muteSlider)
4224
+ return;
4225
+
4226
+ int version = versionSlider.getInteger();
4227
+
4228
+ if (copy.versions[version] != null)
4229
+ {
4230
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4231
+ }
4232
+
4233
+ return;
4234
+ }
40574235
40584236 if (freezematerial)
40594237 {
....@@ -4402,7 +4580,7 @@
44024580
44034581 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
44044582 {
4405
- if (Globals.SAVEONMAKE) // && resetmodel)
4583
+ if (Globals.REPLACEONMAKE) // && resetmodel)
44064584 Save();
44074585 //Tween.set(thing, 0).target(1).start(tweenManager);
44084586 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4644,7 +4822,9 @@
46444822 readobj.ResetDisplayList();
46454823 } catch (Exception e)
46464824 {
4647
- //e.printStackTrace();
4825
+ if (!e.toString().contains("GZIP"))
4826
+ e.printStackTrace();
4827
+
46484828 try
46494829 {
46504830 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
....@@ -4718,12 +4898,14 @@
47184898
47194899 if (readobj != null)
47204900 {
4721
- if (Globals.SAVEONMAKE)
4722
- Save();
4901
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4902
+ // Save();
47234903 try
47244904 {
47254905 //readobj.deepCopySelf(copy);
47264906 copy.clear(); // june 2014
4907
+ copy.skyboxname = readobj.skyboxname;
4908
+ copy.skyboxext = readobj.skyboxext;
47274909 for (int i = 0; i < readobj.size(); i++)
47284910 {
47294911 Object3D child = readobj.get(i); // reserve(i);
....@@ -4764,6 +4946,7 @@
47644946 }
47654947 } catch (ClassCastException e)
47664948 {
4949
+ e.printStackTrace();
47674950 assert (false);
47684951 Composite c = (Composite) copy;
47694952 c.children.clear();
....@@ -4774,6 +4957,17 @@
47744957 c.addChild(csg);
47754958 }
47764959
4960
+ copy.versions = readobj.versions;
4961
+ copy.versionindex = readobj.versionindex;
4962
+
4963
+ if (copy.versions == null)
4964
+ {
4965
+ copy.versions = new byte[100][];
4966
+ copy.versionindex = -1;
4967
+ }
4968
+
4969
+ //? SetUndoStates();
4970
+
47774971 ResetModel();
47784972 copy.HardTouch(); // recompile?
47794973 refreshContents();
....@@ -4883,6 +5077,7 @@
48835077 //ps.print(buffer.toString());
48845078 } catch (IOException e)
48855079 {
5080
+ e.printStackTrace();
48865081 }
48875082 }
48885083