Normand Briere
2019-07-17 a5580a47d246c1272b10adba68070f6e13da5e41
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);
....@@ -306,7 +309,7 @@
306309 //localCopy.parent = null;
307310
308311 frame = new JFrame();
309
- frame.setUndecorated(true);
312
+ frame.setUndecorated(false);
310313 objEditor = this;
311314 this.callee = callee;
312315
....@@ -337,12 +340,17 @@
337340 return frame.action(event, obj);
338341 }
339342
343
+ // Cannot work without static
344
+ static boolean allparams = true;
345
+
346
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
347
+
340348 void SetupMenu()
341349 {
342350 frame.setMenuBar(menuBar = new MenuBar());
343351 menuBar.add(fileMenu = new Menu("File"));
344352 fileMenu.add(newItem = new MenuItem("New"));
345
- fileMenu.add(loadItem = new MenuItem("Open..."));
353
+ fileMenu.add(openItem = new MenuItem("Open..."));
346354
347355 //oe.menuBar.add(menu = new Menu("Include"));
348356 Menu menu = new Menu("Import");
....@@ -374,7 +382,7 @@
374382 }
375383
376384 newItem.addActionListener(this);
377
- loadItem.addActionListener(this);
385
+ openItem.addActionListener(this);
378386 saveItem.addActionListener(this);
379387 saveAsItem.addActionListener(this);
380388 exportAsItem.addActionListener(this);
....@@ -383,6 +391,32 @@
383391 closeItem.addActionListener(this);
384392
385393 objectPanel = new JTabbedPane();
394
+
395
+ ChangeListener changeListener = new ChangeListener()
396
+ {
397
+ public void stateChanged(ChangeEvent changeEvent)
398
+ {
399
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed)
400
+// {
401
+// if (latestObject != null)
402
+// {
403
+// refreshContents(true);
404
+// SetMaterial(latestObject);
405
+// }
406
+//
407
+// materialFlushed = true;
408
+// }
409
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit"))
410
+// {
411
+// if (listUI.size() == 0)
412
+// EditSelection(false);
413
+// }
414
+
415
+ refreshContents(false); // To refresh Info tab
416
+ }
417
+ };
418
+ objectPanel.addChangeListener(changeListener);
419
+
386420 toolbarPanel = new JPanel();
387421 toolbarPanel.setName("Toolbar");
388422 treePanel = new cGridBag();
....@@ -415,7 +449,7 @@
415449 // TEXTAREA infoarea.setLineWrap(true);
416450 // TEXTAREA infoarea.setWrapStyleWord(true);
417451 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
418
- infoPanel.setPreferredSize(new Dimension(50, 200));
452
+ infoPanel.setPreferredSize(new Dimension(1, 1));
419453 infoPanel.setName("Info");
420454 //infoPanel.setLayout(new BorderLayout());
421455 //infoPanel.add(createTextPane());
....@@ -427,7 +461,14 @@
427461 mainPanel.setDividerSize(9);
428462 mainPanel.setDividerLocation(0.5); //1.0);
429463 mainPanel.setResizeWeight(0.5);
430
-
464
+
465
+//mainPanel.setDividerSize((int) (mainPanel.getDividerSize() * 1.5));
466
+ BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) mainPanel.getUI()).getDivider();
467
+ divider.setDividerSize(15);
468
+ divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!"));
469
+
470
+ mainPanel.setUI(new BasicSplitPaneUI());
471
+
431472 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
432473 //mainPanel.setLayout(new GridBagLayout());
433474 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -658,8 +699,8 @@
658699 }
659700 }
660701
661
-static GraphicsDevice device = GraphicsEnvironment
662
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
702
+//static GraphicsDevice device = GraphicsEnvironment
703
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
663704
664705 Rectangle keeprect;
665706 cRadio radio;
....@@ -680,10 +721,19 @@
680721 void Minimize()
681722 {
682723 frame.setState(Frame.ICONIFIED);
724
+ frame.validate();
683725 }
684726
727
+// artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={}
728
+// artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={}
729
+// artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={}
685730 void Maximize()
686731 {
732
+ if (CameraPane.FULLSCREEN)
733
+ {
734
+ ToggleFullScreen();
735
+ }
736
+
687737 if (maximized)
688738 {
689739 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -691,20 +741,36 @@
691741 else
692742 {
693743 keeprect = frame.getBounds();
694
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
695
- Dimension rect2 = frame.getToolkit().getScreenSize();
696
- frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
744
+// Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
745
+// Dimension rect2 = frame.getToolkit().getScreenSize();
746
+// frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
697747 // frame.setState(Frame.MAXIMIZED_BOTH);
748
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
698749 }
699750
700751 maximized ^= true;
752
+
753
+ frame.validate();
701754 }
755
+
756
+ cButton minButton;
757
+ cButton maxButton;
758
+ cButton fullButton;
702759
703760 void ToggleFullScreen()
704761 {
705
- if (CameraPane.FULLSCREEN)
762
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
763
+
764
+ cameraView.ToggleFullScreen();
765
+
766
+ if (!CameraPane.FULLSCREEN)
706767 {
707768 device.setFullScreenWindow(null);
769
+ frame.dispose();
770
+ frame.setUndecorated(false);
771
+ frame.validate();
772
+ frame.setVisible(true);
773
+
708774 //frame.setVisible(false);
709775 // frame.removeNotify();
710776 // frame.setUndecorated(false);
....@@ -714,7 +780,7 @@
714780 // X frame.getContentPane().remove(/*"Center",*/bigThree);
715781 // X framePanel.add(bigThree);
716782 // X frame.getContentPane().add(/*"Center",*/framePanel);
717
- framePanel.setDividerLocation(1);
783
+ framePanel.setDividerLocation(46);
718784
719785 //frame.setVisible(true);
720786 radio.layout = keepButton;
....@@ -729,7 +795,12 @@
729795 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
730796 // frame.getToolkit().getScreenSize().height);
731797 //frame.setVisible(false);
798
+
799
+ frame.dispose();
800
+ frame.setUndecorated(true);
732801 device.setFullScreenWindow(frame);
802
+ frame.validate();
803
+ frame.setVisible(true);
733804 // frame.removeNotify();
734805 // frame.setUndecorated(true);
735806 // frame.addNotify();
....@@ -742,9 +813,30 @@
742813 radio.layout.doClick();
743814 //frame.setVisible(true);
744815 }
745
-
746
- cameraView.ToggleFullScreen();
816
+ frame.validate();
747817 }
818
+
819
+ private byte[] CompressCopy()
820
+ {
821
+ boolean temp = CameraPane.SWITCH;
822
+ CameraPane.SWITCH = false;
823
+
824
+ copy.ExtractBigData(versiontable);
825
+ // if (copy == client)
826
+
827
+ byte[] versions[] = copy.versions;
828
+ copy.versions = null;
829
+
830
+ byte[] compress = Compress(copy);
831
+
832
+ copy.versions = versions;
833
+
834
+ copy.RestoreBigData(versiontable);
835
+
836
+ CameraPane.SWITCH = temp;
837
+
838
+ return compress;
839
+ }
748840
749841 private JTextPane createTextPane()
750842 {
....@@ -884,7 +976,12 @@
884976 JCheckBox speedupCB;
885977 JCheckBox rewindCB;
886978 JCheckBox flipVCB;
979
+
980
+ cCheckBox toggleTextureCB;
981
+ cCheckBox toggleSwitchCB;
982
+
887983 JComboBox texresMenu;
984
+
888985 JButton resetButton;
889986 JButton stepButton;
890987 JButton stepAllButton;
....@@ -1071,12 +1168,12 @@
10711168 namePanel = new cGridBag();
10721169
10731170 nameField = AddText(namePanel, copy.GetName());
1074
- namePanel.add(nameField);
1171
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
10751172 oe.ctrlPanel.add(namePanel);
10761173
10771174 oe.ctrlPanel.Return();
10781175
1079
- if (!GroupEditor.allparams)
1176
+ if (!allparams)
10801177 return;
10811178
10821179 setupPanel = new cGridBag().setVertical(false);
....@@ -1089,20 +1186,21 @@
10891186 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
10901187 hideCB.setToolTipText("Hide object");
10911188 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1092
- markCB.setToolTipText("Set the animation target transform");
1189
+ markCB.setToolTipText("As animation target transform");
10931190
10941191 setupPanel2 = new cGridBag().setVertical(false);
10951192
10961193 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
10971194 rewindCB.setToolTipText("Rewind animation");
10981195
1099
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1100
- randomCB.setToolTipText("Randomly Rewind or Go back and forth");
1196
+ randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
1197
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11011198
1199
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1200
+ link2masterCB.setToolTipText("Attach to support");
1201
+
11021202 if (Globals.ADVANCED)
11031203 {
1104
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1105
- link2masterCB.setToolTipText("Attach to support");
11061204 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11071205 speedupCB.setToolTipText("Option motion capture");
11081206 }
....@@ -1412,14 +1510,17 @@
14121510
14131511 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14141512 //tmp.setName("Edit");
1415
- objectPanel.add(toolboxPanel);
14161513 objectPanel.add(materialPanel);
14171514 // JPanel north = new JPanel(new BorderLayout());
14181515 // north.setName("Edit");
14191516 // north.add(ctrlPanel, BorderLayout.NORTH);
14201517 // objectPanel.add(north);
14211518 objectPanel.add(editPanel);
1422
- objectPanel.add(infoPanel);
1519
+
1520
+ //if (Globals.ADVANCED)
1521
+ objectPanel.add(infoPanel);
1522
+
1523
+ objectPanel.add(toolboxPanel);
14231524
14241525 /*
14251526 aConstraints.gridx = 0;
....@@ -1428,7 +1529,7 @@
14281529 aConstraints.gridy += 1;
14291530 aConstraints.gridwidth = 1;
14301531 mainPanel.add(objectPanel, aConstraints);
1431
- */
1532
+ */
14321533
14331534 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
14341535 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1445,9 +1546,7 @@
14451546 JTabbedPane tabbedPane = new JTabbedPane();
14461547 tabbedPane.add(scrollpane);
14471548
1448
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1449
-
1450
- optionsPanel = new cGridBag().setVertical(true);
1549
+ optionsPanel = new cGridBag().setVertical(false);
14511550
14521551 optionsPanel.setName("Options");
14531552
....@@ -1455,6 +1554,8 @@
14551554
14561555 tabbedPane.add(optionsPanel);
14571556
1557
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1558
+
14581559 scenePanel.add(tabbedPane);
14591560
14601561 /*
....@@ -1527,9 +1628,9 @@
15271628 // aConstraints.gridheight = 1;
15281629
15291630 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1530
- framePanel.setContinuousLayout(true);
1531
- framePanel.setOneTouchExpandable(true);
1532
- framePanel.setDividerLocation(0.8);
1631
+ framePanel.setContinuousLayout(false);
1632
+ framePanel.setOneTouchExpandable(false);
1633
+ //.setDividerLocation(0.8);
15331634 //framePanel.setDividerSize(15);
15341635 //framePanel.setResizeWeight(0.15);
15351636 framePanel.setName("Frame");
....@@ -1547,11 +1648,14 @@
15471648 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
15481649
15491650 frame.setSize(1280, 860);
1550
- frame.setVisible(true);
1551
-
1651
+
15521652 cameraView.requestFocusInWindow();
15531653
15541654 gridPanel.setDividerLocation(1.0);
1655
+
1656
+ frame.validate();
1657
+
1658
+ frame.setVisible(true);
15551659
15561660 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
15571661 frame.addWindowListener(new WindowAdapter()
....@@ -1638,24 +1742,6 @@
16381742 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16391743 colorSection.add(texture);
16401744
1641
- cGridBag anisoU = new cGridBag();
1642
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1643
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1644
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1645
- colorSection.add(anisoU);
1646
-
1647
- cGridBag anisoV = new cGridBag();
1648
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1649
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1650
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1651
- colorSection.add(anisoV);
1652
-
1653
- cGridBag shadowbias = new cGridBag();
1654
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1655
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1656
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1657
- colorSection.add(shadowbias);
1658
-
16591745 panel.add(new JSeparator());
16601746
16611747 panel.add(colorSection);
....@@ -1705,6 +1791,12 @@
17051791 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17061792 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17071793 diffuseSection.add(fakedepth);
1794
+
1795
+ cGridBag shadowbias = new cGridBag();
1796
+ shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1797
+ shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1798
+ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1799
+ diffuseSection.add(shadowbias);
17081800
17091801 panel.add(new JSeparator());
17101802
....@@ -1756,6 +1848,18 @@
17561848 // aConstraints.gridy += 1;
17571849 // aConstraints.gridwidth = 1;
17581850
1851
+ cGridBag anisoU = new cGridBag();
1852
+ anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1853
+ anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1854
+ anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1855
+ specularSection.add(anisoU);
1856
+
1857
+ cGridBag anisoV = new cGridBag();
1858
+ anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1859
+ anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1860
+ anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1861
+ specularSection.add(anisoV);
1862
+
17591863
17601864 panel.add(new JSeparator());
17611865
....@@ -1763,35 +1867,35 @@
17631867
17641868 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17651869
1766
- cGridBag globalSection = new cGridBag().setVertical(true);
1870
+ //cGridBag globalSection = new cGridBag().setVertical(true);
17671871
17681872 cGridBag camera = new cGridBag();
17691873 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
17701874 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17711875 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1772
- globalSection.add(camera);
1876
+ colorSection.add(camera);
17731877
17741878 cGridBag ambient = new cGridBag();
17751879 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
17761880 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17771881 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1778
- globalSection.add(ambient);
1882
+ colorSection.add(ambient);
17791883
17801884 cGridBag backlit = new cGridBag();
17811885 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
17821886 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17831887 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1784
- globalSection.add(backlit);
1888
+ colorSection.add(backlit);
17851889
17861890 cGridBag opacity = new cGridBag();
17871891 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
17881892 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17891893 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1790
- globalSection.add(opacity);
1894
+ colorSection.add(opacity);
17911895
1792
- panel.add(new JSeparator());
1896
+ //panel.add(new JSeparator());
17931897
1794
- panel.add(globalSection);
1898
+ //panel.add(globalSection);
17951899
17961900 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17971901
....@@ -1898,8 +2002,9 @@
18982002 // 3D models
18992003 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19002004 {
1901
- lastConverter = new com.jmex.model.converters.MaxToJme();
1902
- LoadFile(filename, lastConverter);
2005
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2006
+ //LoadFile(filename, lastConverter);
2007
+ LoadObjFile(filename); // New 3ds loader
19032008 continue;
19042009 }
19052010 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2625,6 +2730,7 @@
26252730 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26262731 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26272732 }
2733
+
26282734 //cJME.count++;
26292735 //cJME.count %= 12;
26302736 if (gc)
....@@ -2808,6 +2914,7 @@
28082914 }
28092915 }
28102916 }
2917
+
28112918 cFileSystemPane FSPane;
28122919
28132920 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2861,11 +2968,14 @@
28612968 }
28622969 }
28632970 }
2971
+
28642972 freezematerial = false;
28652973 }
28662974
28672975 void SetMaterial(Object3D object)
28682976 {
2977
+ latestObject = object;
2978
+
28692979 cMaterial mat = object.material;
28702980
28712981 if (mat == null)
....@@ -2977,12 +3087,17 @@
29773087 // }
29783088
29793089 /**/
2980
- if (deselect)
3090
+ if (deselect || child == null)
29813091 {
29823092 //group.deselectAll();
29833093 //freeze = true;
29843094 GetTree().clearSelection();
29853095 //freeze = false;
3096
+
3097
+ if (child == null)
3098
+ {
3099
+ return;
3100
+ }
29863101 }
29873102
29883103 //group.addSelectee(child);
....@@ -3051,7 +3166,7 @@
30513166 cameraView.ToggleDL();
30523167 cameraView.repaint();
30533168 return;
3054
- } else if (event.getSource() == toggleTextureItem)
3169
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
30553170 {
30563171 cameraView.ToggleTexture();
30573172 // june 2013 copy.HardTouch();
....@@ -3090,7 +3205,7 @@
30903205 frame.validate();
30913206
30923207 return;
3093
- } else if (event.getSource() == toggleSwitchItem)
3208
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30943209 {
30953210 cameraView.ToggleSwitch();
30963211 cameraView.repaint();
....@@ -3306,9 +3421,9 @@
33063421 {
33073422 Close();
33083423 //return true;
3309
- } else if (source == loadItem)
3424
+ } else if (source == openItem)
33103425 {
3311
- load();
3426
+ Open();
33123427 //return true;
33133428 } else if (source == newItem)
33143429 {
....@@ -3333,6 +3448,10 @@
33333448 {
33343449 generatePOV();
33353450 //return true;
3451
+ } else if (event.getSource() == archiveItem)
3452
+ {
3453
+ cTools.Archive(frame);
3454
+ return;
33363455 } else if (source == zBufferItem)
33373456 {
33383457 try
....@@ -3384,8 +3503,8 @@
33843503 try
33853504 {
33863505 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3387
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3388
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3506
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3507
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
33893508
33903509 Object3D parent = o.parent;
33913510 o.parent = null;
....@@ -3396,10 +3515,14 @@
33963515
33973516 out.flush();
33983517
3399
- zstream.close();
3518
+ baos //zstream
3519
+ .close();
34003520 out.close();
34013521
3402
- return baos.toByteArray();
3522
+ byte[] bytes = baos.toByteArray();
3523
+
3524
+ System.out.println("save #bytes = " + bytes.length);
3525
+ return bytes;
34033526 } catch (Exception e)
34043527 {
34053528 System.err.println(e);
....@@ -3409,13 +3532,16 @@
34093532
34103533 static public Object Uncompress(byte[] bytes)
34113534 {
3412
- System.out.println("#bytes = " + bytes.length);
3535
+ System.out.println("restore #bytes = " + bytes.length);
34133536 try
34143537 {
34153538 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3416
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3417
- ObjectInputStream in = new ObjectInputStream(istream);
3539
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3540
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
34183541 Object obj = in.readObject();
3542
+
3543
+ bais //istream
3544
+ .close();
34193545 in.close();
34203546
34213547 return obj;
....@@ -3470,39 +3596,77 @@
34703596 return null;
34713597 }
34723598
3473
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
34743599
34753600 public void Save()
3601
+ {
3602
+ //Save(true);
3603
+ Replace();
3604
+ }
3605
+
3606
+ private boolean Equal(byte[] compress, byte[] name)
3607
+ {
3608
+ if (compress.length != name.length)
3609
+ {
3610
+ return false;
3611
+ }
3612
+
3613
+ for (int i=compress.length; --i>=0;)
3614
+ {
3615
+ if (compress[i] != name[i])
3616
+ return false;
3617
+ }
3618
+
3619
+ return true;
3620
+ }
3621
+
3622
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3623
+
3624
+ public boolean Save(boolean user)
34763625 {
34773626 System.err.println("Save");
34783627
34793628 cRadio tab = GetCurrentTab();
34803629
3481
- boolean temp = CameraPane.SWITCH;
3482
- CameraPane.SWITCH = false;
3630
+ byte[] compress = CompressCopy();
34833631
3484
- copy.ExtractBigData(hashtable);
3632
+ boolean thesame = false;
3633
+
3634
+ // Quick heuristic using length. Works only when stream is compressed.
3635
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3636
+ {
3637
+ thesame = true;
3638
+ }
34853639
34863640 //EditorFrame.m_MainFrame.requestFocusInWindow();
3487
- tab.graphs[tab.undoindex++] = Compress(copy);
3488
-
3489
- copy.RestoreBigData(hashtable);
3490
-
3491
- CameraPane.SWITCH = temp;
3492
-
3493
- //assert(hashtable.isEmpty());
3494
-
3495
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3641
+ if (!thesame)
34963642 {
3497
- tab.graphs[i] = null;
3643
+ //tab.user[tab.versionindex] = user;
3644
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3645
+
3646
+ copy.versions[++copy.versionindex] = compress;
3647
+
3648
+ // if (increment)
3649
+ // tab.versionindex++;
34983650 }
34993651
3652
+ //copy.RestoreBigData(versiontable);
3653
+
3654
+ //assert(hashtable.isEmpty());
3655
+
3656
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
3657
+ {
3658
+ //tab.user[i] = false;
3659
+ copy.versions[i] = null;
3660
+ }
3661
+
3662
+ SetUndoStates();
3663
+
35003664 // test save
35013665 if (false)
35023666 {
35033667 try
35043668 {
3505
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3669
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
35063670 ObjectOutputStream p = new ObjectOutputStream(ostream);
35073671
35083672 p.writeObject(copy);
....@@ -3515,14 +3679,18 @@
35153679 e.printStackTrace();
35163680 }
35173681 }
3682
+
3683
+ return !thesame;
35183684 }
35193685
35203686 void CopyChanged(Object3D obj)
35213687 {
3688
+ SetUndoStates();
3689
+
35223690 boolean temp = CameraPane.SWITCH;
35233691 CameraPane.SWITCH = false;
35243692
3525
- copy.ExtractBigData(hashtable);
3693
+ copy.ExtractBigData(versiontable);
35263694
35273695 copy.clear();
35283696
....@@ -3531,7 +3699,7 @@
35313699 copy.add(obj.get(i));
35323700 }
35333701
3534
- copy.RestoreBigData(hashtable);
3702
+ copy.RestoreBigData(versiontable);
35353703
35363704 CameraPane.SWITCH = temp;
35373705
....@@ -3558,42 +3726,103 @@
35583726 refreshContents();
35593727 }
35603728
3561
- public void Undo()
3729
+ cButton undoButton;
3730
+ cButton restoreButton;
3731
+ cButton replaceButton;
3732
+ cButton redoButton;
3733
+
3734
+ void SetUndoStates()
3735
+ {
3736
+ cRadio tab = GetCurrentTab();
3737
+
3738
+ restoreButton.setEnabled(copy.versionindex != -1);
3739
+ replaceButton.setEnabled(copy.versionindex != -1);
3740
+ undoButton.setEnabled(copy.versionindex > 0);
3741
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3742
+ }
3743
+
3744
+ public boolean Undo()
35623745 {
35633746 System.err.println("Undo");
35643747
35653748 cRadio tab = GetCurrentTab();
35663749
3567
- if (tab.undoindex == 0)
3750
+ if (copy.versionindex == 0)
35683751 {
35693752 java.awt.Toolkit.getDefaultToolkit().beep();
3570
- return;
3753
+ return false;
35713754 }
35723755
3573
- if (tab.graphs[tab.undoindex] == null)
3756
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3757
+// {
3758
+// if (Save(false))
3759
+// tab.versionindex -= 1;
3760
+// else
3761
+// {
3762
+// if (tab.versionindex <= 0)
3763
+// return false;
3764
+// else
3765
+// tab.versionindex -= 1;
3766
+// }
3767
+// }
3768
+
3769
+ copy.versionindex -= 1;
3770
+
3771
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3772
+
3773
+ return true;
3774
+ }
3775
+
3776
+ public boolean Restore()
3777
+ {
3778
+ System.err.println("Restore");
3779
+
3780
+ cRadio tab = GetCurrentTab();
3781
+
3782
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
35743783 {
3575
- Save();
3576
- tab.undoindex -= 1;
3784
+ java.awt.Toolkit.getDefaultToolkit().beep();
3785
+ return false;
35773786 }
35783787
3579
- tab.undoindex -= 1;
3788
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3789
+
3790
+ return true;
3791
+ }
35803792
3581
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3793
+ public boolean Replace()
3794
+ {
3795
+ System.err.println("Replace");
3796
+
3797
+ cRadio tab = GetCurrentTab();
3798
+
3799
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3800
+ {
3801
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3802
+ return false;
3803
+ }
3804
+
3805
+ copy.versions[copy.versionindex] = CompressCopy();
3806
+
3807
+ return true;
35823808 }
35833809
35843810 public void Redo()
35853811 {
35863812 cRadio tab = GetCurrentTab();
35873813
3588
- if (tab.graphs[tab.undoindex + 1] == null)
3814
+ if (copy.versions[copy.versionindex + 1] == null)
35893815 {
35903816 java.awt.Toolkit.getDefaultToolkit().beep();
35913817 return;
35923818 }
35933819
3594
- tab.undoindex += 1;
3820
+ copy.versionindex += 1;
35953821
3596
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3822
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3823
+
3824
+ //if (!tab.user[tab.versionindex])
3825
+ // tab.graphs[tab.versionindex] = null;
35973826 }
35983827
35993828 void ImportGFD()
....@@ -3889,9 +4118,22 @@
38894118 //copy.Touch();
38904119 }
38914120
4121
+ cNumberSlider versionField;
4122
+
38924123 public void stateChanged(ChangeEvent e)
38934124 {
38944125 // assert(false);
4126
+ if (e.getSource() == versionField)
4127
+ {
4128
+ int version = versionField.getInteger();
4129
+
4130
+ if (copy.versions[version] != null)
4131
+ {
4132
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4133
+ }
4134
+
4135
+ return;
4136
+ }
38954137
38964138 if (freezematerial)
38974139 {
....@@ -4240,7 +4482,7 @@
42404482
42414483 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
42424484 {
4243
- if (Globals.SAVEONMAKE) // && resetmodel)
4485
+ if (Globals.REPLACEONMAKE) // && resetmodel)
42444486 Save();
42454487 //Tween.set(thing, 0).target(1).start(tweenManager);
42464488 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4556,8 +4798,8 @@
45564798
45574799 if (readobj != null)
45584800 {
4559
- if (Globals.SAVEONMAKE)
4560
- Save();
4801
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4802
+ // Save();
45614803 try
45624804 {
45634805 //readobj.deepCopySelf(copy);
....@@ -4612,13 +4854,18 @@
46124854 c.addChild(csg);
46134855 }
46144856
4857
+ copy.versions = readobj.versions;
4858
+ copy.versionindex = readobj.versionindex;
4859
+
4860
+ SetUndoStates();
4861
+
46154862 ResetModel();
46164863 copy.HardTouch(); // recompile?
46174864 refreshContents();
46184865 }
46194866 }
46204867
4621
- void load() // throws ClassNotFoundException
4868
+ void Open() // throws ClassNotFoundException
46224869 {
46234870 if (Grafreed.standAlone)
46244871 {
....@@ -4735,6 +4982,8 @@
47354982 String filename = browser.getFile();
47364983 if (filename != null && filename.length() > 0)
47374984 {
4985
+ if (!filename.endsWith(".gfd"))
4986
+ filename += ".gfd";
47384987 lastname = browser.getDirectory() + filename;
47394988 save();
47404989 }
....@@ -4901,7 +5150,7 @@
49015150 MenuBar menuBar;
49025151 Menu fileMenu;
49035152 MenuItem newItem;
4904
- MenuItem loadItem;
5153
+ MenuItem openItem;
49055154 MenuItem saveItem;
49065155 MenuItem saveAsItem;
49075156 MenuItem exportAsItem;
....@@ -4924,6 +5173,7 @@
49245173 CheckboxMenuItem toggleSwitchItem;
49255174 CheckboxMenuItem toggleRootItem;
49265175 CheckboxMenuItem animationItem;
5176
+ MenuItem archiveItem;
49275177 CheckboxMenuItem toggleHandleItem;
49285178 CheckboxMenuItem togglePaintItem;
49295179 JSplitPane mainPanel;
....@@ -4945,6 +5195,8 @@
49455195 cGridBag optionsPanel;
49465196
49475197 JTabbedPane objectPanel;
5198
+ boolean materialFlushed;
5199
+ Object3D latestObject;
49485200
49495201 cGridBag XYZPanel;
49505202