Normand Briere
2019-07-19 e79247ef52a0bbb3864d46bb1e2c716005b3ecf3
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.
....@@ -41,61 +44,47 @@
4144
4245 cButton GetButton(String name, boolean border)
4346 {
44
- try
45
- {
46
- ImageIcon icon = GetIcon(name);
47
- return new cButton(icon, border);
48
- }
49
- catch (Exception e)
50
- {
51
- return new cButton(name, border);
52
- }
47
+ ImageIcon icon = GetIcon(name);
48
+ return new cButton(icon, border);
5349 }
5450
5551 cToggleButton GetToggleButton(String name, boolean border)
5652 {
57
- try
58
- {
59
- ImageIcon icon = GetIcon(name);
60
- return new cToggleButton(icon, border);
61
- }
62
- catch (Exception e)
63
- {
64
- return new cToggleButton(name, border);
65
- }
53
+ ImageIcon icon = GetIcon(name);
54
+ return new cToggleButton(icon, border);
6655 }
6756
6857 cCheckBox GetCheckBox(String name, boolean border)
6958 {
59
+ ImageIcon icon = GetIcon(name);
60
+ return new cCheckBox(icon, border);
61
+ }
62
+
63
+ private ImageIcon GetIcon(String name)
64
+ {
7065 try
7166 {
72
- ImageIcon icon = GetIcon(name);
73
- return new cCheckBox(icon, border);
67
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
68
+
69
+ if (image.getWidth() != 24 && image.getHeight() != 24)
70
+ {
71
+ BufferedImage resized = new BufferedImage(24, 24, image.getType());
72
+ Graphics2D g = resized.createGraphics();
73
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
74
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
75
+ g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
76
+ g.dispose();
77
+
78
+ image = resized;
79
+ }
80
+
81
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
82
+ return icon;
7483 }
7584 catch (Exception e)
7685 {
77
- return new cCheckBox(name, border);
86
+ return null;
7887 }
79
- }
80
-
81
- private ImageIcon GetIcon(String name) throws IOException
82
- {
83
- BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
84
-
85
- if (image.getWidth() != 24 && image.getHeight() != 24)
86
- {
87
- BufferedImage resized = new BufferedImage(24, 24, image.getType());
88
- Graphics2D g = resized.createGraphics();
89
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
90
- //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
91
- g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
92
- g.dispose();
93
-
94
- image = resized;
95
- }
96
-
97
- javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
98
- return icon;
9988 }
10089
10190 // SCRIPT
....@@ -279,6 +268,12 @@
279268 client = inClient;
280269 copy = client;
281270
271
+ if (copy.versions == null)
272
+ {
273
+ copy.versions = new byte[100][];
274
+ copy.versionindex = -1;
275
+ }
276
+
282277 // "this" is not called: SetupUI2(objEditor);
283278 }
284279
....@@ -292,6 +287,12 @@
292287 client = inClient;
293288 copy = client;
294289
290
+ if (copy.versions == null)
291
+ {
292
+ copy.versions = new byte[100][];
293
+ copy.versionindex = -1;
294
+ }
295
+
295296 SetupUI2(callee.GetEditor());
296297 }
297298
....@@ -306,7 +307,7 @@
306307 //localCopy.parent = null;
307308
308309 frame = new JFrame();
309
- frame.setUndecorated(true);
310
+ frame.setUndecorated(false);
310311 objEditor = this;
311312 this.callee = callee;
312313
....@@ -324,6 +325,12 @@
324325 copy = localCopy;
325326 copy.editWindow = this;
326327
328
+ if (copy.versions == null)
329
+ {
330
+ copy.versions = new byte[100][];
331
+ copy.versionindex = -1;
332
+ }
333
+
327334 SetupMenu();
328335
329336 //SetupName(objEditor); // new
....@@ -347,7 +354,7 @@
347354 frame.setMenuBar(menuBar = new MenuBar());
348355 menuBar.add(fileMenu = new Menu("File"));
349356 fileMenu.add(newItem = new MenuItem("New"));
350
- fileMenu.add(loadItem = new MenuItem("Open..."));
357
+ fileMenu.add(openItem = new MenuItem("Open..."));
351358
352359 //oe.menuBar.add(menu = new Menu("Include"));
353360 Menu menu = new Menu("Import");
....@@ -379,7 +386,7 @@
379386 }
380387
381388 newItem.addActionListener(this);
382
- loadItem.addActionListener(this);
389
+ openItem.addActionListener(this);
383390 saveItem.addActionListener(this);
384391 saveAsItem.addActionListener(this);
385392 exportAsItem.addActionListener(this);
....@@ -416,11 +423,12 @@
416423
417424 toolbarPanel = new JPanel();
418425 toolbarPanel.setName("Toolbar");
426
+
419427 treePanel = new cGridBag();
420428 treePanel.setName("Tree");
421429
422430 editPanel = new cGridBag().setVertical(true);
423
- editPanel.setName("Edit");
431
+ //editPanel.setName("Edit");
424432
425433 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
426434
....@@ -429,10 +437,10 @@
429437 editPanel.add(ctrlPanel);
430438
431439 toolboxPanel = new cGridBag().setVertical(false);
432
- toolboxPanel.setName("Toolbox");
440
+ //toolboxPanel.setName("Toolbox");
433441
434442 materialPanel = new cGridBag().setVertical(true);
435
- materialPanel.setName("Material");
443
+ //materialPanel.setName("Material");
436444
437445 /*JTextPane*/
438446 infoarea = createTextPane();
....@@ -440,14 +448,15 @@
440448
441449 infoarea.setEditable(true);
442450 SetText();
451
+
443452 // infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
444453 // infoarea.setOpaque(false);
445454 // //infoarea.setForeground(textcolor);
446455 // TEXTAREA infoarea.setLineWrap(true);
447456 // TEXTAREA infoarea.setWrapStyleWord(true);
448457 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
449
- infoPanel.setPreferredSize(new Dimension(50, 200));
450
- infoPanel.setName("Info");
458
+ infoPanel.setPreferredSize(new Dimension(1, 1));
459
+ //infoPanel.setName("Info");
451460 //infoPanel.setLayout(new BorderLayout());
452461 //infoPanel.add(createTextPane());
453462
....@@ -458,7 +467,14 @@
458467 mainPanel.setDividerSize(9);
459468 mainPanel.setDividerLocation(0.5); //1.0);
460469 mainPanel.setResizeWeight(0.5);
461
-
470
+
471
+//mainPanel.setDividerSize((int) (mainPanel.getDividerSize() * 1.5));
472
+ BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) mainPanel.getUI()).getDivider();
473
+ divider.setDividerSize(15);
474
+ divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!"));
475
+
476
+ mainPanel.setUI(new BasicSplitPaneUI());
477
+
462478 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
463479 //mainPanel.setLayout(new GridBagLayout());
464480 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -689,8 +705,8 @@
689705 }
690706 }
691707
692
-static GraphicsDevice device = GraphicsEnvironment
693
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
708
+//static GraphicsDevice device = GraphicsEnvironment
709
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
694710
695711 Rectangle keeprect;
696712 cRadio radio;
....@@ -711,10 +727,19 @@
711727 void Minimize()
712728 {
713729 frame.setState(Frame.ICONIFIED);
730
+ frame.validate();
714731 }
715732
733
+// artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={}
734
+// artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={}
735
+// artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={}
716736 void Maximize()
717737 {
738
+ if (CameraPane.FULLSCREEN)
739
+ {
740
+ ToggleFullScreen();
741
+ }
742
+
718743 if (maximized)
719744 {
720745 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -722,22 +747,36 @@
722747 else
723748 {
724749 keeprect = frame.getBounds();
725
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
726
- Dimension rect2 = frame.getToolkit().getScreenSize();
727
- frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
750
+// Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
751
+// Dimension rect2 = frame.getToolkit().getScreenSize();
752
+// frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
728753 // frame.setState(Frame.MAXIMIZED_BOTH);
754
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
729755 }
730756
731757 maximized ^= true;
758
+
759
+ frame.validate();
732760 }
761
+
762
+ cButton minButton;
763
+ cButton maxButton;
764
+ cButton fullButton;
733765
734766 void ToggleFullScreen()
735767 {
768
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
769
+
736770 cameraView.ToggleFullScreen();
737771
738772 if (!CameraPane.FULLSCREEN)
739773 {
740774 device.setFullScreenWindow(null);
775
+ frame.dispose();
776
+ frame.setUndecorated(false);
777
+ frame.validate();
778
+ frame.setVisible(true);
779
+
741780 //frame.setVisible(false);
742781 // frame.removeNotify();
743782 // frame.setUndecorated(false);
....@@ -747,7 +786,7 @@
747786 // X frame.getContentPane().remove(/*"Center",*/bigThree);
748787 // X framePanel.add(bigThree);
749788 // X frame.getContentPane().add(/*"Center",*/framePanel);
750
- framePanel.setDividerLocation(1);
789
+ framePanel.setDividerLocation(46);
751790
752791 //frame.setVisible(true);
753792 radio.layout = keepButton;
....@@ -762,7 +801,12 @@
762801 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
763802 // frame.getToolkit().getScreenSize().height);
764803 //frame.setVisible(false);
804
+
805
+ frame.dispose();
806
+ frame.setUndecorated(true);
765807 device.setFullScreenWindow(frame);
808
+ frame.validate();
809
+ frame.setVisible(true);
766810 // frame.removeNotify();
767811 // frame.setUndecorated(true);
768812 // frame.addNotify();
....@@ -775,7 +819,30 @@
775819 radio.layout.doClick();
776820 //frame.setVisible(true);
777821 }
822
+ frame.validate();
778823 }
824
+
825
+ private byte[] CompressCopy()
826
+ {
827
+ boolean temp = CameraPane.SWITCH;
828
+ CameraPane.SWITCH = false;
829
+
830
+ copy.ExtractBigData(versiontable);
831
+ // if (copy == client)
832
+
833
+ byte[] versions[] = copy.versions;
834
+ copy.versions = null;
835
+
836
+ byte[] compress = Compress(copy);
837
+
838
+ copy.versions = versions;
839
+
840
+ copy.RestoreBigData(versiontable);
841
+
842
+ CameraPane.SWITCH = temp;
843
+
844
+ return compress;
845
+ }
779846
780847 private JTextPane createTextPane()
781848 {
....@@ -1107,7 +1174,7 @@
11071174 namePanel = new cGridBag();
11081175
11091176 nameField = AddText(namePanel, copy.GetName());
1110
- namePanel.add(nameField);
1177
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
11111178 oe.ctrlPanel.add(namePanel);
11121179
11131180 oe.ctrlPanel.Return();
....@@ -1125,20 +1192,21 @@
11251192 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
11261193 hideCB.setToolTipText("Hide object");
11271194 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1128
- markCB.setToolTipText("Set the animation target transform");
1195
+ markCB.setToolTipText("As animation target transform");
11291196
11301197 setupPanel2 = new cGridBag().setVertical(false);
11311198
11321199 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
11331200 rewindCB.setToolTipText("Rewind animation");
11341201
1135
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1136
- randomCB.setToolTipText("Randomly Rewind or Go back and forth");
1202
+ randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
1203
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11371204
1205
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1206
+ link2masterCB.setToolTipText("Attach to support");
1207
+
11381208 if (Globals.ADVANCED)
11391209 {
1140
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1141
- link2masterCB.setToolTipText("Attach to support");
11421210 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11431211 speedupCB.setToolTipText("Option motion capture");
11441212 }
....@@ -1412,6 +1480,7 @@
14121480 XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll);
14131481 XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll);
14141482 XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
1483
+ //XYZPanel.setName("XYZ");
14151484
14161485 /*
14171486 gridPanel = new JPanel(); //new BorderLayout());
....@@ -1449,13 +1518,23 @@
14491518 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14501519 //tmp.setName("Edit");
14511520 objectPanel.add(materialPanel);
1521
+ objectPanel.setIconAt(0, GetIcon("icons/material.png"));
14521522 // JPanel north = new JPanel(new BorderLayout());
14531523 // north.setName("Edit");
14541524 // north.add(ctrlPanel, BorderLayout.NORTH);
14551525 // objectPanel.add(north);
14561526 objectPanel.add(editPanel);
1457
- objectPanel.add(infoPanel);
1527
+ objectPanel.setIconAt(1, GetIcon("icons/write.png"));
1528
+
1529
+ //if (Globals.ADVANCED)
1530
+ objectPanel.add(infoPanel);
1531
+ objectPanel.setIconAt(2, GetIcon("icons/info.png"));
1532
+
1533
+ objectPanel.add(XYZPanel);
1534
+ objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
1535
+
14581536 objectPanel.add(toolboxPanel);
1537
+ objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
14591538
14601539 /*
14611540 aConstraints.gridx = 0;
....@@ -1476,7 +1555,7 @@
14761555 scrollpane.addMouseWheelListener(this); // Default not fast enough
14771556
14781557 /*JTabbedPane*/ scenePanel = new cGridBag();
1479
- scenePanel.preferredWidth = 6;
1558
+ scenePanel.preferredWidth = 5;
14801559
14811560 JTabbedPane tabbedPane = new JTabbedPane();
14821561 tabbedPane.add(scrollpane);
....@@ -1554,7 +1633,7 @@
15541633 bigThree = new cGridBag();
15551634 bigThree.addComponent(scenePanel);
15561635 bigThree.addComponent(centralPanel);
1557
- bigThree.addComponent(XYZPanel);
1636
+ //bigThree.addComponent(XYZPanel);
15581637
15591638 // // SIDE EFFECT!!!
15601639 // aConstraints.gridx = 0;
....@@ -1563,9 +1642,9 @@
15631642 // aConstraints.gridheight = 1;
15641643
15651644 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1566
- framePanel.setContinuousLayout(true);
1567
- framePanel.setOneTouchExpandable(true);
1568
- framePanel.setDividerLocation(0.8);
1645
+ framePanel.setContinuousLayout(false);
1646
+ framePanel.setOneTouchExpandable(false);
1647
+ //.setDividerLocation(0.8);
15691648 //framePanel.setDividerSize(15);
15701649 //framePanel.setResizeWeight(0.15);
15711650 framePanel.setName("Frame");
....@@ -1584,12 +1663,13 @@
15841663
15851664 frame.setSize(1280, 860);
15861665
1587
- frame.validate();
1588
- frame.setVisible(true);
1589
-
15901666 cameraView.requestFocusInWindow();
15911667
15921668 gridPanel.setDividerLocation(1.0);
1669
+
1670
+ frame.validate();
1671
+
1672
+ frame.setVisible(true);
15931673
15941674 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
15951675 frame.addWindowListener(new WindowAdapter()
....@@ -1676,24 +1756,6 @@
16761756 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16771757 colorSection.add(texture);
16781758
1679
- cGridBag anisoU = new cGridBag();
1680
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1681
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1682
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1683
- colorSection.add(anisoU);
1684
-
1685
- cGridBag anisoV = new cGridBag();
1686
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1687
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1688
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1689
- colorSection.add(anisoV);
1690
-
1691
- cGridBag shadowbias = new cGridBag();
1692
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1693
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1694
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1695
- colorSection.add(shadowbias);
1696
-
16971759 panel.add(new JSeparator());
16981760
16991761 panel.add(colorSection);
....@@ -1743,6 +1805,12 @@
17431805 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17441806 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17451807 diffuseSection.add(fakedepth);
1808
+
1809
+ cGridBag shadowbias = new cGridBag();
1810
+ shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1811
+ shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1812
+ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1813
+ diffuseSection.add(shadowbias);
17461814
17471815 panel.add(new JSeparator());
17481816
....@@ -1794,6 +1862,18 @@
17941862 // aConstraints.gridy += 1;
17951863 // aConstraints.gridwidth = 1;
17961864
1865
+ cGridBag anisoU = new cGridBag();
1866
+ anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1867
+ anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1868
+ anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1869
+ specularSection.add(anisoU);
1870
+
1871
+ cGridBag anisoV = new cGridBag();
1872
+ anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1873
+ anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1874
+ anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1875
+ specularSection.add(anisoV);
1876
+
17971877
17981878 panel.add(new JSeparator());
17991879
....@@ -1801,35 +1881,35 @@
18011881
18021882 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
18031883
1804
- cGridBag globalSection = new cGridBag().setVertical(true);
1884
+ //cGridBag globalSection = new cGridBag().setVertical(true);
18051885
18061886 cGridBag camera = new cGridBag();
18071887 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
18081888 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18091889 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1810
- globalSection.add(camera);
1890
+ colorSection.add(camera);
18111891
18121892 cGridBag ambient = new cGridBag();
18131893 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
18141894 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18151895 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1816
- globalSection.add(ambient);
1896
+ colorSection.add(ambient);
18171897
18181898 cGridBag backlit = new cGridBag();
18191899 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
18201900 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18211901 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1822
- globalSection.add(backlit);
1902
+ colorSection.add(backlit);
18231903
18241904 cGridBag opacity = new cGridBag();
18251905 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
18261906 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18271907 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1828
- globalSection.add(opacity);
1908
+ colorSection.add(opacity);
18291909
1830
- panel.add(new JSeparator());
1910
+ //panel.add(new JSeparator());
18311911
1832
- panel.add(globalSection);
1912
+ //panel.add(globalSection);
18331913
18341914 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
18351915
....@@ -1936,8 +2016,9 @@
19362016 // 3D models
19372017 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19382018 {
1939
- lastConverter = new com.jmex.model.converters.MaxToJme();
1940
- LoadFile(filename, lastConverter);
2019
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2020
+ //LoadFile(filename, lastConverter);
2021
+ LoadObjFile(filename); // New 3ds loader
19412022 continue;
19422023 }
19432024 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2663,6 +2744,7 @@
26632744 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26642745 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26652746 }
2747
+
26662748 //cJME.count++;
26672749 //cJME.count %= 12;
26682750 if (gc)
....@@ -2846,6 +2928,7 @@
28462928 }
28472929 }
28482930 }
2931
+
28492932 cFileSystemPane FSPane;
28502933
28512934 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2899,6 +2982,7 @@
28992982 }
29002983 }
29012984 }
2985
+
29022986 freezematerial = false;
29032987 }
29042988
....@@ -3017,12 +3101,17 @@
30173101 // }
30183102
30193103 /**/
3020
- if (deselect)
3104
+ if (deselect || child == null)
30213105 {
30223106 //group.deselectAll();
30233107 //freeze = true;
30243108 GetTree().clearSelection();
30253109 //freeze = false;
3110
+
3111
+ if (child == null)
3112
+ {
3113
+ return;
3114
+ }
30263115 }
30273116
30283117 //group.addSelectee(child);
....@@ -3346,9 +3435,9 @@
33463435 {
33473436 Close();
33483437 //return true;
3349
- } else if (source == loadItem)
3438
+ } else if (source == openItem)
33503439 {
3351
- load();
3440
+ Open();
33523441 //return true;
33533442 } else if (source == newItem)
33543443 {
....@@ -3373,6 +3462,10 @@
33733462 {
33743463 generatePOV();
33753464 //return true;
3465
+ } else if (event.getSource() == archiveItem)
3466
+ {
3467
+ cTools.Archive(frame);
3468
+ return;
33763469 } else if (source == zBufferItem)
33773470 {
33783471 try
....@@ -3424,8 +3517,8 @@
34243517 try
34253518 {
34263519 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3427
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3428
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3520
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3521
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34293522
34303523 Object3D parent = o.parent;
34313524 o.parent = null;
....@@ -3436,10 +3529,14 @@
34363529
34373530 out.flush();
34383531
3439
- zstream.close();
3532
+ baos //zstream
3533
+ .close();
34403534 out.close();
34413535
3442
- return baos.toByteArray();
3536
+ byte[] bytes = baos.toByteArray();
3537
+
3538
+ System.out.println("save #bytes = " + bytes.length);
3539
+ return bytes;
34433540 } catch (Exception e)
34443541 {
34453542 System.err.println(e);
....@@ -3449,13 +3546,16 @@
34493546
34503547 static public Object Uncompress(byte[] bytes)
34513548 {
3452
- System.out.println("#bytes = " + bytes.length);
3549
+ System.out.println("restore #bytes = " + bytes.length);
34533550 try
34543551 {
34553552 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3456
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3457
- ObjectInputStream in = new ObjectInputStream(istream);
3553
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3554
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
34583555 Object obj = in.readObject();
3556
+
3557
+ bais //istream
3558
+ .close();
34593559 in.close();
34603560
34613561 return obj;
....@@ -3510,31 +3610,67 @@
35103610 return null;
35113611 }
35123612
3513
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35143613
35153614 public void Save()
3615
+ {
3616
+ //Save(true);
3617
+ Replace();
3618
+ }
3619
+
3620
+ private boolean Equal(byte[] compress, byte[] name)
3621
+ {
3622
+ if (compress.length != name.length)
3623
+ {
3624
+ return false;
3625
+ }
3626
+
3627
+ for (int i=compress.length; --i>=0;)
3628
+ {
3629
+ if (compress[i] != name[i])
3630
+ return false;
3631
+ }
3632
+
3633
+ return true;
3634
+ }
3635
+
3636
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3637
+
3638
+ public boolean Save(boolean user)
35163639 {
35173640 System.err.println("Save");
35183641
35193642 cRadio tab = GetCurrentTab();
35203643
3521
- boolean temp = CameraPane.SWITCH;
3522
- CameraPane.SWITCH = false;
3644
+ byte[] compress = CompressCopy();
35233645
3524
- copy.ExtractBigData(hashtable);
3646
+ boolean thesame = false;
3647
+
3648
+ // Quick heuristic using length. Works only when stream is compressed.
3649
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3650
+ {
3651
+ thesame = true;
3652
+ }
35253653
35263654 //EditorFrame.m_MainFrame.requestFocusInWindow();
3527
- tab.graphs[tab.undoindex++] = Compress(copy);
3655
+ if (!thesame)
3656
+ {
3657
+ //tab.user[tab.versionindex] = user;
3658
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3659
+
3660
+ copy.versions[++copy.versionindex] = compress;
3661
+
3662
+ // if (increment)
3663
+ // tab.versionindex++;
3664
+ }
35283665
3529
- copy.RestoreBigData(hashtable);
3666
+ //copy.RestoreBigData(versiontable);
35303667
3531
- CameraPane.SWITCH = temp;
3532
-
35333668 //assert(hashtable.isEmpty());
35343669
3535
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3670
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
35363671 {
3537
- tab.graphs[i] = null;
3672
+ //tab.user[i] = false;
3673
+ copy.versions[i] = null;
35383674 }
35393675
35403676 SetUndoStates();
....@@ -3544,7 +3680,7 @@
35443680 {
35453681 try
35463682 {
3547
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3683
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
35483684 ObjectOutputStream p = new ObjectOutputStream(ostream);
35493685
35503686 p.writeObject(copy);
....@@ -3557,6 +3693,8 @@
35573693 e.printStackTrace();
35583694 }
35593695 }
3696
+
3697
+ return !thesame;
35603698 }
35613699
35623700 void CopyChanged(Object3D obj)
....@@ -3566,7 +3704,7 @@
35663704 boolean temp = CameraPane.SWITCH;
35673705 CameraPane.SWITCH = false;
35683706
3569
- copy.ExtractBigData(hashtable);
3707
+ copy.ExtractBigData(versiontable);
35703708
35713709 copy.clear();
35723710
....@@ -3575,7 +3713,7 @@
35753713 copy.add(obj.get(i));
35763714 }
35773715
3578
- copy.RestoreBigData(hashtable);
3716
+ copy.RestoreBigData(versiontable);
35793717
35803718 CameraPane.SWITCH = temp;
35813719
....@@ -3603,52 +3741,129 @@
36033741 }
36043742
36053743 cButton undoButton;
3744
+ cButton restoreButton;
3745
+ cButton replaceButton;
36063746 cButton redoButton;
36073747
3748
+ boolean muteSlider;
3749
+
3750
+ int VersionCount()
3751
+ {
3752
+ int count = 0;
3753
+
3754
+ for (int i = copy.versions.length; --i >= 0;)
3755
+ {
3756
+ if (copy.versions[i] != null)
3757
+ count++;
3758
+ }
3759
+
3760
+ return count;
3761
+ }
3762
+
36083763 void SetUndoStates()
36093764 {
36103765 cRadio tab = GetCurrentTab();
36113766
3612
- undoButton.setEnabled(tab.undoindex > 0);
3613
- redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3767
+ restoreButton.setEnabled(copy.versionindex != -1);
3768
+ replaceButton.setEnabled(copy.versionindex != -1);
3769
+
3770
+ undoButton.setEnabled(copy.versionindex > 0);
3771
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3772
+
3773
+ muteSlider = true;
3774
+ versionSlider.setMaximum(VersionCount() - 1);
3775
+ versionSlider.setInteger(copy.versionindex);
3776
+ muteSlider = false;
36143777 }
36153778
3616
- public void Undo()
3779
+ public boolean Undo()
36173780 {
3781
+ // Option?
3782
+ Replace();
3783
+
36183784 System.err.println("Undo");
36193785
36203786 cRadio tab = GetCurrentTab();
36213787
3622
- if (tab.undoindex == 0)
3788
+ if (copy.versionindex == 0)
36233789 {
36243790 java.awt.Toolkit.getDefaultToolkit().beep();
3625
- return;
3791
+ return false;
36263792 }
36273793
3628
- if (tab.graphs[tab.undoindex] == null)
3794
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3795
+// {
3796
+// if (Save(false))
3797
+// tab.versionindex -= 1;
3798
+// else
3799
+// {
3800
+// if (tab.versionindex <= 0)
3801
+// return false;
3802
+// else
3803
+// tab.versionindex -= 1;
3804
+// }
3805
+// }
3806
+
3807
+ copy.versionindex -= 1;
3808
+
3809
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3810
+
3811
+ return true;
3812
+ }
3813
+
3814
+ public boolean Restore()
3815
+ {
3816
+ System.err.println("Restore");
3817
+
3818
+ cRadio tab = GetCurrentTab();
3819
+
3820
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
36293821 {
3630
- Save();
3631
- tab.undoindex -= 1;
3822
+ java.awt.Toolkit.getDefaultToolkit().beep();
3823
+ return false;
36323824 }
36333825
3634
- tab.undoindex -= 1;
3826
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3827
+
3828
+ return true;
3829
+ }
36353830
3636
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3831
+ public boolean Replace()
3832
+ {
3833
+ System.err.println("Replace");
3834
+
3835
+ cRadio tab = GetCurrentTab();
3836
+
3837
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3838
+ {
3839
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3840
+ return false;
3841
+ }
3842
+
3843
+ copy.versions[copy.versionindex] = CompressCopy();
3844
+
3845
+ return true;
36373846 }
36383847
36393848 public void Redo()
36403849 {
3850
+ // Option?
3851
+ Replace();
3852
+
36413853 cRadio tab = GetCurrentTab();
36423854
3643
- if (tab.graphs[tab.undoindex + 1] == null)
3855
+ if (copy.versions[copy.versionindex + 1] == null)
36443856 {
36453857 java.awt.Toolkit.getDefaultToolkit().beep();
36463858 return;
36473859 }
36483860
3649
- tab.undoindex += 1;
3861
+ copy.versionindex += 1;
36503862
3651
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3863
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3864
+
3865
+ //if (!tab.user[tab.versionindex])
3866
+ // tab.graphs[tab.versionindex] = null;
36523867 }
36533868
36543869 void ImportGFD()
....@@ -3944,9 +4159,25 @@
39444159 //copy.Touch();
39454160 }
39464161
4162
+ cNumberSlider versionSlider;
4163
+
39474164 public void stateChanged(ChangeEvent e)
39484165 {
39494166 // assert(false);
4167
+ if (e.getSource() == versionSlider)
4168
+ {
4169
+ if (muteSlider)
4170
+ return;
4171
+
4172
+ int version = versionSlider.getInteger();
4173
+
4174
+ if (copy.versions[version] != null)
4175
+ {
4176
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4177
+ }
4178
+
4179
+ return;
4180
+ }
39504181
39514182 if (freezematerial)
39524183 {
....@@ -4295,7 +4526,7 @@
42954526
42964527 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
42974528 {
4298
- if (Globals.SAVEONMAKE) // && resetmodel)
4529
+ if (Globals.REPLACEONMAKE) // && resetmodel)
42994530 Save();
43004531 //Tween.set(thing, 0).target(1).start(tweenManager);
43014532 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4611,8 +4842,8 @@
46114842
46124843 if (readobj != null)
46134844 {
4614
- if (Globals.SAVEONMAKE)
4615
- Save();
4845
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4846
+ // Save();
46164847 try
46174848 {
46184849 //readobj.deepCopySelf(copy);
....@@ -4667,13 +4898,24 @@
46674898 c.addChild(csg);
46684899 }
46694900
4901
+ copy.versions = readobj.versions;
4902
+ copy.versionindex = readobj.versionindex;
4903
+
4904
+ if (copy.versions == null)
4905
+ {
4906
+ copy.versions = new byte[100][];
4907
+ copy.versionindex = -1;
4908
+ }
4909
+
4910
+ //? SetUndoStates();
4911
+
46704912 ResetModel();
46714913 copy.HardTouch(); // recompile?
46724914 refreshContents();
46734915 }
46744916 }
46754917
4676
- void load() // throws ClassNotFoundException
4918
+ void Open() // throws ClassNotFoundException
46774919 {
46784920 if (Grafreed.standAlone)
46794921 {
....@@ -4958,7 +5200,7 @@
49585200 MenuBar menuBar;
49595201 Menu fileMenu;
49605202 MenuItem newItem;
4961
- MenuItem loadItem;
5203
+ MenuItem openItem;
49625204 MenuItem saveItem;
49635205 MenuItem saveAsItem;
49645206 MenuItem exportAsItem;
....@@ -4981,6 +5223,7 @@
49815223 CheckboxMenuItem toggleSwitchItem;
49825224 CheckboxMenuItem toggleRootItem;
49835225 CheckboxMenuItem animationItem;
5226
+ MenuItem archiveItem;
49845227 CheckboxMenuItem toggleHandleItem;
49855228 CheckboxMenuItem togglePaintItem;
49865229 JSplitPane mainPanel;