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
....@@ -49,6 +50,79 @@
4950
5051 }
5152 }
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
+ }
52126
53127 public void init()
54128 {
....@@ -58,7 +132,7 @@
58132 universe.material = new cMaterial();
59133 //god.addChild(universe);
60134 universe.name = "Applet";
61
- grafreeD = this;
135
+ grafreed = this;
62136 }
63137
64138 /**/
....@@ -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)
....@@ -626,12 +701,12 @@
626701
627702 System.out.println("jarfile = " + jarfile);
628703
629
- String command = javaPath + " -Xmx2048m -Djava.library.path=" + jarpath;
704
+ String command = javaPath + " -Xmx1024m -Djava.library.path=" + jarpath;
630705
631706 // -Djava.library.path=/Users/nbriere/Projects/shared/lib
632707 if (jarfile.charAt(2) == ':')
633708 {
634
- command = "\"" + javaPath + "\" -Xmx2048m -Djava.library.path=" + jarpath;
709
+ command = "\"" + javaPath + "\" -Xmx1024m -Djava.library.path=" + jarpath;
635710 // On Windows systems, the path is /C:/
636711 jarfile = jarfile.substring(1, jarfile.length());
637712 System.out.println("jarfile = " + jarfile);
....@@ -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 }
....@@ -849,19 +968,67 @@
849968
850969 //Monitor mon=MonitorFactory.start("myFirstMonitor");
851970 standAlone = true;
852
- grafreeD = new Grafreed();
853
- grafreeD.universe = new cGroup();
854
- grafreeD.universe.name = "Grafreed";
855
- 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
+
856980 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
857981
858
- grafreeD.universe.root = true;
859
- grafreeD.universe.openEditWindow(null, true); //, true);
982
+ grafreed.universe.root = true;
983
+ grafreed.universe.openEditWindow(null, true); //, true);
860984 //mon.stop();
861985 //System.out.println(mon);
862986 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
987
+
988
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
863989 }
864990
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
+
8651032 // Timer callback
8661033 public void actionPerformed(ActionEvent e)
8671034 {
....@@ -1085,7 +1252,7 @@
10851252 } while (avail > 0 && numRead >= 0);
10861253 return new String(data, 0, pos, "US-ASCII");
10871254 }
1088
- public static Grafreed grafreeD;
1255
+ public static Grafreed grafreed;
10891256 public static boolean standAlone = true;
10901257 public Composite universe;
10911258 public static Object3D clipboard = new Object3D();