Normand Briere
2019-08-18 66aca73cce89e4b4d7521862760edf4b0888bc38
Grafreed.java
....@@ -5,6 +5,7 @@
55
66 import java.io.*;
77
8
+import java.util.ArrayList;
89 import javax.swing.UIManager;
910 import javax.swing.plaf.metal.MetalLookAndFeel;
1011 import javax.swing.plaf.ColorUIResource;
....@@ -14,9 +15,7 @@
1415
1516 //import com.jamonapi.*;
1617 public class Grafreed extends Applet implements ActionListener
17
-{
18
- static boolean NIMBUSLAF = true;
19
-
18
+{
2019 static int RENDERME = 0;
2120
2221 static boolean epsequal = false;
....@@ -47,6 +46,79 @@
4746 b = !!b;
4847 new Exception().printStackTrace(); // assert(b);
4948
49
+ }
50
+ }
51
+
52
+ public static String RemovePrefix(String s, String prefix)
53
+ {
54
+ if (s != null && prefix != null && s.startsWith(prefix))
55
+ {
56
+ return s.substring(prefix.length());
57
+ }
58
+
59
+ return s;
60
+ }
61
+
62
+ static void ParseFileSystem(java.io.File dir, iResourceCallBack callback, String prefix)
63
+ {
64
+ callback.ResourceCallBack(RemovePrefix(dir.toString(),prefix).split("/"));
65
+ File[] listFiles = dir.listFiles();
66
+ if (listFiles != null)
67
+ {
68
+ for (java.io.File file : listFiles)
69
+ {
70
+ ParseFileSystem(file, callback, prefix);
71
+ }
72
+ }
73
+ }
74
+
75
+ static interface iResourceCallBack
76
+ {
77
+ void ResourceCallBack(String[] path);
78
+ }
79
+
80
+ static void ParseResources(String path, iResourceCallBack callback)
81
+ {
82
+ java.io.File jarFile = new java.io.File(Grafreed.class.getProtectionDomain().getCodeSource().getLocation().getPath());
83
+
84
+ if (jarFile.isFile())
85
+ {
86
+ // Run with JAR file
87
+ try
88
+ {
89
+ java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
90
+ java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries(); //gives ALL entries in jar
91
+ while (entries.hasMoreElements())
92
+ {
93
+ String name = entries.nextElement().getName();
94
+
95
+ if (name.startsWith(path + "/"))
96
+ callback.ResourceCallBack(RemovePrefix(name, path + "/").split("/"));
97
+ }
98
+ jar.close();
99
+ } catch (Exception ex)
100
+ {
101
+ ex.printStackTrace();
102
+ }
103
+ } else
104
+ {
105
+ // Run with IDE
106
+ final java.net.URL url = Object3D.class.getResource("/" + path);
107
+ if (url != null)
108
+ {
109
+ try
110
+ {
111
+ java.io.File apps = new java.io.File(url.toURI());
112
+ ParseFileSystem(apps, callback, RemovePrefix(url.toString() + "/", "file:"));
113
+// for (java.io.File app : apps.listFiles())
114
+// {
115
+// //System.out.println(RemovePrefix(app.toString(), RemovePrefix(url.toString(), "file:") + "/"));
116
+// }
117
+ } catch (Exception ex)
118
+ {
119
+ ex.printStackTrace();
120
+ }
121
+ }
50122 }
51123 }
52124
....@@ -603,7 +675,8 @@
603675
604676 public static void main(String argv[])
605677 {
606
- String osArch = System.getProperty("os.arch");
678
+ String osArch = System.getProperty("os.arch");
679
+ if (Globals.DEBUG)
607680 System.out.println("os.arch = " + osArch);
608681
609682 if (argv.length == 0)
....@@ -810,20 +883,30 @@
810883
811884
812885 /**/
813
- if (NIMBUSLAF)
886
+ if (Globals.NIMBUSLAF)
814887 {
815888 try
816889 {
817
- Object o = UIManager.getInstalledLookAndFeels();
890
+ //Object o = UIManager.getInstalledLookAndFeels();
818891
819892 javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
820893 //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.beigeTheme));
821
- UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
894
+ //UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
822895
823896 UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
824897 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
825898 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
826899 //UIManager.put("nimbusBase", new Color(0,0,0));
900
+
901
+ javax.swing.UIDefaults ui = UIManager.getDefaults();
902
+
903
+ ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(0,8,0,0));
904
+
905
+ for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();)
906
+ {
907
+ Object key = e.nextElement();
908
+ System.out.println(key + " --> " + ui.get(key));
909
+ }
827910 }
828911 catch (Exception e)
829912 {
....@@ -833,12 +916,95 @@
833916 {
834917 try
835918 {
836
- MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
837
- MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme));
919
+ //Object o = UIManager.getInstalledLookAndFeels();
920
+
921
+ MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
922
+ //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme));
923
+ //UIManager.put("ScrollBar.background", new javax.swing.plaf.ColorUIResource(100,0,0));
924
+ UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
925
+
926
+ javax.swing.UIDefaults ui = UIManager.getDefaults();
927
+
928
+ Object x = ui.get("TabbedPane.background");
929
+
838930 UIManager.setLookAndFeel(new MetalLookAndFeel());
839
- //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
840931 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
932
+ //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
841933 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
934
+
935
+ ui = UIManager.getDefaults();
936
+
937
+ ArrayList gradient = new java.util.ArrayList(5);
938
+ gradient.add(1.0);
939
+ gradient.add(0.0);
940
+ gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255));
941
+ gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192));
942
+ gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0));
943
+
944
+ ui.put("Button.gradient", gradient);
945
+
946
+ //ui.put("RadioButton.icon", ObjEditor.GetIcon("icons/white-sphere-icon.png"));
947
+ //ui.put("RadioButtonMenuItem.checkIcon", ObjEditor.GetIcon("icons/fit.png"));
948
+ //ui.put("RadioButtonMenuItem.arrowIcon", ObjEditor.GetIcon("icons/fit.png"));
949
+
950
+ ui.put("Slider.foreground", new javax.swing.plaf.ColorUIResource(0,0,0));
951
+ ui.put("Slider.horizontalThumbIcon", ObjEditor.GetIcon("icons/white-sphere-icon.png"));
952
+
953
+ /*
954
+TabbedPane.unselectedBackground Color
955
+TabbedPane.unselectedTabBackground Color
956
+TabbedPane.unselectedTabForeground Color
957
+TabbedPane.unselectedTabHighlight Color
958
+TabbedPane.unselectedTabShadow
959
+ */
960
+// ui.put("TabbedPane.contentAreaColor", new javax.swing.plaf.ColorUIResource(0,100,0));
961
+ //ui.put("TabbedPane.selected", new javax.swing.plaf.ColorUIResource(200,0,200));
962
+
963
+ ui.put("TabbedPane.background", new javax.swing.plaf.ColorUIResource(150,150,150));
964
+ ui.put("TabbedPane.foreground", new javax.swing.plaf.ColorUIResource(50,50,50));
965
+ ui.put("TabbedPane.light", new javax.swing.plaf.ColorUIResource(255,255,255));
966
+ ui.put("TabbedPane.selectedForeground", new javax.swing.plaf.ColorUIResource(0,0,0));
967
+ ui.put("TabbedPane.selectHighlight", new javax.swing.plaf.ColorUIResource(255,255,255));
968
+ ui.put("TabbedPane.darkShadow", new javax.swing.plaf.ColorUIResource(0,0,0));
969
+
970
+// ui.put("TabbedPane.shadow", new javax.swing.plaf.ColorUIResource(200,0,0));
971
+// ui.put("TabbedPane.tabAreaBackground", new javax.swing.plaf.ColorUIResource(0,200,0));
972
+// ui.put("TabbedPane.unselectedBackground", new javax.swing.plaf.ColorUIResource(200,200,0));
973
+// ui.put("TabbedPane.unselectedTabBackground", new javax.swing.plaf.ColorUIResource(0,0,200));
974
+// ui.put("TabbedPane.unselectedTabForeground", new javax.swing.plaf.ColorUIResource(200,0,200));
975
+// ui.put("TabbedPane.unselectedTabHighlight", new javax.swing.plaf.ColorUIResource(0,200,200));
976
+// ui.put("TabbedPane.unselectedTabShadow", new javax.swing.plaf.ColorUIResource(200,200,200));
977
+
978
+ ui.put("TabbedPane.textIconGap", 0);
979
+ ui.put("TabbedPane.contentBorderInsets", new javax.swing.plaf.InsetsUIResource(0,0,0,0));
980
+ ui.put("TabbedPane.tabAreaInsets", new javax.swing.plaf.InsetsUIResource(1,1,0,0));
981
+ ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(0,8,0,0));
982
+
983
+ Object openIcon2 = ui.get("Tree.openIcon");
984
+
985
+ ui.put("Tree.openIcon", ObjEditor.GetIcon("icons/folderopen.png"));
986
+ ui.put("Tree.closedIcon", ObjEditor.GetIcon("icons/folderclose.png"));
987
+ ui.put("Tree.leafIcon", ObjEditor.GetIcon("icons/file.png"));
988
+
989
+ //javax.swing.plaf.metal.MetalIconFactory.getHorizontalSliderThumbIcon().
990
+ Object o = ui.get("Slider.horizontalThumbIcon");
991
+
992
+ gradient = new java.util.ArrayList(5);
993
+ gradient.add(1.0);
994
+ gradient.add(0.0);
995
+ gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192));
996
+ gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255));
997
+ gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0));
998
+
999
+ ui.put("ToggleButton.gradient", gradient);
1000
+ //ui.put("Button[MouseOver].backgroundPainter", new com.sun.java.swing.plaf.nimbus.ButtonPainter());
1001
+ //ui.put("Button.highlight", new javax.swing.plaf.ColorUIResource(155,155,155));
1002
+
1003
+ for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();)
1004
+ {
1005
+ Object key = e.nextElement();
1006
+ //System.out.println(key + " --> " + ui.get(key));
1007
+ }
8421008 } catch (Exception e)
8431009 {
8441010 }
....@@ -855,6 +1021,9 @@
8551021 grafreed.universe = new cGroup();
8561022 grafreed.universe.name = "Grafreed";
8571023 grafreed.universe.material = new cMaterial();
1024
+ grafreed.universe.skyboxname = "cubemaps/penguins-skyboxes/yonder";
1025
+ grafreed.universe.skyboxext = "jpg";
1026
+
8581027 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
8591028
8601029 grafreed.universe.root = true;
....@@ -862,6 +1031,8 @@
8621031 //mon.stop();
8631032 //System.out.println(mon);
8641033 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
1034
+
1035
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
8651036 }
8661037
8671038 static Object3D materials;
....@@ -877,6 +1048,8 @@
8771048 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
8781049
8791050 readobj = (Object3D) p.readObject();
1051
+ p.close();
1052
+ zstream.close();
8801053 istream.close();
8811054
8821055 readobj.ResetDisplayList();
....@@ -890,6 +1063,7 @@
8901063 java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream);
8911064
8921065 readobj = (Object3D) p.readObject();
1066
+ p.close();
8931067 istream.close();
8941068
8951069 readobj.ResetDisplayList();
....@@ -1023,6 +1197,11 @@
10231197
10241198 static public Object clone(Object o)
10251199 {
1200
+ if (o instanceof Object3D)
1201
+ {
1202
+ assert(((Object3D)o).parent == null);
1203
+ }
1204
+
10261205 if (o == null)
10271206 return null;
10281207