Normand Briere
2019-07-14 bc829f47837b5a001f911542140b0b8e63c2bb0c
ObjEditor.java
....@@ -4,6 +4,7 @@
44
55 import java.awt.*;
66 import java.awt.event.*;
7
+import java.awt.image.BufferedImage;
78 import javax.swing.*;
89 import javax.swing.event.*;
910 import javax.swing.text.*;
....@@ -13,6 +14,9 @@
1314 import javax.swing.plaf.metal.MetalLookAndFeel;
1415 //import javax.swing.plaf.ColorUIResource;
1516 //import javax.swing.plaf.metal.DefaultMetalTheme;
17
+
18
+import javax.swing.plaf.basic.BasicSplitPaneDivider;
19
+import javax.swing.plaf.basic.BasicSplitPaneUI;
1620
1721 //import javax.media.opengl.GLCanvas;
1822
....@@ -37,6 +41,65 @@
3741 JFrame frame;
3842
3943 static ObjEditor theFrame;
44
+
45
+ cButton GetButton(String name, boolean border)
46
+ {
47
+ try
48
+ {
49
+ ImageIcon icon = GetIcon(name);
50
+ return new cButton(icon, border);
51
+ }
52
+ catch (Exception e)
53
+ {
54
+ return new cButton(name, border);
55
+ }
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);
68
+ }
69
+ }
70
+
71
+ cCheckBox GetCheckBox(String name, boolean border)
72
+ {
73
+ try
74
+ {
75
+ ImageIcon icon = GetIcon(name);
76
+ return new cCheckBox(icon, border);
77
+ }
78
+ catch (Exception e)
79
+ {
80
+ return new cCheckBox(name, border);
81
+ }
82
+ }
83
+
84
+ private ImageIcon GetIcon(String name) throws IOException
85
+ {
86
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
87
+
88
+ if (image.getWidth() != 24 && image.getHeight() != 24)
89
+ {
90
+ BufferedImage resized = new BufferedImage(24, 24, image.getType());
91
+ Graphics2D g = resized.createGraphics();
92
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
93
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
94
+ g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
95
+ g.dispose();
96
+
97
+ image = resized;
98
+ }
99
+
100
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
101
+ return icon;
102
+ }
40103
41104 // SCRIPT
42105
....@@ -147,7 +210,7 @@
147210
148211 objEditor.ctrlPanel.remove(namePanel);
149212
150
- if (!GroupEditor.allparams)
213
+ if (!allparams)
151214 return;
152215
153216 // objEditor.ctrlPanel.remove(liveCB);
....@@ -246,7 +309,7 @@
246309 //localCopy.parent = null;
247310
248311 frame = new JFrame();
249
- frame.setUndecorated(true);
312
+ frame.setUndecorated(false);
250313 objEditor = this;
251314 this.callee = callee;
252315
....@@ -277,12 +340,17 @@
277340 return frame.action(event, obj);
278341 }
279342
343
+ // Cannot work without static
344
+ static boolean allparams = true;
345
+
346
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
347
+
280348 void SetupMenu()
281349 {
282350 frame.setMenuBar(menuBar = new MenuBar());
283351 menuBar.add(fileMenu = new Menu("File"));
284352 fileMenu.add(newItem = new MenuItem("New"));
285
- fileMenu.add(loadItem = new MenuItem("Open..."));
353
+ fileMenu.add(openItem = new MenuItem("Open..."));
286354
287355 //oe.menuBar.add(menu = new Menu("Include"));
288356 Menu menu = new Menu("Import");
....@@ -314,7 +382,7 @@
314382 }
315383
316384 newItem.addActionListener(this);
317
- loadItem.addActionListener(this);
385
+ openItem.addActionListener(this);
318386 saveItem.addActionListener(this);
319387 saveAsItem.addActionListener(this);
320388 exportAsItem.addActionListener(this);
....@@ -323,6 +391,32 @@
323391 closeItem.addActionListener(this);
324392
325393 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
+
326420 toolbarPanel = new JPanel();
327421 toolbarPanel.setName("Toolbar");
328422 treePanel = new cGridBag();
....@@ -337,9 +431,12 @@
337431 editPanel.add(editCommandsPanel);
338432 editPanel.add(ctrlPanel);
339433
340
- materialPanel = new cGridBag().setVertical(true);
434
+ toolboxPanel = new cGridBag().setVertical(false);
435
+ toolboxPanel.setName("Toolbox");
341436
437
+ materialPanel = new cGridBag().setVertical(true);
342438 materialPanel.setName("Material");
439
+
343440 /*JTextPane*/
344441 infoarea = createTextPane();
345442 doc = infoarea.getStyledDocument();
....@@ -352,7 +449,7 @@
352449 // TEXTAREA infoarea.setLineWrap(true);
353450 // TEXTAREA infoarea.setWrapStyleWord(true);
354451 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
355
- infoPanel.setPreferredSize(new Dimension(50, 200));
452
+ infoPanel.setPreferredSize(new Dimension(1, 1));
356453 infoPanel.setName("Info");
357454 //infoPanel.setLayout(new BorderLayout());
358455 //infoPanel.add(createTextPane());
....@@ -364,7 +461,14 @@
364461 mainPanel.setDividerSize(9);
365462 mainPanel.setDividerLocation(0.5); //1.0);
366463 mainPanel.setResizeWeight(0.5);
367
-
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
+
368472 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
369473 //mainPanel.setLayout(new GridBagLayout());
370474 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -595,8 +699,8 @@
595699 }
596700 }
597701
598
-static GraphicsDevice device = GraphicsEnvironment
599
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
702
+//static GraphicsDevice device = GraphicsEnvironment
703
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
600704
601705 Rectangle keeprect;
602706 cRadio radio;
....@@ -612,13 +716,24 @@
612716
613717 boolean maximized;
614718
719
+ cButton fullscreenLayout;
720
+
615721 void Minimize()
616722 {
617723 frame.setState(Frame.ICONIFIED);
724
+ frame.validate();
618725 }
619726
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={}
620730 void Maximize()
621731 {
732
+ if (CameraPane.FULLSCREEN)
733
+ {
734
+ ToggleFullScreen();
735
+ }
736
+
622737 if (maximized)
623738 {
624739 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -626,20 +741,36 @@
626741 else
627742 {
628743 keeprect = frame.getBounds();
629
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
630
- Dimension rect2 = frame.getToolkit().getScreenSize();
631
- 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);
632747 // frame.setState(Frame.MAXIMIZED_BOTH);
748
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
633749 }
634750
635751 maximized ^= true;
752
+
753
+ frame.validate();
636754 }
755
+
756
+ cButton minButton;
757
+ cButton maxButton;
758
+ cButton fullButton;
637759
638760 void ToggleFullScreen()
639761 {
640
- if (CameraPane.FULLSCREEN)
762
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
763
+
764
+ cameraView.ToggleFullScreen();
765
+
766
+ if (!CameraPane.FULLSCREEN)
641767 {
642768 device.setFullScreenWindow(null);
769
+ frame.dispose();
770
+ frame.setUndecorated(false);
771
+ frame.validate();
772
+ frame.setVisible(true);
773
+
643774 //frame.setVisible(false);
644775 // frame.removeNotify();
645776 // frame.setUndecorated(false);
....@@ -649,7 +780,7 @@
649780 // X frame.getContentPane().remove(/*"Center",*/bigThree);
650781 // X framePanel.add(bigThree);
651782 // X frame.getContentPane().add(/*"Center",*/framePanel);
652
- framePanel.setDividerLocation(1);
783
+ framePanel.setDividerLocation(46);
653784
654785 //frame.setVisible(true);
655786 radio.layout = keepButton;
....@@ -664,7 +795,12 @@
664795 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
665796 // frame.getToolkit().getScreenSize().height);
666797 //frame.setVisible(false);
798
+
799
+ frame.dispose();
800
+ frame.setUndecorated(true);
667801 device.setFullScreenWindow(frame);
802
+ frame.validate();
803
+ frame.setVisible(true);
668804 // frame.removeNotify();
669805 // frame.setUndecorated(true);
670806 // frame.addNotify();
....@@ -673,12 +809,11 @@
673809 // X frame.getContentPane().add(/*"Center",*/bigThree);
674810 framePanel.setDividerLocation(0);
675811
676
- radio.layout = twoButton;
812
+ radio.layout = fullscreenLayout;
677813 radio.layout.doClick();
678814 //frame.setVisible(true);
679815 }
680
-
681
- cameraView.ToggleFullScreen();
816
+ frame.validate();
682817 }
683818
684819 private JTextPane createTextPane()
....@@ -819,7 +954,12 @@
819954 JCheckBox speedupCB;
820955 JCheckBox rewindCB;
821956 JCheckBox flipVCB;
957
+
958
+ cCheckBox toggleTextureCB;
959
+ cCheckBox toggleSwitchCB;
960
+
822961 JComboBox texresMenu;
962
+
823963 JButton resetButton;
824964 JButton stepButton;
825965 JButton stepAllButton;
....@@ -1006,12 +1146,12 @@
10061146 namePanel = new cGridBag();
10071147
10081148 nameField = AddText(namePanel, copy.GetName());
1009
- namePanel.add(nameField);
1149
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
10101150 oe.ctrlPanel.add(namePanel);
10111151
10121152 oe.ctrlPanel.Return();
10131153
1014
- if (!GroupEditor.allparams)
1154
+ if (!allparams)
10151155 return;
10161156
10171157 setupPanel = new cGridBag().setVertical(false);
....@@ -1024,20 +1164,21 @@
10241164 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
10251165 hideCB.setToolTipText("Hide object");
10261166 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1027
- markCB.setToolTipText("Set the animation target transform");
1167
+ markCB.setToolTipText("As animation target transform");
10281168
10291169 setupPanel2 = new cGridBag().setVertical(false);
10301170
10311171 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
10321172 rewindCB.setToolTipText("Rewind animation");
10331173
1034
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1035
- 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)");
10361176
1177
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1178
+ link2masterCB.setToolTipText("Attach to support");
1179
+
10371180 if (Globals.ADVANCED)
10381181 {
1039
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1040
- link2masterCB.setToolTipText("Attach to support");
10411182 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
10421183 speedupCB.setToolTipText("Option motion capture");
10431184 }
....@@ -1353,7 +1494,11 @@
13531494 // north.add(ctrlPanel, BorderLayout.NORTH);
13541495 // objectPanel.add(north);
13551496 objectPanel.add(editPanel);
1356
- objectPanel.add(infoPanel);
1497
+
1498
+ //if (Globals.ADVANCED)
1499
+ objectPanel.add(infoPanel);
1500
+
1501
+ objectPanel.add(toolboxPanel);
13571502
13581503 /*
13591504 aConstraints.gridx = 0;
....@@ -1362,7 +1507,7 @@
13621507 aConstraints.gridy += 1;
13631508 aConstraints.gridwidth = 1;
13641509 mainPanel.add(objectPanel, aConstraints);
1365
- */
1510
+ */
13661511
13671512 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
13681513 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1379,9 +1524,7 @@
13791524 JTabbedPane tabbedPane = new JTabbedPane();
13801525 tabbedPane.add(scrollpane);
13811526
1382
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1383
-
1384
- optionsPanel = new cGridBag().setVertical(true);
1527
+ optionsPanel = new cGridBag().setVertical(false);
13851528
13861529 optionsPanel.setName("Options");
13871530
....@@ -1389,6 +1532,8 @@
13891532
13901533 tabbedPane.add(optionsPanel);
13911534
1535
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1536
+
13921537 scenePanel.add(tabbedPane);
13931538
13941539 /*
....@@ -1461,9 +1606,9 @@
14611606 // aConstraints.gridheight = 1;
14621607
14631608 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1464
- framePanel.setContinuousLayout(true);
1465
- framePanel.setOneTouchExpandable(true);
1466
- framePanel.setDividerLocation(0.8);
1609
+ framePanel.setContinuousLayout(false);
1610
+ framePanel.setOneTouchExpandable(false);
1611
+ //.setDividerLocation(0.8);
14671612 //framePanel.setDividerSize(15);
14681613 //framePanel.setResizeWeight(0.15);
14691614 framePanel.setName("Frame");
....@@ -1481,11 +1626,14 @@
14811626 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
14821627
14831628 frame.setSize(1280, 860);
1484
- frame.setVisible(true);
1485
-
1629
+
14861630 cameraView.requestFocusInWindow();
14871631
14881632 gridPanel.setDividerLocation(1.0);
1633
+
1634
+ frame.validate();
1635
+
1636
+ frame.setVisible(true);
14891637
14901638 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
14911639 frame.addWindowListener(new WindowAdapter()
....@@ -1572,24 +1720,6 @@
15721720 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
15731721 colorSection.add(texture);
15741722
1575
- cGridBag anisoU = new cGridBag();
1576
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1577
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1578
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1579
- colorSection.add(anisoU);
1580
-
1581
- cGridBag anisoV = new cGridBag();
1582
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1583
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1584
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1585
- colorSection.add(anisoV);
1586
-
1587
- cGridBag shadowbias = new cGridBag();
1588
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1589
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1590
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1591
- colorSection.add(shadowbias);
1592
-
15931723 panel.add(new JSeparator());
15941724
15951725 panel.add(colorSection);
....@@ -1639,6 +1769,12 @@
16391769 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
16401770 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
16411771 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);
16421778
16431779 panel.add(new JSeparator());
16441780
....@@ -1690,6 +1826,18 @@
16901826 // aConstraints.gridy += 1;
16911827 // aConstraints.gridwidth = 1;
16921828
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
+
16931841
16941842 panel.add(new JSeparator());
16951843
....@@ -1697,35 +1845,35 @@
16971845
16981846 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
16991847
1700
- cGridBag globalSection = new cGridBag().setVertical(true);
1848
+ //cGridBag globalSection = new cGridBag().setVertical(true);
17011849
17021850 cGridBag camera = new cGridBag();
17031851 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
17041852 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17051853 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1706
- globalSection.add(camera);
1854
+ colorSection.add(camera);
17071855
17081856 cGridBag ambient = new cGridBag();
17091857 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
17101858 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17111859 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1712
- globalSection.add(ambient);
1860
+ colorSection.add(ambient);
17131861
17141862 cGridBag backlit = new cGridBag();
17151863 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
17161864 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17171865 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1718
- globalSection.add(backlit);
1866
+ colorSection.add(backlit);
17191867
17201868 cGridBag opacity = new cGridBag();
17211869 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
17221870 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17231871 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1724
- globalSection.add(opacity);
1872
+ colorSection.add(opacity);
17251873
1726
- panel.add(new JSeparator());
1874
+ //panel.add(new JSeparator());
17271875
1728
- panel.add(globalSection);
1876
+ //panel.add(globalSection);
17291877
17301878 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17311879
....@@ -1832,8 +1980,9 @@
18321980 // 3D models
18331981 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
18341982 {
1835
- lastConverter = new com.jmex.model.converters.MaxToJme();
1836
- LoadFile(filename, lastConverter);
1983
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
1984
+ //LoadFile(filename, lastConverter);
1985
+ LoadObjFile(filename); // New 3ds loader
18371986 continue;
18381987 }
18391988 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2559,6 +2708,7 @@
25592708 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
25602709 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
25612710 }
2711
+
25622712 //cJME.count++;
25632713 //cJME.count %= 12;
25642714 if (gc)
....@@ -2742,6 +2892,7 @@
27422892 }
27432893 }
27442894 }
2895
+
27452896 cFileSystemPane FSPane;
27462897
27472898 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2795,11 +2946,14 @@
27952946 }
27962947 }
27972948 }
2949
+
27982950 freezematerial = false;
27992951 }
28002952
28012953 void SetMaterial(Object3D object)
28022954 {
2955
+ latestObject = object;
2956
+
28032957 cMaterial mat = object.material;
28042958
28052959 if (mat == null)
....@@ -2911,12 +3065,17 @@
29113065 // }
29123066
29133067 /**/
2914
- if (deselect)
3068
+ if (deselect || child == null)
29153069 {
29163070 //group.deselectAll();
29173071 //freeze = true;
29183072 GetTree().clearSelection();
29193073 //freeze = false;
3074
+
3075
+ if (child == null)
3076
+ {
3077
+ return;
3078
+ }
29203079 }
29213080
29223081 //group.addSelectee(child);
....@@ -2985,7 +3144,7 @@
29853144 cameraView.ToggleDL();
29863145 cameraView.repaint();
29873146 return;
2988
- } else if (event.getSource() == toggleTextureItem)
3147
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
29893148 {
29903149 cameraView.ToggleTexture();
29913150 // june 2013 copy.HardTouch();
....@@ -3024,7 +3183,7 @@
30243183 frame.validate();
30253184
30263185 return;
3027
- } else if (event.getSource() == toggleSwitchItem)
3186
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30283187 {
30293188 cameraView.ToggleSwitch();
30303189 cameraView.repaint();
....@@ -3240,9 +3399,9 @@
32403399 {
32413400 Close();
32423401 //return true;
3243
- } else if (source == loadItem)
3402
+ } else if (source == openItem)
32443403 {
3245
- load();
3404
+ Open();
32463405 //return true;
32473406 } else if (source == newItem)
32483407 {
....@@ -3267,6 +3426,10 @@
32673426 {
32683427 generatePOV();
32693428 //return true;
3429
+ } else if (event.getSource() == archiveItem)
3430
+ {
3431
+ cTools.Archive(frame);
3432
+ return;
32703433 } else if (source == zBufferItem)
32713434 {
32723435 try
....@@ -3318,8 +3481,8 @@
33183481 try
33193482 {
33203483 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3321
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3322
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3484
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3485
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
33233486
33243487 Object3D parent = o.parent;
33253488 o.parent = null;
....@@ -3330,10 +3493,14 @@
33303493
33313494 out.flush();
33323495
3333
- zstream.close();
3496
+ baos //zstream
3497
+ .close();
33343498 out.close();
33353499
3336
- return baos.toByteArray();
3500
+ byte[] bytes = baos.toByteArray();
3501
+
3502
+ System.out.println("save #bytes = " + bytes.length);
3503
+ return bytes;
33373504 } catch (Exception e)
33383505 {
33393506 System.err.println(e);
....@@ -3343,13 +3510,16 @@
33433510
33443511 static public Object Uncompress(byte[] bytes)
33453512 {
3346
- System.out.println("#bytes = " + bytes.length);
3513
+ System.out.println("restore #bytes = " + bytes.length);
33473514 try
33483515 {
33493516 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3350
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3351
- ObjectInputStream in = new ObjectInputStream(istream);
3517
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3518
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
33523519 Object obj = in.readObject();
3520
+
3521
+ bais //istream
3522
+ .close();
33533523 in.close();
33543524
33553525 return obj;
....@@ -3408,6 +3578,29 @@
34083578
34093579 public void Save()
34103580 {
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
+ {
3602
+ System.err.println("Save");
3603
+
34113604 cRadio tab = GetCurrentTab();
34123605
34133606 boolean temp = CameraPane.SWITCH;
....@@ -3415,20 +3608,42 @@
34153608
34163609 copy.ExtractBigData(hashtable);
34173610
3418
- //EditorFrame.m_MainFrame.requestFocusInWindow();
3419
- tab.graphs[tab.undoindex++] = Compress(copy);
3420
-
3421
- copy.RestoreBigData(hashtable);
3611
+ byte[] compress = Compress(copy);
34223612
34233613 CameraPane.SWITCH = temp;
34243614
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
+
34253637 //assert(hashtable.isEmpty());
34263638
34273639 for (int i = tab.undoindex; i < tab.graphs.length; i++)
34283640 {
3429
- tab.graphs[i] = null;
3641
+ //tab.user[i] = false;
3642
+ // tab.graphs[i] = null;
34303643 }
34313644
3645
+ SetUndoStates();
3646
+
34323647 // test save
34333648 if (false)
34343649 {
....@@ -3447,10 +3662,14 @@
34473662 e.printStackTrace();
34483663 }
34493664 }
3665
+
3666
+ return !thesame;
34503667 }
34513668
34523669 void CopyChanged(Object3D obj)
34533670 {
3671
+ SetUndoStates();
3672
+
34543673 boolean temp = CameraPane.SWITCH;
34553674 CameraPane.SWITCH = false;
34563675
....@@ -3490,25 +3709,47 @@
34903709 refreshContents();
34913710 }
34923711
3493
- public void Undo()
3712
+ cButton undoButton;
3713
+ cButton redoButton;
3714
+
3715
+ void SetUndoStates()
34943716 {
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()
3724
+ {
3725
+ System.err.println("Undo");
3726
+
34953727 cRadio tab = GetCurrentTab();
34963728
34973729 if (tab.undoindex == 0)
34983730 {
34993731 java.awt.Toolkit.getDefaultToolkit().beep();
3500
- return;
3732
+ return false;
35013733 }
35023734
3503
- if (tab.graphs[tab.undoindex] == null)
3735
+ if (tab.graphs[tab.undoindex] == null) // || !tab.user[tab.undoindex])
35043736 {
3505
- Save();
3506
- 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
+ }
35073746 }
35083747
35093748 tab.undoindex -= 1;
35103749
35113750 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3751
+
3752
+ return true;
35123753 }
35133754
35143755 public void Redo()
....@@ -3524,6 +3765,9 @@
35243765 tab.undoindex += 1;
35253766
35263767 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3768
+
3769
+ //if (!tab.user[tab.undoindex])
3770
+ // tab.graphs[tab.undoindex] = null;
35273771 }
35283772
35293773 void ImportGFD()
....@@ -3675,7 +3919,7 @@
36753919 assert false;
36763920 }
36773921
3678
- void EditSelection()
3922
+ void EditSelection(boolean newWindow)
36793923 {
36803924 }
36813925
....@@ -4170,7 +4414,8 @@
41704414
41714415 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
41724416 {
4173
- Save();
4417
+ if (Globals.SAVEONMAKE) // && resetmodel)
4418
+ Save();
41744419 //Tween.set(thing, 0).target(1).start(tweenManager);
41754420 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
41764421 // if (thing instanceof GenericJointDemo)
....@@ -4257,6 +4502,12 @@
42574502 {
42584503 ResetModel();
42594504 Select(thing.GetTreePath(), true, false); // unselect... false);
4505
+
4506
+ if (thing.Size() == 0)
4507
+ {
4508
+ //EditSelection(false);
4509
+ }
4510
+
42604511 refreshContents();
42614512 }
42624513
....@@ -4479,7 +4730,8 @@
44794730
44804731 if (readobj != null)
44814732 {
4482
- Save();
4733
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4734
+ // Save();
44834735 try
44844736 {
44854737 //readobj.deepCopySelf(copy);
....@@ -4540,7 +4792,7 @@
45404792 }
45414793 }
45424794
4543
- void load() // throws ClassNotFoundException
4795
+ void Open() // throws ClassNotFoundException
45444796 {
45454797 if (Grafreed.standAlone)
45464798 {
....@@ -4657,6 +4909,8 @@
46574909 String filename = browser.getFile();
46584910 if (filename != null && filename.length() > 0)
46594911 {
4912
+ if (!filename.endsWith(".gfd"))
4913
+ filename += ".gfd";
46604914 lastname = browser.getDirectory() + filename;
46614915 save();
46624916 }
....@@ -4823,7 +5077,7 @@
48235077 MenuBar menuBar;
48245078 Menu fileMenu;
48255079 MenuItem newItem;
4826
- MenuItem loadItem;
5080
+ MenuItem openItem;
48275081 MenuItem saveItem;
48285082 MenuItem saveAsItem;
48295083 MenuItem exportAsItem;
....@@ -4846,22 +5100,36 @@
48465100 CheckboxMenuItem toggleSwitchItem;
48475101 CheckboxMenuItem toggleRootItem;
48485102 CheckboxMenuItem animationItem;
5103
+ MenuItem archiveItem;
48495104 CheckboxMenuItem toggleHandleItem;
48505105 CheckboxMenuItem togglePaintItem;
48515106 JSplitPane mainPanel;
48525107 JScrollPane scrollpane;
5108
+
48535109 JPanel toolbarPanel;
5110
+
48545111 cGridBag treePanel;
5112
+
48555113 JPanel radioPanel;
48565114 ButtonGroup buttonGroup;
4857
- cGridBag ctrlPanel;
5115
+
5116
+ cGridBag toolboxPanel;
48585117 cGridBag materialPanel;
5118
+ cGridBag ctrlPanel;
5119
+
48595120 JScrollPane infoPanel;
5121
+
48605122 cGridBag optionsPanel;
5123
+
48615124 JTabbedPane objectPanel;
5125
+ boolean materialFlushed;
5126
+ Object3D latestObject;
5127
+
48625128 cGridBag XYZPanel;
5129
+
48635130 JSplitPane gridPanel;
48645131 JSplitPane bigPanel;
5132
+
48655133 cGridBag bigThree;
48665134 cGridBag scenePanel;
48675135 cGridBag centralPanel;
....@@ -4976,7 +5244,7 @@
49765244 cNumberSlider fogField;
49775245 JLabel opacityPowerLabel;
49785246 cNumberSlider opacityPowerField;
4979
- JTree jTree;
5247
+ cTree jTree;
49805248 //ObjectUI parent;
49815249
49825250 cNumberSlider normalpushField;