Normand Briere
2019-06-24 47cd0f0a3870d843cb758535316060d30f15c811
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,67 @@
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
+ cToggleButton GetToggleButton(String name, boolean border)
56
+ {
57
+ try
58
+ {
59
+ ImageIcon icon = GetIcon(name);
60
+ return new cToggleButton(icon, border);
61
+ }
62
+ catch (Exception e)
63
+ {
64
+ return new cToggleButton(name, border);
65
+ }
66
+ }
67
+
68
+ cCheckBox GetCheckBox(String name, boolean border)
69
+ {
70
+ try
71
+ {
72
+ ImageIcon icon = GetIcon(name);
73
+ return new cCheckBox(icon, border);
74
+ }
75
+ catch (Exception e)
76
+ {
77
+ return new cCheckBox(name, border);
78
+ }
79
+ }
80
+
81
+ private ImageIcon GetIcon(String name) throws IOException
82
+ {
83
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
84
+
85
+ if (image.getWidth() != 24 && image.getHeight() != 24)
86
+ {
87
+ BufferedImage resized = new BufferedImage(24, 24, image.getType());
88
+ Graphics2D g = resized.createGraphics();
89
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
90
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
91
+ g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
92
+ g.dispose();
93
+
94
+ image = resized;
95
+ }
96
+
97
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
98
+ return icon;
99
+ }
38100
39101 // SCRIPT
40102
....@@ -168,7 +230,8 @@
168230 // objEditor.ctrlPanel.remove(remarkButton);
169231
170232 objEditor.ctrlPanel.remove(setupPanel);
171
- objEditor.ctrlPanel.remove(commandsPanel);
233
+ objEditor.ctrlPanel.remove(setupPanel2);
234
+ objEditor.ctrlPanel.remove(objectCommandsPanel);
172235 objEditor.ctrlPanel.remove(pushPanel);
173236 //objEditor.ctrlPanel.remove(fillPanel);
174237
....@@ -243,6 +306,7 @@
243306 //localCopy.parent = null;
244307
245308 frame = new JFrame();
309
+ frame.setUndecorated(true);
246310 objEditor = this;
247311 this.callee = callee;
248312
....@@ -278,7 +342,7 @@
278342 frame.setMenuBar(menuBar = new MenuBar());
279343 menuBar.add(fileMenu = new Menu("File"));
280344 fileMenu.add(newItem = new MenuItem("New"));
281
- fileMenu.add(loadItem = new MenuItem("Load..."));
345
+ fileMenu.add(loadItem = new MenuItem("Open..."));
282346
283347 //oe.menuBar.add(menu = new Menu("Include"));
284348 Menu menu = new Menu("Import");
....@@ -323,10 +387,22 @@
323387 toolbarPanel.setName("Toolbar");
324388 treePanel = new cGridBag();
325389 treePanel.setName("Tree");
390
+
391
+ editPanel = new cGridBag().setVertical(true);
392
+ editPanel.setName("Edit");
393
+
326394 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
327
- ctrlPanel.setName("Edit");
395
+
396
+ editCommandsPanel = new cGridBag();
397
+ editPanel.add(editCommandsPanel);
398
+ editPanel.add(ctrlPanel);
399
+
400
+ toolboxPanel = new cGridBag().setVertical(false);
401
+ toolboxPanel.setName("Toolbox");
402
+
328403 materialPanel = new cGridBag().setVertical(true);
329404 materialPanel.setName("Material");
405
+
330406 /*JTextPane*/
331407 infoarea = createTextPane();
332408 doc = infoarea.getStyledDocument();
....@@ -419,10 +495,10 @@
419495 e.printStackTrace();
420496 }
421497
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();
498
+// String selection = infoarea.getText();
499
+// java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
500
+// java.awt.datatransfer.Clipboard clipboard =
501
+// Toolkit.getDefaultToolkit().getSystemClipboard();
426502 //clipboard.setContents(data, data);
427503 }
428504
....@@ -582,19 +658,91 @@
582658 }
583659 }
584660
661
+static GraphicsDevice device = GraphicsEnvironment
662
+ .getLocalGraphicsEnvironment().getScreenDevices()[0];
663
+
664
+ Rectangle keeprect;
665
+ cRadio radio;
666
+
667
+cButton keepButton;
668
+ cButton twoButton; // Full 3D
669
+ cButton sixButton;
670
+ cButton threeButton;
671
+ cButton sevenButton;
672
+ cButton fourButton; // full panel
673
+ cButton oneButton; // full XYZ
674
+ //cButton currentLayout;
675
+
676
+ boolean maximized;
677
+
678
+ cButton fullscreenLayout;
679
+
680
+ void Minimize()
681
+ {
682
+ frame.setState(Frame.ICONIFIED);
683
+ }
684
+
685
+ void Maximize()
686
+ {
687
+ if (maximized)
688
+ {
689
+ frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
690
+ }
691
+ else
692
+ {
693
+ keeprect = frame.getBounds();
694
+ Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
695
+ Dimension rect2 = frame.getToolkit().getScreenSize();
696
+ frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
697
+// frame.setState(Frame.MAXIMIZED_BOTH);
698
+ }
699
+
700
+ maximized ^= true;
701
+ }
702
+
585703 void ToggleFullScreen()
586704 {
587705 if (CameraPane.FULLSCREEN)
588706 {
589
- frame.getContentPane().remove(/*"Center",*/bigThree);
590
- framePanel.add(bigThree);
591
- frame.getContentPane().add(/*"Center",*/framePanel);
707
+ device.setFullScreenWindow(null);
708
+ //frame.setVisible(false);
709
+// frame.removeNotify();
710
+// frame.setUndecorated(false);
711
+// frame.addNotify();
712
+ //frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
713
+
714
+// X frame.getContentPane().remove(/*"Center",*/bigThree);
715
+// X framePanel.add(bigThree);
716
+// X frame.getContentPane().add(/*"Center",*/framePanel);
717
+ framePanel.setDividerLocation(1);
718
+
719
+ //frame.setVisible(true);
720
+ radio.layout = keepButton;
721
+ //theFrame = null;
722
+ keepButton = null;
723
+ radio.layout.doClick();
724
+
592725 } else
593726 {
594
- frame.getContentPane().remove(/*"Center",*/framePanel);
595
- framePanel.remove(bigThree);
596
- frame.getContentPane().add(/*"Center",*/bigThree);
727
+ keepButton = radio.layout;
728
+ //keeprect = frame.getBounds();
729
+// frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
730
+// frame.getToolkit().getScreenSize().height);
731
+ //frame.setVisible(false);
732
+ device.setFullScreenWindow(frame);
733
+// frame.removeNotify();
734
+// frame.setUndecorated(true);
735
+// frame.addNotify();
736
+// X frame.getContentPane().remove(/*"Center",*/framePanel);
737
+// X framePanel.remove(bigThree);
738
+// X frame.getContentPane().add(/*"Center",*/bigThree);
739
+ framePanel.setDividerLocation(0);
740
+
741
+ radio.layout = fullscreenLayout;
742
+ radio.layout.doClick();
743
+ //frame.setVisible(true);
597744 }
745
+
598746 cameraView.ToggleFullScreen();
599747 }
600748
....@@ -745,9 +893,13 @@
745893 JButton fasterButton;
746894 JButton remarkButton;
747895
896
+ cGridBag editPanel;
897
+ cGridBag editCommandsPanel;
898
+
748899 cGridBag namePanel;
749900 cGridBag setupPanel;
750
- cGridBag commandsPanel;
901
+ cGridBag setupPanel2;
902
+ cGridBag objectCommandsPanel;
751903 cGridBag pushPanel;
752904 cGridBag fillPanel;
753905
....@@ -939,40 +1091,44 @@
9391091 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
9401092 markCB.setToolTipText("Set the animation target transform");
9411093
942
- rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
1094
+ setupPanel2 = new cGridBag().setVertical(false);
1095
+
1096
+ rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
9431097 rewindCB.setToolTipText("Rewind animation");
9441098
945
- randomCB = AddCheckBox(setupPanel, "Random", copy.random);
946
- randomCB.setToolTipText("Option for switch node");
1099
+ randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1100
+ randomCB.setToolTipText("Randomly Rewind or Go back and forth");
9471101
9481102 if (Globals.ADVANCED)
9491103 {
950
- link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
1104
+ link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
9511105 link2masterCB.setToolTipText("Attach to support");
952
- speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
1106
+ speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
9531107 speedupCB.setToolTipText("Option motion capture");
9541108 }
9551109
9561110 oe.ctrlPanel.add(setupPanel);
9571111 oe.ctrlPanel.Return();
1112
+ oe.ctrlPanel.add(setupPanel2);
1113
+ oe.ctrlPanel.Return();
9581114
959
- commandsPanel = new cGridBag().setVertical(false);
1115
+ objectCommandsPanel = new cGridBag().setVertical(false);
9601116
961
- resetButton = AddButton(commandsPanel, "Reset");
1117
+ resetButton = AddButton(objectCommandsPanel, "Reset");
9621118 resetButton.setToolTipText("Jump to frame zero");
963
- stepButton = AddButton(commandsPanel, "Step");
1119
+ stepButton = AddButton(objectCommandsPanel, "Step");
9641120 stepButton.setToolTipText("Step one frame");
9651121 // resetAllButton = AddButton(oe, "Reset All");
9661122 // stepAllButton = AddButton(oe, "Step All");
9671123 // Return();
968
- slowerButton = AddButton(commandsPanel, "Slow");
1124
+ slowerButton = AddButton(objectCommandsPanel, "Slow");
9691125 slowerButton.setToolTipText("Decrease animation speed");
970
- fasterButton = AddButton(commandsPanel, "Fast");
1126
+ fasterButton = AddButton(objectCommandsPanel, "Fast");
9711127 fasterButton.setToolTipText("Increase animation speed");
972
- remarkButton = AddButton(commandsPanel, "Remark");
1128
+ remarkButton = AddButton(objectCommandsPanel, "Remark");
9731129 remarkButton.setToolTipText("Set the current transform as the target");
9741130
975
- oe.ctrlPanel.add(commandsPanel);
1131
+ oe.ctrlPanel.add(objectCommandsPanel);
9761132 oe.ctrlPanel.Return();
9771133
9781134 pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH, 1.1); // To have the buttons
....@@ -1178,8 +1334,11 @@
11781334 //worldPanel.setName("World");
11791335 centralPanel = new cGridBag();
11801336 centralPanel.preferredWidth = 20;
1181
- timelinePanel = new JPanel(new BorderLayout());
1182
- timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
1337
+
1338
+ if (Globals.ADVANCED)
1339
+ {
1340
+ timelinePanel = new JPanel(new BorderLayout());
1341
+ timelineMenubar = new timeflow.app.TimeflowApp().TimeFlowWindow(timelinePanel);
11831342
11841343 cameraPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cameraView, timelinePanel);
11851344 cameraPanel.setContinuousLayout(true);
....@@ -1188,7 +1347,10 @@
11881347 // cameraPanel.setDividerSize(9);
11891348 cameraPanel.setResizeWeight(1.0);
11901349
1350
+ }
1351
+
11911352 centralPanel.add(cameraView);
1353
+ centralPanel.setFocusable(true);
11921354 //frame.setJMenuBar(timelineMenubar);
11931355 //centralPanel.add(timelinePanel);
11941356
....@@ -1250,12 +1412,13 @@
12501412
12511413 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
12521414 //tmp.setName("Edit");
1415
+ objectPanel.add(toolboxPanel);
12531416 objectPanel.add(materialPanel);
12541417 // JPanel north = new JPanel(new BorderLayout());
12551418 // north.setName("Edit");
12561419 // north.add(ctrlPanel, BorderLayout.NORTH);
12571420 // objectPanel.add(north);
1258
- objectPanel.add(ctrlPanel);
1421
+ objectPanel.add(editPanel);
12591422 objectPanel.add(infoPanel);
12601423
12611424 /*
....@@ -1386,6 +1549,8 @@
13861549 frame.setSize(1280, 860);
13871550 frame.setVisible(true);
13881551
1552
+ cameraView.requestFocusInWindow();
1553
+
13891554 gridPanel.setDividerLocation(1.0);
13901555
13911556 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
....@@ -2072,19 +2237,19 @@
20722237
20732238 void LoadObjFile(String fullname)
20742239 {
2075
- /*
2240
+ System.out.println("Loading " + fullname);
2241
+ /**/
20762242 //lastFilename = fullname;
20772243 if(loadObjThread == null)
20782244 {
2079
- loadObjThread = new LoadOBJThread();
2080
- loadObjThread.start();
2245
+ loadObjThread = new LoadOBJThread();
2246
+ loadObjThread.start();
20812247 }
20822248
20832249 loadObjThread.add(fullname);
2084
- */
2250
+ /**/
20852251
2086
- System.out.println("Loading " + fullname);
2087
- makeSomething(new FileObject(fullname, true), true);
2252
+ //makeSomething(new FileObject(fullname, true), true);
20882253 }
20892254
20902255 void LoadGFDFile(String fullname)
....@@ -3214,7 +3379,7 @@
32143379 objEditor.refreshContents();
32153380 }
32163381
3217
- static public byte[] Compress(Object o)
3382
+ static public byte[] Compress(Object3D o)
32183383 {
32193384 try
32203385 {
....@@ -3222,8 +3387,13 @@
32223387 java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
32233388 ObjectOutputStream out = new ObjectOutputStream(zstream);
32243389
3390
+ Object3D parent = o.parent;
3391
+ o.parent = null;
3392
+
32253393 out.writeObject(o);
32263394
3395
+ o.parent = parent;
3396
+
32273397 out.flush();
32283398
32293399 zstream.close();
....@@ -3304,7 +3474,12 @@
33043474
33053475 public void Save()
33063476 {
3477
+ System.err.println("Save");
3478
+
33073479 cRadio tab = GetCurrentTab();
3480
+
3481
+ boolean temp = CameraPane.SWITCH;
3482
+ CameraPane.SWITCH = false;
33083483
33093484 copy.ExtractBigData(hashtable);
33103485
....@@ -3312,6 +3487,8 @@
33123487 tab.graphs[tab.undoindex++] = Compress(copy);
33133488
33143489 copy.RestoreBigData(hashtable);
3490
+
3491
+ CameraPane.SWITCH = temp;
33153492
33163493 //assert(hashtable.isEmpty());
33173494
....@@ -3342,6 +3519,9 @@
33423519
33433520 void CopyChanged(Object3D obj)
33443521 {
3522
+ boolean temp = CameraPane.SWITCH;
3523
+ CameraPane.SWITCH = false;
3524
+
33453525 copy.ExtractBigData(hashtable);
33463526
33473527 copy.clear();
....@@ -3352,6 +3532,8 @@
33523532 }
33533533
33543534 copy.RestoreBigData(hashtable);
3535
+
3536
+ CameraPane.SWITCH = temp;
33553537
33563538 //assert(hashtable.isEmpty());
33573539
....@@ -3378,6 +3560,8 @@
33783560
33793561 public void Undo()
33803562 {
3563
+ System.err.println("Undo");
3564
+
33813565 cRadio tab = GetCurrentTab();
33823566
33833567 if (tab.undoindex == 0)
....@@ -3561,7 +3745,7 @@
35613745 assert false;
35623746 }
35633747
3564
- void EditSelection()
3748
+ void EditSelection(boolean newWindow)
35653749 {
35663750 }
35673751
....@@ -4056,7 +4240,8 @@
40564240
40574241 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
40584242 {
4059
- Save();
4243
+ if (Globals.SAVEONMAKE) // && resetmodel)
4244
+ Save();
40604245 //Tween.set(thing, 0).target(1).start(tweenManager);
40614246 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
40624247 // if (thing instanceof GenericJointDemo)
....@@ -4143,6 +4328,12 @@
41434328 {
41444329 ResetModel();
41454330 Select(thing.GetTreePath(), true, false); // unselect... false);
4331
+
4332
+ if (thing.Size() == 0)
4333
+ {
4334
+ //EditSelection(false);
4335
+ }
4336
+
41464337 refreshContents();
41474338 }
41484339
....@@ -4280,6 +4471,7 @@
42804471
42814472 try
42824473 {
4474
+ // Try compressed version first.
42834475 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
42844476 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
42854477 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4349,6 +4541,12 @@
43494541
43504542 void LoadIt(Object obj)
43514543 {
4544
+ if (obj == null)
4545
+ {
4546
+ // Invalid file
4547
+ return;
4548
+ }
4549
+
43524550 System.out.println("Loaded " + obj);
43534551 //new Exception().printStackTrace();
43544552 Object3D readobj = (Object3D) obj;
....@@ -4358,6 +4556,7 @@
43584556
43594557 if (readobj != null)
43604558 {
4559
+ if (Globals.SAVEONMAKE)
43614560 Save();
43624561 try
43634562 {
....@@ -4729,18 +4928,29 @@
47294928 CheckboxMenuItem togglePaintItem;
47304929 JSplitPane mainPanel;
47314930 JScrollPane scrollpane;
4931
+
47324932 JPanel toolbarPanel;
4933
+
47334934 cGridBag treePanel;
4935
+
47344936 JPanel radioPanel;
47354937 ButtonGroup buttonGroup;
4736
- cGridBag ctrlPanel;
4938
+
4939
+ cGridBag toolboxPanel;
47374940 cGridBag materialPanel;
4941
+ cGridBag ctrlPanel;
4942
+
47384943 JScrollPane infoPanel;
4944
+
47394945 cGridBag optionsPanel;
4946
+
47404947 JTabbedPane objectPanel;
4948
+
47414949 cGridBag XYZPanel;
4950
+
47424951 JSplitPane gridPanel;
47434952 JSplitPane bigPanel;
4953
+
47444954 cGridBag bigThree;
47454955 cGridBag scenePanel;
47464956 cGridBag centralPanel;
....@@ -4855,7 +5065,7 @@
48555065 cNumberSlider fogField;
48565066 JLabel opacityPowerLabel;
48575067 cNumberSlider opacityPowerField;
4858
- JTree jTree;
5068
+ cTree jTree;
48595069 //ObjectUI parent;
48605070
48615071 cNumberSlider normalpushField;