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,7 +3360,7 @@
32143360 objEditor.refreshContents();
32153361 }
32163362
3217
- static public byte[] Compress(Object o)
3363
+ static public byte[] Compress(Object3D o)
32183364 {
32193365 try
32203366 {
....@@ -3222,8 +3368,13 @@
32223368 java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
32233369 ObjectOutputStream out = new ObjectOutputStream(zstream);
32243370
3371
+ Object3D parent = o.parent;
3372
+ o.parent = null;
3373
+
32253374 out.writeObject(o);
32263375
3376
+ o.parent = parent;
3377
+
32273378 out.flush();
32283379
32293380 zstream.close();
....@@ -3239,6 +3390,7 @@
32393390
32403391 static public Object Uncompress(byte[] bytes)
32413392 {
3393
+ System.out.println("#bytes = " + bytes.length);
32423394 try
32433395 {
32443396 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
....@@ -3303,14 +3455,21 @@
33033455
33043456 public void Save()
33053457 {
3458
+ System.err.println("Save");
3459
+
33063460 cRadio tab = GetCurrentTab();
3461
+
3462
+ boolean temp = CameraPane.SWITCH;
3463
+ CameraPane.SWITCH = false;
33073464
33083465 copy.ExtractBigData(hashtable);
33093466
33103467 //EditorFrame.m_MainFrame.requestFocusInWindow();
3311
- tab.graphs[tab.undoindex++] = (Object3D)clone(copy);
3468
+ tab.graphs[tab.undoindex++] = Compress(copy);
33123469
33133470 copy.RestoreBigData(hashtable);
3471
+
3472
+ CameraPane.SWITCH = temp;
33143473
33153474 //assert(hashtable.isEmpty());
33163475
....@@ -3341,6 +3500,9 @@
33413500
33423501 void CopyChanged(Object3D obj)
33433502 {
3503
+ boolean temp = CameraPane.SWITCH;
3504
+ CameraPane.SWITCH = false;
3505
+
33443506 copy.ExtractBigData(hashtable);
33453507
33463508 copy.clear();
....@@ -3351,6 +3513,8 @@
33513513 }
33523514
33533515 copy.RestoreBigData(hashtable);
3516
+
3517
+ CameraPane.SWITCH = temp;
33543518
33553519 //assert(hashtable.isEmpty());
33563520
....@@ -3377,6 +3541,8 @@
33773541
33783542 public void Undo()
33793543 {
3544
+ System.err.println("Undo");
3545
+
33803546 cRadio tab = GetCurrentTab();
33813547
33823548 if (tab.undoindex == 0)
....@@ -3393,7 +3559,7 @@
33933559
33943560 tab.undoindex -= 1;
33953561
3396
- CopyChanged(tab.graphs[tab.undoindex]);
3562
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33973563 }
33983564
33993565 public void Redo()
....@@ -3408,7 +3574,7 @@
34083574
34093575 tab.undoindex += 1;
34103576
3411
- CopyChanged(tab.graphs[tab.undoindex]);
3577
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
34123578 }
34133579
34143580 void ImportGFD()
....@@ -4055,7 +4221,8 @@
40554221
40564222 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
40574223 {
4058
- Save();
4224
+ if (Globals.SAVEONMAKE)
4225
+ Save();
40594226 //Tween.set(thing, 0).target(1).start(tweenManager);
40604227 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
40614228 // if (thing instanceof GenericJointDemo)
....@@ -4279,6 +4446,7 @@
42794446
42804447 try
42814448 {
4449
+ // Try compressed version first.
42824450 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
42834451 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
42844452 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4348,6 +4516,12 @@
43484516
43494517 void LoadIt(Object obj)
43504518 {
4519
+ if (obj == null)
4520
+ {
4521
+ // Invalid file
4522
+ return;
4523
+ }
4524
+
43514525 System.out.println("Loaded " + obj);
43524526 //new Exception().printStackTrace();
43534527 Object3D readobj = (Object3D) obj;
....@@ -4357,6 +4531,7 @@
43574531
43584532 if (readobj != null)
43594533 {
4534
+ if (Globals.SAVEONMAKE)
43604535 Save();
43614536 try
43624537 {