Normand Briere
2019-06-27 1807e7752960ac229cddd34b100e92cadbac9459
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,14 @@
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
+ mainPanel.setUI(new BasicSplitPaneUI());
471
+
355472 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
356473 //mainPanel.setLayout(new GridBagLayout());
357474 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -419,10 +536,10 @@
419536 e.printStackTrace();
420537 }
421538
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();
539
+// String selection = infoarea.getText();
540
+// java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
541
+// java.awt.datatransfer.Clipboard clipboard =
542
+// Toolkit.getDefaultToolkit().getSystemClipboard();
426543 //clipboard.setContents(data, data);
427544 }
428545
....@@ -582,20 +699,92 @@
582699 }
583700 }
584701
702
+static GraphicsDevice device = GraphicsEnvironment
703
+ .getLocalGraphicsEnvironment().getScreenDevices()[0];
704
+
705
+ Rectangle keeprect;
706
+ cRadio radio;
707
+
708
+cButton keepButton;
709
+ cButton twoButton; // Full 3D
710
+ cButton sixButton;
711
+ cButton threeButton;
712
+ cButton sevenButton;
713
+ cButton fourButton; // full panel
714
+ cButton oneButton; // full XYZ
715
+ //cButton currentLayout;
716
+
717
+ boolean maximized;
718
+
719
+ cButton fullscreenLayout;
720
+
721
+ void Minimize()
722
+ {
723
+ frame.setState(Frame.ICONIFIED);
724
+ }
725
+
726
+ void Maximize()
727
+ {
728
+ if (maximized)
729
+ {
730
+ frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
731
+ }
732
+ else
733
+ {
734
+ keeprect = frame.getBounds();
735
+ Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
736
+ Dimension rect2 = frame.getToolkit().getScreenSize();
737
+ frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
738
+// frame.setState(Frame.MAXIMIZED_BOTH);
739
+ }
740
+
741
+ maximized ^= true;
742
+ }
743
+
585744 void ToggleFullScreen()
586745 {
587
- if (CameraPane.FULLSCREEN)
746
+ cameraView.ToggleFullScreen();
747
+
748
+ if (!CameraPane.FULLSCREEN)
588749 {
589
- frame.getContentPane().remove(/*"Center",*/bigThree);
590
- framePanel.add(bigThree);
591
- frame.getContentPane().add(/*"Center",*/framePanel);
750
+ device.setFullScreenWindow(null);
751
+ //frame.setVisible(false);
752
+// frame.removeNotify();
753
+// frame.setUndecorated(false);
754
+// frame.addNotify();
755
+ //frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
756
+
757
+// X frame.getContentPane().remove(/*"Center",*/bigThree);
758
+// X framePanel.add(bigThree);
759
+// X frame.getContentPane().add(/*"Center",*/framePanel);
760
+ framePanel.setDividerLocation(1);
761
+
762
+ //frame.setVisible(true);
763
+ radio.layout = keepButton;
764
+ //theFrame = null;
765
+ keepButton = null;
766
+ radio.layout.doClick();
767
+
592768 } else
593769 {
594
- frame.getContentPane().remove(/*"Center",*/framePanel);
595
- framePanel.remove(bigThree);
596
- frame.getContentPane().add(/*"Center",*/bigThree);
770
+ keepButton = radio.layout;
771
+ //keeprect = frame.getBounds();
772
+// frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
773
+// frame.getToolkit().getScreenSize().height);
774
+ //frame.setVisible(false);
775
+ device.setFullScreenWindow(frame);
776
+// frame.removeNotify();
777
+// frame.setUndecorated(true);
778
+// frame.addNotify();
779
+// X frame.getContentPane().remove(/*"Center",*/framePanel);
780
+// X framePanel.remove(bigThree);
781
+// X frame.getContentPane().add(/*"Center",*/bigThree);
782
+ framePanel.setDividerLocation(0);
783
+
784
+ radio.layout = fullscreenLayout;
785
+ radio.layout.doClick();
786
+ //frame.setVisible(true);
597787 }
598
- cameraView.ToggleFullScreen();
599788 }
600789
601790 private JTextPane createTextPane()
....@@ -736,7 +925,12 @@
736925 JCheckBox speedupCB;
737926 JCheckBox rewindCB;
738927 JCheckBox flipVCB;
928
+
929
+ cCheckBox toggleTextureCB;
930
+ cCheckBox toggleSwitchCB;
931
+
739932 JComboBox texresMenu;
933
+
740934 JButton resetButton;
741935 JButton stepButton;
742936 JButton stepAllButton;
....@@ -745,9 +939,13 @@
745939 JButton fasterButton;
746940 JButton remarkButton;
747941
942
+ cGridBag editPanel;
943
+ cGridBag editCommandsPanel;
944
+
748945 cGridBag namePanel;
749946 cGridBag setupPanel;
750
- cGridBag commandsPanel;
947
+ cGridBag setupPanel2;
948
+ cGridBag objectCommandsPanel;
751949 cGridBag pushPanel;
752950 cGridBag fillPanel;
753951
....@@ -924,7 +1122,7 @@
9241122
9251123 oe.ctrlPanel.Return();
9261124
927
- if (!GroupEditor.allparams)
1125
+ if (!allparams)
9281126 return;
9291127
9301128 setupPanel = new cGridBag().setVertical(false);
....@@ -937,42 +1135,46 @@
9371135 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
9381136 hideCB.setToolTipText("Hide object");
9391137 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
940
- markCB.setToolTipText("Set the animation target transform");
1138
+ markCB.setToolTipText("As animation target transform");
9411139
942
- rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
1140
+ setupPanel2 = new cGridBag().setVertical(false);
1141
+
1142
+ rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
9431143 rewindCB.setToolTipText("Rewind animation");
9441144
945
- randomCB = AddCheckBox(setupPanel, "Random", copy.random);
946
- randomCB.setToolTipText("Option for switch node");
1145
+ randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1146
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
9471147
9481148 if (Globals.ADVANCED)
9491149 {
950
- link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
1150
+ link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
9511151 link2masterCB.setToolTipText("Attach to support");
952
- speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
1152
+ speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
9531153 speedupCB.setToolTipText("Option motion capture");
9541154 }
9551155
9561156 oe.ctrlPanel.add(setupPanel);
9571157 oe.ctrlPanel.Return();
1158
+ oe.ctrlPanel.add(setupPanel2);
1159
+ oe.ctrlPanel.Return();
9581160
959
- commandsPanel = new cGridBag().setVertical(false);
1161
+ objectCommandsPanel = new cGridBag().setVertical(false);
9601162
961
- resetButton = AddButton(commandsPanel, "Reset");
1163
+ resetButton = AddButton(objectCommandsPanel, "Reset");
9621164 resetButton.setToolTipText("Jump to frame zero");
963
- stepButton = AddButton(commandsPanel, "Step");
1165
+ stepButton = AddButton(objectCommandsPanel, "Step");
9641166 stepButton.setToolTipText("Step one frame");
9651167 // resetAllButton = AddButton(oe, "Reset All");
9661168 // stepAllButton = AddButton(oe, "Step All");
9671169 // Return();
968
- slowerButton = AddButton(commandsPanel, "Slow");
1170
+ slowerButton = AddButton(objectCommandsPanel, "Slow");
9691171 slowerButton.setToolTipText("Decrease animation speed");
970
- fasterButton = AddButton(commandsPanel, "Fast");
1172
+ fasterButton = AddButton(objectCommandsPanel, "Fast");
9711173 fasterButton.setToolTipText("Increase animation speed");
972
- remarkButton = AddButton(commandsPanel, "Remark");
1174
+ remarkButton = AddButton(objectCommandsPanel, "Remark");
9731175 remarkButton.setToolTipText("Set the current transform as the target");
9741176
975
- oe.ctrlPanel.add(commandsPanel);
1177
+ oe.ctrlPanel.add(objectCommandsPanel);
9761178 oe.ctrlPanel.Return();
9771179
9781180 pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH, 1.1); // To have the buttons
....@@ -1178,8 +1380,11 @@
11781380 //worldPanel.setName("World");
11791381 centralPanel = new cGridBag();
11801382 centralPanel.preferredWidth = 20;
1181
- timelinePanel = new JPanel(new BorderLayout());
1182
- timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
1383
+
1384
+ if (Globals.ADVANCED)
1385
+ {
1386
+ timelinePanel = new JPanel(new BorderLayout());
1387
+ timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
11831388
11841389 cameraPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cameraView, timelinePanel);
11851390 cameraPanel.setContinuousLayout(true);
....@@ -1188,7 +1393,10 @@
11881393 // cameraPanel.setDividerSize(9);
11891394 cameraPanel.setResizeWeight(1.0);
11901395
1396
+ }
1397
+
11911398 centralPanel.add(cameraView);
1399
+ centralPanel.setFocusable(true);
11921400 //frame.setJMenuBar(timelineMenubar);
11931401 //centralPanel.add(timelinePanel);
11941402
....@@ -1255,8 +1463,9 @@
12551463 // north.setName("Edit");
12561464 // north.add(ctrlPanel, BorderLayout.NORTH);
12571465 // objectPanel.add(north);
1258
- objectPanel.add(ctrlPanel);
1466
+ objectPanel.add(editPanel);
12591467 objectPanel.add(infoPanel);
1468
+ objectPanel.add(toolboxPanel);
12601469
12611470 /*
12621471 aConstraints.gridx = 0;
....@@ -1265,7 +1474,7 @@
12651474 aConstraints.gridy += 1;
12661475 aConstraints.gridwidth = 1;
12671476 mainPanel.add(objectPanel, aConstraints);
1268
- */
1477
+ */
12691478
12701479 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
12711480 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1282,9 +1491,7 @@
12821491 JTabbedPane tabbedPane = new JTabbedPane();
12831492 tabbedPane.add(scrollpane);
12841493
1285
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1286
-
1287
- optionsPanel = new cGridBag().setVertical(true);
1494
+ optionsPanel = new cGridBag().setVertical(false);
12881495
12891496 optionsPanel.setName("Options");
12901497
....@@ -1292,6 +1499,8 @@
12921499
12931500 tabbedPane.add(optionsPanel);
12941501
1502
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1503
+
12951504 scenePanel.add(tabbedPane);
12961505
12971506 /*
....@@ -1384,8 +1593,12 @@
13841593 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
13851594
13861595 frame.setSize(1280, 860);
1596
+
1597
+ frame.validate();
13871598 frame.setVisible(true);
13881599
1600
+ cameraView.requestFocusInWindow();
1601
+
13891602 gridPanel.setDividerLocation(1.0);
13901603
13911604 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
....@@ -1935,6 +2148,7 @@
19352148 e2.printStackTrace();
19362149 }
19372150 }
2151
+
19382152 LoadJMEThread loadThread;
19392153
19402154 class LoadJMEThread extends Thread
....@@ -1992,6 +2206,7 @@
19922206 //LoadFile0(filename, converter);
19932207 }
19942208 }
2209
+
19952210 LoadOBJThread loadObjThread;
19962211
19972212 class LoadOBJThread extends Thread
....@@ -2070,19 +2285,19 @@
20702285
20712286 void LoadObjFile(String fullname)
20722287 {
2073
- /*
2288
+ System.out.println("Loading " + fullname);
2289
+ /**/
20742290 //lastFilename = fullname;
20752291 if(loadObjThread == null)
20762292 {
2077
- loadObjThread = new LoadOBJThread();
2078
- loadObjThread.start();
2293
+ loadObjThread = new LoadOBJThread();
2294
+ loadObjThread.start();
20792295 }
20802296
20812297 loadObjThread.add(fullname);
2082
- */
2298
+ /**/
20832299
2084
- System.out.println("Loading " + fullname);
2085
- makeSomething(new FileObject(fullname, true), true);
2300
+ //makeSomething(new FileObject(fullname, true), true);
20862301 }
20872302
20882303 void LoadGFDFile(String fullname)
....@@ -2699,6 +2914,8 @@
26992914
27002915 void SetMaterial(Object3D object)
27012916 {
2917
+ latestObject = object;
2918
+
27022919 cMaterial mat = object.material;
27032920
27042921 if (mat == null)
....@@ -2810,12 +3027,17 @@
28103027 // }
28113028
28123029 /**/
2813
- if (deselect)
3030
+ if (deselect || child == null)
28143031 {
28153032 //group.deselectAll();
28163033 //freeze = true;
28173034 GetTree().clearSelection();
28183035 //freeze = false;
3036
+
3037
+ if (child == null)
3038
+ {
3039
+ return;
3040
+ }
28193041 }
28203042
28213043 //group.addSelectee(child);
....@@ -2884,7 +3106,7 @@
28843106 cameraView.ToggleDL();
28853107 cameraView.repaint();
28863108 return;
2887
- } else if (event.getSource() == toggleTextureItem)
3109
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
28883110 {
28893111 cameraView.ToggleTexture();
28903112 // june 2013 copy.HardTouch();
....@@ -2923,9 +3145,9 @@
29233145 frame.validate();
29243146
29253147 return;
2926
- } else if (event.getSource() == toggleSwitchItem)
3148
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
29273149 {
2928
- cameraView.ToggleRandom();
3150
+ cameraView.ToggleSwitch();
29293151 cameraView.repaint();
29303152 return;
29313153 } else if (event.getSource() == toggleHandleItem)
....@@ -3212,23 +3434,45 @@
32123434 objEditor.refreshContents();
32133435 }
32143436
3215
- Object3D graphs[] = new Object3D[10000];
3216
- int undoindex = 0;
3217
-
3218
- static public Object clone(Object o)
3437
+ static public byte[] Compress(Object3D o)
32193438 {
32203439 try
32213440 {
32223441 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3223
- ObjectOutputStream out = new ObjectOutputStream(baos);
3442
+ java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3443
+ ObjectOutputStream out = new ObjectOutputStream(zstream);
32243444
3445
+ Object3D parent = o.parent;
3446
+ o.parent = null;
3447
+
32253448 out.writeObject(o);
3449
+
3450
+ o.parent = parent;
3451
+
3452
+ out.flush();
32263453
3227
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3228
- ObjectInputStream in = new ObjectInputStream(bais);
3454
+ zstream.close();
3455
+ out.close();
3456
+
3457
+ return baos.toByteArray();
3458
+ } catch (Exception e)
3459
+ {
3460
+ System.err.println(e);
3461
+ return null;
3462
+ }
3463
+ }
3464
+
3465
+ static public Object Uncompress(byte[] bytes)
3466
+ {
3467
+ System.out.println("#bytes = " + bytes.length);
3468
+ try
3469
+ {
3470
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3471
+ java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3472
+ ObjectInputStream in = new ObjectInputStream(istream);
32293473 Object obj = in.readObject();
32303474 in.close();
3231
- out.close();
3475
+
32323476 return obj;
32333477 } catch (Exception e)
32343478 {
....@@ -3237,24 +3481,85 @@
32373481 }
32383482 }
32393483
3484
+ static public Object clone(Object o)
3485
+ {
3486
+ try
3487
+ {
3488
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3489
+ ObjectOutputStream out = new ObjectOutputStream(baos);
3490
+
3491
+ out.writeObject(o);
3492
+
3493
+ out.flush();
3494
+ out.close();
3495
+
3496
+ byte[] bytes = baos.toByteArray();
3497
+
3498
+ System.out.println("clone = " + bytes.length);
3499
+
3500
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3501
+ ObjectInputStream in = new ObjectInputStream(bais);
3502
+ Object obj = in.readObject();
3503
+ in.close();
3504
+
3505
+ return obj;
3506
+ } catch (Exception e)
3507
+ {
3508
+ System.err.println(e);
3509
+ return null;
3510
+ }
3511
+ }
3512
+
3513
+ cRadio GetCurrentTab()
3514
+ {
3515
+ cRadio ab;
3516
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3517
+ {
3518
+ ab = (cRadio)e.nextElement();
3519
+ if(ab.GetObject() == copy)
3520
+ {
3521
+ return ab;
3522
+ }
3523
+ }
3524
+
3525
+ return null;
3526
+ }
3527
+
3528
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3529
+
32403530 public void Save()
32413531 {
3242
- if (true) return;
3532
+ System.err.println("Save");
3533
+
3534
+ cRadio tab = GetCurrentTab();
3535
+
3536
+ boolean temp = CameraPane.SWITCH;
3537
+ CameraPane.SWITCH = false;
3538
+
3539
+ copy.ExtractBigData(hashtable);
32433540
32443541 //EditorFrame.m_MainFrame.requestFocusInWindow();
3245
- graphs[undoindex++] = (Object3D)clone(copy);
3542
+ tab.graphs[tab.undoindex++] = Compress(copy);
32463543
3247
- for (int i = undoindex; i < graphs.length; i++)
3544
+ copy.RestoreBigData(hashtable);
3545
+
3546
+ CameraPane.SWITCH = temp;
3547
+
3548
+ //assert(hashtable.isEmpty());
3549
+
3550
+ for (int i = tab.undoindex; i < tab.graphs.length; i++)
32483551 {
3249
- graphs[i] = null;
3552
+ tab.graphs[i] = null;
32503553 }
32513554
3555
+ SetUndoStates();
3556
+
32523557 // test save
32533558 if (false)
32543559 {
32553560 try
32563561 {
3257
- FileOutputStream ostream = new FileOutputStream("save" + undoindex);
3562
+ FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
32583563 ObjectOutputStream p = new ObjectOutputStream(ostream);
32593564
32603565 p.writeObject(copy);
....@@ -3269,48 +3574,96 @@
32693574 }
32703575 }
32713576
3577
+ void CopyChanged(Object3D obj)
3578
+ {
3579
+ SetUndoStates();
3580
+
3581
+ boolean temp = CameraPane.SWITCH;
3582
+ CameraPane.SWITCH = false;
3583
+
3584
+ copy.ExtractBigData(hashtable);
3585
+
3586
+ copy.clear();
3587
+
3588
+ for (int i=0; i<obj.Size(); i++)
3589
+ {
3590
+ copy.add(obj.get(i));
3591
+ }
3592
+
3593
+ copy.RestoreBigData(hashtable);
3594
+
3595
+ CameraPane.SWITCH = temp;
3596
+
3597
+ //assert(hashtable.isEmpty());
3598
+
3599
+ copy.Touch();
3600
+
3601
+ ResetModel();
3602
+ copy.HardTouch(); // recompile?
3603
+
3604
+ cRadio ab;
3605
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3606
+ {
3607
+ ab = (cRadio)e.nextElement();
3608
+ Object3D test = copy.GetObject(ab.object.GetUUID());
3609
+ //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
3610
+ if (test != null)
3611
+ {
3612
+ test.editWindow = ab.object.editWindow;
3613
+ ab.object = test;
3614
+ }
3615
+ }
3616
+
3617
+ refreshContents();
3618
+ }
3619
+
3620
+ cButton undoButton;
3621
+ cButton redoButton;
3622
+
3623
+ void SetUndoStates()
3624
+ {
3625
+ cRadio tab = GetCurrentTab();
3626
+
3627
+ undoButton.setEnabled(tab.undoindex > 0);
3628
+ redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3629
+ }
3630
+
32723631 public void Undo()
32733632 {
3274
- if (undoindex == 0)
3633
+ System.err.println("Undo");
3634
+
3635
+ cRadio tab = GetCurrentTab();
3636
+
3637
+ if (tab.undoindex == 0)
32753638 {
32763639 java.awt.Toolkit.getDefaultToolkit().beep();
32773640 return;
32783641 }
32793642
3280
- if (graphs[undoindex] == null)
3643
+ if (tab.graphs[tab.undoindex] == null)
32813644 {
32823645 Save();
3283
- undoindex -= 1;
3646
+ tab.undoindex -= 1;
32843647 }
32853648
3286
- undoindex -= 1;
3649
+ tab.undoindex -= 1;
32873650
3288
- copy = graphs[undoindex];
3289
-
3290
- cameraView.object = copy;
3291
- copy.Touch();
3292
-
3293
- ResetModel();
3294
- refreshContents();
3651
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
32953652 }
32963653
32973654 public void Redo()
32983655 {
3299
- if (graphs[undoindex + 1] == null)
3656
+ cRadio tab = GetCurrentTab();
3657
+
3658
+ if (tab.graphs[tab.undoindex + 1] == null)
33003659 {
33013660 java.awt.Toolkit.getDefaultToolkit().beep();
33023661 return;
33033662 }
33043663
3305
- undoindex += 1;
3664
+ tab.undoindex += 1;
33063665
3307
- copy = graphs[undoindex];
3308
-
3309
- cameraView.object = copy;
3310
- copy.Touch();
3311
-
3312
- ResetModel();
3313
- refreshContents();
3666
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33143667 }
33153668
33163669 void ImportGFD()
....@@ -3462,7 +3815,7 @@
34623815 assert false;
34633816 }
34643817
3465
- void EditSelection()
3818
+ void EditSelection(boolean newWindow)
34663819 {
34673820 }
34683821
....@@ -3957,7 +4310,8 @@
39574310
39584311 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
39594312 {
3960
- Save();
4313
+ if (Globals.SAVEONMAKE) // && resetmodel)
4314
+ Save();
39614315 //Tween.set(thing, 0).target(1).start(tweenManager);
39624316 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
39634317 // if (thing instanceof GenericJointDemo)
....@@ -4044,6 +4398,12 @@
40444398 {
40454399 ResetModel();
40464400 Select(thing.GetTreePath(), true, false); // unselect... false);
4401
+
4402
+ if (thing.Size() == 0)
4403
+ {
4404
+ //EditSelection(false);
4405
+ }
4406
+
40474407 refreshContents();
40484408 }
40494409
....@@ -4181,6 +4541,7 @@
41814541
41824542 try
41834543 {
4544
+ // Try compressed version first.
41844545 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
41854546 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
41864547 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4250,6 +4611,12 @@
42504611
42514612 void LoadIt(Object obj)
42524613 {
4614
+ if (obj == null)
4615
+ {
4616
+ // Invalid file
4617
+ return;
4618
+ }
4619
+
42534620 System.out.println("Loaded " + obj);
42544621 //new Exception().printStackTrace();
42554622 Object3D readobj = (Object3D) obj;
....@@ -4259,6 +4626,8 @@
42594626
42604627 if (readobj != null)
42614628 {
4629
+ if (Globals.SAVEONMAKE)
4630
+ Save();
42624631 try
42634632 {
42644633 //readobj.deepCopySelf(copy);
....@@ -4436,6 +4805,8 @@
44364805 String filename = browser.getFile();
44374806 if (filename != null && filename.length() > 0)
44384807 {
4808
+ if (!filename.endsWith(".gfd"))
4809
+ filename += ".gfd";
44394810 lastname = browser.getDirectory() + filename;
44404811 save();
44414812 }
....@@ -4629,18 +5000,31 @@
46295000 CheckboxMenuItem togglePaintItem;
46305001 JSplitPane mainPanel;
46315002 JScrollPane scrollpane;
5003
+
46325004 JPanel toolbarPanel;
5005
+
46335006 cGridBag treePanel;
5007
+
46345008 JPanel radioPanel;
46355009 ButtonGroup buttonGroup;
4636
- cGridBag ctrlPanel;
5010
+
5011
+ cGridBag toolboxPanel;
46375012 cGridBag materialPanel;
5013
+ cGridBag ctrlPanel;
5014
+
46385015 JScrollPane infoPanel;
5016
+
46395017 cGridBag optionsPanel;
5018
+
46405019 JTabbedPane objectPanel;
5020
+ boolean materialFlushed;
5021
+ Object3D latestObject;
5022
+
46415023 cGridBag XYZPanel;
5024
+
46425025 JSplitPane gridPanel;
46435026 JSplitPane bigPanel;
5027
+
46445028 cGridBag bigThree;
46455029 cGridBag scenePanel;
46465030 cGridBag centralPanel;
....@@ -4755,7 +5139,7 @@
47555139 cNumberSlider fogField;
47565140 JLabel opacityPowerLabel;
47575141 cNumberSlider opacityPowerField;
4758
- JTree jTree;
5142
+ cTree jTree;
47595143 //ObjectUI parent;
47605144
47615145 cNumberSlider normalpushField;