Normand Briere
2019-08-17 5892f05411c3d4dce2d8a59e0966dc2e1843a971
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
....@@ -23,6 +24,8 @@
2324 static float epsvertex2 = 0.001f;
2425 static boolean linkUV = false; // not uniform at load time
2526
27
+ static boolean smoothmode = false;
28
+
2629 static Wav wav = new Wav("/Users/nbriere/0ut/wavs/monoformat"); // output");
2730 static boolean hassound = false;
2831 static boolean savesound = false;
....@@ -41,7 +44,84 @@
4144 static void Assert(boolean b)
4245 {
4346 if (!b)
47
+ {
48
+ b = !!b;
4449 new Exception().printStackTrace(); // assert(b);
50
+
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
+ }
124
+ }
45125 }
46126
47127 public void init()
....@@ -52,7 +132,7 @@
52132 universe.material = new cMaterial();
53133 //god.addChild(universe);
54134 universe.name = "Applet";
55
- grafreeD = this;
135
+ grafreed = this;
56136 }
57137
58138 /**/
....@@ -597,7 +677,8 @@
597677
598678 public static void main(String argv[])
599679 {
600
- String osArch = System.getProperty("os.arch");
680
+ String osArch = System.getProperty("os.arch");
681
+ if (Globals.DEBUG)
601682 System.out.println("os.arch = " + osArch);
602683
603684 if (argv.length == 0)
....@@ -818,6 +899,13 @@
818899 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
819900 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
820901 //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
+ }
821909 }
822910 catch (Exception e)
823911 {
....@@ -827,12 +915,49 @@
827915 {
828916 try
829917 {
830
- MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
831
- 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));
832923 UIManager.setLookAndFeel(new MetalLookAndFeel());
833924 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
834925 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
926
+ //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
835927 //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
+ }
836961 } catch (Exception e)
837962 {
838963 }
....@@ -843,19 +968,67 @@
843968
844969 //Monitor mon=MonitorFactory.start("myFirstMonitor");
845970 standAlone = true;
846
- grafreeD = new Grafreed();
847
- grafreeD.universe = new Composite();
848
- grafreeD.universe.name = "Grafreed";
849
- grafreeD.universe.material = new cMaterial();
971
+ grafreed = new Grafreed();
972
+ grafreed.materials = ReadGFD(grafreed.getClass().getClassLoader().getResourceAsStream("gfd/materials.gfd"));
973
+
974
+ grafreed.universe = new cGroup();
975
+ grafreed.universe.name = "Grafreed";
976
+ grafreed.universe.material = new cMaterial();
977
+ grafreed.universe.skyboxname = "cubemaps/penguins-skyboxes/yonder";
978
+ grafreed.universe.skyboxext = "jpg";
979
+
850980 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
851981
852
- grafreeD.universe.root = true;
853
- grafreeD.universe.openEditWindow(null, true); //, true);
982
+ grafreed.universe.root = true;
983
+ grafreed.universe.openEditWindow(null, true); //, true);
854984 //mon.stop();
855985 //System.out.println(mon);
856986 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
987
+
988
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
857989 }
858990
991
+ static Object3D materials;
992
+
993
+ static Object3D ReadGFD(java.io.InputStream istream)
994
+ {
995
+ Object3D readobj = null;
996
+
997
+ try
998
+ {
999
+ // Try compressed version first.
1000
+ java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
1001
+ java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
1002
+
1003
+ readobj = (Object3D) p.readObject();
1004
+ p.close();
1005
+ zstream.close();
1006
+ istream.close();
1007
+
1008
+ readobj.ResetDisplayList();
1009
+ } catch (Exception e)
1010
+ {
1011
+ if (!e.toString().contains("GZIP"))
1012
+ e.printStackTrace();
1013
+
1014
+ try
1015
+ {
1016
+ java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream);
1017
+
1018
+ readobj = (Object3D) p.readObject();
1019
+ p.close();
1020
+ istream.close();
1021
+
1022
+ readobj.ResetDisplayList();
1023
+ } catch (Exception e2)
1024
+ {
1025
+ e2.printStackTrace();
1026
+ }
1027
+ }
1028
+
1029
+ return readobj;
1030
+ }
1031
+
8591032 // Timer callback
8601033 public void actionPerformed(ActionEvent e)
8611034 {
....@@ -870,7 +1043,7 @@
8701043 static int depth = 0;
8711044 static java.util.Stack stack = new java.util.Stack();
8721045 static boolean traceoff = false; // true;
873
- static float[] colorV = new float[5];
1046
+ static float[] colorV = new float[4]; // 5];
8741047
8751048 static void traceon()
8761049 {
....@@ -1079,7 +1252,7 @@
10791252 } while (avail > 0 && numRead >= 0);
10801253 return new String(data, 0, pos, "US-ASCII");
10811254 }
1082
- public static Grafreed grafreeD;
1255
+ public static Grafreed grafreed;
10831256 public static boolean standAlone = true;
10841257 public Composite universe;
10851258 public static Object3D clipboard = new Object3D();