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;
....@@ -47,6 +48,79 @@
4748
4849 }
4950 }
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
+ }
123
+ }
50124
51125 public void init()
52126 {
....@@ -56,7 +130,7 @@
56130 universe.material = new cMaterial();
57131 //god.addChild(universe);
58132 universe.name = "Applet";
59
- grafreeD = this;
133
+ grafreed = this;
60134 }
61135
62136 /**/
....@@ -601,7 +675,8 @@
601675
602676 public static void main(String argv[])
603677 {
604
- String osArch = System.getProperty("os.arch");
678
+ String osArch = System.getProperty("os.arch");
679
+ if (Globals.DEBUG)
605680 System.out.println("os.arch = " + osArch);
606681
607682 if (argv.length == 0)
....@@ -808,20 +883,30 @@
808883
809884
810885 /**/
811
- if (NIMBUSLAF)
886
+ if (Globals.NIMBUSLAF)
812887 {
813888 try
814889 {
815
- Object o = UIManager.getInstalledLookAndFeels();
890
+ //Object o = UIManager.getInstalledLookAndFeels();
816891
817892 javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
818893 //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.beigeTheme));
819
- UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
894
+ //UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
820895
821896 UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
822897 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
823898 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
824899 //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
+ }
825910 }
826911 catch (Exception e)
827912 {
....@@ -831,12 +916,95 @@
831916 {
832917 try
833918 {
834
- MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
835
- 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
+
836930 UIManager.setLookAndFeel(new MetalLookAndFeel());
837
- //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
838931 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
932
+ //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
839933 //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
+ }
8401008 } catch (Exception e)
8411009 {
8421010 }
....@@ -847,19 +1015,67 @@
8471015
8481016 //Monitor mon=MonitorFactory.start("myFirstMonitor");
8491017 standAlone = true;
850
- grafreeD = new Grafreed();
851
- grafreeD.universe = new cGroup();
852
- grafreeD.universe.name = "Grafreed";
853
- 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
+
8541027 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
8551028
856
- grafreeD.universe.root = true;
857
- grafreeD.universe.openEditWindow(null, true); //, true);
1029
+ grafreed.universe.root = true;
1030
+ grafreed.universe.openEditWindow(null, true); //, true);
8581031 //mon.stop();
8591032 //System.out.println(mon);
8601033 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
1034
+
1035
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
8611036 }
8621037
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
+
8631079 // Timer callback
8641080 public void actionPerformed(ActionEvent e)
8651081 {
....@@ -874,7 +1090,7 @@
8741090 static int depth = 0;
8751091 static java.util.Stack stack = new java.util.Stack();
8761092 static boolean traceoff = false; // true;
877
- static float[] colorV = new float[5];
1093
+ static float[] colorV = new float[4]; // 5];
8781094
8791095 static void traceon()
8801096 {
....@@ -981,6 +1197,11 @@
9811197
9821198 static public Object clone(Object o)
9831199 {
1200
+ if (o instanceof Object3D)
1201
+ {
1202
+ assert(((Object3D)o).parent == null);
1203
+ }
1204
+
9841205 if (o == null)
9851206 return null;
9861207
....@@ -1083,7 +1304,7 @@
10831304 } while (avail > 0 && numRead >= 0);
10841305 return new String(data, 0, pos, "US-ASCII");
10851306 }
1086
- public static Grafreed grafreeD;
1307
+ public static Grafreed grafreed;
10871308 public static boolean standAlone = true;
10881309 public Composite universe;
10891310 public static Object3D clipboard = new Object3D();