Normand Briere
2019-08-17 d5d6485126da83b06645e90e3e4ce66659a56009
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;
....@@ -15,7 +16,7 @@
1516 //import com.jamonapi.*;
1617 public class Grafreed extends Applet implements ActionListener
1718 {
18
- static boolean NIMBUSLAF = true;
19
+ static boolean NIMBUSLAF = false; // true;
1920
2021 static int RENDERME = 0;
2122
....@@ -47,6 +48,79 @@
4748 b = !!b;
4849 new Exception().printStackTrace(); // assert(b);
4950
51
+ }
52
+ }
53
+
54
+ public static String RemovePrefix(String s, String prefix)
55
+ {
56
+ if (s != null && prefix != null && s.startsWith(prefix))
57
+ {
58
+ return s.substring(prefix.length());
59
+ }
60
+
61
+ return s;
62
+ }
63
+
64
+ static void ParseFileSystem(java.io.File dir, iResourceCallBack callback, String prefix)
65
+ {
66
+ callback.ResourceCallBack(RemovePrefix(dir.toString(),prefix).split("/"));
67
+ File[] listFiles = dir.listFiles();
68
+ if (listFiles != null)
69
+ {
70
+ for (java.io.File file : listFiles)
71
+ {
72
+ ParseFileSystem(file, callback, prefix);
73
+ }
74
+ }
75
+ }
76
+
77
+ static interface iResourceCallBack
78
+ {
79
+ void ResourceCallBack(String[] path);
80
+ }
81
+
82
+ static void ParseResources(String path, iResourceCallBack callback)
83
+ {
84
+ java.io.File jarFile = new java.io.File(Grafreed.class.getProtectionDomain().getCodeSource().getLocation().getPath());
85
+
86
+ if (jarFile.isFile())
87
+ {
88
+ // Run with JAR file
89
+ try
90
+ {
91
+ java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
92
+ java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries(); //gives ALL entries in jar
93
+ while (entries.hasMoreElements())
94
+ {
95
+ String name = entries.nextElement().getName();
96
+
97
+ if (name.startsWith(path + "/"))
98
+ callback.ResourceCallBack(RemovePrefix(name, path + "/").split("/"));
99
+ }
100
+ jar.close();
101
+ } catch (Exception ex)
102
+ {
103
+ ex.printStackTrace();
104
+ }
105
+ } else
106
+ {
107
+ // Run with IDE
108
+ final java.net.URL url = Object3D.class.getResource("/" + path);
109
+ if (url != null)
110
+ {
111
+ try
112
+ {
113
+ java.io.File apps = new java.io.File(url.toURI());
114
+ ParseFileSystem(apps, callback, RemovePrefix(url.toString() + "/", "file:"));
115
+// for (java.io.File app : apps.listFiles())
116
+// {
117
+// //System.out.println(RemovePrefix(app.toString(), RemovePrefix(url.toString(), "file:") + "/"));
118
+// }
119
+ } catch (Exception ex)
120
+ {
121
+ ex.printStackTrace();
122
+ }
123
+ }
50124 }
51125 }
52126
....@@ -603,7 +677,8 @@
603677
604678 public static void main(String argv[])
605679 {
606
- String osArch = System.getProperty("os.arch");
680
+ String osArch = System.getProperty("os.arch");
681
+ if (Globals.DEBUG)
607682 System.out.println("os.arch = " + osArch);
608683
609684 if (argv.length == 0)
....@@ -824,6 +899,13 @@
824899 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
825900 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
826901 //UIManager.put("nimbusBase", new Color(0,0,0));
902
+
903
+ javax.swing.UIDefaults ui = UIManager.getDefaults();
904
+ for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();)
905
+ {
906
+ Object key = e.nextElement();
907
+ System.out.println(key + " --> " + ui.get(key));
908
+ }
827909 }
828910 catch (Exception e)
829911 {
....@@ -833,12 +915,49 @@
833915 {
834916 try
835917 {
836
- MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
837
- MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme));
918
+ //Object o = UIManager.getInstalledLookAndFeels();
919
+
920
+ MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
921
+ //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme));
922
+ //UIManager.put("ScrollBar.background", new javax.swing.plaf.ColorUIResource(100,0,0));
838923 UIManager.setLookAndFeel(new MetalLookAndFeel());
839924 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
840925 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
926
+ //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
841927 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
928
+
929
+ javax.swing.UIDefaults ui = UIManager.getDefaults();
930
+ ArrayList gradient = new java.util.ArrayList(5);
931
+ gradient.add(1.0);
932
+ gradient.add(0.0);
933
+ gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255));
934
+ gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192));
935
+ gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0));
936
+
937
+ ui.put("Button.gradient", gradient);
938
+ ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(0,8,0,0));
939
+ ui.put("Slider.foreground", new javax.swing.plaf.ColorUIResource(0,0,0));
940
+ ui.put("Slider.horizontalThumbIcon", ObjEditor.GetIcon("icons/white-sphere-icon.png"));
941
+
942
+ //javax.swing.plaf.metal.MetalIconFactory.getHorizontalSliderThumbIcon().
943
+ Object o = ui.get("Slider.horizontalThumbIcon");
944
+
945
+ gradient = new java.util.ArrayList(5);
946
+ gradient.add(1.0);
947
+ gradient.add(0.0);
948
+ gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192));
949
+ gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255));
950
+ gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0));
951
+
952
+ ui.put("ToggleButton.gradient", gradient);
953
+ //ui.put("Button[MouseOver].backgroundPainter", new com.sun.java.swing.plaf.nimbus.ButtonPainter());
954
+ //ui.put("Button.highlight", new javax.swing.plaf.ColorUIResource(155,155,155));
955
+
956
+ for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();)
957
+ {
958
+ Object key = e.nextElement();
959
+ //System.out.println(key + " --> " + ui.get(key));
960
+ }
842961 } catch (Exception e)
843962 {
844963 }
....@@ -855,6 +974,9 @@
855974 grafreed.universe = new cGroup();
856975 grafreed.universe.name = "Grafreed";
857976 grafreed.universe.material = new cMaterial();
977
+ grafreed.universe.skyboxname = "cubemaps/penguins-skyboxes/yonder";
978
+ grafreed.universe.skyboxext = "jpg";
979
+
858980 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
859981
860982 grafreed.universe.root = true;
....@@ -862,6 +984,8 @@
862984 //mon.stop();
863985 //System.out.println(mon);
864986 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
987
+
988
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
865989 }
866990
867991 static Object3D materials;
....@@ -877,6 +1001,8 @@
8771001 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
8781002
8791003 readobj = (Object3D) p.readObject();
1004
+ p.close();
1005
+ zstream.close();
8801006 istream.close();
8811007
8821008 readobj.ResetDisplayList();
....@@ -890,6 +1016,7 @@
8901016 java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream);
8911017
8921018 readobj = (Object3D) p.readObject();
1019
+ p.close();
8931020 istream.close();
8941021
8951022 readobj.ResetDisplayList();
....@@ -1023,6 +1150,11 @@
10231150
10241151 static public Object clone(Object o)
10251152 {
1153
+ if (o instanceof Object3D)
1154
+ {
1155
+ assert(((Object3D)o).parent == null);
1156
+ }
1157
+
10261158 if (o == null)
10271159 return null;
10281160