Normand Briere
2019-06-23 8088590686a45e71278f9a52bb9cc37943dc0c37
ObjEditor.java
....@@ -36,6 +36,8 @@
3636 GroupEditor callee;
3737 JFrame frame;
3838
39
+ static ObjEditor theFrame;
40
+
3941 // SCRIPT
4042
4143 transient JFrame textpanel = null;
....@@ -168,6 +170,7 @@
168170 // objEditor.ctrlPanel.remove(remarkButton);
169171
170172 objEditor.ctrlPanel.remove(setupPanel);
173
+ objEditor.ctrlPanel.remove(setupPanel2);
171174 objEditor.ctrlPanel.remove(commandsPanel);
172175 objEditor.ctrlPanel.remove(pushPanel);
173176 //objEditor.ctrlPanel.remove(fillPanel);
....@@ -243,6 +246,7 @@
243246 //localCopy.parent = null;
244247
245248 frame = new JFrame();
249
+ frame.setUndecorated(true);
246250 objEditor = this;
247251 this.callee = callee;
248252
....@@ -278,7 +282,7 @@
278282 frame.setMenuBar(menuBar = new MenuBar());
279283 menuBar.add(fileMenu = new Menu("File"));
280284 fileMenu.add(newItem = new MenuItem("New"));
281
- fileMenu.add(loadItem = new MenuItem("Load..."));
285
+ fileMenu.add(loadItem = new MenuItem("Open..."));
282286
283287 //oe.menuBar.add(menu = new Menu("Include"));
284288 Menu menu = new Menu("Import");
....@@ -419,10 +423,10 @@
419423 e.printStackTrace();
420424 }
421425
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();
426
+// String selection = infoarea.getText();
427
+// java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
428
+// java.awt.datatransfer.Clipboard clipboard =
429
+// Toolkit.getDefaultToolkit().getSystemClipboard();
426430 //clipboard.setContents(data, data);
427431 }
428432
....@@ -582,19 +586,89 @@
582586 }
583587 }
584588
589
+static GraphicsDevice device = GraphicsEnvironment
590
+ .getLocalGraphicsEnvironment().getScreenDevices()[0];
591
+
592
+ Rectangle keeprect;
593
+ cRadio radio;
594
+
595
+cButton keepButton;
596
+ cButton twoButton; // Full 3D
597
+ cButton sixButton;
598
+ cButton threeButton;
599
+ cButton sevenButton;
600
+ cButton fourButton; // full panel
601
+ cButton oneButton; // full XYZ
602
+ //cButton currentLayout;
603
+
604
+ boolean maximized;
605
+
606
+ void Minimize()
607
+ {
608
+ frame.setState(Frame.ICONIFIED);
609
+ }
610
+
611
+ void Maximize()
612
+ {
613
+ if (maximized)
614
+ {
615
+ frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
616
+ }
617
+ else
618
+ {
619
+ keeprect = frame.getBounds();
620
+ Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
621
+ Dimension rect2 = frame.getToolkit().getScreenSize();
622
+ frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
623
+// frame.setState(Frame.MAXIMIZED_BOTH);
624
+ }
625
+
626
+ maximized ^= true;
627
+ }
628
+
585629 void ToggleFullScreen()
586630 {
587631 if (CameraPane.FULLSCREEN)
588632 {
589
- frame.getContentPane().remove(/*"Center",*/bigThree);
590
- framePanel.add(bigThree);
591
- frame.getContentPane().add(/*"Center",*/framePanel);
633
+ device.setFullScreenWindow(null);
634
+ //frame.setVisible(false);
635
+// frame.removeNotify();
636
+// frame.setUndecorated(false);
637
+// frame.addNotify();
638
+ //frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
639
+
640
+// X frame.getContentPane().remove(/*"Center",*/bigThree);
641
+// X framePanel.add(bigThree);
642
+// X frame.getContentPane().add(/*"Center",*/framePanel);
643
+ framePanel.setDividerLocation(1);
644
+
645
+ //frame.setVisible(true);
646
+ radio.layout = keepButton;
647
+ //theFrame = null;
648
+ keepButton = null;
649
+ radio.layout.doClick();
650
+
592651 } else
593652 {
594
- frame.getContentPane().remove(/*"Center",*/framePanel);
595
- framePanel.remove(bigThree);
596
- frame.getContentPane().add(/*"Center",*/bigThree);
653
+ keepButton = radio.layout;
654
+ //keeprect = frame.getBounds();
655
+// frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
656
+// frame.getToolkit().getScreenSize().height);
657
+ //frame.setVisible(false);
658
+ device.setFullScreenWindow(frame);
659
+// frame.removeNotify();
660
+// frame.setUndecorated(true);
661
+// frame.addNotify();
662
+// X frame.getContentPane().remove(/*"Center",*/framePanel);
663
+// X framePanel.remove(bigThree);
664
+// X frame.getContentPane().add(/*"Center",*/bigThree);
665
+ framePanel.setDividerLocation(0);
666
+
667
+ radio.layout = twoButton;
668
+ radio.layout.doClick();
669
+ //frame.setVisible(true);
597670 }
671
+
598672 cameraView.ToggleFullScreen();
599673 }
600674
....@@ -747,6 +821,7 @@
747821
748822 cGridBag namePanel;
749823 cGridBag setupPanel;
824
+ cGridBag setupPanel2;
750825 cGridBag commandsPanel;
751826 cGridBag pushPanel;
752827 cGridBag fillPanel;
....@@ -939,21 +1014,25 @@
9391014 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
9401015 markCB.setToolTipText("Set the animation target transform");
9411016
942
- rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
1017
+ setupPanel2 = new cGridBag().setVertical(false);
1018
+
1019
+ rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
9431020 rewindCB.setToolTipText("Rewind animation");
9441021
945
- randomCB = AddCheckBox(setupPanel, "Random", copy.random);
946
- randomCB.setToolTipText("Option for switch node");
1022
+ randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1023
+ randomCB.setToolTipText("Randomly Rewind or Go back and forth");
9471024
9481025 if (Globals.ADVANCED)
9491026 {
950
- link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
1027
+ link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
9511028 link2masterCB.setToolTipText("Attach to support");
952
- speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
1029
+ speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
9531030 speedupCB.setToolTipText("Option motion capture");
9541031 }
9551032
9561033 oe.ctrlPanel.add(setupPanel);
1034
+ oe.ctrlPanel.Return();
1035
+ oe.ctrlPanel.add(setupPanel2);
9571036 oe.ctrlPanel.Return();
9581037
9591038 commandsPanel = new cGridBag().setVertical(false);
....@@ -1178,8 +1257,11 @@
11781257 //worldPanel.setName("World");
11791258 centralPanel = new cGridBag();
11801259 centralPanel.preferredWidth = 20;
1181
- timelinePanel = new JPanel(new BorderLayout());
1182
- timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
1260
+
1261
+ if (Globals.ADVANCED)
1262
+ {
1263
+ timelinePanel = new JPanel(new BorderLayout());
1264
+ timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
11831265
11841266 cameraPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cameraView, timelinePanel);
11851267 cameraPanel.setContinuousLayout(true);
....@@ -1188,7 +1270,10 @@
11881270 // cameraPanel.setDividerSize(9);
11891271 cameraPanel.setResizeWeight(1.0);
11901272
1273
+ }
1274
+
11911275 centralPanel.add(cameraView);
1276
+ centralPanel.setFocusable(true);
11921277 //frame.setJMenuBar(timelineMenubar);
11931278 //centralPanel.add(timelinePanel);
11941279
....@@ -1386,6 +1471,8 @@
13861471 frame.setSize(1280, 860);
13871472 frame.setVisible(true);
13881473
1474
+ cameraView.requestFocusInWindow();
1475
+
13891476 gridPanel.setDividerLocation(1.0);
13901477
13911478 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
....@@ -1935,6 +2022,7 @@
19352022 e2.printStackTrace();
19362023 }
19372024 }
2025
+
19382026 LoadJMEThread loadThread;
19392027
19402028 class LoadJMEThread extends Thread
....@@ -1992,6 +2080,7 @@
19922080 //LoadFile0(filename, converter);
19932081 }
19942082 }
2083
+
19952084 LoadOBJThread loadObjThread;
19962085
19972086 class LoadOBJThread extends Thread
....@@ -2070,19 +2159,19 @@
20702159
20712160 void LoadObjFile(String fullname)
20722161 {
2073
- /*
2162
+ System.out.println("Loading " + fullname);
2163
+ /**/
20742164 //lastFilename = fullname;
20752165 if(loadObjThread == null)
20762166 {
2077
- loadObjThread = new LoadOBJThread();
2078
- loadObjThread.start();
2167
+ loadObjThread = new LoadOBJThread();
2168
+ loadObjThread.start();
20792169 }
20802170
20812171 loadObjThread.add(fullname);
2082
- */
2172
+ /**/
20832173
2084
- System.out.println("Loading " + fullname);
2085
- makeSomething(new FileObject(fullname, true), true);
2174
+ //makeSomething(new FileObject(fullname, true), true);
20862175 }
20872176
20882177 void LoadGFDFile(String fullname)
....@@ -2925,7 +3014,7 @@
29253014 return;
29263015 } else if (event.getSource() == toggleSwitchItem)
29273016 {
2928
- cameraView.ToggleRandom();
3017
+ cameraView.ToggleSwitch();
29293018 cameraView.repaint();
29303019 return;
29313020 } else if (event.getSource() == toggleHandleItem)
....@@ -3212,23 +3301,45 @@
32123301 objEditor.refreshContents();
32133302 }
32143303
3215
- Object3D graphs[] = new Object3D[10000];
3216
- int undoindex = 0;
3217
-
3218
- static public Object clone(Object o)
3304
+ static public byte[] Compress(Object3D o)
32193305 {
32203306 try
32213307 {
32223308 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3223
- ObjectOutputStream out = new ObjectOutputStream(baos);
3309
+ java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3310
+ ObjectOutputStream out = new ObjectOutputStream(zstream);
32243311
3312
+ Object3D parent = o.parent;
3313
+ o.parent = null;
3314
+
32253315 out.writeObject(o);
3316
+
3317
+ o.parent = parent;
3318
+
3319
+ out.flush();
32263320
3227
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3228
- ObjectInputStream in = new ObjectInputStream(bais);
3321
+ zstream.close();
3322
+ out.close();
3323
+
3324
+ return baos.toByteArray();
3325
+ } catch (Exception e)
3326
+ {
3327
+ System.err.println(e);
3328
+ return null;
3329
+ }
3330
+ }
3331
+
3332
+ static public Object Uncompress(byte[] bytes)
3333
+ {
3334
+ System.out.println("#bytes = " + bytes.length);
3335
+ try
3336
+ {
3337
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3338
+ java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3339
+ ObjectInputStream in = new ObjectInputStream(istream);
32293340 Object obj = in.readObject();
32303341 in.close();
3231
- out.close();
3342
+
32323343 return obj;
32333344 } catch (Exception e)
32343345 {
....@@ -3237,16 +3348,73 @@
32373348 }
32383349 }
32393350
3351
+ static public Object clone(Object o)
3352
+ {
3353
+ try
3354
+ {
3355
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3356
+ ObjectOutputStream out = new ObjectOutputStream(baos);
3357
+
3358
+ out.writeObject(o);
3359
+
3360
+ out.flush();
3361
+ out.close();
3362
+
3363
+ byte[] bytes = baos.toByteArray();
3364
+
3365
+ System.out.println("clone = " + bytes.length);
3366
+
3367
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3368
+ ObjectInputStream in = new ObjectInputStream(bais);
3369
+ Object obj = in.readObject();
3370
+ in.close();
3371
+
3372
+ return obj;
3373
+ } catch (Exception e)
3374
+ {
3375
+ System.err.println(e);
3376
+ return null;
3377
+ }
3378
+ }
3379
+
3380
+ cRadio GetCurrentTab()
3381
+ {
3382
+ cRadio ab;
3383
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3384
+ {
3385
+ ab = (cRadio)e.nextElement();
3386
+ if(ab.GetObject() == copy)
3387
+ {
3388
+ return ab;
3389
+ }
3390
+ }
3391
+
3392
+ return null;
3393
+ }
3394
+
3395
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3396
+
32403397 public void Save()
32413398 {
3242
- if (true) return;
3399
+ cRadio tab = GetCurrentTab();
3400
+
3401
+ boolean temp = CameraPane.SWITCH;
3402
+ CameraPane.SWITCH = false;
3403
+
3404
+ copy.ExtractBigData(hashtable);
32433405
32443406 //EditorFrame.m_MainFrame.requestFocusInWindow();
3245
- graphs[undoindex++] = (Object3D)clone(copy);
3407
+ tab.graphs[tab.undoindex++] = Compress(copy);
32463408
3247
- for (int i = undoindex; i < graphs.length; i++)
3409
+ copy.RestoreBigData(hashtable);
3410
+
3411
+ CameraPane.SWITCH = temp;
3412
+
3413
+ //assert(hashtable.isEmpty());
3414
+
3415
+ for (int i = tab.undoindex; i < tab.graphs.length; i++)
32483416 {
3249
- graphs[i] = null;
3417
+ tab.graphs[i] = null;
32503418 }
32513419
32523420 // test save
....@@ -3254,7 +3422,7 @@
32543422 {
32553423 try
32563424 {
3257
- FileOutputStream ostream = new FileOutputStream("save" + undoindex);
3425
+ FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
32583426 ObjectOutputStream p = new ObjectOutputStream(ostream);
32593427
32603428 p.writeObject(copy);
....@@ -3269,48 +3437,81 @@
32693437 }
32703438 }
32713439
3440
+ void CopyChanged(Object3D obj)
3441
+ {
3442
+ boolean temp = CameraPane.SWITCH;
3443
+ CameraPane.SWITCH = false;
3444
+
3445
+ copy.ExtractBigData(hashtable);
3446
+
3447
+ copy.clear();
3448
+
3449
+ for (int i=0; i<obj.Size(); i++)
3450
+ {
3451
+ copy.add(obj.get(i));
3452
+ }
3453
+
3454
+ copy.RestoreBigData(hashtable);
3455
+
3456
+ CameraPane.SWITCH = temp;
3457
+
3458
+ //assert(hashtable.isEmpty());
3459
+
3460
+ copy.Touch();
3461
+
3462
+ ResetModel();
3463
+ copy.HardTouch(); // recompile?
3464
+
3465
+ cRadio ab;
3466
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3467
+ {
3468
+ ab = (cRadio)e.nextElement();
3469
+ Object3D test = copy.GetObject(ab.object.GetUUID());
3470
+ //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
3471
+ if (test != null)
3472
+ {
3473
+ test.editWindow = ab.object.editWindow;
3474
+ ab.object = test;
3475
+ }
3476
+ }
3477
+
3478
+ refreshContents();
3479
+ }
3480
+
32723481 public void Undo()
32733482 {
3274
- if (undoindex == 0)
3483
+ cRadio tab = GetCurrentTab();
3484
+
3485
+ if (tab.undoindex == 0)
32753486 {
32763487 java.awt.Toolkit.getDefaultToolkit().beep();
32773488 return;
32783489 }
32793490
3280
- if (graphs[undoindex] == null)
3491
+ if (tab.graphs[tab.undoindex] == null)
32813492 {
32823493 Save();
3283
- undoindex -= 1;
3494
+ tab.undoindex -= 1;
32843495 }
32853496
3286
- undoindex -= 1;
3497
+ tab.undoindex -= 1;
32873498
3288
- copy = graphs[undoindex];
3289
-
3290
- cameraView.object = copy;
3291
- copy.Touch();
3292
-
3293
- ResetModel();
3294
- refreshContents();
3499
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
32953500 }
32963501
32973502 public void Redo()
32983503 {
3299
- if (graphs[undoindex + 1] == null)
3504
+ cRadio tab = GetCurrentTab();
3505
+
3506
+ if (tab.graphs[tab.undoindex + 1] == null)
33003507 {
33013508 java.awt.Toolkit.getDefaultToolkit().beep();
33023509 return;
33033510 }
33043511
3305
- undoindex += 1;
3512
+ tab.undoindex += 1;
33063513
3307
- copy = graphs[undoindex];
3308
-
3309
- cameraView.object = copy;
3310
- copy.Touch();
3311
-
3312
- ResetModel();
3313
- refreshContents();
3514
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33143515 }
33153516
33163517 void ImportGFD()
....@@ -4181,6 +4382,7 @@
41814382
41824383 try
41834384 {
4385
+ // Try compressed version first.
41844386 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
41854387 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
41864388 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4250,6 +4452,12 @@
42504452
42514453 void LoadIt(Object obj)
42524454 {
4455
+ if (obj == null)
4456
+ {
4457
+ // Invalid file
4458
+ return;
4459
+ }
4460
+
42534461 System.out.println("Loaded " + obj);
42544462 //new Exception().printStackTrace();
42554463 Object3D readobj = (Object3D) obj;
....@@ -4259,6 +4467,7 @@
42594467
42604468 if (readobj != null)
42614469 {
4470
+ Save();
42624471 try
42634472 {
42644473 //readobj.deepCopySelf(copy);