Normand Briere
2019-06-27 f78dd18c66d607b693c0bf5937fc59181bf5a26b
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
....@@ -35,6 +39,67 @@
3539
3640 GroupEditor callee;
3741 JFrame frame;
42
+
43
+ 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
+ }
38103
39104 // SCRIPT
40105
....@@ -145,7 +210,7 @@
145210
146211 objEditor.ctrlPanel.remove(namePanel);
147212
148
- if (!GroupEditor.allparams)
213
+ if (!allparams)
149214 return;
150215
151216 // objEditor.ctrlPanel.remove(liveCB);
....@@ -168,7 +233,8 @@
168233 // objEditor.ctrlPanel.remove(remarkButton);
169234
170235 objEditor.ctrlPanel.remove(setupPanel);
171
- objEditor.ctrlPanel.remove(commandsPanel);
236
+ objEditor.ctrlPanel.remove(setupPanel2);
237
+ objEditor.ctrlPanel.remove(objectCommandsPanel);
172238 objEditor.ctrlPanel.remove(pushPanel);
173239 //objEditor.ctrlPanel.remove(fillPanel);
174240
....@@ -243,6 +309,7 @@
243309 //localCopy.parent = null;
244310
245311 frame = new JFrame();
312
+ frame.setUndecorated(true);
246313 objEditor = this;
247314 this.callee = callee;
248315
....@@ -273,12 +340,17 @@
273340 return frame.action(event, obj);
274341 }
275342
343
+ // Cannot work without static
344
+ static boolean allparams = true;
345
+
346
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
347
+
276348 void SetupMenu()
277349 {
278350 frame.setMenuBar(menuBar = new MenuBar());
279351 menuBar.add(fileMenu = new Menu("File"));
280352 fileMenu.add(newItem = new MenuItem("New"));
281
- fileMenu.add(loadItem = new MenuItem("Load..."));
353
+ fileMenu.add(loadItem = new MenuItem("Open..."));
282354
283355 //oe.menuBar.add(menu = new Menu("Include"));
284356 Menu menu = new Menu("Import");
....@@ -319,14 +391,52 @@
319391 closeItem.addActionListener(this);
320392
321393 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
+
322420 toolbarPanel = new JPanel();
323421 toolbarPanel.setName("Toolbar");
324422 treePanel = new cGridBag();
325423 treePanel.setName("Tree");
424
+
425
+ editPanel = new cGridBag().setVertical(true);
426
+ editPanel.setName("Edit");
427
+
326428 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
327
- ctrlPanel.setName("Edit");
429
+
430
+ editCommandsPanel = new cGridBag();
431
+ editPanel.add(editCommandsPanel);
432
+ editPanel.add(ctrlPanel);
433
+
434
+ toolboxPanel = new cGridBag().setVertical(false);
435
+ toolboxPanel.setName("Toolbox");
436
+
328437 materialPanel = new cGridBag().setVertical(true);
329438 materialPanel.setName("Material");
439
+
330440 /*JTextPane*/
331441 infoarea = createTextPane();
332442 doc = infoarea.getStyledDocument();
....@@ -351,7 +461,13 @@
351461 mainPanel.setDividerSize(9);
352462 mainPanel.setDividerLocation(0.5); //1.0);
353463 mainPanel.setResizeWeight(0.5);
354
-
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
+
355471 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
356472 //mainPanel.setLayout(new GridBagLayout());
357473 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -419,10 +535,10 @@
419535 e.printStackTrace();
420536 }
421537
422
- String selection = infoarea.getText();
423
- java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
424
- java.awt.datatransfer.Clipboard clipboard =
425
- Toolkit.getDefaultToolkit().getSystemClipboard();
538
+// String selection = infoarea.getText();
539
+// java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
540
+// java.awt.datatransfer.Clipboard clipboard =
541
+// Toolkit.getDefaultToolkit().getSystemClipboard();
426542 //clipboard.setContents(data, data);
427543 }
428544
....@@ -582,20 +698,92 @@
582698 }
583699 }
584700
701
+static GraphicsDevice device = GraphicsEnvironment
702
+ .getLocalGraphicsEnvironment().getScreenDevices()[0];
703
+
704
+ Rectangle keeprect;
705
+ cRadio radio;
706
+
707
+cButton keepButton;
708
+ cButton twoButton; // Full 3D
709
+ cButton sixButton;
710
+ cButton threeButton;
711
+ cButton sevenButton;
712
+ cButton fourButton; // full panel
713
+ cButton oneButton; // full XYZ
714
+ //cButton currentLayout;
715
+
716
+ boolean maximized;
717
+
718
+ cButton fullscreenLayout;
719
+
720
+ void Minimize()
721
+ {
722
+ frame.setState(Frame.ICONIFIED);
723
+ }
724
+
725
+ void Maximize()
726
+ {
727
+ if (maximized)
728
+ {
729
+ frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
730
+ }
731
+ else
732
+ {
733
+ keeprect = frame.getBounds();
734
+ Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
735
+ Dimension rect2 = frame.getToolkit().getScreenSize();
736
+ frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
737
+// frame.setState(Frame.MAXIMIZED_BOTH);
738
+ }
739
+
740
+ maximized ^= true;
741
+ }
742
+
585743 void ToggleFullScreen()
586744 {
587
- if (CameraPane.FULLSCREEN)
745
+ cameraView.ToggleFullScreen();
746
+
747
+ if (!CameraPane.FULLSCREEN)
588748 {
589
- frame.getContentPane().remove(/*"Center",*/bigThree);
590
- framePanel.add(bigThree);
591
- frame.getContentPane().add(/*"Center",*/framePanel);
749
+ device.setFullScreenWindow(null);
750
+ //frame.setVisible(false);
751
+// frame.removeNotify();
752
+// frame.setUndecorated(false);
753
+// frame.addNotify();
754
+ //frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
755
+
756
+// X frame.getContentPane().remove(/*"Center",*/bigThree);
757
+// X framePanel.add(bigThree);
758
+// X frame.getContentPane().add(/*"Center",*/framePanel);
759
+ framePanel.setDividerLocation(1);
760
+
761
+ //frame.setVisible(true);
762
+ radio.layout = keepButton;
763
+ //theFrame = null;
764
+ keepButton = null;
765
+ radio.layout.doClick();
766
+
592767 } else
593768 {
594
- frame.getContentPane().remove(/*"Center",*/framePanel);
595
- framePanel.remove(bigThree);
596
- frame.getContentPane().add(/*"Center",*/bigThree);
769
+ keepButton = radio.layout;
770
+ //keeprect = frame.getBounds();
771
+// frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
772
+// frame.getToolkit().getScreenSize().height);
773
+ //frame.setVisible(false);
774
+ device.setFullScreenWindow(frame);
775
+// frame.removeNotify();
776
+// frame.setUndecorated(true);
777
+// frame.addNotify();
778
+// X frame.getContentPane().remove(/*"Center",*/framePanel);
779
+// X framePanel.remove(bigThree);
780
+// X frame.getContentPane().add(/*"Center",*/bigThree);
781
+ framePanel.setDividerLocation(0);
782
+
783
+ radio.layout = fullscreenLayout;
784
+ radio.layout.doClick();
785
+ //frame.setVisible(true);
597786 }
598
- cameraView.ToggleFullScreen();
599787 }
600788
601789 private JTextPane createTextPane()
....@@ -736,7 +924,12 @@
736924 JCheckBox speedupCB;
737925 JCheckBox rewindCB;
738926 JCheckBox flipVCB;
927
+
928
+ cCheckBox toggleTextureCB;
929
+ cCheckBox toggleSwitchCB;
930
+
739931 JComboBox texresMenu;
932
+
740933 JButton resetButton;
741934 JButton stepButton;
742935 JButton stepAllButton;
....@@ -745,9 +938,13 @@
745938 JButton fasterButton;
746939 JButton remarkButton;
747940
941
+ cGridBag editPanel;
942
+ cGridBag editCommandsPanel;
943
+
748944 cGridBag namePanel;
749945 cGridBag setupPanel;
750
- cGridBag commandsPanel;
946
+ cGridBag setupPanel2;
947
+ cGridBag objectCommandsPanel;
751948 cGridBag pushPanel;
752949 cGridBag fillPanel;
753950
....@@ -924,7 +1121,7 @@
9241121
9251122 oe.ctrlPanel.Return();
9261123
927
- if (!GroupEditor.allparams)
1124
+ if (!allparams)
9281125 return;
9291126
9301127 setupPanel = new cGridBag().setVertical(false);
....@@ -937,42 +1134,46 @@
9371134 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
9381135 hideCB.setToolTipText("Hide object");
9391136 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
940
- markCB.setToolTipText("Set the animation target transform");
1137
+ markCB.setToolTipText("As animation target transform");
9411138
942
- rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
1139
+ setupPanel2 = new cGridBag().setVertical(false);
1140
+
1141
+ rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
9431142 rewindCB.setToolTipText("Rewind animation");
9441143
945
- randomCB = AddCheckBox(setupPanel, "Random", copy.random);
946
- randomCB.setToolTipText("Option for switch node");
1144
+ randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1145
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
9471146
9481147 if (Globals.ADVANCED)
9491148 {
950
- link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
1149
+ link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
9511150 link2masterCB.setToolTipText("Attach to support");
952
- speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
1151
+ speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
9531152 speedupCB.setToolTipText("Option motion capture");
9541153 }
9551154
9561155 oe.ctrlPanel.add(setupPanel);
9571156 oe.ctrlPanel.Return();
1157
+ oe.ctrlPanel.add(setupPanel2);
1158
+ oe.ctrlPanel.Return();
9581159
959
- commandsPanel = new cGridBag().setVertical(false);
1160
+ objectCommandsPanel = new cGridBag().setVertical(false);
9601161
961
- resetButton = AddButton(commandsPanel, "Reset");
1162
+ resetButton = AddButton(objectCommandsPanel, "Reset");
9621163 resetButton.setToolTipText("Jump to frame zero");
963
- stepButton = AddButton(commandsPanel, "Step");
1164
+ stepButton = AddButton(objectCommandsPanel, "Step");
9641165 stepButton.setToolTipText("Step one frame");
9651166 // resetAllButton = AddButton(oe, "Reset All");
9661167 // stepAllButton = AddButton(oe, "Step All");
9671168 // Return();
968
- slowerButton = AddButton(commandsPanel, "Slow");
1169
+ slowerButton = AddButton(objectCommandsPanel, "Slow");
9691170 slowerButton.setToolTipText("Decrease animation speed");
970
- fasterButton = AddButton(commandsPanel, "Fast");
1171
+ fasterButton = AddButton(objectCommandsPanel, "Fast");
9711172 fasterButton.setToolTipText("Increase animation speed");
972
- remarkButton = AddButton(commandsPanel, "Remark");
1173
+ remarkButton = AddButton(objectCommandsPanel, "Remark");
9731174 remarkButton.setToolTipText("Set the current transform as the target");
9741175
975
- oe.ctrlPanel.add(commandsPanel);
1176
+ oe.ctrlPanel.add(objectCommandsPanel);
9761177 oe.ctrlPanel.Return();
9771178
9781179 pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH, 1.1); // To have the buttons
....@@ -1178,8 +1379,11 @@
11781379 //worldPanel.setName("World");
11791380 centralPanel = new cGridBag();
11801381 centralPanel.preferredWidth = 20;
1181
- timelinePanel = new JPanel(new BorderLayout());
1182
- timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
1382
+
1383
+ if (Globals.ADVANCED)
1384
+ {
1385
+ timelinePanel = new JPanel(new BorderLayout());
1386
+ timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
11831387
11841388 cameraPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cameraView, timelinePanel);
11851389 cameraPanel.setContinuousLayout(true);
....@@ -1188,7 +1392,10 @@
11881392 // cameraPanel.setDividerSize(9);
11891393 cameraPanel.setResizeWeight(1.0);
11901394
1395
+ }
1396
+
11911397 centralPanel.add(cameraView);
1398
+ centralPanel.setFocusable(true);
11921399 //frame.setJMenuBar(timelineMenubar);
11931400 //centralPanel.add(timelinePanel);
11941401
....@@ -1255,8 +1462,9 @@
12551462 // north.setName("Edit");
12561463 // north.add(ctrlPanel, BorderLayout.NORTH);
12571464 // objectPanel.add(north);
1258
- objectPanel.add(ctrlPanel);
1465
+ objectPanel.add(editPanel);
12591466 objectPanel.add(infoPanel);
1467
+ objectPanel.add(toolboxPanel);
12601468
12611469 /*
12621470 aConstraints.gridx = 0;
....@@ -1265,7 +1473,7 @@
12651473 aConstraints.gridy += 1;
12661474 aConstraints.gridwidth = 1;
12671475 mainPanel.add(objectPanel, aConstraints);
1268
- */
1476
+ */
12691477
12701478 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
12711479 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1282,9 +1490,7 @@
12821490 JTabbedPane tabbedPane = new JTabbedPane();
12831491 tabbedPane.add(scrollpane);
12841492
1285
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1286
-
1287
- optionsPanel = new cGridBag().setVertical(true);
1493
+ optionsPanel = new cGridBag().setVertical(false);
12881494
12891495 optionsPanel.setName("Options");
12901496
....@@ -1292,6 +1498,8 @@
12921498
12931499 tabbedPane.add(optionsPanel);
12941500
1501
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1502
+
12951503 scenePanel.add(tabbedPane);
12961504
12971505 /*
....@@ -1384,8 +1592,12 @@
13841592 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
13851593
13861594 frame.setSize(1280, 860);
1595
+
1596
+ frame.validate();
13871597 frame.setVisible(true);
13881598
1599
+ cameraView.requestFocusInWindow();
1600
+
13891601 gridPanel.setDividerLocation(1.0);
13901602
13911603 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
....@@ -1935,6 +2147,7 @@
19352147 e2.printStackTrace();
19362148 }
19372149 }
2150
+
19382151 LoadJMEThread loadThread;
19392152
19402153 class LoadJMEThread extends Thread
....@@ -1992,6 +2205,7 @@
19922205 //LoadFile0(filename, converter);
19932206 }
19942207 }
2208
+
19952209 LoadOBJThread loadObjThread;
19962210
19972211 class LoadOBJThread extends Thread
....@@ -2070,19 +2284,19 @@
20702284
20712285 void LoadObjFile(String fullname)
20722286 {
2073
- /*
2287
+ System.out.println("Loading " + fullname);
2288
+ /**/
20742289 //lastFilename = fullname;
20752290 if(loadObjThread == null)
20762291 {
2077
- loadObjThread = new LoadOBJThread();
2078
- loadObjThread.start();
2292
+ loadObjThread = new LoadOBJThread();
2293
+ loadObjThread.start();
20792294 }
20802295
20812296 loadObjThread.add(fullname);
2082
- */
2297
+ /**/
20832298
2084
- System.out.println("Loading " + fullname);
2085
- makeSomething(new FileObject(fullname, true), true);
2299
+ //makeSomething(new FileObject(fullname, true), true);
20862300 }
20872301
20882302 void LoadGFDFile(String fullname)
....@@ -2699,6 +2913,8 @@
26992913
27002914 void SetMaterial(Object3D object)
27012915 {
2916
+ latestObject = object;
2917
+
27022918 cMaterial mat = object.material;
27032919
27042920 if (mat == null)
....@@ -2810,12 +3026,17 @@
28103026 // }
28113027
28123028 /**/
2813
- if (deselect)
3029
+ if (deselect || child == null)
28143030 {
28153031 //group.deselectAll();
28163032 //freeze = true;
28173033 GetTree().clearSelection();
28183034 //freeze = false;
3035
+
3036
+ if (child == null)
3037
+ {
3038
+ return;
3039
+ }
28193040 }
28203041
28213042 //group.addSelectee(child);
....@@ -2884,7 +3105,7 @@
28843105 cameraView.ToggleDL();
28853106 cameraView.repaint();
28863107 return;
2887
- } else if (event.getSource() == toggleTextureItem)
3108
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
28883109 {
28893110 cameraView.ToggleTexture();
28903111 // june 2013 copy.HardTouch();
....@@ -2923,9 +3144,9 @@
29233144 frame.validate();
29243145
29253146 return;
2926
- } else if (event.getSource() == toggleSwitchItem)
3147
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
29273148 {
2928
- cameraView.ToggleRandom();
3149
+ cameraView.ToggleSwitch();
29293150 cameraView.repaint();
29303151 return;
29313152 } else if (event.getSource() == toggleHandleItem)
....@@ -3212,23 +3433,45 @@
32123433 objEditor.refreshContents();
32133434 }
32143435
3215
- Object3D graphs[] = new Object3D[10000];
3216
- int undoindex = 0;
3217
-
3218
- static public Object clone(Object o)
3436
+ static public byte[] Compress(Object3D o)
32193437 {
32203438 try
32213439 {
32223440 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3223
- ObjectOutputStream out = new ObjectOutputStream(baos);
3441
+ java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3442
+ ObjectOutputStream out = new ObjectOutputStream(zstream);
32243443
3444
+ Object3D parent = o.parent;
3445
+ o.parent = null;
3446
+
32253447 out.writeObject(o);
3448
+
3449
+ o.parent = parent;
3450
+
3451
+ out.flush();
32263452
3227
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3228
- ObjectInputStream in = new ObjectInputStream(bais);
3453
+ zstream.close();
3454
+ out.close();
3455
+
3456
+ return baos.toByteArray();
3457
+ } catch (Exception e)
3458
+ {
3459
+ System.err.println(e);
3460
+ return null;
3461
+ }
3462
+ }
3463
+
3464
+ static public Object Uncompress(byte[] bytes)
3465
+ {
3466
+ System.out.println("#bytes = " + bytes.length);
3467
+ try
3468
+ {
3469
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3470
+ java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3471
+ ObjectInputStream in = new ObjectInputStream(istream);
32293472 Object obj = in.readObject();
32303473 in.close();
3231
- out.close();
3474
+
32323475 return obj;
32333476 } catch (Exception e)
32343477 {
....@@ -3237,24 +3480,85 @@
32373480 }
32383481 }
32393482
3483
+ static public Object clone(Object o)
3484
+ {
3485
+ try
3486
+ {
3487
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3488
+ ObjectOutputStream out = new ObjectOutputStream(baos);
3489
+
3490
+ out.writeObject(o);
3491
+
3492
+ out.flush();
3493
+ out.close();
3494
+
3495
+ byte[] bytes = baos.toByteArray();
3496
+
3497
+ System.out.println("clone = " + bytes.length);
3498
+
3499
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3500
+ ObjectInputStream in = new ObjectInputStream(bais);
3501
+ Object obj = in.readObject();
3502
+ in.close();
3503
+
3504
+ return obj;
3505
+ } catch (Exception e)
3506
+ {
3507
+ System.err.println(e);
3508
+ return null;
3509
+ }
3510
+ }
3511
+
3512
+ cRadio GetCurrentTab()
3513
+ {
3514
+ cRadio ab;
3515
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3516
+ {
3517
+ ab = (cRadio)e.nextElement();
3518
+ if(ab.GetObject() == copy)
3519
+ {
3520
+ return ab;
3521
+ }
3522
+ }
3523
+
3524
+ return null;
3525
+ }
3526
+
3527
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3528
+
32403529 public void Save()
32413530 {
3242
- if (true) return;
3531
+ System.err.println("Save");
3532
+
3533
+ cRadio tab = GetCurrentTab();
3534
+
3535
+ boolean temp = CameraPane.SWITCH;
3536
+ CameraPane.SWITCH = false;
3537
+
3538
+ copy.ExtractBigData(hashtable);
32433539
32443540 //EditorFrame.m_MainFrame.requestFocusInWindow();
3245
- graphs[undoindex++] = (Object3D)clone(copy);
3541
+ tab.graphs[tab.undoindex++] = Compress(copy);
32463542
3247
- for (int i = undoindex; i < graphs.length; i++)
3543
+ copy.RestoreBigData(hashtable);
3544
+
3545
+ CameraPane.SWITCH = temp;
3546
+
3547
+ //assert(hashtable.isEmpty());
3548
+
3549
+ for (int i = tab.undoindex; i < tab.graphs.length; i++)
32483550 {
3249
- graphs[i] = null;
3551
+ tab.graphs[i] = null;
32503552 }
32513553
3554
+ SetUndoStates();
3555
+
32523556 // test save
32533557 if (false)
32543558 {
32553559 try
32563560 {
3257
- FileOutputStream ostream = new FileOutputStream("save" + undoindex);
3561
+ FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
32583562 ObjectOutputStream p = new ObjectOutputStream(ostream);
32593563
32603564 p.writeObject(copy);
....@@ -3269,48 +3573,96 @@
32693573 }
32703574 }
32713575
3576
+ void CopyChanged(Object3D obj)
3577
+ {
3578
+ SetUndoStates();
3579
+
3580
+ boolean temp = CameraPane.SWITCH;
3581
+ CameraPane.SWITCH = false;
3582
+
3583
+ copy.ExtractBigData(hashtable);
3584
+
3585
+ copy.clear();
3586
+
3587
+ for (int i=0; i<obj.Size(); i++)
3588
+ {
3589
+ copy.add(obj.get(i));
3590
+ }
3591
+
3592
+ copy.RestoreBigData(hashtable);
3593
+
3594
+ CameraPane.SWITCH = temp;
3595
+
3596
+ //assert(hashtable.isEmpty());
3597
+
3598
+ copy.Touch();
3599
+
3600
+ ResetModel();
3601
+ copy.HardTouch(); // recompile?
3602
+
3603
+ cRadio ab;
3604
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3605
+ {
3606
+ ab = (cRadio)e.nextElement();
3607
+ Object3D test = copy.GetObject(ab.object.GetUUID());
3608
+ //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
3609
+ if (test != null)
3610
+ {
3611
+ test.editWindow = ab.object.editWindow;
3612
+ ab.object = test;
3613
+ }
3614
+ }
3615
+
3616
+ refreshContents();
3617
+ }
3618
+
3619
+ cButton undoButton;
3620
+ cButton redoButton;
3621
+
3622
+ void SetUndoStates()
3623
+ {
3624
+ cRadio tab = GetCurrentTab();
3625
+
3626
+ undoButton.setEnabled(tab.undoindex > 0);
3627
+ redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3628
+ }
3629
+
32723630 public void Undo()
32733631 {
3274
- if (undoindex == 0)
3632
+ System.err.println("Undo");
3633
+
3634
+ cRadio tab = GetCurrentTab();
3635
+
3636
+ if (tab.undoindex == 0)
32753637 {
32763638 java.awt.Toolkit.getDefaultToolkit().beep();
32773639 return;
32783640 }
32793641
3280
- if (graphs[undoindex] == null)
3642
+ if (tab.graphs[tab.undoindex] == null)
32813643 {
32823644 Save();
3283
- undoindex -= 1;
3645
+ tab.undoindex -= 1;
32843646 }
32853647
3286
- undoindex -= 1;
3648
+ tab.undoindex -= 1;
32873649
3288
- copy = graphs[undoindex];
3289
-
3290
- cameraView.object = copy;
3291
- copy.Touch();
3292
-
3293
- ResetModel();
3294
- refreshContents();
3650
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
32953651 }
32963652
32973653 public void Redo()
32983654 {
3299
- if (graphs[undoindex + 1] == null)
3655
+ cRadio tab = GetCurrentTab();
3656
+
3657
+ if (tab.graphs[tab.undoindex + 1] == null)
33003658 {
33013659 java.awt.Toolkit.getDefaultToolkit().beep();
33023660 return;
33033661 }
33043662
3305
- undoindex += 1;
3663
+ tab.undoindex += 1;
33063664
3307
- copy = graphs[undoindex];
3308
-
3309
- cameraView.object = copy;
3310
- copy.Touch();
3311
-
3312
- ResetModel();
3313
- refreshContents();
3665
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33143666 }
33153667
33163668 void ImportGFD()
....@@ -3462,7 +3814,7 @@
34623814 assert false;
34633815 }
34643816
3465
- void EditSelection()
3817
+ void EditSelection(boolean newWindow)
34663818 {
34673819 }
34683820
....@@ -3957,7 +4309,8 @@
39574309
39584310 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
39594311 {
3960
- Save();
4312
+ if (Globals.SAVEONMAKE) // && resetmodel)
4313
+ Save();
39614314 //Tween.set(thing, 0).target(1).start(tweenManager);
39624315 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
39634316 // if (thing instanceof GenericJointDemo)
....@@ -4044,6 +4397,12 @@
40444397 {
40454398 ResetModel();
40464399 Select(thing.GetTreePath(), true, false); // unselect... false);
4400
+
4401
+ if (thing.Size() == 0)
4402
+ {
4403
+ //EditSelection(false);
4404
+ }
4405
+
40474406 refreshContents();
40484407 }
40494408
....@@ -4181,6 +4540,7 @@
41814540
41824541 try
41834542 {
4543
+ // Try compressed version first.
41844544 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
41854545 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
41864546 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4250,6 +4610,12 @@
42504610
42514611 void LoadIt(Object obj)
42524612 {
4613
+ if (obj == null)
4614
+ {
4615
+ // Invalid file
4616
+ return;
4617
+ }
4618
+
42534619 System.out.println("Loaded " + obj);
42544620 //new Exception().printStackTrace();
42554621 Object3D readobj = (Object3D) obj;
....@@ -4259,6 +4625,8 @@
42594625
42604626 if (readobj != null)
42614627 {
4628
+ if (Globals.SAVEONMAKE)
4629
+ Save();
42624630 try
42634631 {
42644632 //readobj.deepCopySelf(copy);
....@@ -4436,6 +4804,8 @@
44364804 String filename = browser.getFile();
44374805 if (filename != null && filename.length() > 0)
44384806 {
4807
+ if (!filename.endsWith(".gfd"))
4808
+ filename += ".gfd";
44394809 lastname = browser.getDirectory() + filename;
44404810 save();
44414811 }
....@@ -4629,18 +4999,31 @@
46294999 CheckboxMenuItem togglePaintItem;
46305000 JSplitPane mainPanel;
46315001 JScrollPane scrollpane;
5002
+
46325003 JPanel toolbarPanel;
5004
+
46335005 cGridBag treePanel;
5006
+
46345007 JPanel radioPanel;
46355008 ButtonGroup buttonGroup;
4636
- cGridBag ctrlPanel;
5009
+
5010
+ cGridBag toolboxPanel;
46375011 cGridBag materialPanel;
5012
+ cGridBag ctrlPanel;
5013
+
46385014 JScrollPane infoPanel;
5015
+
46395016 cGridBag optionsPanel;
5017
+
46405018 JTabbedPane objectPanel;
5019
+ boolean materialFlushed;
5020
+ Object3D latestObject;
5021
+
46415022 cGridBag XYZPanel;
5023
+
46425024 JSplitPane gridPanel;
46435025 JSplitPane bigPanel;
5026
+
46445027 cGridBag bigThree;
46455028 cGridBag scenePanel;
46465029 cGridBag centralPanel;
....@@ -4755,7 +5138,7 @@
47555138 cNumberSlider fogField;
47565139 JLabel opacityPowerLabel;
47575140 cNumberSlider opacityPowerField;
4758
- JTree jTree;
5141
+ cTree jTree;
47595142 //ObjectUI parent;
47605143
47615144 cNumberSlider normalpushField;