Normand Briere
2019-08-01 29d5516687020263d3ae0454ce81879a3a450af0
ObjEditor.java
....@@ -41,64 +41,78 @@
4141 JFrame frame;
4242
4343 static ObjEditor theFrame;
44
+
45
+ public cGridBag GetSeparator()
46
+ {
47
+ cGridBag separator = new cGridBag();
48
+ separator.add(new JSeparator());
49
+ separator.preferredHeight = 5;
50
+ return separator;
51
+ }
4452
4553 cButton GetButton(String name, boolean border)
4654 {
47
- try
48
- {
49
- ImageIcon icon = GetIcon(name);
50
- return new cButton(icon, border);
51
- }
52
- catch (Exception e)
53
- {
54
- return new cButton(name, border);
55
- }
55
+ ImageIcon icon = GetIcon(name);
56
+ return new cButton(icon, border);
57
+ }
58
+
59
+ cLabel GetLabel(String name, boolean border)
60
+ {
61
+ //ImageIcon icon = GetIcon(name);
62
+ return new cLabel(GetImage(name), border);
5663 }
5764
5865 cToggleButton GetToggleButton(String name, boolean border)
5966 {
60
- try
61
- {
62
- ImageIcon icon = GetIcon(name);
63
- return new cToggleButton(icon, border);
64
- }
65
- catch (Exception e)
66
- {
67
- return new cToggleButton(name, border);
68
- }
67
+ ImageIcon icon = GetIcon(name);
68
+ return new cToggleButton(icon, border);
6969 }
7070
7171 cCheckBox GetCheckBox(String name, boolean border)
7272 {
73
+ ImageIcon icon = GetIcon(name);
74
+ return new cCheckBox(icon, border);
75
+ }
76
+
77
+ ImageIcon GetIcon(String name)
78
+ {
7379 try
7480 {
75
- ImageIcon icon = GetIcon(name);
76
- return new cCheckBox(icon, border);
81
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
82
+
83
+// if (image.getWidth() > 48 && image.getHeight() > 48)
84
+// {
85
+// BufferedImage resized = new BufferedImage(48, 48, image.getType());
86
+// Graphics2D g = resized.createGraphics();
87
+// g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
88
+// //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
89
+// g.drawImage(image, 0, 0, 48, 48, 0, 0, image.getWidth(), image.getHeight(), null);
90
+// g.dispose();
91
+//
92
+// image = resized;
93
+// }
94
+
95
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
96
+ return icon;
7797 }
7898 catch (Exception e)
7999 {
80
- return new cCheckBox(name, border);
100
+ return null;
81101 }
82102 }
83
-
84
- private ImageIcon GetIcon(String name) throws IOException
103
+
104
+ BufferedImage GetImage(String name)
85105 {
86
- BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
87
-
88
- if (image.getWidth() != 24 && image.getHeight() != 24)
106
+ try
89107 {
90
- BufferedImage resized = new BufferedImage(24, 24, image.getType());
91
- Graphics2D g = resized.createGraphics();
92
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
93
- //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
94
- g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
95
- g.dispose();
96
-
97
- image = resized;
108
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
109
+
110
+ return image;
98111 }
99
-
100
- javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
101
- return icon;
112
+ catch (Exception e)
113
+ {
114
+ return null;
115
+ }
102116 }
103117
104118 // SCRIPT
....@@ -282,6 +296,12 @@
282296 client = inClient;
283297 copy = client;
284298
299
+ if (copy.versions == null)
300
+ {
301
+ copy.versions = new byte[100][];
302
+ copy.versionindex = -1;
303
+ }
304
+
285305 // "this" is not called: SetupUI2(objEditor);
286306 }
287307
....@@ -295,6 +315,12 @@
295315 client = inClient;
296316 copy = client;
297317
318
+ if (copy.versions == null)
319
+ {
320
+ copy.versions = new byte[100][];
321
+ copy.versionindex = -1;
322
+ }
323
+
298324 SetupUI2(callee.GetEditor());
299325 }
300326
....@@ -327,6 +353,12 @@
327353 copy = localCopy;
328354 copy.editWindow = this;
329355
356
+ if (copy.versions == null)
357
+ {
358
+// copy.versions = new byte[100][];
359
+// copy.versionindex = -1;
360
+ }
361
+
330362 SetupMenu();
331363
332364 //SetupName(objEditor); // new
....@@ -419,11 +451,12 @@
419451
420452 toolbarPanel = new JPanel();
421453 toolbarPanel.setName("Toolbar");
454
+
422455 treePanel = new cGridBag();
423456 treePanel.setName("Tree");
424457
425458 editPanel = new cGridBag().setVertical(true);
426
- editPanel.setName("Edit");
459
+ //editPanel.setName("Edit");
427460
428461 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
429462
....@@ -431,11 +464,11 @@
431464 editPanel.add(editCommandsPanel);
432465 editPanel.add(ctrlPanel);
433466
434
- toolboxPanel = new cGridBag().setVertical(false);
435
- toolboxPanel.setName("Toolbox");
467
+ toolboxPanel = new cGridBag().setVertical(true);
468
+ //toolboxPanel.setName("Toolbox");
436469
437470 materialPanel = new cGridBag().setVertical(true);
438
- materialPanel.setName("Material");
471
+ //materialPanel.setName("Material");
439472
440473 /*JTextPane*/
441474 infoarea = createTextPane();
....@@ -443,6 +476,7 @@
443476
444477 infoarea.setEditable(true);
445478 SetText();
479
+
446480 // infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
447481 // infoarea.setOpaque(false);
448482 // //infoarea.setForeground(textcolor);
....@@ -450,7 +484,7 @@
450484 // TEXTAREA infoarea.setWrapStyleWord(true);
451485 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
452486 infoPanel.setPreferredSize(new Dimension(1, 1));
453
- infoPanel.setName("Info");
487
+ //infoPanel.setName("Info");
454488 //infoPanel.setLayout(new BorderLayout());
455489 //infoPanel.add(createTextPane());
456490
....@@ -968,7 +1002,7 @@
9681002 // NumberSlider vDivsField;
9691003 // JCheckBox endcaps;
9701004 JCheckBox liveCB;
971
- JCheckBox selectCB;
1005
+ JCheckBox selectableCB;
9721006 JCheckBox hideCB;
9731007 JCheckBox link2masterCB;
9741008 JCheckBox markCB;
....@@ -1180,13 +1214,16 @@
11801214
11811215 liveCB = AddCheckBox(setupPanel, "Live", copy.live);
11821216 liveCB.setToolTipText("Animate object");
1183
- selectCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
1184
- selectCB.setToolTipText("Make object selectable");
1217
+ selectableCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
1218
+ selectableCB.setToolTipText("Make object selectable");
11851219 // Return();
1220
+
11861221 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
11871222 hideCB.setToolTipText("Hide object");
11881223 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
11891224 markCB.setToolTipText("As animation target transform");
1225
+
1226
+ ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
11901227
11911228 setupPanel2 = new cGridBag().setVertical(false);
11921229
....@@ -1474,6 +1511,7 @@
14741511 XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll);
14751512 XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll);
14761513 XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
1514
+ //XYZPanel.setName("XYZ");
14771515
14781516 /*
14791517 gridPanel = new JPanel(); //new BorderLayout());
....@@ -1511,16 +1549,29 @@
15111549 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
15121550 //tmp.setName("Edit");
15131551 objectPanel.add(materialPanel);
1552
+ objectPanel.setIconAt(0, GetIcon("icons/material.png"));
1553
+ objectPanel.setToolTipTextAt(0, "Material panel");
1554
+
15141555 // JPanel north = new JPanel(new BorderLayout());
15151556 // north.setName("Edit");
15161557 // north.add(ctrlPanel, BorderLayout.NORTH);
15171558 // objectPanel.add(north);
15181559 objectPanel.add(editPanel);
1560
+ objectPanel.setIconAt(1, GetIcon("icons/write.png"));
1561
+ objectPanel.setToolTipTextAt(1, "Edit panel");
15191562
15201563 //if (Globals.ADVANCED)
15211564 objectPanel.add(infoPanel);
1565
+ objectPanel.setIconAt(2, GetIcon("icons/info.png"));
1566
+ objectPanel.setToolTipTextAt(2, "Info panel");
1567
+
1568
+ objectPanel.add(XYZPanel);
1569
+ objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
1570
+ objectPanel.setToolTipTextAt(3, "XYZ/RGB panel");
15221571
15231572 objectPanel.add(toolboxPanel);
1573
+ objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
1574
+ objectPanel.setToolTipTextAt(4, "Objects/backgrounds panel");
15241575
15251576 /*
15261577 aConstraints.gridx = 0;
....@@ -1541,7 +1592,7 @@
15411592 scrollpane.addMouseWheelListener(this); // Default not fast enough
15421593
15431594 /*JTabbedPane*/ scenePanel = new cGridBag();
1544
- scenePanel.preferredWidth = 6;
1595
+ scenePanel.preferredWidth = 5;
15451596
15461597 JTabbedPane tabbedPane = new JTabbedPane();
15471598 tabbedPane.add(scrollpane);
....@@ -1619,7 +1670,7 @@
16191670 bigThree = new cGridBag();
16201671 bigThree.addComponent(scenePanel);
16211672 bigThree.addComponent(centralPanel);
1622
- bigThree.addComponent(XYZPanel);
1673
+ //bigThree.addComponent(XYZPanel);
16231674
16241675 // // SIDE EFFECT!!!
16251676 // aConstraints.gridx = 0;
....@@ -1660,7 +1711,6 @@
16601711 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
16611712 frame.addWindowListener(new WindowAdapter()
16621713 {
1663
-
16641714 public void windowClosing(WindowEvent e)
16651715 {
16661716 Close();
....@@ -1722,27 +1772,48 @@
17221772 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17231773
17241774 cGridBag colorSection = new cGridBag().setVertical(true);
1775
+
1776
+ cGridBag huepanel = new cGridBag();
1777
+ cGridBag huelabel = new cGridBag();
1778
+ huelabel.add(GetLabel("icons/hue.png", false));
1779
+ huelabel.preferredWidth = 20;
1780
+ huepanel.add(new cGridBag()); // Label
1781
+ huepanel.add(huelabel); // Field/slider
1782
+
1783
+ huepanel.preferredHeight = 7;
1784
+
1785
+ colorSection.add(huepanel);
17251786
17261787 cGridBag color = new cGridBag();
1727
- color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints);
1728
- colorLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1729
- color.add(colorField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1788
+
1789
+ color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints);
1790
+ colorLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1791
+ color.add(colorField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
1792
+
17301793 //colorField.preferredWidth = 200;
17311794 colorSection.add(color);
17321795
17331796 cGridBag modulation = new cGridBag();
17341797 modulation.add(modulationLabel = new JLabel("Saturation")); // , aConstraints);
17351798 modulationLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1736
- modulation.add(modulationField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1799
+ modulation.add(modulationField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
17371800 colorSection.add(modulation);
17381801
1802
+ cGridBag opacity = new cGridBag();
1803
+ opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
1804
+ opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1805
+ opacity.add(opacityField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
1806
+ colorSection.add(opacity);
1807
+
1808
+ colorSection.add(GetSeparator());
1809
+
17391810 cGridBag texture = new cGridBag();
17401811 texture.add(textureLabel = new JLabel("Texture")); // , aConstraints);
17411812 textureLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17421813 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
17431814 colorSection.add(texture);
17441815
1745
- panel.add(new JSeparator());
1816
+ panel.add(GetSeparator());
17461817
17471818 panel.add(colorSection);
17481819
....@@ -1798,7 +1869,7 @@
17981869 shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17991870 diffuseSection.add(shadowbias);
18001871
1801
- panel.add(new JSeparator());
1872
+ panel.add(GetSeparator());
18021873
18031874 panel.add(diffuseSection);
18041875
....@@ -1861,7 +1932,7 @@
18611932 specularSection.add(anisoV);
18621933
18631934
1864
- panel.add(new JSeparator());
1935
+ panel.add(GetSeparator());
18651936
18661937 panel.add(specularSection);
18671938
....@@ -1886,12 +1957,6 @@
18861957 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18871958 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
18881959 colorSection.add(backlit);
1889
-
1890
- cGridBag opacity = new cGridBag();
1891
- opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
1892
- opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1893
- opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1894
- colorSection.add(opacity);
18951960
18961961 //panel.add(new JSeparator());
18971962
....@@ -1937,7 +2002,7 @@
19372002 opacityPower.add(opacityPowerField = new cNumberSlider(this, 0.0, 10 /*10 dec 2013*/)); // , aConstraints);
19382003 textureSection.add(opacityPower);
19392004
1940
- panel.add(new JSeparator());
2005
+ panel.add(GetSeparator());
19412006
19422007 panel.add(textureSection);
19432008
....@@ -3236,7 +3301,7 @@
32363301 {
32373302 copy.live ^= true;
32383303 return;
3239
- } else if (event.getSource() == selectCB)
3304
+ } else if (event.getSource() == selectableCB)
32403305 {
32413306 copy.dontselect ^= true;
32423307 return;
....@@ -3627,7 +3692,7 @@
36273692
36283693 cRadio tab = GetCurrentTab();
36293694
3630
- byte[] compress = CompressCopy();
3695
+ byte[] compress = CompressCopy(); // Saved version. No need for "Replace".
36313696
36323697 boolean thesame = false;
36333698
....@@ -3694,6 +3759,9 @@
36943759
36953760 copy.clear();
36963761
3762
+ copy.skyboxname = obj.skyboxname;
3763
+ copy.skyboxext = obj.skyboxext;
3764
+
36973765 for (int i=0; i<obj.Size(); i++)
36983766 {
36993767 copy.add(obj.get(i));
....@@ -3731,18 +3799,42 @@
37313799 cButton replaceButton;
37323800 cButton redoButton;
37333801
3802
+ boolean muteSlider;
3803
+
3804
+ int VersionCount()
3805
+ {
3806
+ int count = 0;
3807
+
3808
+ for (int i = copy.versions.length; --i >= 0;)
3809
+ {
3810
+ if (copy.versions[i] != null)
3811
+ count++;
3812
+ }
3813
+
3814
+ return count;
3815
+ }
3816
+
37343817 void SetUndoStates()
37353818 {
37363819 cRadio tab = GetCurrentTab();
37373820
37383821 restoreButton.setEnabled(copy.versionindex != -1);
37393822 replaceButton.setEnabled(copy.versionindex != -1);
3823
+
37403824 undoButton.setEnabled(copy.versionindex > 0);
37413825 redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3826
+
3827
+ muteSlider = true;
3828
+ versionSlider.setMaximum(VersionCount() - 1);
3829
+ versionSlider.setInteger(copy.versionindex);
3830
+ muteSlider = false;
37423831 }
37433832
37443833 public boolean Undo()
37453834 {
3835
+ // Option?
3836
+ Replace();
3837
+
37463838 System.err.println("Undo");
37473839
37483840 cRadio tab = GetCurrentTab();
....@@ -3809,6 +3901,9 @@
38093901
38103902 public void Redo()
38113903 {
3904
+ // Option?
3905
+ Replace();
3906
+
38123907 cRadio tab = GetCurrentTab();
38133908
38143909 if (copy.versions[copy.versionindex + 1] == null)
....@@ -4118,14 +4213,17 @@
41184213 //copy.Touch();
41194214 }
41204215
4121
- cNumberSlider versionField;
4216
+ cNumberSlider versionSlider;
41224217
41234218 public void stateChanged(ChangeEvent e)
41244219 {
41254220 // assert(false);
4126
- if (e.getSource() == versionField)
4221
+ if (e.getSource() == versionSlider)
41274222 {
4128
- int version = versionField.getInteger();
4223
+ if (muteSlider)
4224
+ return;
4225
+
4226
+ int version = versionSlider.getInteger();
41294227
41304228 if (copy.versions[version] != null)
41314229 {
....@@ -4724,7 +4822,9 @@
47244822 readobj.ResetDisplayList();
47254823 } catch (Exception e)
47264824 {
4727
- //e.printStackTrace();
4825
+ if (!e.toString().contains("GZIP"))
4826
+ e.printStackTrace();
4827
+
47284828 try
47294829 {
47304830 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
....@@ -4804,6 +4904,8 @@
48044904 {
48054905 //readobj.deepCopySelf(copy);
48064906 copy.clear(); // june 2014
4907
+ copy.skyboxname = readobj.skyboxname;
4908
+ copy.skyboxext = readobj.skyboxext;
48074909 for (int i = 0; i < readobj.size(); i++)
48084910 {
48094911 Object3D child = readobj.get(i); // reserve(i);
....@@ -4844,6 +4946,7 @@
48444946 }
48454947 } catch (ClassCastException e)
48464948 {
4949
+ e.printStackTrace();
48474950 assert (false);
48484951 Composite c = (Composite) copy;
48494952 c.children.clear();
....@@ -4857,7 +4960,13 @@
48574960 copy.versions = readobj.versions;
48584961 copy.versionindex = readobj.versionindex;
48594962
4860
- SetUndoStates();
4963
+ if (copy.versions == null)
4964
+ {
4965
+ copy.versions = new byte[100][];
4966
+ copy.versionindex = -1;
4967
+ }
4968
+
4969
+ //? SetUndoStates();
48614970
48624971 ResetModel();
48634972 copy.HardTouch(); // recompile?
....@@ -4968,6 +5077,7 @@
49685077 //ps.print(buffer.toString());
49695078 } catch (IOException e)
49705079 {
5080
+ e.printStackTrace();
49715081 }
49725082 }
49735083