Normand Briere
2019-06-24 914255f70cf047897212839cbf3a6722703f4457
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.*;
....@@ -35,6 +36,54 @@
3536
3637 GroupEditor callee;
3738 JFrame frame;
39
+
40
+ static ObjEditor theFrame;
41
+
42
+ cButton GetButton(String name, boolean border)
43
+ {
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
+ }
53
+ }
54
+
55
+ cCheckBox GetCheckBox(String name, boolean border)
56
+ {
57
+ try
58
+ {
59
+ ImageIcon icon = GetIcon(name);
60
+ return new cCheckBox(icon, border);
61
+ }
62
+ catch (Exception e)
63
+ {
64
+ return new cCheckBox(name, border);
65
+ }
66
+ }
67
+
68
+ private ImageIcon GetIcon(String name) throws IOException
69
+ {
70
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
71
+
72
+ if (image.getWidth() != 24 && image.getHeight() != 24)
73
+ {
74
+ BufferedImage resized = new BufferedImage(24, 24, image.getType());
75
+ Graphics2D g = resized.createGraphics();
76
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
77
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
78
+ g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
79
+ g.dispose();
80
+
81
+ image = resized;
82
+ }
83
+
84
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
85
+ return icon;
86
+ }
3887
3988 // SCRIPT
4089
....@@ -168,7 +217,8 @@
168217 // objEditor.ctrlPanel.remove(remarkButton);
169218
170219 objEditor.ctrlPanel.remove(setupPanel);
171
- objEditor.ctrlPanel.remove(commandsPanel);
220
+ objEditor.ctrlPanel.remove(setupPanel2);
221
+ objEditor.ctrlPanel.remove(objectCommandsPanel);
172222 objEditor.ctrlPanel.remove(pushPanel);
173223 //objEditor.ctrlPanel.remove(fillPanel);
174224
....@@ -243,6 +293,7 @@
243293 //localCopy.parent = null;
244294
245295 frame = new JFrame();
296
+ frame.setUndecorated(true);
246297 objEditor = this;
247298 this.callee = callee;
248299
....@@ -278,7 +329,7 @@
278329 frame.setMenuBar(menuBar = new MenuBar());
279330 menuBar.add(fileMenu = new Menu("File"));
280331 fileMenu.add(newItem = new MenuItem("New"));
281
- fileMenu.add(loadItem = new MenuItem("Load..."));
332
+ fileMenu.add(loadItem = new MenuItem("Open..."));
282333
283334 //oe.menuBar.add(menu = new Menu("Include"));
284335 Menu menu = new Menu("Import");
....@@ -323,9 +374,18 @@
323374 toolbarPanel.setName("Toolbar");
324375 treePanel = new cGridBag();
325376 treePanel.setName("Tree");
377
+
378
+ editPanel = new cGridBag().setVertical(true);
379
+ editPanel.setName("Edit");
380
+
326381 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
327
- ctrlPanel.setName("Edit");
382
+
383
+ editCommandsPanel = new cGridBag();
384
+ editPanel.add(editCommandsPanel);
385
+ editPanel.add(ctrlPanel);
386
+
328387 materialPanel = new cGridBag().setVertical(true);
388
+
329389 materialPanel.setName("Material");
330390 /*JTextPane*/
331391 infoarea = createTextPane();
....@@ -419,10 +479,10 @@
419479 e.printStackTrace();
420480 }
421481
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();
482
+// String selection = infoarea.getText();
483
+// java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
484
+// java.awt.datatransfer.Clipboard clipboard =
485
+// Toolkit.getDefaultToolkit().getSystemClipboard();
426486 //clipboard.setContents(data, data);
427487 }
428488
....@@ -582,19 +642,89 @@
582642 }
583643 }
584644
645
+static GraphicsDevice device = GraphicsEnvironment
646
+ .getLocalGraphicsEnvironment().getScreenDevices()[0];
647
+
648
+ Rectangle keeprect;
649
+ cRadio radio;
650
+
651
+cButton keepButton;
652
+ cButton twoButton; // Full 3D
653
+ cButton sixButton;
654
+ cButton threeButton;
655
+ cButton sevenButton;
656
+ cButton fourButton; // full panel
657
+ cButton oneButton; // full XYZ
658
+ //cButton currentLayout;
659
+
660
+ boolean maximized;
661
+
662
+ void Minimize()
663
+ {
664
+ frame.setState(Frame.ICONIFIED);
665
+ }
666
+
667
+ void Maximize()
668
+ {
669
+ if (maximized)
670
+ {
671
+ frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
672
+ }
673
+ else
674
+ {
675
+ keeprect = frame.getBounds();
676
+ Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
677
+ Dimension rect2 = frame.getToolkit().getScreenSize();
678
+ frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
679
+// frame.setState(Frame.MAXIMIZED_BOTH);
680
+ }
681
+
682
+ maximized ^= true;
683
+ }
684
+
585685 void ToggleFullScreen()
586686 {
587687 if (CameraPane.FULLSCREEN)
588688 {
589
- frame.getContentPane().remove(/*"Center",*/bigThree);
590
- framePanel.add(bigThree);
591
- frame.getContentPane().add(/*"Center",*/framePanel);
689
+ device.setFullScreenWindow(null);
690
+ //frame.setVisible(false);
691
+// frame.removeNotify();
692
+// frame.setUndecorated(false);
693
+// frame.addNotify();
694
+ //frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
695
+
696
+// X frame.getContentPane().remove(/*"Center",*/bigThree);
697
+// X framePanel.add(bigThree);
698
+// X frame.getContentPane().add(/*"Center",*/framePanel);
699
+ framePanel.setDividerLocation(1);
700
+
701
+ //frame.setVisible(true);
702
+ radio.layout = keepButton;
703
+ //theFrame = null;
704
+ keepButton = null;
705
+ radio.layout.doClick();
706
+
592707 } else
593708 {
594
- frame.getContentPane().remove(/*"Center",*/framePanel);
595
- framePanel.remove(bigThree);
596
- frame.getContentPane().add(/*"Center",*/bigThree);
709
+ keepButton = radio.layout;
710
+ //keeprect = frame.getBounds();
711
+// frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
712
+// frame.getToolkit().getScreenSize().height);
713
+ //frame.setVisible(false);
714
+ device.setFullScreenWindow(frame);
715
+// frame.removeNotify();
716
+// frame.setUndecorated(true);
717
+// frame.addNotify();
718
+// X frame.getContentPane().remove(/*"Center",*/framePanel);
719
+// X framePanel.remove(bigThree);
720
+// X frame.getContentPane().add(/*"Center",*/bigThree);
721
+ framePanel.setDividerLocation(0);
722
+
723
+ radio.layout = twoButton;
724
+ radio.layout.doClick();
725
+ //frame.setVisible(true);
597726 }
727
+
598728 cameraView.ToggleFullScreen();
599729 }
600730
....@@ -745,9 +875,13 @@
745875 JButton fasterButton;
746876 JButton remarkButton;
747877
878
+ cGridBag editPanel;
879
+ cGridBag editCommandsPanel;
880
+
748881 cGridBag namePanel;
749882 cGridBag setupPanel;
750
- cGridBag commandsPanel;
883
+ cGridBag setupPanel2;
884
+ cGridBag objectCommandsPanel;
751885 cGridBag pushPanel;
752886 cGridBag fillPanel;
753887
....@@ -939,40 +1073,44 @@
9391073 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
9401074 markCB.setToolTipText("Set the animation target transform");
9411075
942
- rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
1076
+ setupPanel2 = new cGridBag().setVertical(false);
1077
+
1078
+ rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
9431079 rewindCB.setToolTipText("Rewind animation");
9441080
945
- randomCB = AddCheckBox(setupPanel, "Random", copy.random);
946
- randomCB.setToolTipText("Option for switch node");
1081
+ randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1082
+ randomCB.setToolTipText("Randomly Rewind or Go back and forth");
9471083
9481084 if (Globals.ADVANCED)
9491085 {
950
- link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
1086
+ link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
9511087 link2masterCB.setToolTipText("Attach to support");
952
- speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
1088
+ speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
9531089 speedupCB.setToolTipText("Option motion capture");
9541090 }
9551091
9561092 oe.ctrlPanel.add(setupPanel);
9571093 oe.ctrlPanel.Return();
1094
+ oe.ctrlPanel.add(setupPanel2);
1095
+ oe.ctrlPanel.Return();
9581096
959
- commandsPanel = new cGridBag().setVertical(false);
1097
+ objectCommandsPanel = new cGridBag().setVertical(false);
9601098
961
- resetButton = AddButton(commandsPanel, "Reset");
1099
+ resetButton = AddButton(objectCommandsPanel, "Reset");
9621100 resetButton.setToolTipText("Jump to frame zero");
963
- stepButton = AddButton(commandsPanel, "Step");
1101
+ stepButton = AddButton(objectCommandsPanel, "Step");
9641102 stepButton.setToolTipText("Step one frame");
9651103 // resetAllButton = AddButton(oe, "Reset All");
9661104 // stepAllButton = AddButton(oe, "Step All");
9671105 // Return();
968
- slowerButton = AddButton(commandsPanel, "Slow");
1106
+ slowerButton = AddButton(objectCommandsPanel, "Slow");
9691107 slowerButton.setToolTipText("Decrease animation speed");
970
- fasterButton = AddButton(commandsPanel, "Fast");
1108
+ fasterButton = AddButton(objectCommandsPanel, "Fast");
9711109 fasterButton.setToolTipText("Increase animation speed");
972
- remarkButton = AddButton(commandsPanel, "Remark");
1110
+ remarkButton = AddButton(objectCommandsPanel, "Remark");
9731111 remarkButton.setToolTipText("Set the current transform as the target");
9741112
975
- oe.ctrlPanel.add(commandsPanel);
1113
+ oe.ctrlPanel.add(objectCommandsPanel);
9761114 oe.ctrlPanel.Return();
9771115
9781116 pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH, 1.1); // To have the buttons
....@@ -1178,8 +1316,11 @@
11781316 //worldPanel.setName("World");
11791317 centralPanel = new cGridBag();
11801318 centralPanel.preferredWidth = 20;
1181
- timelinePanel = new JPanel(new BorderLayout());
1182
- timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
1319
+
1320
+ if (Globals.ADVANCED)
1321
+ {
1322
+ timelinePanel = new JPanel(new BorderLayout());
1323
+ timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
11831324
11841325 cameraPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cameraView, timelinePanel);
11851326 cameraPanel.setContinuousLayout(true);
....@@ -1188,7 +1329,10 @@
11881329 // cameraPanel.setDividerSize(9);
11891330 cameraPanel.setResizeWeight(1.0);
11901331
1332
+ }
1333
+
11911334 centralPanel.add(cameraView);
1335
+ centralPanel.setFocusable(true);
11921336 //frame.setJMenuBar(timelineMenubar);
11931337 //centralPanel.add(timelinePanel);
11941338
....@@ -1255,7 +1399,7 @@
12551399 // north.setName("Edit");
12561400 // north.add(ctrlPanel, BorderLayout.NORTH);
12571401 // objectPanel.add(north);
1258
- objectPanel.add(ctrlPanel);
1402
+ objectPanel.add(editPanel);
12591403 objectPanel.add(infoPanel);
12601404
12611405 /*
....@@ -1386,6 +1530,8 @@
13861530 frame.setSize(1280, 860);
13871531 frame.setVisible(true);
13881532
1533
+ cameraView.requestFocusInWindow();
1534
+
13891535 gridPanel.setDividerLocation(1.0);
13901536
13911537 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
....@@ -2072,19 +2218,19 @@
20722218
20732219 void LoadObjFile(String fullname)
20742220 {
2075
- /*
2221
+ System.out.println("Loading " + fullname);
2222
+ /**/
20762223 //lastFilename = fullname;
20772224 if(loadObjThread == null)
20782225 {
2079
- loadObjThread = new LoadOBJThread();
2080
- loadObjThread.start();
2226
+ loadObjThread = new LoadOBJThread();
2227
+ loadObjThread.start();
20812228 }
20822229
20832230 loadObjThread.add(fullname);
2084
- */
2231
+ /**/
20852232
2086
- System.out.println("Loading " + fullname);
2087
- makeSomething(new FileObject(fullname, true), true);
2233
+ //makeSomething(new FileObject(fullname, true), true);
20882234 }
20892235
20902236 void LoadGFDFile(String fullname)
....@@ -2927,7 +3073,7 @@
29273073 return;
29283074 } else if (event.getSource() == toggleSwitchItem)
29293075 {
2930
- cameraView.ToggleRandom();
3076
+ cameraView.ToggleSwitch();
29313077 cameraView.repaint();
29323078 return;
29333079 } else if (event.getSource() == toggleHandleItem)
....@@ -3214,6 +3360,53 @@
32143360 objEditor.refreshContents();
32153361 }
32163362
3363
+ static public byte[] Compress(Object3D o)
3364
+ {
3365
+ try
3366
+ {
3367
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3368
+ java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3369
+ ObjectOutputStream out = new ObjectOutputStream(zstream);
3370
+
3371
+ Object3D parent = o.parent;
3372
+ o.parent = null;
3373
+
3374
+ out.writeObject(o);
3375
+
3376
+ o.parent = parent;
3377
+
3378
+ out.flush();
3379
+
3380
+ zstream.close();
3381
+ out.close();
3382
+
3383
+ return baos.toByteArray();
3384
+ } catch (Exception e)
3385
+ {
3386
+ System.err.println(e);
3387
+ return null;
3388
+ }
3389
+ }
3390
+
3391
+ static public Object Uncompress(byte[] bytes)
3392
+ {
3393
+ System.out.println("#bytes = " + bytes.length);
3394
+ try
3395
+ {
3396
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3397
+ java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3398
+ ObjectInputStream in = new ObjectInputStream(istream);
3399
+ Object obj = in.readObject();
3400
+ in.close();
3401
+
3402
+ return obj;
3403
+ } catch (Exception e)
3404
+ {
3405
+ System.err.println(e);
3406
+ return null;
3407
+ }
3408
+ }
3409
+
32173410 static public Object clone(Object o)
32183411 {
32193412 try
....@@ -3222,12 +3415,19 @@
32223415 ObjectOutputStream out = new ObjectOutputStream(baos);
32233416
32243417 out.writeObject(o);
3418
+
3419
+ out.flush();
3420
+ out.close();
3421
+
3422
+ byte[] bytes = baos.toByteArray();
3423
+
3424
+ System.out.println("clone = " + bytes.length);
32253425
3226
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3426
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
32273427 ObjectInputStream in = new ObjectInputStream(bais);
32283428 Object obj = in.readObject();
32293429 in.close();
3230
- out.close();
3430
+
32313431 return obj;
32323432 } catch (Exception e)
32333433 {
....@@ -3242,7 +3442,7 @@
32423442 for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
32433443 {
32443444 ab = (cRadio)e.nextElement();
3245
- if(ab.GetObject() == client)
3445
+ if(ab.GetObject() == copy)
32463446 {
32473447 return ab;
32483448 }
....@@ -3251,13 +3451,28 @@
32513451 return null;
32523452 }
32533453
3454
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3455
+
32543456 public void Save()
32553457 {
3458
+ System.err.println("Save");
3459
+
32563460 cRadio tab = GetCurrentTab();
32573461
3462
+ boolean temp = CameraPane.SWITCH;
3463
+ CameraPane.SWITCH = false;
3464
+
3465
+ copy.ExtractBigData(hashtable);
3466
+
32583467 //EditorFrame.m_MainFrame.requestFocusInWindow();
3259
- tab.graphs[tab.undoindex++] = (Object3D)clone(copy);
3468
+ tab.graphs[tab.undoindex++] = Compress(copy);
32603469
3470
+ copy.RestoreBigData(hashtable);
3471
+
3472
+ CameraPane.SWITCH = temp;
3473
+
3474
+ //assert(hashtable.isEmpty());
3475
+
32613476 for (int i = tab.undoindex; i < tab.graphs.length; i++)
32623477 {
32633478 tab.graphs[i] = null;
....@@ -3285,12 +3500,23 @@
32853500
32863501 void CopyChanged(Object3D obj)
32873502 {
3503
+ boolean temp = CameraPane.SWITCH;
3504
+ CameraPane.SWITCH = false;
3505
+
3506
+ copy.ExtractBigData(hashtable);
3507
+
32883508 copy.clear();
32893509
32903510 for (int i=0; i<obj.Size(); i++)
32913511 {
32923512 copy.add(obj.get(i));
32933513 }
3514
+
3515
+ copy.RestoreBigData(hashtable);
3516
+
3517
+ CameraPane.SWITCH = temp;
3518
+
3519
+ //assert(hashtable.isEmpty());
32943520
32953521 copy.Touch();
32963522
....@@ -3315,6 +3541,8 @@
33153541
33163542 public void Undo()
33173543 {
3544
+ System.err.println("Undo");
3545
+
33183546 cRadio tab = GetCurrentTab();
33193547
33203548 if (tab.undoindex == 0)
....@@ -3331,7 +3559,7 @@
33313559
33323560 tab.undoindex -= 1;
33333561
3334
- CopyChanged(tab.graphs[tab.undoindex]);
3562
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33353563 }
33363564
33373565 public void Redo()
....@@ -3346,7 +3574,7 @@
33463574
33473575 tab.undoindex += 1;
33483576
3349
- CopyChanged(tab.graphs[tab.undoindex]);
3577
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33503578 }
33513579
33523580 void ImportGFD()
....@@ -3993,7 +4221,8 @@
39934221
39944222 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
39954223 {
3996
- Save();
4224
+ if (Globals.SAVEONMAKE)
4225
+ Save();
39974226 //Tween.set(thing, 0).target(1).start(tweenManager);
39984227 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
39994228 // if (thing instanceof GenericJointDemo)
....@@ -4217,6 +4446,7 @@
42174446
42184447 try
42194448 {
4449
+ // Try compressed version first.
42204450 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
42214451 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
42224452 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4286,6 +4516,12 @@
42864516
42874517 void LoadIt(Object obj)
42884518 {
4519
+ if (obj == null)
4520
+ {
4521
+ // Invalid file
4522
+ return;
4523
+ }
4524
+
42894525 System.out.println("Loaded " + obj);
42904526 //new Exception().printStackTrace();
42914527 Object3D readobj = (Object3D) obj;
....@@ -4295,6 +4531,8 @@
42954531
42964532 if (readobj != null)
42974533 {
4534
+ if (Globals.SAVEONMAKE)
4535
+ Save();
42984536 try
42994537 {
43004538 //readobj.deepCopySelf(copy);