Normand Briere
2019-07-14 bc829f47837b5a001f911542140b0b8e63c2bb0c
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,8 +813,7 @@
742813 radio.layout.doClick();
743814 //frame.setVisible(true);
744815 }
745
-
746
- cameraView.ToggleFullScreen();
816
+ frame.validate();
747817 }
748818
749819 private JTextPane createTextPane()
....@@ -884,7 +954,12 @@
884954 JCheckBox speedupCB;
885955 JCheckBox rewindCB;
886956 JCheckBox flipVCB;
957
+
958
+ cCheckBox toggleTextureCB;
959
+ cCheckBox toggleSwitchCB;
960
+
887961 JComboBox texresMenu;
962
+
888963 JButton resetButton;
889964 JButton stepButton;
890965 JButton stepAllButton;
....@@ -1071,12 +1146,12 @@
10711146 namePanel = new cGridBag();
10721147
10731148 nameField = AddText(namePanel, copy.GetName());
1074
- namePanel.add(nameField);
1149
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
10751150 oe.ctrlPanel.add(namePanel);
10761151
10771152 oe.ctrlPanel.Return();
10781153
1079
- if (!GroupEditor.allparams)
1154
+ if (!allparams)
10801155 return;
10811156
10821157 setupPanel = new cGridBag().setVertical(false);
....@@ -1089,20 +1164,21 @@
10891164 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
10901165 hideCB.setToolTipText("Hide object");
10911166 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1092
- markCB.setToolTipText("Set the animation target transform");
1167
+ markCB.setToolTipText("As animation target transform");
10931168
10941169 setupPanel2 = new cGridBag().setVertical(false);
10951170
10961171 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
10971172 rewindCB.setToolTipText("Rewind animation");
10981173
1099
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1100
- randomCB.setToolTipText("Randomly Rewind or Go back and forth");
1174
+ randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
1175
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11011176
1177
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1178
+ link2masterCB.setToolTipText("Attach to support");
1179
+
11021180 if (Globals.ADVANCED)
11031181 {
1104
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1105
- link2masterCB.setToolTipText("Attach to support");
11061182 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11071183 speedupCB.setToolTipText("Option motion capture");
11081184 }
....@@ -1412,14 +1488,17 @@
14121488
14131489 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14141490 //tmp.setName("Edit");
1415
- objectPanel.add(toolboxPanel);
14161491 objectPanel.add(materialPanel);
14171492 // JPanel north = new JPanel(new BorderLayout());
14181493 // north.setName("Edit");
14191494 // north.add(ctrlPanel, BorderLayout.NORTH);
14201495 // objectPanel.add(north);
14211496 objectPanel.add(editPanel);
1422
- objectPanel.add(infoPanel);
1497
+
1498
+ //if (Globals.ADVANCED)
1499
+ objectPanel.add(infoPanel);
1500
+
1501
+ objectPanel.add(toolboxPanel);
14231502
14241503 /*
14251504 aConstraints.gridx = 0;
....@@ -1428,7 +1507,7 @@
14281507 aConstraints.gridy += 1;
14291508 aConstraints.gridwidth = 1;
14301509 mainPanel.add(objectPanel, aConstraints);
1431
- */
1510
+ */
14321511
14331512 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
14341513 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1445,9 +1524,7 @@
14451524 JTabbedPane tabbedPane = new JTabbedPane();
14461525 tabbedPane.add(scrollpane);
14471526
1448
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1449
-
1450
- optionsPanel = new cGridBag().setVertical(true);
1527
+ optionsPanel = new cGridBag().setVertical(false);
14511528
14521529 optionsPanel.setName("Options");
14531530
....@@ -1455,6 +1532,8 @@
14551532
14561533 tabbedPane.add(optionsPanel);
14571534
1535
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1536
+
14581537 scenePanel.add(tabbedPane);
14591538
14601539 /*
....@@ -1527,9 +1606,9 @@
15271606 // aConstraints.gridheight = 1;
15281607
15291608 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1530
- framePanel.setContinuousLayout(true);
1531
- framePanel.setOneTouchExpandable(true);
1532
- framePanel.setDividerLocation(0.8);
1609
+ framePanel.setContinuousLayout(false);
1610
+ framePanel.setOneTouchExpandable(false);
1611
+ //.setDividerLocation(0.8);
15331612 //framePanel.setDividerSize(15);
15341613 //framePanel.setResizeWeight(0.15);
15351614 framePanel.setName("Frame");
....@@ -1547,11 +1626,14 @@
15471626 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
15481627
15491628 frame.setSize(1280, 860);
1550
- frame.setVisible(true);
1551
-
1629
+
15521630 cameraView.requestFocusInWindow();
15531631
15541632 gridPanel.setDividerLocation(1.0);
1633
+
1634
+ frame.validate();
1635
+
1636
+ frame.setVisible(true);
15551637
15561638 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
15571639 frame.addWindowListener(new WindowAdapter()
....@@ -1638,24 +1720,6 @@
16381720 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16391721 colorSection.add(texture);
16401722
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
-
16591723 panel.add(new JSeparator());
16601724
16611725 panel.add(colorSection);
....@@ -1705,6 +1769,12 @@
17051769 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17061770 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17071771 diffuseSection.add(fakedepth);
1772
+
1773
+ cGridBag shadowbias = new cGridBag();
1774
+ shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1775
+ shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1776
+ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1777
+ diffuseSection.add(shadowbias);
17081778
17091779 panel.add(new JSeparator());
17101780
....@@ -1756,6 +1826,18 @@
17561826 // aConstraints.gridy += 1;
17571827 // aConstraints.gridwidth = 1;
17581828
1829
+ cGridBag anisoU = new cGridBag();
1830
+ anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1831
+ anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1832
+ anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1833
+ specularSection.add(anisoU);
1834
+
1835
+ cGridBag anisoV = new cGridBag();
1836
+ anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1837
+ anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1838
+ anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1839
+ specularSection.add(anisoV);
1840
+
17591841
17601842 panel.add(new JSeparator());
17611843
....@@ -1763,35 +1845,35 @@
17631845
17641846 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17651847
1766
- cGridBag globalSection = new cGridBag().setVertical(true);
1848
+ //cGridBag globalSection = new cGridBag().setVertical(true);
17671849
17681850 cGridBag camera = new cGridBag();
17691851 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
17701852 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17711853 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1772
- globalSection.add(camera);
1854
+ colorSection.add(camera);
17731855
17741856 cGridBag ambient = new cGridBag();
17751857 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
17761858 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17771859 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1778
- globalSection.add(ambient);
1860
+ colorSection.add(ambient);
17791861
17801862 cGridBag backlit = new cGridBag();
17811863 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
17821864 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17831865 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1784
- globalSection.add(backlit);
1866
+ colorSection.add(backlit);
17851867
17861868 cGridBag opacity = new cGridBag();
17871869 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
17881870 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17891871 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1790
- globalSection.add(opacity);
1872
+ colorSection.add(opacity);
17911873
1792
- panel.add(new JSeparator());
1874
+ //panel.add(new JSeparator());
17931875
1794
- panel.add(globalSection);
1876
+ //panel.add(globalSection);
17951877
17961878 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17971879
....@@ -1898,8 +1980,9 @@
18981980 // 3D models
18991981 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19001982 {
1901
- lastConverter = new com.jmex.model.converters.MaxToJme();
1902
- LoadFile(filename, lastConverter);
1983
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
1984
+ //LoadFile(filename, lastConverter);
1985
+ LoadObjFile(filename); // New 3ds loader
19031986 continue;
19041987 }
19051988 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2625,6 +2708,7 @@
26252708 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26262709 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26272710 }
2711
+
26282712 //cJME.count++;
26292713 //cJME.count %= 12;
26302714 if (gc)
....@@ -2808,6 +2892,7 @@
28082892 }
28092893 }
28102894 }
2895
+
28112896 cFileSystemPane FSPane;
28122897
28132898 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2861,11 +2946,14 @@
28612946 }
28622947 }
28632948 }
2949
+
28642950 freezematerial = false;
28652951 }
28662952
28672953 void SetMaterial(Object3D object)
28682954 {
2955
+ latestObject = object;
2956
+
28692957 cMaterial mat = object.material;
28702958
28712959 if (mat == null)
....@@ -2977,12 +3065,17 @@
29773065 // }
29783066
29793067 /**/
2980
- if (deselect)
3068
+ if (deselect || child == null)
29813069 {
29823070 //group.deselectAll();
29833071 //freeze = true;
29843072 GetTree().clearSelection();
29853073 //freeze = false;
3074
+
3075
+ if (child == null)
3076
+ {
3077
+ return;
3078
+ }
29863079 }
29873080
29883081 //group.addSelectee(child);
....@@ -3051,7 +3144,7 @@
30513144 cameraView.ToggleDL();
30523145 cameraView.repaint();
30533146 return;
3054
- } else if (event.getSource() == toggleTextureItem)
3147
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
30553148 {
30563149 cameraView.ToggleTexture();
30573150 // june 2013 copy.HardTouch();
....@@ -3090,7 +3183,7 @@
30903183 frame.validate();
30913184
30923185 return;
3093
- } else if (event.getSource() == toggleSwitchItem)
3186
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30943187 {
30953188 cameraView.ToggleSwitch();
30963189 cameraView.repaint();
....@@ -3306,9 +3399,9 @@
33063399 {
33073400 Close();
33083401 //return true;
3309
- } else if (source == loadItem)
3402
+ } else if (source == openItem)
33103403 {
3311
- load();
3404
+ Open();
33123405 //return true;
33133406 } else if (source == newItem)
33143407 {
....@@ -3333,6 +3426,10 @@
33333426 {
33343427 generatePOV();
33353428 //return true;
3429
+ } else if (event.getSource() == archiveItem)
3430
+ {
3431
+ cTools.Archive(frame);
3432
+ return;
33363433 } else if (source == zBufferItem)
33373434 {
33383435 try
....@@ -3384,8 +3481,8 @@
33843481 try
33853482 {
33863483 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3387
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3388
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3484
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3485
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
33893486
33903487 Object3D parent = o.parent;
33913488 o.parent = null;
....@@ -3396,10 +3493,14 @@
33963493
33973494 out.flush();
33983495
3399
- zstream.close();
3496
+ baos //zstream
3497
+ .close();
34003498 out.close();
34013499
3402
- return baos.toByteArray();
3500
+ byte[] bytes = baos.toByteArray();
3501
+
3502
+ System.out.println("save #bytes = " + bytes.length);
3503
+ return bytes;
34033504 } catch (Exception e)
34043505 {
34053506 System.err.println(e);
....@@ -3409,13 +3510,16 @@
34093510
34103511 static public Object Uncompress(byte[] bytes)
34113512 {
3412
- System.out.println("#bytes = " + bytes.length);
3513
+ System.out.println("restore #bytes = " + bytes.length);
34133514 try
34143515 {
34153516 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3416
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3417
- ObjectInputStream in = new ObjectInputStream(istream);
3517
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3518
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
34183519 Object obj = in.readObject();
3520
+
3521
+ bais //istream
3522
+ .close();
34193523 in.close();
34203524
34213525 return obj;
....@@ -3474,6 +3578,27 @@
34743578
34753579 public void Save()
34763580 {
3581
+ Save(true);
3582
+ }
3583
+
3584
+ private boolean Equal(byte[] compress, byte[] name)
3585
+ {
3586
+ if (compress.length != name.length)
3587
+ {
3588
+ return false;
3589
+ }
3590
+
3591
+ for (int i=compress.length; --i>=0;)
3592
+ {
3593
+ if (compress[i] != name[i])
3594
+ return false;
3595
+ }
3596
+
3597
+ return true;
3598
+ }
3599
+
3600
+ public boolean Save(boolean user)
3601
+ {
34773602 System.err.println("Save");
34783603
34793604 cRadio tab = GetCurrentTab();
....@@ -3483,20 +3608,42 @@
34833608
34843609 copy.ExtractBigData(hashtable);
34853610
3486
- //EditorFrame.m_MainFrame.requestFocusInWindow();
3487
- tab.graphs[tab.undoindex++] = Compress(copy);
3488
-
3489
- copy.RestoreBigData(hashtable);
3611
+ byte[] compress = Compress(copy);
34903612
34913613 CameraPane.SWITCH = temp;
34923614
3615
+ boolean thesame = false;
3616
+
3617
+ // 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]))
3619
+ {
3620
+ thesame = true;
3621
+ }
3622
+
3623
+ //EditorFrame.m_MainFrame.requestFocusInWindow();
3624
+ if (!thesame)
3625
+ {
3626
+ //tab.user[tab.undoindex] = user;
3627
+ boolean increment = tab.graphs[tab.undoindex] == null;
3628
+
3629
+ tab.graphs[tab.undoindex] = compress;
3630
+
3631
+ if (increment)
3632
+ tab.undoindex++;
3633
+ }
3634
+
3635
+ copy.RestoreBigData(hashtable);
3636
+
34933637 //assert(hashtable.isEmpty());
34943638
34953639 for (int i = tab.undoindex; i < tab.graphs.length; i++)
34963640 {
3497
- tab.graphs[i] = null;
3641
+ //tab.user[i] = false;
3642
+ // tab.graphs[i] = null;
34983643 }
34993644
3645
+ SetUndoStates();
3646
+
35003647 // test save
35013648 if (false)
35023649 {
....@@ -3515,10 +3662,14 @@
35153662 e.printStackTrace();
35163663 }
35173664 }
3665
+
3666
+ return !thesame;
35183667 }
35193668
35203669 void CopyChanged(Object3D obj)
35213670 {
3671
+ SetUndoStates();
3672
+
35223673 boolean temp = CameraPane.SWITCH;
35233674 CameraPane.SWITCH = false;
35243675
....@@ -3558,7 +3709,18 @@
35583709 refreshContents();
35593710 }
35603711
3561
- public void Undo()
3712
+ cButton undoButton;
3713
+ cButton redoButton;
3714
+
3715
+ void SetUndoStates()
3716
+ {
3717
+ cRadio tab = GetCurrentTab();
3718
+
3719
+ undoButton.setEnabled(tab.undoindex > 0);
3720
+ redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3721
+ }
3722
+
3723
+ public boolean Undo()
35623724 {
35633725 System.err.println("Undo");
35643726
....@@ -3567,18 +3729,27 @@
35673729 if (tab.undoindex == 0)
35683730 {
35693731 java.awt.Toolkit.getDefaultToolkit().beep();
3570
- return;
3732
+ return false;
35713733 }
35723734
3573
- if (tab.graphs[tab.undoindex] == null)
3735
+ if (tab.graphs[tab.undoindex] == null) // || !tab.user[tab.undoindex])
35743736 {
3575
- Save();
3576
- tab.undoindex -= 1;
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
+ }
35773746 }
35783747
35793748 tab.undoindex -= 1;
35803749
35813750 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3751
+
3752
+ return true;
35823753 }
35833754
35843755 public void Redo()
....@@ -3594,6 +3765,9 @@
35943765 tab.undoindex += 1;
35953766
35963767 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3768
+
3769
+ //if (!tab.user[tab.undoindex])
3770
+ // tab.graphs[tab.undoindex] = null;
35973771 }
35983772
35993773 void ImportGFD()
....@@ -4556,8 +4730,8 @@
45564730
45574731 if (readobj != null)
45584732 {
4559
- if (Globals.SAVEONMAKE)
4560
- Save();
4733
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4734
+ // Save();
45614735 try
45624736 {
45634737 //readobj.deepCopySelf(copy);
....@@ -4618,7 +4792,7 @@
46184792 }
46194793 }
46204794
4621
- void load() // throws ClassNotFoundException
4795
+ void Open() // throws ClassNotFoundException
46224796 {
46234797 if (Grafreed.standAlone)
46244798 {
....@@ -4735,6 +4909,8 @@
47354909 String filename = browser.getFile();
47364910 if (filename != null && filename.length() > 0)
47374911 {
4912
+ if (!filename.endsWith(".gfd"))
4913
+ filename += ".gfd";
47384914 lastname = browser.getDirectory() + filename;
47394915 save();
47404916 }
....@@ -4901,7 +5077,7 @@
49015077 MenuBar menuBar;
49025078 Menu fileMenu;
49035079 MenuItem newItem;
4904
- MenuItem loadItem;
5080
+ MenuItem openItem;
49055081 MenuItem saveItem;
49065082 MenuItem saveAsItem;
49075083 MenuItem exportAsItem;
....@@ -4924,6 +5100,7 @@
49245100 CheckboxMenuItem toggleSwitchItem;
49255101 CheckboxMenuItem toggleRootItem;
49265102 CheckboxMenuItem animationItem;
5103
+ MenuItem archiveItem;
49275104 CheckboxMenuItem toggleHandleItem;
49285105 CheckboxMenuItem togglePaintItem;
49295106 JSplitPane mainPanel;
....@@ -4945,6 +5122,8 @@
49455122 cGridBag optionsPanel;
49465123
49475124 JTabbedPane objectPanel;
5125
+ boolean materialFlushed;
5126
+ Object3D latestObject;
49485127
49495128 cGridBag XYZPanel;
49505129