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.
....@@ -49,6 +52,19 @@
4952 catch (Exception e)
5053 {
5154 return new cButton(name, border);
55
+ }
56
+ }
57
+
58
+ cToggleButton GetToggleButton(String name, boolean border)
59
+ {
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);
5268 }
5369 }
5470
....@@ -194,7 +210,7 @@
194210
195211 objEditor.ctrlPanel.remove(namePanel);
196212
197
- if (!GroupEditor.allparams)
213
+ if (!allparams)
198214 return;
199215
200216 // objEditor.ctrlPanel.remove(liveCB);
....@@ -293,7 +309,7 @@
293309 //localCopy.parent = null;
294310
295311 frame = new JFrame();
296
- frame.setUndecorated(true);
312
+ frame.setUndecorated(false);
297313 objEditor = this;
298314 this.callee = callee;
299315
....@@ -324,12 +340,17 @@
324340 return frame.action(event, obj);
325341 }
326342
343
+ // Cannot work without static
344
+ static boolean allparams = true;
345
+
346
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
347
+
327348 void SetupMenu()
328349 {
329350 frame.setMenuBar(menuBar = new MenuBar());
330351 menuBar.add(fileMenu = new Menu("File"));
331352 fileMenu.add(newItem = new MenuItem("New"));
332
- fileMenu.add(loadItem = new MenuItem("Open..."));
353
+ fileMenu.add(openItem = new MenuItem("Open..."));
333354
334355 //oe.menuBar.add(menu = new Menu("Include"));
335356 Menu menu = new Menu("Import");
....@@ -361,7 +382,7 @@
361382 }
362383
363384 newItem.addActionListener(this);
364
- loadItem.addActionListener(this);
385
+ openItem.addActionListener(this);
365386 saveItem.addActionListener(this);
366387 saveAsItem.addActionListener(this);
367388 exportAsItem.addActionListener(this);
....@@ -370,6 +391,32 @@
370391 closeItem.addActionListener(this);
371392
372393 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
+
373420 toolbarPanel = new JPanel();
374421 toolbarPanel.setName("Toolbar");
375422 treePanel = new cGridBag();
....@@ -384,9 +431,12 @@
384431 editPanel.add(editCommandsPanel);
385432 editPanel.add(ctrlPanel);
386433
387
- materialPanel = new cGridBag().setVertical(true);
434
+ toolboxPanel = new cGridBag().setVertical(false);
435
+ toolboxPanel.setName("Toolbox");
388436
437
+ materialPanel = new cGridBag().setVertical(true);
389438 materialPanel.setName("Material");
439
+
390440 /*JTextPane*/
391441 infoarea = createTextPane();
392442 doc = infoarea.getStyledDocument();
....@@ -399,7 +449,7 @@
399449 // TEXTAREA infoarea.setLineWrap(true);
400450 // TEXTAREA infoarea.setWrapStyleWord(true);
401451 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
402
- infoPanel.setPreferredSize(new Dimension(50, 200));
452
+ infoPanel.setPreferredSize(new Dimension(1, 1));
403453 infoPanel.setName("Info");
404454 //infoPanel.setLayout(new BorderLayout());
405455 //infoPanel.add(createTextPane());
....@@ -411,7 +461,14 @@
411461 mainPanel.setDividerSize(9);
412462 mainPanel.setDividerLocation(0.5); //1.0);
413463 mainPanel.setResizeWeight(0.5);
414
-
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
+
415472 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
416473 //mainPanel.setLayout(new GridBagLayout());
417474 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -642,8 +699,8 @@
642699 }
643700 }
644701
645
-static GraphicsDevice device = GraphicsEnvironment
646
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
702
+//static GraphicsDevice device = GraphicsEnvironment
703
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
647704
648705 Rectangle keeprect;
649706 cRadio radio;
....@@ -659,13 +716,24 @@
659716
660717 boolean maximized;
661718
719
+ cButton fullscreenLayout;
720
+
662721 void Minimize()
663722 {
664723 frame.setState(Frame.ICONIFIED);
724
+ frame.validate();
665725 }
666726
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={}
667730 void Maximize()
668731 {
732
+ if (CameraPane.FULLSCREEN)
733
+ {
734
+ ToggleFullScreen();
735
+ }
736
+
669737 if (maximized)
670738 {
671739 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -673,20 +741,36 @@
673741 else
674742 {
675743 keeprect = frame.getBounds();
676
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
677
- Dimension rect2 = frame.getToolkit().getScreenSize();
678
- 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);
679747 // frame.setState(Frame.MAXIMIZED_BOTH);
748
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
680749 }
681750
682751 maximized ^= true;
752
+
753
+ frame.validate();
683754 }
755
+
756
+ cButton minButton;
757
+ cButton maxButton;
758
+ cButton fullButton;
684759
685760 void ToggleFullScreen()
686761 {
687
- if (CameraPane.FULLSCREEN)
762
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
763
+
764
+ cameraView.ToggleFullScreen();
765
+
766
+ if (!CameraPane.FULLSCREEN)
688767 {
689768 device.setFullScreenWindow(null);
769
+ frame.dispose();
770
+ frame.setUndecorated(false);
771
+ frame.validate();
772
+ frame.setVisible(true);
773
+
690774 //frame.setVisible(false);
691775 // frame.removeNotify();
692776 // frame.setUndecorated(false);
....@@ -696,7 +780,7 @@
696780 // X frame.getContentPane().remove(/*"Center",*/bigThree);
697781 // X framePanel.add(bigThree);
698782 // X frame.getContentPane().add(/*"Center",*/framePanel);
699
- framePanel.setDividerLocation(1);
783
+ framePanel.setDividerLocation(46);
700784
701785 //frame.setVisible(true);
702786 radio.layout = keepButton;
....@@ -711,7 +795,12 @@
711795 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
712796 // frame.getToolkit().getScreenSize().height);
713797 //frame.setVisible(false);
798
+
799
+ frame.dispose();
800
+ frame.setUndecorated(true);
714801 device.setFullScreenWindow(frame);
802
+ frame.validate();
803
+ frame.setVisible(true);
715804 // frame.removeNotify();
716805 // frame.setUndecorated(true);
717806 // frame.addNotify();
....@@ -720,12 +809,11 @@
720809 // X frame.getContentPane().add(/*"Center",*/bigThree);
721810 framePanel.setDividerLocation(0);
722811
723
- radio.layout = twoButton;
812
+ radio.layout = fullscreenLayout;
724813 radio.layout.doClick();
725814 //frame.setVisible(true);
726815 }
727
-
728
- cameraView.ToggleFullScreen();
816
+ frame.validate();
729817 }
730818
731819 private JTextPane createTextPane()
....@@ -866,7 +954,12 @@
866954 JCheckBox speedupCB;
867955 JCheckBox rewindCB;
868956 JCheckBox flipVCB;
957
+
958
+ cCheckBox toggleTextureCB;
959
+ cCheckBox toggleSwitchCB;
960
+
869961 JComboBox texresMenu;
962
+
870963 JButton resetButton;
871964 JButton stepButton;
872965 JButton stepAllButton;
....@@ -1053,12 +1146,12 @@
10531146 namePanel = new cGridBag();
10541147
10551148 nameField = AddText(namePanel, copy.GetName());
1056
- namePanel.add(nameField);
1149
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
10571150 oe.ctrlPanel.add(namePanel);
10581151
10591152 oe.ctrlPanel.Return();
10601153
1061
- if (!GroupEditor.allparams)
1154
+ if (!allparams)
10621155 return;
10631156
10641157 setupPanel = new cGridBag().setVertical(false);
....@@ -1071,20 +1164,21 @@
10711164 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
10721165 hideCB.setToolTipText("Hide object");
10731166 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1074
- markCB.setToolTipText("Set the animation target transform");
1167
+ markCB.setToolTipText("As animation target transform");
10751168
10761169 setupPanel2 = new cGridBag().setVertical(false);
10771170
10781171 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
10791172 rewindCB.setToolTipText("Rewind animation");
10801173
1081
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1082
- 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)");
10831176
1177
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1178
+ link2masterCB.setToolTipText("Attach to support");
1179
+
10841180 if (Globals.ADVANCED)
10851181 {
1086
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1087
- link2masterCB.setToolTipText("Attach to support");
10881182 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
10891183 speedupCB.setToolTipText("Option motion capture");
10901184 }
....@@ -1400,7 +1494,11 @@
14001494 // north.add(ctrlPanel, BorderLayout.NORTH);
14011495 // objectPanel.add(north);
14021496 objectPanel.add(editPanel);
1403
- objectPanel.add(infoPanel);
1497
+
1498
+ //if (Globals.ADVANCED)
1499
+ objectPanel.add(infoPanel);
1500
+
1501
+ objectPanel.add(toolboxPanel);
14041502
14051503 /*
14061504 aConstraints.gridx = 0;
....@@ -1409,7 +1507,7 @@
14091507 aConstraints.gridy += 1;
14101508 aConstraints.gridwidth = 1;
14111509 mainPanel.add(objectPanel, aConstraints);
1412
- */
1510
+ */
14131511
14141512 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
14151513 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1426,9 +1524,7 @@
14261524 JTabbedPane tabbedPane = new JTabbedPane();
14271525 tabbedPane.add(scrollpane);
14281526
1429
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1430
-
1431
- optionsPanel = new cGridBag().setVertical(true);
1527
+ optionsPanel = new cGridBag().setVertical(false);
14321528
14331529 optionsPanel.setName("Options");
14341530
....@@ -1436,6 +1532,8 @@
14361532
14371533 tabbedPane.add(optionsPanel);
14381534
1535
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1536
+
14391537 scenePanel.add(tabbedPane);
14401538
14411539 /*
....@@ -1508,9 +1606,9 @@
15081606 // aConstraints.gridheight = 1;
15091607
15101608 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1511
- framePanel.setContinuousLayout(true);
1512
- framePanel.setOneTouchExpandable(true);
1513
- framePanel.setDividerLocation(0.8);
1609
+ framePanel.setContinuousLayout(false);
1610
+ framePanel.setOneTouchExpandable(false);
1611
+ //.setDividerLocation(0.8);
15141612 //framePanel.setDividerSize(15);
15151613 //framePanel.setResizeWeight(0.15);
15161614 framePanel.setName("Frame");
....@@ -1528,11 +1626,14 @@
15281626 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
15291627
15301628 frame.setSize(1280, 860);
1531
- frame.setVisible(true);
1532
-
1629
+
15331630 cameraView.requestFocusInWindow();
15341631
15351632 gridPanel.setDividerLocation(1.0);
1633
+
1634
+ frame.validate();
1635
+
1636
+ frame.setVisible(true);
15361637
15371638 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
15381639 frame.addWindowListener(new WindowAdapter()
....@@ -1619,24 +1720,6 @@
16191720 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16201721 colorSection.add(texture);
16211722
1622
- cGridBag anisoU = new cGridBag();
1623
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1624
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1625
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1626
- colorSection.add(anisoU);
1627
-
1628
- cGridBag anisoV = new cGridBag();
1629
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1630
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1631
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1632
- colorSection.add(anisoV);
1633
-
1634
- cGridBag shadowbias = new cGridBag();
1635
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1636
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1637
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1638
- colorSection.add(shadowbias);
1639
-
16401723 panel.add(new JSeparator());
16411724
16421725 panel.add(colorSection);
....@@ -1686,6 +1769,12 @@
16861769 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
16871770 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
16881771 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);
16891778
16901779 panel.add(new JSeparator());
16911780
....@@ -1737,6 +1826,18 @@
17371826 // aConstraints.gridy += 1;
17381827 // aConstraints.gridwidth = 1;
17391828
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
+
17401841
17411842 panel.add(new JSeparator());
17421843
....@@ -1744,35 +1845,35 @@
17441845
17451846 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17461847
1747
- cGridBag globalSection = new cGridBag().setVertical(true);
1848
+ //cGridBag globalSection = new cGridBag().setVertical(true);
17481849
17491850 cGridBag camera = new cGridBag();
17501851 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
17511852 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17521853 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1753
- globalSection.add(camera);
1854
+ colorSection.add(camera);
17541855
17551856 cGridBag ambient = new cGridBag();
17561857 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
17571858 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17581859 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1759
- globalSection.add(ambient);
1860
+ colorSection.add(ambient);
17601861
17611862 cGridBag backlit = new cGridBag();
17621863 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
17631864 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17641865 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1765
- globalSection.add(backlit);
1866
+ colorSection.add(backlit);
17661867
17671868 cGridBag opacity = new cGridBag();
17681869 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
17691870 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17701871 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1771
- globalSection.add(opacity);
1872
+ colorSection.add(opacity);
17721873
1773
- panel.add(new JSeparator());
1874
+ //panel.add(new JSeparator());
17741875
1775
- panel.add(globalSection);
1876
+ //panel.add(globalSection);
17761877
17771878 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17781879
....@@ -1879,8 +1980,9 @@
18791980 // 3D models
18801981 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
18811982 {
1882
- lastConverter = new com.jmex.model.converters.MaxToJme();
1883
- LoadFile(filename, lastConverter);
1983
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
1984
+ //LoadFile(filename, lastConverter);
1985
+ LoadObjFile(filename); // New 3ds loader
18841986 continue;
18851987 }
18861988 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2606,6 +2708,7 @@
26062708 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26072709 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26082710 }
2711
+
26092712 //cJME.count++;
26102713 //cJME.count %= 12;
26112714 if (gc)
....@@ -2789,6 +2892,7 @@
27892892 }
27902893 }
27912894 }
2895
+
27922896 cFileSystemPane FSPane;
27932897
27942898 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2842,11 +2946,14 @@
28422946 }
28432947 }
28442948 }
2949
+
28452950 freezematerial = false;
28462951 }
28472952
28482953 void SetMaterial(Object3D object)
28492954 {
2955
+ latestObject = object;
2956
+
28502957 cMaterial mat = object.material;
28512958
28522959 if (mat == null)
....@@ -2958,12 +3065,17 @@
29583065 // }
29593066
29603067 /**/
2961
- if (deselect)
3068
+ if (deselect || child == null)
29623069 {
29633070 //group.deselectAll();
29643071 //freeze = true;
29653072 GetTree().clearSelection();
29663073 //freeze = false;
3074
+
3075
+ if (child == null)
3076
+ {
3077
+ return;
3078
+ }
29673079 }
29683080
29693081 //group.addSelectee(child);
....@@ -3032,7 +3144,7 @@
30323144 cameraView.ToggleDL();
30333145 cameraView.repaint();
30343146 return;
3035
- } else if (event.getSource() == toggleTextureItem)
3147
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
30363148 {
30373149 cameraView.ToggleTexture();
30383150 // june 2013 copy.HardTouch();
....@@ -3071,7 +3183,7 @@
30713183 frame.validate();
30723184
30733185 return;
3074
- } else if (event.getSource() == toggleSwitchItem)
3186
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30753187 {
30763188 cameraView.ToggleSwitch();
30773189 cameraView.repaint();
....@@ -3287,9 +3399,9 @@
32873399 {
32883400 Close();
32893401 //return true;
3290
- } else if (source == loadItem)
3402
+ } else if (source == openItem)
32913403 {
3292
- load();
3404
+ Open();
32933405 //return true;
32943406 } else if (source == newItem)
32953407 {
....@@ -3314,6 +3426,10 @@
33143426 {
33153427 generatePOV();
33163428 //return true;
3429
+ } else if (event.getSource() == archiveItem)
3430
+ {
3431
+ cTools.Archive(frame);
3432
+ return;
33173433 } else if (source == zBufferItem)
33183434 {
33193435 try
....@@ -3365,8 +3481,8 @@
33653481 try
33663482 {
33673483 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3368
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3369
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3484
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3485
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
33703486
33713487 Object3D parent = o.parent;
33723488 o.parent = null;
....@@ -3377,10 +3493,14 @@
33773493
33783494 out.flush();
33793495
3380
- zstream.close();
3496
+ baos //zstream
3497
+ .close();
33813498 out.close();
33823499
3383
- return baos.toByteArray();
3500
+ byte[] bytes = baos.toByteArray();
3501
+
3502
+ System.out.println("save #bytes = " + bytes.length);
3503
+ return bytes;
33843504 } catch (Exception e)
33853505 {
33863506 System.err.println(e);
....@@ -3390,13 +3510,16 @@
33903510
33913511 static public Object Uncompress(byte[] bytes)
33923512 {
3393
- System.out.println("#bytes = " + bytes.length);
3513
+ System.out.println("restore #bytes = " + bytes.length);
33943514 try
33953515 {
33963516 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3397
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3398
- ObjectInputStream in = new ObjectInputStream(istream);
3517
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3518
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
33993519 Object obj = in.readObject();
3520
+
3521
+ bais //istream
3522
+ .close();
34003523 in.close();
34013524
34023525 return obj;
....@@ -3455,6 +3578,27 @@
34553578
34563579 public void Save()
34573580 {
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
+ {
34583602 System.err.println("Save");
34593603
34603604 cRadio tab = GetCurrentTab();
....@@ -3464,20 +3608,42 @@
34643608
34653609 copy.ExtractBigData(hashtable);
34663610
3467
- //EditorFrame.m_MainFrame.requestFocusInWindow();
3468
- tab.graphs[tab.undoindex++] = Compress(copy);
3469
-
3470
- copy.RestoreBigData(hashtable);
3611
+ byte[] compress = Compress(copy);
34713612
34723613 CameraPane.SWITCH = temp;
34733614
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
+
34743637 //assert(hashtable.isEmpty());
34753638
34763639 for (int i = tab.undoindex; i < tab.graphs.length; i++)
34773640 {
3478
- tab.graphs[i] = null;
3641
+ //tab.user[i] = false;
3642
+ // tab.graphs[i] = null;
34793643 }
34803644
3645
+ SetUndoStates();
3646
+
34813647 // test save
34823648 if (false)
34833649 {
....@@ -3496,10 +3662,14 @@
34963662 e.printStackTrace();
34973663 }
34983664 }
3665
+
3666
+ return !thesame;
34993667 }
35003668
35013669 void CopyChanged(Object3D obj)
35023670 {
3671
+ SetUndoStates();
3672
+
35033673 boolean temp = CameraPane.SWITCH;
35043674 CameraPane.SWITCH = false;
35053675
....@@ -3539,7 +3709,18 @@
35393709 refreshContents();
35403710 }
35413711
3542
- 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()
35433724 {
35443725 System.err.println("Undo");
35453726
....@@ -3548,18 +3729,27 @@
35483729 if (tab.undoindex == 0)
35493730 {
35503731 java.awt.Toolkit.getDefaultToolkit().beep();
3551
- return;
3732
+ return false;
35523733 }
35533734
3554
- if (tab.graphs[tab.undoindex] == null)
3735
+ if (tab.graphs[tab.undoindex] == null) // || !tab.user[tab.undoindex])
35553736 {
3556
- Save();
3557
- 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
+ }
35583746 }
35593747
35603748 tab.undoindex -= 1;
35613749
35623750 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3751
+
3752
+ return true;
35633753 }
35643754
35653755 public void Redo()
....@@ -3575,6 +3765,9 @@
35753765 tab.undoindex += 1;
35763766
35773767 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3768
+
3769
+ //if (!tab.user[tab.undoindex])
3770
+ // tab.graphs[tab.undoindex] = null;
35783771 }
35793772
35803773 void ImportGFD()
....@@ -3726,7 +3919,7 @@
37263919 assert false;
37273920 }
37283921
3729
- void EditSelection()
3922
+ void EditSelection(boolean newWindow)
37303923 {
37313924 }
37323925
....@@ -4221,7 +4414,7 @@
42214414
42224415 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
42234416 {
4224
- if (Globals.SAVEONMAKE)
4417
+ if (Globals.SAVEONMAKE) // && resetmodel)
42254418 Save();
42264419 //Tween.set(thing, 0).target(1).start(tweenManager);
42274420 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4309,6 +4502,12 @@
43094502 {
43104503 ResetModel();
43114504 Select(thing.GetTreePath(), true, false); // unselect... false);
4505
+
4506
+ if (thing.Size() == 0)
4507
+ {
4508
+ //EditSelection(false);
4509
+ }
4510
+
43124511 refreshContents();
43134512 }
43144513
....@@ -4531,8 +4730,8 @@
45314730
45324731 if (readobj != null)
45334732 {
4534
- if (Globals.SAVEONMAKE)
4535
- Save();
4733
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4734
+ // Save();
45364735 try
45374736 {
45384737 //readobj.deepCopySelf(copy);
....@@ -4593,7 +4792,7 @@
45934792 }
45944793 }
45954794
4596
- void load() // throws ClassNotFoundException
4795
+ void Open() // throws ClassNotFoundException
45974796 {
45984797 if (Grafreed.standAlone)
45994798 {
....@@ -4710,6 +4909,8 @@
47104909 String filename = browser.getFile();
47114910 if (filename != null && filename.length() > 0)
47124911 {
4912
+ if (!filename.endsWith(".gfd"))
4913
+ filename += ".gfd";
47134914 lastname = browser.getDirectory() + filename;
47144915 save();
47154916 }
....@@ -4876,7 +5077,7 @@
48765077 MenuBar menuBar;
48775078 Menu fileMenu;
48785079 MenuItem newItem;
4879
- MenuItem loadItem;
5080
+ MenuItem openItem;
48805081 MenuItem saveItem;
48815082 MenuItem saveAsItem;
48825083 MenuItem exportAsItem;
....@@ -4899,22 +5100,36 @@
48995100 CheckboxMenuItem toggleSwitchItem;
49005101 CheckboxMenuItem toggleRootItem;
49015102 CheckboxMenuItem animationItem;
5103
+ MenuItem archiveItem;
49025104 CheckboxMenuItem toggleHandleItem;
49035105 CheckboxMenuItem togglePaintItem;
49045106 JSplitPane mainPanel;
49055107 JScrollPane scrollpane;
5108
+
49065109 JPanel toolbarPanel;
5110
+
49075111 cGridBag treePanel;
5112
+
49085113 JPanel radioPanel;
49095114 ButtonGroup buttonGroup;
4910
- cGridBag ctrlPanel;
5115
+
5116
+ cGridBag toolboxPanel;
49115117 cGridBag materialPanel;
5118
+ cGridBag ctrlPanel;
5119
+
49125120 JScrollPane infoPanel;
5121
+
49135122 cGridBag optionsPanel;
5123
+
49145124 JTabbedPane objectPanel;
5125
+ boolean materialFlushed;
5126
+ Object3D latestObject;
5127
+
49155128 cGridBag XYZPanel;
5129
+
49165130 JSplitPane gridPanel;
49175131 JSplitPane bigPanel;
5132
+
49185133 cGridBag bigThree;
49195134 cGridBag scenePanel;
49205135 cGridBag centralPanel;
....@@ -5029,7 +5244,7 @@
50295244 cNumberSlider fogField;
50305245 JLabel opacityPowerLabel;
50315246 cNumberSlider opacityPowerField;
5032
- JTree jTree;
5247
+ cTree jTree;
50335248 //ObjectUI parent;
50345249
50355250 cNumberSlider normalpushField;