Normand Briere
2019-06-26 89b25e7cc97f6fe221dfd41c4d463500f8a31bc1
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.*;
....@@ -37,6 +38,65 @@
3738 JFrame frame;
3839
3940 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
+ }
40100
41101 // SCRIPT
42102
....@@ -147,7 +207,7 @@
147207
148208 objEditor.ctrlPanel.remove(namePanel);
149209
150
- if (!GroupEditor.allparams)
210
+ if (!allparams)
151211 return;
152212
153213 // objEditor.ctrlPanel.remove(liveCB);
....@@ -277,6 +337,11 @@
277337 return frame.action(event, obj);
278338 }
279339
340
+ // Cannot work without static
341
+ static boolean allparams = true;
342
+
343
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
344
+
280345 void SetupMenu()
281346 {
282347 frame.setMenuBar(menuBar = new MenuBar());
....@@ -323,6 +388,32 @@
323388 closeItem.addActionListener(this);
324389
325390 objectPanel = new JTabbedPane();
391
+
392
+ ChangeListener changeListener = new ChangeListener()
393
+ {
394
+ public void stateChanged(ChangeEvent changeEvent)
395
+ {
396
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed)
397
+// {
398
+// if (latestObject != null)
399
+// {
400
+// refreshContents(true);
401
+// SetMaterial(latestObject);
402
+// }
403
+//
404
+// materialFlushed = true;
405
+// }
406
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit"))
407
+// {
408
+// if (listUI.size() == 0)
409
+// EditSelection(false);
410
+// }
411
+
412
+ refreshContents(false); // To refresh Info tab
413
+ }
414
+ };
415
+ objectPanel.addChangeListener(changeListener);
416
+
326417 toolbarPanel = new JPanel();
327418 toolbarPanel.setName("Toolbar");
328419 treePanel = new cGridBag();
....@@ -337,9 +428,12 @@
337428 editPanel.add(editCommandsPanel);
338429 editPanel.add(ctrlPanel);
339430
340
- materialPanel = new cGridBag().setVertical(true);
431
+ toolboxPanel = new cGridBag().setVertical(false);
432
+ toolboxPanel.setName("Toolbox");
341433
434
+ materialPanel = new cGridBag().setVertical(true);
342435 materialPanel.setName("Material");
436
+
343437 /*JTextPane*/
344438 infoarea = createTextPane();
345439 doc = infoarea.getStyledDocument();
....@@ -612,6 +706,8 @@
612706
613707 boolean maximized;
614708
709
+ cButton fullscreenLayout;
710
+
615711 void Minimize()
616712 {
617713 frame.setState(Frame.ICONIFIED);
....@@ -637,7 +733,9 @@
637733
638734 void ToggleFullScreen()
639735 {
640
- if (CameraPane.FULLSCREEN)
736
+ cameraView.ToggleFullScreen();
737
+
738
+ if (!CameraPane.FULLSCREEN)
641739 {
642740 device.setFullScreenWindow(null);
643741 //frame.setVisible(false);
....@@ -673,12 +771,10 @@
673771 // X frame.getContentPane().add(/*"Center",*/bigThree);
674772 framePanel.setDividerLocation(0);
675773
676
- radio.layout = twoButton;
774
+ radio.layout = fullscreenLayout;
677775 radio.layout.doClick();
678776 //frame.setVisible(true);
679777 }
680
-
681
- cameraView.ToggleFullScreen();
682778 }
683779
684780 private JTextPane createTextPane()
....@@ -819,7 +915,12 @@
819915 JCheckBox speedupCB;
820916 JCheckBox rewindCB;
821917 JCheckBox flipVCB;
918
+
919
+ cCheckBox toggleTextureCB;
920
+ cCheckBox toggleSwitchCB;
921
+
822922 JComboBox texresMenu;
923
+
823924 JButton resetButton;
824925 JButton stepButton;
825926 JButton stepAllButton;
....@@ -1011,7 +1112,7 @@
10111112
10121113 oe.ctrlPanel.Return();
10131114
1014
- if (!GroupEditor.allparams)
1115
+ if (!allparams)
10151116 return;
10161117
10171118 setupPanel = new cGridBag().setVertical(false);
....@@ -1354,6 +1455,7 @@
13541455 // objectPanel.add(north);
13551456 objectPanel.add(editPanel);
13561457 objectPanel.add(infoPanel);
1458
+ objectPanel.add(toolboxPanel);
13571459
13581460 /*
13591461 aConstraints.gridx = 0;
....@@ -1362,7 +1464,7 @@
13621464 aConstraints.gridy += 1;
13631465 aConstraints.gridwidth = 1;
13641466 mainPanel.add(objectPanel, aConstraints);
1365
- */
1467
+ */
13661468
13671469 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
13681470 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1379,9 +1481,7 @@
13791481 JTabbedPane tabbedPane = new JTabbedPane();
13801482 tabbedPane.add(scrollpane);
13811483
1382
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1383
-
1384
- optionsPanel = new cGridBag().setVertical(true);
1484
+ optionsPanel = new cGridBag().setVertical(false);
13851485
13861486 optionsPanel.setName("Options");
13871487
....@@ -1389,6 +1489,8 @@
13891489
13901490 tabbedPane.add(optionsPanel);
13911491
1492
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1493
+
13921494 scenePanel.add(tabbedPane);
13931495
13941496 /*
....@@ -1481,6 +1583,8 @@
14811583 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
14821584
14831585 frame.setSize(1280, 860);
1586
+
1587
+ frame.validate();
14841588 frame.setVisible(true);
14851589
14861590 cameraView.requestFocusInWindow();
....@@ -2800,6 +2904,8 @@
28002904
28012905 void SetMaterial(Object3D object)
28022906 {
2907
+ latestObject = object;
2908
+
28032909 cMaterial mat = object.material;
28042910
28052911 if (mat == null)
....@@ -2985,7 +3091,7 @@
29853091 cameraView.ToggleDL();
29863092 cameraView.repaint();
29873093 return;
2988
- } else if (event.getSource() == toggleTextureItem)
3094
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
29893095 {
29903096 cameraView.ToggleTexture();
29913097 // june 2013 copy.HardTouch();
....@@ -3024,7 +3130,7 @@
30243130 frame.validate();
30253131
30263132 return;
3027
- } else if (event.getSource() == toggleSwitchItem)
3133
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30283134 {
30293135 cameraView.ToggleSwitch();
30303136 cameraView.repaint();
....@@ -3408,6 +3514,8 @@
34083514
34093515 public void Save()
34103516 {
3517
+ System.err.println("Save");
3518
+
34113519 cRadio tab = GetCurrentTab();
34123520
34133521 boolean temp = CameraPane.SWITCH;
....@@ -3429,6 +3537,8 @@
34293537 tab.graphs[i] = null;
34303538 }
34313539
3540
+ SetUndoStates();
3541
+
34323542 // test save
34333543 if (false)
34343544 {
....@@ -3451,6 +3561,8 @@
34513561
34523562 void CopyChanged(Object3D obj)
34533563 {
3564
+ SetUndoStates();
3565
+
34543566 boolean temp = CameraPane.SWITCH;
34553567 CameraPane.SWITCH = false;
34563568
....@@ -3490,8 +3602,21 @@
34903602 refreshContents();
34913603 }
34923604
3605
+ cButton undoButton;
3606
+ cButton redoButton;
3607
+
3608
+ void SetUndoStates()
3609
+ {
3610
+ cRadio tab = GetCurrentTab();
3611
+
3612
+ undoButton.setEnabled(tab.undoindex > 0);
3613
+ redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3614
+ }
3615
+
34933616 public void Undo()
34943617 {
3618
+ System.err.println("Undo");
3619
+
34953620 cRadio tab = GetCurrentTab();
34963621
34973622 if (tab.undoindex == 0)
....@@ -3675,7 +3800,7 @@
36753800 assert false;
36763801 }
36773802
3678
- void EditSelection()
3803
+ void EditSelection(boolean newWindow)
36793804 {
36803805 }
36813806
....@@ -4170,7 +4295,8 @@
41704295
41714296 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
41724297 {
4173
- Save();
4298
+ if (Globals.SAVEONMAKE) // && resetmodel)
4299
+ Save();
41744300 //Tween.set(thing, 0).target(1).start(tweenManager);
41754301 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
41764302 // if (thing instanceof GenericJointDemo)
....@@ -4257,6 +4383,12 @@
42574383 {
42584384 ResetModel();
42594385 Select(thing.GetTreePath(), true, false); // unselect... false);
4386
+
4387
+ if (thing.Size() == 0)
4388
+ {
4389
+ //EditSelection(false);
4390
+ }
4391
+
42604392 refreshContents();
42614393 }
42624394
....@@ -4479,6 +4611,7 @@
44794611
44804612 if (readobj != null)
44814613 {
4614
+ if (Globals.SAVEONMAKE)
44824615 Save();
44834616 try
44844617 {
....@@ -4657,6 +4790,8 @@
46574790 String filename = browser.getFile();
46584791 if (filename != null && filename.length() > 0)
46594792 {
4793
+ if (!filename.endsWith(".gfd"))
4794
+ filename += ".gfd";
46604795 lastname = browser.getDirectory() + filename;
46614796 save();
46624797 }
....@@ -4850,18 +4985,31 @@
48504985 CheckboxMenuItem togglePaintItem;
48514986 JSplitPane mainPanel;
48524987 JScrollPane scrollpane;
4988
+
48534989 JPanel toolbarPanel;
4990
+
48544991 cGridBag treePanel;
4992
+
48554993 JPanel radioPanel;
48564994 ButtonGroup buttonGroup;
4857
- cGridBag ctrlPanel;
4995
+
4996
+ cGridBag toolboxPanel;
48584997 cGridBag materialPanel;
4998
+ cGridBag ctrlPanel;
4999
+
48595000 JScrollPane infoPanel;
5001
+
48605002 cGridBag optionsPanel;
5003
+
48615004 JTabbedPane objectPanel;
5005
+ boolean materialFlushed;
5006
+ Object3D latestObject;
5007
+
48625008 cGridBag XYZPanel;
5009
+
48635010 JSplitPane gridPanel;
48645011 JSplitPane bigPanel;
5012
+
48655013 cGridBag bigThree;
48665014 cGridBag scenePanel;
48675015 cGridBag centralPanel;
....@@ -4976,7 +5124,7 @@
49765124 cNumberSlider fogField;
49775125 JLabel opacityPowerLabel;
49785126 cNumberSlider opacityPowerField;
4979
- JTree jTree;
5127
+ cTree jTree;
49805128 //ObjectUI parent;
49815129
49825130 cNumberSlider normalpushField;