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,15 +15,15 @@
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;
2322 static float epsvertex2 = 0.001f;
2423 static boolean linkUV = false; // not uniform at load time
2524
25
+ static boolean smoothmode = false;
26
+
2627 static Wav wav = new Wav("/Users/nbriere/0ut/wavs/monoformat"); // output");
2728 static boolean hassound = false;
2829 static boolean savesound = false;
....@@ -41,7 +42,84 @@
4142 static void Assert(boolean b)
4243 {
4344 if (!b)
45
+ {
46
+ b = !!b;
4447 new Exception().printStackTrace(); // assert(b);
48
+
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
+ }
122
+ }
45123 }
46124
47125 public void init()
....@@ -52,7 +130,7 @@
52130 universe.material = new cMaterial();
53131 //god.addChild(universe);
54132 universe.name = "Applet";
55
- grafreeD = this;
133
+ grafreed = this;
56134 }
57135
58136 /**/
....@@ -597,7 +675,8 @@
597675
598676 public static void main(String argv[])
599677 {
600
- String osArch = System.getProperty("os.arch");
678
+ String osArch = System.getProperty("os.arch");
679
+ if (Globals.DEBUG)
601680 System.out.println("os.arch = " + osArch);
602681
603682 if (argv.length == 0)
....@@ -804,20 +883,30 @@
804883
805884
806885 /**/
807
- if (NIMBUSLAF)
886
+ if (Globals.NIMBUSLAF)
808887 {
809888 try
810889 {
811
- Object o = UIManager.getInstalledLookAndFeels();
890
+ //Object o = UIManager.getInstalledLookAndFeels();
812891
813892 javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
814893 //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.beigeTheme));
815
- UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
894
+ //UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
816895
817896 UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
818897 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
819898 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
820899 //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
+ }
821910 }
822911 catch (Exception e)
823912 {
....@@ -827,12 +916,95 @@
827916 {
828917 try
829918 {
830
- MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
831
- 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
+
832930 UIManager.setLookAndFeel(new MetalLookAndFeel());
833
- //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
834931 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
932
+ //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
835933 //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
+ }
8361008 } catch (Exception e)
8371009 {
8381010 }
....@@ -843,19 +1015,67 @@
8431015
8441016 //Monitor mon=MonitorFactory.start("myFirstMonitor");
8451017 standAlone = true;
846
- grafreeD = new Grafreed();
847
- grafreeD.universe = new Composite();
848
- grafreeD.universe.name = "Grafreed";
849
- grafreeD.universe.material = new cMaterial();
1018
+ grafreed = new Grafreed();
1019
+ grafreed.materials = ReadGFD(grafreed.getClass().getClassLoader().getResourceAsStream("gfd/materials.gfd"));
1020
+
1021
+ grafreed.universe = new cGroup();
1022
+ grafreed.universe.name = "Grafreed";
1023
+ grafreed.universe.material = new cMaterial();
1024
+ grafreed.universe.skyboxname = "cubemaps/penguins-skyboxes/yonder";
1025
+ grafreed.universe.skyboxext = "jpg";
1026
+
8501027 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
8511028
852
- grafreeD.universe.root = true;
853
- grafreeD.universe.openEditWindow(null, true); //, true);
1029
+ grafreed.universe.root = true;
1030
+ grafreed.universe.openEditWindow(null, true); //, true);
8541031 //mon.stop();
8551032 //System.out.println(mon);
8561033 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
1034
+
1035
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
8571036 }
8581037
1038
+ static Object3D materials;
1039
+
1040
+ static Object3D ReadGFD(java.io.InputStream istream)
1041
+ {
1042
+ Object3D readobj = null;
1043
+
1044
+ try
1045
+ {
1046
+ // Try compressed version first.
1047
+ java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
1048
+ java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
1049
+
1050
+ readobj = (Object3D) p.readObject();
1051
+ p.close();
1052
+ zstream.close();
1053
+ istream.close();
1054
+
1055
+ readobj.ResetDisplayList();
1056
+ } catch (Exception e)
1057
+ {
1058
+ if (!e.toString().contains("GZIP"))
1059
+ e.printStackTrace();
1060
+
1061
+ try
1062
+ {
1063
+ java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream);
1064
+
1065
+ readobj = (Object3D) p.readObject();
1066
+ p.close();
1067
+ istream.close();
1068
+
1069
+ readobj.ResetDisplayList();
1070
+ } catch (Exception e2)
1071
+ {
1072
+ e2.printStackTrace();
1073
+ }
1074
+ }
1075
+
1076
+ return readobj;
1077
+ }
1078
+
8591079 // Timer callback
8601080 public void actionPerformed(ActionEvent e)
8611081 {
....@@ -870,7 +1090,7 @@
8701090 static int depth = 0;
8711091 static java.util.Stack stack = new java.util.Stack();
8721092 static boolean traceoff = false; // true;
873
- static float[] colorV = new float[5];
1093
+ static float[] colorV = new float[4]; // 5];
8741094
8751095 static void traceon()
8761096 {
....@@ -977,6 +1197,11 @@
9771197
9781198 static public Object clone(Object o)
9791199 {
1200
+ if (o instanceof Object3D)
1201
+ {
1202
+ assert(((Object3D)o).parent == null);
1203
+ }
1204
+
9801205 if (o == null)
9811206 return null;
9821207
....@@ -1079,7 +1304,7 @@
10791304 } while (avail > 0 && numRead >= 0);
10801305 return new String(data, 0, pos, "US-ASCII");
10811306 }
1082
- public static Grafreed grafreeD;
1307
+ public static Grafreed grafreed;
10831308 public static boolean standAlone = true;
10841309 public Composite universe;
10851310 public static Object3D clipboard = new Object3D();