.. | .. |
---|
49 | 49 | |
---|
50 | 50 | } |
---|
51 | 51 | } |
---|
| 52 | + |
---|
| 53 | + public static String RemovePrefix(String s, String prefix) |
---|
| 54 | + { |
---|
| 55 | + if (s != null && prefix != null && s.startsWith(prefix)) |
---|
| 56 | + { |
---|
| 57 | + return s.substring(prefix.length()); |
---|
| 58 | + } |
---|
| 59 | + |
---|
| 60 | + return s; |
---|
| 61 | + } |
---|
| 62 | + |
---|
| 63 | + static void ParseFileSystem(java.io.File dir, iResourceCallBack callback, String prefix) |
---|
| 64 | + { |
---|
| 65 | + callback.ResourceCallBack(RemovePrefix(dir.toString(),prefix).split("/")); |
---|
| 66 | + File[] listFiles = dir.listFiles(); |
---|
| 67 | + if (listFiles != null) |
---|
| 68 | + { |
---|
| 69 | + for (java.io.File file : listFiles) |
---|
| 70 | + { |
---|
| 71 | + ParseFileSystem(file, callback, prefix); |
---|
| 72 | + } |
---|
| 73 | + } |
---|
| 74 | + } |
---|
| 75 | + |
---|
| 76 | + static interface iResourceCallBack |
---|
| 77 | + { |
---|
| 78 | + void ResourceCallBack(String[] path); |
---|
| 79 | + } |
---|
| 80 | + |
---|
| 81 | + static void ParseResources(String path, iResourceCallBack callback) |
---|
| 82 | + { |
---|
| 83 | + java.io.File jarFile = new java.io.File(Grafreed.class.getProtectionDomain().getCodeSource().getLocation().getPath()); |
---|
| 84 | + |
---|
| 85 | + if (jarFile.isFile()) |
---|
| 86 | + { |
---|
| 87 | + // Run with JAR file |
---|
| 88 | + try |
---|
| 89 | + { |
---|
| 90 | + java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile); |
---|
| 91 | + java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries(); //gives ALL entries in jar |
---|
| 92 | + while (entries.hasMoreElements()) |
---|
| 93 | + { |
---|
| 94 | + String name = entries.nextElement().getName(); |
---|
| 95 | + |
---|
| 96 | + if (name.startsWith(path + "/")) |
---|
| 97 | + callback.ResourceCallBack(RemovePrefix(name, path + "/").split("/")); |
---|
| 98 | + } |
---|
| 99 | + jar.close(); |
---|
| 100 | + } catch (Exception ex) |
---|
| 101 | + { |
---|
| 102 | + ex.printStackTrace(); |
---|
| 103 | + } |
---|
| 104 | + } else |
---|
| 105 | + { |
---|
| 106 | + // Run with IDE |
---|
| 107 | + final java.net.URL url = Object3D.class.getResource("/" + path); |
---|
| 108 | + if (url != null) |
---|
| 109 | + { |
---|
| 110 | + try |
---|
| 111 | + { |
---|
| 112 | + java.io.File apps = new java.io.File(url.toURI()); |
---|
| 113 | + ParseFileSystem(apps, callback, RemovePrefix(url.toString() + "/", "file:")); |
---|
| 114 | +// for (java.io.File app : apps.listFiles()) |
---|
| 115 | +// { |
---|
| 116 | +// //System.out.println(RemovePrefix(app.toString(), RemovePrefix(url.toString(), "file:") + "/")); |
---|
| 117 | +// } |
---|
| 118 | + } catch (Exception ex) |
---|
| 119 | + { |
---|
| 120 | + ex.printStackTrace(); |
---|
| 121 | + } |
---|
| 122 | + } |
---|
| 123 | + } |
---|
| 124 | + } |
---|
52 | 125 | |
---|
53 | 126 | public void init() |
---|
54 | 127 | { |
---|
.. | .. |
---|
58 | 131 | universe.material = new cMaterial(); |
---|
59 | 132 | //god.addChild(universe); |
---|
60 | 133 | universe.name = "Applet"; |
---|
61 | | - grafreeD = this; |
---|
| 134 | + grafreed = this; |
---|
62 | 135 | } |
---|
63 | 136 | |
---|
64 | 137 | /**/ |
---|
.. | .. |
---|
849 | 922 | |
---|
850 | 923 | //Monitor mon=MonitorFactory.start("myFirstMonitor"); |
---|
851 | 924 | standAlone = true; |
---|
852 | | - grafreeD = new Grafreed(); |
---|
853 | | - grafreeD.universe = new cGroup(); |
---|
854 | | - grafreeD.universe.name = "Grafreed"; |
---|
855 | | - grafreeD.universe.material = new cMaterial(); |
---|
| 925 | + grafreed = new Grafreed(); |
---|
| 926 | + grafreed.materials = ReadGFD(grafreed.getClass().getClassLoader().getResourceAsStream("gfd/materials.gfd")); |
---|
| 927 | + |
---|
| 928 | + grafreed.universe = new cGroup(); |
---|
| 929 | + grafreed.universe.name = "Grafreed"; |
---|
| 930 | + grafreed.universe.material = new cMaterial(); |
---|
| 931 | + grafreed.universe.skyboxname = "cubemaps/penguins-skyboxes/tropic"; |
---|
| 932 | + grafreed.universe.skyboxext = "jpg"; |
---|
| 933 | + |
---|
856 | 934 | // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE; |
---|
857 | 935 | |
---|
858 | | - grafreeD.universe.root = true; |
---|
859 | | - grafreeD.universe.openEditWindow(null, true); //, true); |
---|
| 936 | + grafreed.universe.root = true; |
---|
| 937 | + grafreed.universe.openEditWindow(null, true); //, true); |
---|
860 | 938 | //mon.stop(); |
---|
861 | 939 | //System.out.println(mon); |
---|
862 | 940 | //timeflow.app.TimeflowAppLauncher.GetTimeFlow(); |
---|
| 941 | + |
---|
| 942 | + javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS); |
---|
863 | 943 | } |
---|
864 | 944 | |
---|
| 945 | + static Object3D materials; |
---|
| 946 | + |
---|
| 947 | + static Object3D ReadGFD(java.io.InputStream istream) |
---|
| 948 | + { |
---|
| 949 | + Object3D readobj = null; |
---|
| 950 | + |
---|
| 951 | + try |
---|
| 952 | + { |
---|
| 953 | + // Try compressed version first. |
---|
| 954 | + java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream); |
---|
| 955 | + java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream); |
---|
| 956 | + |
---|
| 957 | + readobj = (Object3D) p.readObject(); |
---|
| 958 | + p.close(); |
---|
| 959 | + zstream.close(); |
---|
| 960 | + istream.close(); |
---|
| 961 | + |
---|
| 962 | + readobj.ResetDisplayList(); |
---|
| 963 | + } catch (Exception e) |
---|
| 964 | + { |
---|
| 965 | + if (!e.toString().contains("GZIP")) |
---|
| 966 | + e.printStackTrace(); |
---|
| 967 | + |
---|
| 968 | + try |
---|
| 969 | + { |
---|
| 970 | + java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream); |
---|
| 971 | + |
---|
| 972 | + readobj = (Object3D) p.readObject(); |
---|
| 973 | + p.close(); |
---|
| 974 | + istream.close(); |
---|
| 975 | + |
---|
| 976 | + readobj.ResetDisplayList(); |
---|
| 977 | + } catch (Exception e2) |
---|
| 978 | + { |
---|
| 979 | + e2.printStackTrace(); |
---|
| 980 | + } |
---|
| 981 | + } |
---|
| 982 | + |
---|
| 983 | + return readobj; |
---|
| 984 | + } |
---|
| 985 | + |
---|
865 | 986 | // Timer callback |
---|
866 | 987 | public void actionPerformed(ActionEvent e) |
---|
867 | 988 | { |
---|
.. | .. |
---|
876 | 997 | static int depth = 0; |
---|
877 | 998 | static java.util.Stack stack = new java.util.Stack(); |
---|
878 | 999 | static boolean traceoff = false; // true; |
---|
879 | | - static float[] colorV = new float[5]; |
---|
| 1000 | + static float[] colorV = new float[4]; // 5]; |
---|
880 | 1001 | |
---|
881 | 1002 | static void traceon() |
---|
882 | 1003 | { |
---|
.. | .. |
---|
1085 | 1206 | } while (avail > 0 && numRead >= 0); |
---|
1086 | 1207 | return new String(data, 0, pos, "US-ASCII"); |
---|
1087 | 1208 | } |
---|
1088 | | - public static Grafreed grafreeD; |
---|
| 1209 | + public static Grafreed grafreed; |
---|
1089 | 1210 | public static boolean standAlone = true; |
---|
1090 | 1211 | public Composite universe; |
---|
1091 | 1212 | public static Object3D clipboard = new Object3D(); |
---|