.. | .. |
---|
5 | 5 | |
---|
6 | 6 | import java.io.*; |
---|
7 | 7 | |
---|
| 8 | +import java.util.ArrayList; |
---|
8 | 9 | import javax.swing.UIManager; |
---|
9 | 10 | import javax.swing.plaf.metal.MetalLookAndFeel; |
---|
10 | 11 | import javax.swing.plaf.ColorUIResource; |
---|
.. | .. |
---|
12 | 13 | |
---|
13 | 14 | import javax.sound.sampled.*; |
---|
14 | 15 | |
---|
| 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 | + |
---|
15 | 27 | //import com.jamonapi.*; |
---|
16 | 28 | public class Grafreed extends Applet implements ActionListener |
---|
17 | | -{ |
---|
18 | | - static boolean NIMBUSLAF = true; |
---|
19 | | - |
---|
| 29 | +{ |
---|
20 | 30 | static int RENDERME = 0; |
---|
21 | 31 | |
---|
22 | 32 | static boolean epsequal = false; |
---|
.. | .. |
---|
47 | 57 | b = !!b; |
---|
48 | 58 | new Exception().printStackTrace(); // assert(b); |
---|
49 | 59 | |
---|
| 60 | + } |
---|
| 61 | + } |
---|
| 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 | + } |
---|
50 | 133 | } |
---|
51 | 134 | } |
---|
52 | 135 | |
---|
.. | .. |
---|
601 | 684 | PlayWord(word, 1); |
---|
602 | 685 | } |
---|
603 | 686 | |
---|
| 687 | + static boolean isWindows; |
---|
| 688 | + |
---|
604 | 689 | public static void main(String argv[]) |
---|
605 | 690 | { |
---|
606 | | - String osArch = System.getProperty("os.arch"); |
---|
| 691 | + String osArch = System.getProperty("os.arch"); |
---|
| 692 | + if (Globals.DEBUG) |
---|
607 | 693 | System.out.println("os.arch = " + osArch); |
---|
608 | 694 | |
---|
| 695 | + String osName = System.getProperty("os.name"); |
---|
| 696 | + |
---|
| 697 | + isWindows = !osName.equals("Mac OS X"); |
---|
| 698 | + |
---|
609 | 699 | if (argv.length == 0) |
---|
610 | 700 | { |
---|
611 | 701 | String javaPath = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; |
---|
.. | .. |
---|
808 | 898 | // try{Thread.sleep(5000);}catch(Exception e){} |
---|
809 | 899 | // PlayAudio("/Users/nbriere/Downloads/Footsteps-6.wav", 4, 1); |
---|
810 | 900 | |
---|
811 | | - |
---|
812 | 901 | /**/ |
---|
813 | | - if (NIMBUSLAF) |
---|
| 902 | + if (Globals.NIMBUSLAF) |
---|
814 | 903 | { |
---|
815 | 904 | try |
---|
816 | 905 | { |
---|
817 | | - Object o = UIManager.getInstalledLookAndFeels(); |
---|
| 906 | + //Object o = UIManager.getInstalledLookAndFeels(); |
---|
818 | 907 | |
---|
819 | 908 | javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme()); |
---|
820 | 909 | //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.beigeTheme)); |
---|
821 | | - UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel()); |
---|
| 910 | + //UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel()); |
---|
822 | 911 | |
---|
823 | 912 | UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); |
---|
824 | 913 | //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); |
---|
825 | 914 | //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); |
---|
826 | 915 | //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 | + } |
---|
827 | 926 | } |
---|
828 | 927 | catch (Exception e) |
---|
829 | 928 | { |
---|
.. | .. |
---|
833 | 932 | { |
---|
834 | 933 | try |
---|
835 | 934 | { |
---|
836 | | - MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); |
---|
837 | | - 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 | + |
---|
838 | 946 | UIManager.setLookAndFeel(new MetalLookAndFeel()); |
---|
839 | | - //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); |
---|
840 | 947 | //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); |
---|
| 948 | + //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); |
---|
841 | 949 | //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 | + } |
---|
842 | 1026 | } catch (Exception e) |
---|
843 | 1027 | { |
---|
844 | 1028 | } |
---|
845 | 1029 | } |
---|
846 | 1030 | /**/ |
---|
| 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 | + ///////////// |
---|
847 | 1075 | |
---|
848 | 1076 | // javax.swing.ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); |
---|
849 | 1077 | |
---|
850 | 1078 | //Monitor mon=MonitorFactory.start("myFirstMonitor"); |
---|
851 | 1079 | standAlone = true; |
---|
852 | | - grafreed = new Grafreed(); |
---|
| 1080 | + |
---|
| 1081 | + grafreed = new Grafreed(); |
---|
| 1082 | + |
---|
853 | 1083 | grafreed.materials = ReadGFD(grafreed.getClass().getClassLoader().getResourceAsStream("gfd/materials.gfd")); |
---|
854 | 1084 | |
---|
855 | 1085 | grafreed.universe = new cGroup(); |
---|
856 | 1086 | grafreed.universe.name = "Grafreed"; |
---|
857 | 1087 | grafreed.universe.material = new cMaterial(); |
---|
| 1088 | + |
---|
858 | 1089 | // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE; |
---|
859 | 1090 | |
---|
860 | 1091 | grafreed.universe.root = true; |
---|
861 | 1092 | grafreed.universe.openEditWindow(null, true); //, true); |
---|
| 1093 | + grafreed.universe.editWindow.New(); |
---|
| 1094 | + |
---|
862 | 1095 | //mon.stop(); |
---|
863 | 1096 | //System.out.println(mon); |
---|
864 | 1097 | //timeflow.app.TimeflowAppLauncher.GetTimeFlow(); |
---|
| 1098 | + |
---|
| 1099 | + javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS); |
---|
865 | 1100 | } |
---|
866 | 1101 | |
---|
| 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 | + |
---|
867 | 1129 | static Object3D materials; |
---|
868 | 1130 | |
---|
869 | 1131 | static Object3D ReadGFD(java.io.InputStream istream) |
---|
.. | .. |
---|
877 | 1139 | java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream); |
---|
878 | 1140 | |
---|
879 | 1141 | readobj = (Object3D) p.readObject(); |
---|
| 1142 | + p.close(); |
---|
| 1143 | + zstream.close(); |
---|
880 | 1144 | istream.close(); |
---|
881 | 1145 | |
---|
882 | 1146 | readobj.ResetDisplayList(); |
---|
.. | .. |
---|
890 | 1154 | java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream); |
---|
891 | 1155 | |
---|
892 | 1156 | readobj = (Object3D) p.readObject(); |
---|
| 1157 | + p.close(); |
---|
893 | 1158 | istream.close(); |
---|
894 | 1159 | |
---|
895 | 1160 | readobj.ResetDisplayList(); |
---|
.. | .. |
---|
1023 | 1288 | |
---|
1024 | 1289 | static public Object clone(Object o) |
---|
1025 | 1290 | { |
---|
| 1291 | + if (o instanceof Object3D) |
---|
| 1292 | + { |
---|
| 1293 | + assert(((Object3D)o).parent == null); |
---|
| 1294 | + } |
---|
| 1295 | + |
---|
1026 | 1296 | if (o == null) |
---|
1027 | 1297 | return null; |
---|
1028 | 1298 | |
---|