Normand Briere
2019-09-18 f9325048496d7cdbcad233f8a6b84c88e79adcc2
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;
....@@ -12,17 +13,28 @@
1213
1314 import javax.sound.sampled.*;
1415
16
+import javax.net.ssl.HostnameVerifier;
17
+import javax.net.ssl.HttpsURLConnection;
18
+import javax.net.ssl.SSLContext;
19
+import javax.net.ssl.SSLSession;
20
+import javax.net.ssl.TrustManager;
21
+import javax.net.ssl.X509TrustManager;
22
+
23
+import java.security.cert.X509Certificate;
24
+import java.net.Authenticator;
25
+import java.net.PasswordAuthentication;
26
+
1527 //import com.jamonapi.*;
1628 public class Grafreed extends Applet implements ActionListener
17
-{
18
- static boolean NIMBUSLAF = true;
19
-
29
+{
2030 static int RENDERME = 0;
2131
2232 static boolean epsequal = false;
2333 static float epsvertex2 = 0.001f;
2434 static boolean linkUV = false; // not uniform at load time
2535
36
+ static boolean smoothmode = false;
37
+
2638 static Wav wav = new Wav("/Users/nbriere/0ut/wavs/monoformat"); // output");
2739 static boolean hassound = false;
2840 static boolean savesound = false;
....@@ -47,6 +59,79 @@
4759
4860 }
4961 }
62
+
63
+ public static String RemovePrefix(String s, String prefix)
64
+ {
65
+ if (s != null && prefix != null && s.startsWith(prefix))
66
+ {
67
+ return s.substring(prefix.length());
68
+ }
69
+
70
+ return s;
71
+ }
72
+
73
+ static void ParseFileSystem(java.io.File dir, iResourceCallBack callback, String prefix)
74
+ {
75
+ callback.ResourceCallBack(RemovePrefix(dir.toString(),prefix).split("/"));
76
+ File[] listFiles = dir.listFiles();
77
+ if (listFiles != null)
78
+ {
79
+ for (java.io.File file : listFiles)
80
+ {
81
+ ParseFileSystem(file, callback, prefix);
82
+ }
83
+ }
84
+ }
85
+
86
+ static interface iResourceCallBack
87
+ {
88
+ void ResourceCallBack(String[] path);
89
+ }
90
+
91
+ static void ParseResources(String path, iResourceCallBack callback)
92
+ {
93
+ java.io.File jarFile = new java.io.File(Grafreed.class.getProtectionDomain().getCodeSource().getLocation().getPath());
94
+
95
+ if (jarFile.isFile())
96
+ {
97
+ // Run with JAR file
98
+ try
99
+ {
100
+ java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
101
+ java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries(); //gives ALL entries in jar
102
+ while (entries.hasMoreElements())
103
+ {
104
+ String name = entries.nextElement().getName();
105
+
106
+ if (name.startsWith(path + "/"))
107
+ callback.ResourceCallBack(RemovePrefix(name, path + "/").split("/"));
108
+ }
109
+ jar.close();
110
+ } catch (Exception ex)
111
+ {
112
+ ex.printStackTrace();
113
+ }
114
+ } else
115
+ {
116
+ // Run with IDE
117
+ final java.net.URL url = Object3D.class.getResource("/" + path);
118
+ if (url != null)
119
+ {
120
+ try
121
+ {
122
+ java.io.File apps = new java.io.File(url.toURI());
123
+ ParseFileSystem(apps, callback, RemovePrefix(url.toString() + "/", "file:"));
124
+// for (java.io.File app : apps.listFiles())
125
+// {
126
+// //System.out.println(RemovePrefix(app.toString(), RemovePrefix(url.toString(), "file:") + "/"));
127
+// }
128
+ } catch (Exception ex)
129
+ {
130
+ ex.printStackTrace();
131
+ }
132
+ }
133
+ }
134
+ }
50135
51136 public void init()
52137 {
....@@ -56,7 +141,7 @@
56141 universe.material = new cMaterial();
57142 //god.addChild(universe);
58143 universe.name = "Applet";
59
- grafreeD = this;
144
+ grafreed = this;
60145 }
61146
62147 /**/
....@@ -599,11 +684,18 @@
599684 PlayWord(word, 1);
600685 }
601686
687
+ static boolean isWindows;
688
+
602689 public static void main(String argv[])
603690 {
604
- String osArch = System.getProperty("os.arch");
691
+ String osArch = System.getProperty("os.arch");
692
+ if (Globals.DEBUG)
605693 System.out.println("os.arch = " + osArch);
606694
695
+ String osName = System.getProperty("os.name");
696
+
697
+ isWindows = !osName.equals("Mac OS X");
698
+
607699 if (argv.length == 0)
608700 {
609701 String javaPath = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
....@@ -806,22 +898,31 @@
806898 // try{Thread.sleep(5000);}catch(Exception e){}
807899 // PlayAudio("/Users/nbriere/Downloads/Footsteps-6.wav", 4, 1);
808900
809
-
810901 /**/
811
- if (NIMBUSLAF)
902
+ if (Globals.NIMBUSLAF)
812903 {
813904 try
814905 {
815
- Object o = UIManager.getInstalledLookAndFeels();
906
+ //Object o = UIManager.getInstalledLookAndFeels();
816907
817908 javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
818909 //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.beigeTheme));
819
- UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
910
+ //UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
820911
821912 UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
822913 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
823914 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
824915 //UIManager.put("nimbusBase", new Color(0,0,0));
916
+
917
+ javax.swing.UIDefaults ui = UIManager.getDefaults();
918
+
919
+ ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(0,8,0,0));
920
+
921
+ for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();)
922
+ {
923
+ Object key = e.nextElement();
924
+ System.out.println(key + " --> " + ui.get(key));
925
+ }
825926 }
826927 catch (Exception e)
827928 {
....@@ -831,35 +932,241 @@
831932 {
832933 try
833934 {
834
- MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
835
- MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme));
935
+ //Object o = UIManager.getInstalledLookAndFeels();
936
+
937
+ MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme());
938
+ //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme));
939
+ //UIManager.put("ScrollBar.background", new javax.swing.plaf.ColorUIResource(100,0,0));
940
+ UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
941
+
942
+ javax.swing.UIDefaults ui = UIManager.getDefaults();
943
+
944
+ Object x = ui.get("TabbedPane.background");
945
+
836946 UIManager.setLookAndFeel(new MetalLookAndFeel());
837
- //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
838947 //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
948
+ //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
839949 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
950
+
951
+ ui = UIManager.getDefaults();
952
+
953
+ x = ui.get("RadioButton.icon");
954
+
955
+ ArrayList gradient = new java.util.ArrayList(5);
956
+ gradient.add(1.0);
957
+ gradient.add(0.0);
958
+ gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255));
959
+ gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192));
960
+ gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0));
961
+
962
+ ui.put("Button.gradient", gradient);
963
+
964
+ //ui.put("RadioButton.icon", new CheckBox()); //ObjEditor.GetIcon("icons/white-sphere-icon.png")));
965
+ ui.put("CheckBox.icon", new CheckBox()); //ObjEditor.GetIcon("icons/white-sphere-icon.png")));
966
+ //ui.put("CheckBoxMenuItem.checkIcon", ObjEditor.GetIcon("icons/white-sphere-icon.png"));
967
+
968
+ ui.put("Slider.foreground", new javax.swing.plaf.ColorUIResource(0,0,0));
969
+ ui.put("Slider.horizontalThumbIcon", ObjEditor.GetIcon("icons/white-sphere-icon.png"));
970
+
971
+ /*
972
+TabbedPane.unselectedBackground Color
973
+TabbedPane.unselectedTabBackground Color
974
+TabbedPane.unselectedTabForeground Color
975
+TabbedPane.unselectedTabHighlight Color
976
+TabbedPane.unselectedTabShadow
977
+ */
978
+// ui.put("TabbedPane.contentAreaColor", new javax.swing.plaf.ColorUIResource(0,100,0));
979
+ //ui.put("TabbedPane.selected", new javax.swing.plaf.ColorUIResource(200,0,200));
980
+
981
+ ui.put("TabbedPane.background", new javax.swing.plaf.ColorUIResource(150,150,150));
982
+ ui.put("TabbedPane.foreground", new javax.swing.plaf.ColorUIResource(50,50,50));
983
+ ui.put("TabbedPane.light", new javax.swing.plaf.ColorUIResource(255,255,255));
984
+ ui.put("TabbedPane.selectedForeground", new javax.swing.plaf.ColorUIResource(0,0,0));
985
+ ui.put("TabbedPane.selectHighlight", new javax.swing.plaf.ColorUIResource(255,255,255));
986
+ ui.put("TabbedPane.darkShadow", new javax.swing.plaf.ColorUIResource(0,0,0));
987
+
988
+// ui.put("TabbedPane.shadow", new javax.swing.plaf.ColorUIResource(200,0,0));
989
+// ui.put("TabbedPane.tabAreaBackground", new javax.swing.plaf.ColorUIResource(0,200,0));
990
+// ui.put("TabbedPane.unselectedBackground", new javax.swing.plaf.ColorUIResource(200,200,0));
991
+// ui.put("TabbedPane.unselectedTabBackground", new javax.swing.plaf.ColorUIResource(0,0,200));
992
+// ui.put("TabbedPane.unselectedTabForeground", new javax.swing.plaf.ColorUIResource(200,0,200));
993
+// ui.put("TabbedPane.unselectedTabHighlight", new javax.swing.plaf.ColorUIResource(0,200,200));
994
+// ui.put("TabbedPane.unselectedTabShadow", new javax.swing.plaf.ColorUIResource(200,200,200));
995
+
996
+ ui.put("TabbedPane.textIconGap", 0);
997
+ ui.put("TabbedPane.contentBorderInsets", new javax.swing.plaf.InsetsUIResource(0,0,0,0));
998
+ ui.put("TabbedPane.tabAreaInsets", new javax.swing.plaf.InsetsUIResource(1,1,0,0));
999
+ ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(0,8,0,0));
1000
+
1001
+ Object openIcon2 = ui.get("Tree.openIcon");
1002
+
1003
+ ui.put("Tree.openIcon", ObjEditor.GetIcon("icons/folderopen.png"));
1004
+ ui.put("Tree.closedIcon", ObjEditor.GetIcon("icons/folderclose.png"));
1005
+ ui.put("Tree.leafIcon", ObjEditor.GetIcon("icons/file.png"));
1006
+
1007
+ //javax.swing.plaf.metal.MetalIconFactory.getHorizontalSliderThumbIcon().
1008
+ Object o = ui.get("Slider.horizontalThumbIcon");
1009
+
1010
+ gradient = new java.util.ArrayList(5);
1011
+ gradient.add(1.0);
1012
+ gradient.add(0.0);
1013
+ gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192));
1014
+ gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255));
1015
+ gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0));
1016
+
1017
+ ui.put("ToggleButton.gradient", gradient);
1018
+ //ui.put("Button[MouseOver].backgroundPainter", new com.sun.java.swing.plaf.nimbus.ButtonPainter());
1019
+ //ui.put("Button.highlight", new javax.swing.plaf.ColorUIResource(155,155,155));
1020
+
1021
+ for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();)
1022
+ {
1023
+ Object key = e.nextElement();
1024
+ //System.out.println(key + " --> " + ui.get(key));
1025
+ }
8401026 } catch (Exception e)
8411027 {
8421028 }
8431029 }
8441030 /**/
1031
+
1032
+ // Create a trust manager that does not validate certificate chains
1033
+ final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
1034
+ @Override
1035
+ public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
1036
+ }
1037
+
1038
+ @Override
1039
+ public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
1040
+ }
1041
+
1042
+ @Override
1043
+ public X509Certificate[] getAcceptedIssuers() {
1044
+ return null;
1045
+ }
1046
+ } };
1047
+
1048
+ try
1049
+ {
1050
+ // Install the all-trusting trust manager
1051
+ final SSLContext sslContext = SSLContext.getInstance("SSL");
1052
+ sslContext.init(null, trustAllCerts, null);
1053
+ // Create an ssl socket factory with our all-trusting manager
1054
+ HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
1055
+ HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
1056
+ public boolean verify(String urlHostName, SSLSession session) {
1057
+ return true;
1058
+ }
1059
+ });
1060
+ // be authentic
1061
+ Authenticator.setDefault(new Authenticator() {
1062
+ @Override
1063
+ protected PasswordAuthentication getPasswordAuthentication() {
1064
+ return new PasswordAuthentication("args[0]", "args[1]".toCharArray());
1065
+ }
1066
+ });
1067
+ }
1068
+ catch (Exception e)
1069
+ {
1070
+ e.printStackTrace();
1071
+ }
1072
+
1073
+
1074
+ /////////////
8451075
8461076 // javax.swing.ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
8471077
8481078 //Monitor mon=MonitorFactory.start("myFirstMonitor");
8491079 standAlone = true;
850
- grafreeD = new Grafreed();
851
- grafreeD.universe = new cGroup();
852
- grafreeD.universe.name = "Grafreed";
853
- grafreeD.universe.material = new cMaterial();
1080
+
1081
+ grafreed = new Grafreed();
1082
+
1083
+ grafreed.materials = ReadGFD(grafreed.getClass().getClassLoader().getResourceAsStream("gfd/materials.gfd"));
1084
+
1085
+ grafreed.universe = new cGroup();
1086
+ grafreed.universe.name = "Grafreed";
1087
+ grafreed.universe.material = new cMaterial();
1088
+
8541089 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
8551090
856
- grafreeD.universe.root = true;
857
- grafreeD.universe.openEditWindow(null, true); //, true);
1091
+ grafreed.universe.root = true;
1092
+ grafreed.universe.openEditWindow(null, true); //, true);
1093
+ grafreed.universe.editWindow.New();
1094
+
8581095 //mon.stop();
8591096 //System.out.println(mon);
8601097 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
1098
+
1099
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
8611100 }
8621101
1102
+ static class CheckBox extends javax.swing.plaf.metal.MetalCheckBoxIcon
1103
+ {
1104
+ java.awt.image.BufferedImage image;
1105
+
1106
+ CheckBox()
1107
+ {
1108
+ try
1109
+ {
1110
+ image = javax.imageio.ImageIO.read(ObjEditor.class.getClassLoader().getResourceAsStream("icons/checkbox.png"));
1111
+ }
1112
+ catch (Exception e)
1113
+ {
1114
+ }
1115
+ }
1116
+
1117
+ protected void drawCheck(Component c, Graphics g, int x, int y)
1118
+ {
1119
+ super.drawCheck(c, g, x, y);
1120
+ }
1121
+
1122
+ public void paintIcon(Component c, Graphics g, int x, int y)
1123
+ {
1124
+ g.drawImage(image, x-1, y-1, 19, 19, null);
1125
+ super.paintIcon(c, g, x+2, y+2);
1126
+ }
1127
+ }
1128
+
1129
+ static Object3D materials;
1130
+
1131
+ static Object3D ReadGFD(java.io.InputStream istream)
1132
+ {
1133
+ Object3D readobj = null;
1134
+
1135
+ try
1136
+ {
1137
+ // Try compressed version first.
1138
+ java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
1139
+ java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
1140
+
1141
+ readobj = (Object3D) p.readObject();
1142
+ p.close();
1143
+ zstream.close();
1144
+ istream.close();
1145
+
1146
+ readobj.ResetDisplayList();
1147
+ } catch (Exception e)
1148
+ {
1149
+ if (!e.toString().contains("GZIP"))
1150
+ e.printStackTrace();
1151
+
1152
+ try
1153
+ {
1154
+ java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream);
1155
+
1156
+ readobj = (Object3D) p.readObject();
1157
+ p.close();
1158
+ istream.close();
1159
+
1160
+ readobj.ResetDisplayList();
1161
+ } catch (Exception e2)
1162
+ {
1163
+ e2.printStackTrace();
1164
+ }
1165
+ }
1166
+
1167
+ return readobj;
1168
+ }
1169
+
8631170 // Timer callback
8641171 public void actionPerformed(ActionEvent e)
8651172 {
....@@ -874,7 +1181,7 @@
8741181 static int depth = 0;
8751182 static java.util.Stack stack = new java.util.Stack();
8761183 static boolean traceoff = false; // true;
877
- static float[] colorV = new float[5];
1184
+ static float[] colorV = new float[4]; // 5];
8781185
8791186 static void traceon()
8801187 {
....@@ -981,6 +1288,11 @@
9811288
9821289 static public Object clone(Object o)
9831290 {
1291
+ if (o instanceof Object3D)
1292
+ {
1293
+ assert(((Object3D)o).parent == null);
1294
+ }
1295
+
9841296 if (o == null)
9851297 return null;
9861298
....@@ -1083,7 +1395,7 @@
10831395 } while (avail > 0 && numRead >= 0);
10841396 return new String(data, 0, pos, "US-ASCII");
10851397 }
1086
- public static Grafreed grafreeD;
1398
+ public static Grafreed grafreed;
10871399 public static boolean standAlone = true;
10881400 public Composite universe;
10891401 public static Object3D clipboard = new Object3D();