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
....@@ -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;
....@@ -47,6 +50,79 @@
4750
4851 }
4952 }
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
+ }
125
+ }
50126
51127 public void init()
52128 {
....@@ -56,7 +132,7 @@
56132 universe.material = new cMaterial();
57133 //god.addChild(universe);
58134 universe.name = "Applet";
59
- grafreeD = this;
135
+ grafreed = this;
60136 }
61137
62138 /**/
....@@ -601,7 +677,8 @@
601677
602678 public static void main(String argv[])
603679 {
604
- String osArch = System.getProperty("os.arch");
680
+ String osArch = System.getProperty("os.arch");
681
+ if (Globals.DEBUG)
605682 System.out.println("os.arch = " + osArch);
606683
607684 if (argv.length == 0)
....@@ -822,6 +899,13 @@
822899 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
823900 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
824901 //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
+ }
825909 }
826910 catch (Exception e)
827911 {
....@@ -831,12 +915,49 @@
831915 {
832916 try
833917 {
834
- MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
835
- 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));
836923 UIManager.setLookAndFeel(new MetalLookAndFeel());
837924 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
838925 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
926
+ //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
839927 //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
+ }
840961 } catch (Exception e)
841962 {
842963 }
....@@ -847,19 +968,67 @@
847968
848969 //Monitor mon=MonitorFactory.start("myFirstMonitor");
849970 standAlone = true;
850
- grafreeD = new Grafreed();
851
- grafreeD.universe = new cGroup();
852
- grafreeD.universe.name = "Grafreed";
853
- 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
+
854980 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
855981
856
- grafreeD.universe.root = true;
857
- grafreeD.universe.openEditWindow(null, true); //, true);
982
+ grafreed.universe.root = true;
983
+ grafreed.universe.openEditWindow(null, true); //, true);
858984 //mon.stop();
859985 //System.out.println(mon);
860986 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
987
+
988
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
861989 }
862990
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
+
8631032 // Timer callback
8641033 public void actionPerformed(ActionEvent e)
8651034 {
....@@ -874,7 +1043,7 @@
8741043 static int depth = 0;
8751044 static java.util.Stack stack = new java.util.Stack();
8761045 static boolean traceoff = false; // true;
877
- static float[] colorV = new float[5];
1046
+ static float[] colorV = new float[4]; // 5];
8781047
8791048 static void traceon()
8801049 {
....@@ -981,6 +1150,11 @@
9811150
9821151 static public Object clone(Object o)
9831152 {
1153
+ if (o instanceof Object3D)
1154
+ {
1155
+ assert(((Object3D)o).parent == null);
1156
+ }
1157
+
9841158 if (o == null)
9851159 return null;
9861160
....@@ -1083,7 +1257,7 @@
10831257 } while (avail > 0 && numRead >= 0);
10841258 return new String(data, 0, pos, "US-ASCII");
10851259 }
1086
- public static Grafreed grafreeD;
1260
+ public static Grafreed grafreed;
10871261 public static boolean standAlone = true;
10881262 public Composite universe;
10891263 public static Object3D clipboard = new Object3D();