Normand Briere
2019-07-18 d7a17c35c443e2cb6c09eaa3cfeaf590a571faa1
ObjEditor.java
....@@ -15,6 +15,9 @@
1515 //import javax.swing.plaf.ColorUIResource;
1616 //import javax.swing.plaf.metal.DefaultMetalTheme;
1717
18
+import javax.swing.plaf.basic.BasicSplitPaneDivider;
19
+import javax.swing.plaf.basic.BasicSplitPaneUI;
20
+
1821 //import javax.media.opengl.GLCanvas;
1922
2023 import //weka.core.
....@@ -207,7 +210,7 @@
207210
208211 objEditor.ctrlPanel.remove(namePanel);
209212
210
- if (!GroupEditor.allparams)
213
+ if (!allparams)
211214 return;
212215
213216 // objEditor.ctrlPanel.remove(liveCB);
....@@ -279,6 +282,12 @@
279282 client = inClient;
280283 copy = client;
281284
285
+ if (copy.versions == null)
286
+ {
287
+ copy.versions = new byte[100][];
288
+ copy.versionindex = -1;
289
+ }
290
+
282291 // "this" is not called: SetupUI2(objEditor);
283292 }
284293
....@@ -292,6 +301,12 @@
292301 client = inClient;
293302 copy = client;
294303
304
+ if (copy.versions == null)
305
+ {
306
+ copy.versions = new byte[100][];
307
+ copy.versionindex = -1;
308
+ }
309
+
295310 SetupUI2(callee.GetEditor());
296311 }
297312
....@@ -306,7 +321,7 @@
306321 //localCopy.parent = null;
307322
308323 frame = new JFrame();
309
- frame.setUndecorated(true);
324
+ frame.setUndecorated(false);
310325 objEditor = this;
311326 this.callee = callee;
312327
....@@ -324,6 +339,12 @@
324339 copy = localCopy;
325340 copy.editWindow = this;
326341
342
+ if (copy.versions == null)
343
+ {
344
+ copy.versions = new byte[100][];
345
+ copy.versionindex = -1;
346
+ }
347
+
327348 SetupMenu();
328349
329350 //SetupName(objEditor); // new
....@@ -337,12 +358,17 @@
337358 return frame.action(event, obj);
338359 }
339360
361
+ // Cannot work without static
362
+ static boolean allparams = true;
363
+
364
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
365
+
340366 void SetupMenu()
341367 {
342368 frame.setMenuBar(menuBar = new MenuBar());
343369 menuBar.add(fileMenu = new Menu("File"));
344370 fileMenu.add(newItem = new MenuItem("New"));
345
- fileMenu.add(loadItem = new MenuItem("Open..."));
371
+ fileMenu.add(openItem = new MenuItem("Open..."));
346372
347373 //oe.menuBar.add(menu = new Menu("Include"));
348374 Menu menu = new Menu("Import");
....@@ -374,7 +400,7 @@
374400 }
375401
376402 newItem.addActionListener(this);
377
- loadItem.addActionListener(this);
403
+ openItem.addActionListener(this);
378404 saveItem.addActionListener(this);
379405 saveAsItem.addActionListener(this);
380406 exportAsItem.addActionListener(this);
....@@ -397,6 +423,11 @@
397423 // }
398424 //
399425 // materialFlushed = true;
426
+// }
427
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit"))
428
+// {
429
+// if (listUI.size() == 0)
430
+// EditSelection(false);
400431 // }
401432
402433 refreshContents(false); // To refresh Info tab
....@@ -436,7 +467,7 @@
436467 // TEXTAREA infoarea.setLineWrap(true);
437468 // TEXTAREA infoarea.setWrapStyleWord(true);
438469 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
439
- infoPanel.setPreferredSize(new Dimension(50, 200));
470
+ infoPanel.setPreferredSize(new Dimension(1, 1));
440471 infoPanel.setName("Info");
441472 //infoPanel.setLayout(new BorderLayout());
442473 //infoPanel.add(createTextPane());
....@@ -448,7 +479,14 @@
448479 mainPanel.setDividerSize(9);
449480 mainPanel.setDividerLocation(0.5); //1.0);
450481 mainPanel.setResizeWeight(0.5);
451
-
482
+
483
+//mainPanel.setDividerSize((int) (mainPanel.getDividerSize() * 1.5));
484
+ BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) mainPanel.getUI()).getDivider();
485
+ divider.setDividerSize(15);
486
+ divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!"));
487
+
488
+ mainPanel.setUI(new BasicSplitPaneUI());
489
+
452490 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
453491 //mainPanel.setLayout(new GridBagLayout());
454492 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -679,8 +717,8 @@
679717 }
680718 }
681719
682
-static GraphicsDevice device = GraphicsEnvironment
683
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
720
+//static GraphicsDevice device = GraphicsEnvironment
721
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
684722
685723 Rectangle keeprect;
686724 cRadio radio;
....@@ -701,10 +739,19 @@
701739 void Minimize()
702740 {
703741 frame.setState(Frame.ICONIFIED);
742
+ frame.validate();
704743 }
705744
745
+// artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={}
746
+// artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={}
747
+// artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={}
706748 void Maximize()
707749 {
750
+ if (CameraPane.FULLSCREEN)
751
+ {
752
+ ToggleFullScreen();
753
+ }
754
+
708755 if (maximized)
709756 {
710757 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -712,20 +759,36 @@
712759 else
713760 {
714761 keeprect = frame.getBounds();
715
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
716
- Dimension rect2 = frame.getToolkit().getScreenSize();
717
- frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
762
+// Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
763
+// Dimension rect2 = frame.getToolkit().getScreenSize();
764
+// frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
718765 // frame.setState(Frame.MAXIMIZED_BOTH);
766
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
719767 }
720768
721769 maximized ^= true;
770
+
771
+ frame.validate();
722772 }
773
+
774
+ cButton minButton;
775
+ cButton maxButton;
776
+ cButton fullButton;
723777
724778 void ToggleFullScreen()
725779 {
726
- if (CameraPane.FULLSCREEN)
780
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
781
+
782
+ cameraView.ToggleFullScreen();
783
+
784
+ if (!CameraPane.FULLSCREEN)
727785 {
728786 device.setFullScreenWindow(null);
787
+ frame.dispose();
788
+ frame.setUndecorated(false);
789
+ frame.validate();
790
+ frame.setVisible(true);
791
+
729792 //frame.setVisible(false);
730793 // frame.removeNotify();
731794 // frame.setUndecorated(false);
....@@ -735,7 +798,7 @@
735798 // X frame.getContentPane().remove(/*"Center",*/bigThree);
736799 // X framePanel.add(bigThree);
737800 // X frame.getContentPane().add(/*"Center",*/framePanel);
738
- framePanel.setDividerLocation(1);
801
+ framePanel.setDividerLocation(46);
739802
740803 //frame.setVisible(true);
741804 radio.layout = keepButton;
....@@ -750,7 +813,12 @@
750813 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
751814 // frame.getToolkit().getScreenSize().height);
752815 //frame.setVisible(false);
816
+
817
+ frame.dispose();
818
+ frame.setUndecorated(true);
753819 device.setFullScreenWindow(frame);
820
+ frame.validate();
821
+ frame.setVisible(true);
754822 // frame.removeNotify();
755823 // frame.setUndecorated(true);
756824 // frame.addNotify();
....@@ -763,9 +831,30 @@
763831 radio.layout.doClick();
764832 //frame.setVisible(true);
765833 }
766
-
767
- cameraView.ToggleFullScreen();
834
+ frame.validate();
768835 }
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
+ }
769858
770859 private JTextPane createTextPane()
771860 {
....@@ -1097,12 +1186,12 @@
10971186 namePanel = new cGridBag();
10981187
10991188 nameField = AddText(namePanel, copy.GetName());
1100
- namePanel.add(nameField);
1189
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
11011190 oe.ctrlPanel.add(namePanel);
11021191
11031192 oe.ctrlPanel.Return();
11041193
1105
- if (!GroupEditor.allparams)
1194
+ if (!allparams)
11061195 return;
11071196
11081197 setupPanel = new cGridBag().setVertical(false);
....@@ -1115,20 +1204,21 @@
11151204 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
11161205 hideCB.setToolTipText("Hide object");
11171206 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1118
- markCB.setToolTipText("Set the animation target transform");
1207
+ markCB.setToolTipText("As animation target transform");
11191208
11201209 setupPanel2 = new cGridBag().setVertical(false);
11211210
11221211 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
11231212 rewindCB.setToolTipText("Rewind animation");
11241213
1125
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1126
- randomCB.setToolTipText("Randomly Rewind or Go back and forth");
1214
+ randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
1215
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11271216
1217
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1218
+ link2masterCB.setToolTipText("Attach to support");
1219
+
11281220 if (Globals.ADVANCED)
11291221 {
1130
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1131
- link2masterCB.setToolTipText("Attach to support");
11321222 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11331223 speedupCB.setToolTipText("Option motion capture");
11341224 }
....@@ -1439,13 +1529,16 @@
14391529 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14401530 //tmp.setName("Edit");
14411531 objectPanel.add(materialPanel);
1442
- objectPanel.add(toolboxPanel);
14431532 // JPanel north = new JPanel(new BorderLayout());
14441533 // north.setName("Edit");
14451534 // north.add(ctrlPanel, BorderLayout.NORTH);
14461535 // objectPanel.add(north);
14471536 objectPanel.add(editPanel);
1448
- objectPanel.add(infoPanel);
1537
+
1538
+ //if (Globals.ADVANCED)
1539
+ objectPanel.add(infoPanel);
1540
+
1541
+ objectPanel.add(toolboxPanel);
14491542
14501543 /*
14511544 aConstraints.gridx = 0;
....@@ -1454,7 +1547,7 @@
14541547 aConstraints.gridy += 1;
14551548 aConstraints.gridwidth = 1;
14561549 mainPanel.add(objectPanel, aConstraints);
1457
- */
1550
+ */
14581551
14591552 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
14601553 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1553,9 +1646,9 @@
15531646 // aConstraints.gridheight = 1;
15541647
15551648 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1556
- framePanel.setContinuousLayout(true);
1557
- framePanel.setOneTouchExpandable(true);
1558
- framePanel.setDividerLocation(0.8);
1649
+ framePanel.setContinuousLayout(false);
1650
+ framePanel.setOneTouchExpandable(false);
1651
+ //.setDividerLocation(0.8);
15591652 //framePanel.setDividerSize(15);
15601653 //framePanel.setResizeWeight(0.15);
15611654 framePanel.setName("Frame");
....@@ -1574,12 +1667,13 @@
15741667
15751668 frame.setSize(1280, 860);
15761669
1577
- frame.validate();
1578
- frame.setVisible(true);
1579
-
15801670 cameraView.requestFocusInWindow();
15811671
15821672 gridPanel.setDividerLocation(1.0);
1673
+
1674
+ frame.validate();
1675
+
1676
+ frame.setVisible(true);
15831677
15841678 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
15851679 frame.addWindowListener(new WindowAdapter()
....@@ -1666,24 +1760,6 @@
16661760 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16671761 colorSection.add(texture);
16681762
1669
- cGridBag anisoU = new cGridBag();
1670
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1671
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1672
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1673
- colorSection.add(anisoU);
1674
-
1675
- cGridBag anisoV = new cGridBag();
1676
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1677
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1678
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1679
- colorSection.add(anisoV);
1680
-
1681
- cGridBag shadowbias = new cGridBag();
1682
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1683
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1684
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1685
- colorSection.add(shadowbias);
1686
-
16871763 panel.add(new JSeparator());
16881764
16891765 panel.add(colorSection);
....@@ -1733,6 +1809,12 @@
17331809 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17341810 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17351811 diffuseSection.add(fakedepth);
1812
+
1813
+ cGridBag shadowbias = new cGridBag();
1814
+ shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1815
+ shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1816
+ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1817
+ diffuseSection.add(shadowbias);
17361818
17371819 panel.add(new JSeparator());
17381820
....@@ -1784,6 +1866,18 @@
17841866 // aConstraints.gridy += 1;
17851867 // aConstraints.gridwidth = 1;
17861868
1869
+ cGridBag anisoU = new cGridBag();
1870
+ anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1871
+ anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1872
+ anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1873
+ specularSection.add(anisoU);
1874
+
1875
+ cGridBag anisoV = new cGridBag();
1876
+ anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1877
+ anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1878
+ anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1879
+ specularSection.add(anisoV);
1880
+
17871881
17881882 panel.add(new JSeparator());
17891883
....@@ -1791,35 +1885,35 @@
17911885
17921886 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17931887
1794
- cGridBag globalSection = new cGridBag().setVertical(true);
1888
+ //cGridBag globalSection = new cGridBag().setVertical(true);
17951889
17961890 cGridBag camera = new cGridBag();
17971891 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
17981892 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17991893 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1800
- globalSection.add(camera);
1894
+ colorSection.add(camera);
18011895
18021896 cGridBag ambient = new cGridBag();
18031897 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
18041898 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18051899 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1806
- globalSection.add(ambient);
1900
+ colorSection.add(ambient);
18071901
18081902 cGridBag backlit = new cGridBag();
18091903 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
18101904 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18111905 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1812
- globalSection.add(backlit);
1906
+ colorSection.add(backlit);
18131907
18141908 cGridBag opacity = new cGridBag();
18151909 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
18161910 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18171911 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1818
- globalSection.add(opacity);
1912
+ colorSection.add(opacity);
18191913
1820
- panel.add(new JSeparator());
1914
+ //panel.add(new JSeparator());
18211915
1822
- panel.add(globalSection);
1916
+ //panel.add(globalSection);
18231917
18241918 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
18251919
....@@ -1926,8 +2020,9 @@
19262020 // 3D models
19272021 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19282022 {
1929
- lastConverter = new com.jmex.model.converters.MaxToJme();
1930
- LoadFile(filename, lastConverter);
2023
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2024
+ //LoadFile(filename, lastConverter);
2025
+ LoadObjFile(filename); // New 3ds loader
19312026 continue;
19322027 }
19332028 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2653,6 +2748,7 @@
26532748 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26542749 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26552750 }
2751
+
26562752 //cJME.count++;
26572753 //cJME.count %= 12;
26582754 if (gc)
....@@ -2836,6 +2932,7 @@
28362932 }
28372933 }
28382934 }
2935
+
28392936 cFileSystemPane FSPane;
28402937
28412938 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2889,6 +2986,7 @@
28892986 }
28902987 }
28912988 }
2989
+
28922990 freezematerial = false;
28932991 }
28942992
....@@ -3007,12 +3105,17 @@
30073105 // }
30083106
30093107 /**/
3010
- if (deselect)
3108
+ if (deselect || child == null)
30113109 {
30123110 //group.deselectAll();
30133111 //freeze = true;
30143112 GetTree().clearSelection();
30153113 //freeze = false;
3114
+
3115
+ if (child == null)
3116
+ {
3117
+ return;
3118
+ }
30163119 }
30173120
30183121 //group.addSelectee(child);
....@@ -3336,9 +3439,9 @@
33363439 {
33373440 Close();
33383441 //return true;
3339
- } else if (source == loadItem)
3442
+ } else if (source == openItem)
33403443 {
3341
- load();
3444
+ Open();
33423445 //return true;
33433446 } else if (source == newItem)
33443447 {
....@@ -3363,6 +3466,10 @@
33633466 {
33643467 generatePOV();
33653468 //return true;
3469
+ } else if (event.getSource() == archiveItem)
3470
+ {
3471
+ cTools.Archive(frame);
3472
+ return;
33663473 } else if (source == zBufferItem)
33673474 {
33683475 try
....@@ -3414,8 +3521,8 @@
34143521 try
34153522 {
34163523 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3417
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3418
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3524
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3525
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34193526
34203527 Object3D parent = o.parent;
34213528 o.parent = null;
....@@ -3426,10 +3533,14 @@
34263533
34273534 out.flush();
34283535
3429
- zstream.close();
3536
+ baos //zstream
3537
+ .close();
34303538 out.close();
34313539
3432
- return baos.toByteArray();
3540
+ byte[] bytes = baos.toByteArray();
3541
+
3542
+ System.out.println("save #bytes = " + bytes.length);
3543
+ return bytes;
34333544 } catch (Exception e)
34343545 {
34353546 System.err.println(e);
....@@ -3439,13 +3550,16 @@
34393550
34403551 static public Object Uncompress(byte[] bytes)
34413552 {
3442
- System.out.println("#bytes = " + bytes.length);
3553
+ System.out.println("restore #bytes = " + bytes.length);
34433554 try
34443555 {
34453556 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3446
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3447
- ObjectInputStream in = new ObjectInputStream(istream);
3557
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3558
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
34483559 Object obj = in.readObject();
3560
+
3561
+ bais //istream
3562
+ .close();
34493563 in.close();
34503564
34513565 return obj;
....@@ -3500,39 +3614,77 @@
35003614 return null;
35013615 }
35023616
3503
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35043617
35053618 public void Save()
3619
+ {
3620
+ //Save(true);
3621
+ Replace();
3622
+ }
3623
+
3624
+ private boolean Equal(byte[] compress, byte[] name)
3625
+ {
3626
+ if (compress.length != name.length)
3627
+ {
3628
+ return false;
3629
+ }
3630
+
3631
+ for (int i=compress.length; --i>=0;)
3632
+ {
3633
+ if (compress[i] != name[i])
3634
+ return false;
3635
+ }
3636
+
3637
+ return true;
3638
+ }
3639
+
3640
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3641
+
3642
+ public boolean Save(boolean user)
35063643 {
35073644 System.err.println("Save");
35083645
35093646 cRadio tab = GetCurrentTab();
35103647
3511
- boolean temp = CameraPane.SWITCH;
3512
- CameraPane.SWITCH = false;
3648
+ byte[] compress = CompressCopy();
35133649
3514
- copy.ExtractBigData(hashtable);
3650
+ boolean thesame = false;
3651
+
3652
+ // Quick heuristic using length. Works only when stream is compressed.
3653
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3654
+ {
3655
+ thesame = true;
3656
+ }
35153657
35163658 //EditorFrame.m_MainFrame.requestFocusInWindow();
3517
- tab.graphs[tab.undoindex++] = Compress(copy);
3518
-
3519
- copy.RestoreBigData(hashtable);
3520
-
3521
- CameraPane.SWITCH = temp;
3522
-
3523
- //assert(hashtable.isEmpty());
3524
-
3525
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3659
+ if (!thesame)
35263660 {
3527
- tab.graphs[i] = null;
3661
+ //tab.user[tab.versionindex] = user;
3662
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3663
+
3664
+ copy.versions[++copy.versionindex] = compress;
3665
+
3666
+ // if (increment)
3667
+ // tab.versionindex++;
35283668 }
35293669
3670
+ //copy.RestoreBigData(versiontable);
3671
+
3672
+ //assert(hashtable.isEmpty());
3673
+
3674
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
3675
+ {
3676
+ //tab.user[i] = false;
3677
+ copy.versions[i] = null;
3678
+ }
3679
+
3680
+ SetUndoStates();
3681
+
35303682 // test save
35313683 if (false)
35323684 {
35333685 try
35343686 {
3535
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3687
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
35363688 ObjectOutputStream p = new ObjectOutputStream(ostream);
35373689
35383690 p.writeObject(copy);
....@@ -3545,14 +3697,18 @@
35453697 e.printStackTrace();
35463698 }
35473699 }
3700
+
3701
+ return !thesame;
35483702 }
35493703
35503704 void CopyChanged(Object3D obj)
35513705 {
3706
+ SetUndoStates();
3707
+
35523708 boolean temp = CameraPane.SWITCH;
35533709 CameraPane.SWITCH = false;
35543710
3555
- copy.ExtractBigData(hashtable);
3711
+ copy.ExtractBigData(versiontable);
35563712
35573713 copy.clear();
35583714
....@@ -3561,7 +3717,7 @@
35613717 copy.add(obj.get(i));
35623718 }
35633719
3564
- copy.RestoreBigData(hashtable);
3720
+ copy.RestoreBigData(versiontable);
35653721
35663722 CameraPane.SWITCH = temp;
35673723
....@@ -3588,42 +3744,130 @@
35883744 refreshContents();
35893745 }
35903746
3591
- public void Undo()
3747
+ cButton undoButton;
3748
+ cButton restoreButton;
3749
+ cButton replaceButton;
3750
+ cButton redoButton;
3751
+
3752
+ boolean muteSlider;
3753
+
3754
+ int VersionCount()
35923755 {
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
+
3767
+ void SetUndoStates()
3768
+ {
3769
+ cRadio tab = GetCurrentTab();
3770
+
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;
3781
+ }
3782
+
3783
+ public boolean Undo()
3784
+ {
3785
+ // Option?
3786
+ Replace();
3787
+
35933788 System.err.println("Undo");
35943789
35953790 cRadio tab = GetCurrentTab();
35963791
3597
- if (tab.undoindex == 0)
3792
+ if (copy.versionindex == 0)
35983793 {
35993794 java.awt.Toolkit.getDefaultToolkit().beep();
3600
- return;
3795
+ return false;
36013796 }
36023797
3603
- if (tab.graphs[tab.undoindex] == null)
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)
36043825 {
3605
- Save();
3606
- tab.undoindex -= 1;
3826
+ java.awt.Toolkit.getDefaultToolkit().beep();
3827
+ return false;
36073828 }
36083829
3609
- tab.undoindex -= 1;
3830
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3831
+
3832
+ return true;
3833
+ }
36103834
3611
- 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();
3848
+
3849
+ return true;
36123850 }
36133851
36143852 public void Redo()
36153853 {
3854
+ // Option?
3855
+ Replace();
3856
+
36163857 cRadio tab = GetCurrentTab();
36173858
3618
- if (tab.graphs[tab.undoindex + 1] == null)
3859
+ if (copy.versions[copy.versionindex + 1] == null)
36193860 {
36203861 java.awt.Toolkit.getDefaultToolkit().beep();
36213862 return;
36223863 }
36233864
3624
- tab.undoindex += 1;
3865
+ copy.versionindex += 1;
36253866
3626
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3867
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3868
+
3869
+ //if (!tab.user[tab.versionindex])
3870
+ // tab.graphs[tab.versionindex] = null;
36273871 }
36283872
36293873 void ImportGFD()
....@@ -3919,9 +4163,25 @@
39194163 //copy.Touch();
39204164 }
39214165
4166
+ cNumberSlider versionSlider;
4167
+
39224168 public void stateChanged(ChangeEvent e)
39234169 {
39244170 // 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
+ }
39254185
39264186 if (freezematerial)
39274187 {
....@@ -4270,7 +4530,7 @@
42704530
42714531 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
42724532 {
4273
- if (Globals.SAVEONMAKE) // && resetmodel)
4533
+ if (Globals.REPLACEONMAKE) // && resetmodel)
42744534 Save();
42754535 //Tween.set(thing, 0).target(1).start(tweenManager);
42764536 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4586,8 +4846,8 @@
45864846
45874847 if (readobj != null)
45884848 {
4589
- if (Globals.SAVEONMAKE)
4590
- Save();
4849
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4850
+ // Save();
45914851 try
45924852 {
45934853 //readobj.deepCopySelf(copy);
....@@ -4642,13 +4902,24 @@
46424902 c.addChild(csg);
46434903 }
46444904
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
+
46454916 ResetModel();
46464917 copy.HardTouch(); // recompile?
46474918 refreshContents();
46484919 }
46494920 }
46504921
4651
- void load() // throws ClassNotFoundException
4922
+ void Open() // throws ClassNotFoundException
46524923 {
46534924 if (Grafreed.standAlone)
46544925 {
....@@ -4765,6 +5036,8 @@
47655036 String filename = browser.getFile();
47665037 if (filename != null && filename.length() > 0)
47675038 {
5039
+ if (!filename.endsWith(".gfd"))
5040
+ filename += ".gfd";
47685041 lastname = browser.getDirectory() + filename;
47695042 save();
47705043 }
....@@ -4931,7 +5204,7 @@
49315204 MenuBar menuBar;
49325205 Menu fileMenu;
49335206 MenuItem newItem;
4934
- MenuItem loadItem;
5207
+ MenuItem openItem;
49355208 MenuItem saveItem;
49365209 MenuItem saveAsItem;
49375210 MenuItem exportAsItem;
....@@ -4954,6 +5227,7 @@
49545227 CheckboxMenuItem toggleSwitchItem;
49555228 CheckboxMenuItem toggleRootItem;
49565229 CheckboxMenuItem animationItem;
5230
+ MenuItem archiveItem;
49575231 CheckboxMenuItem toggleHandleItem;
49585232 CheckboxMenuItem togglePaintItem;
49595233 JSplitPane mainPanel;