.. | .. |
---|
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; |
---|
.. | .. |
---|
14 | 15 | |
---|
15 | 16 | //import com.jamonapi.*; |
---|
16 | 17 | public class Grafreed extends Applet implements ActionListener |
---|
17 | | -{ |
---|
18 | | - static boolean NIMBUSLAF = true; |
---|
19 | | - |
---|
| 18 | +{ |
---|
20 | 19 | static int RENDERME = 0; |
---|
21 | 20 | |
---|
22 | 21 | static boolean epsequal = false; |
---|
.. | .. |
---|
49 | 48 | |
---|
50 | 49 | } |
---|
51 | 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 | + } |
---|
| 123 | + } |
---|
52 | 124 | |
---|
53 | 125 | public void init() |
---|
54 | 126 | { |
---|
.. | .. |
---|
58 | 130 | universe.material = new cMaterial(); |
---|
59 | 131 | //god.addChild(universe); |
---|
60 | 132 | universe.name = "Applet"; |
---|
61 | | - grafreeD = this; |
---|
| 133 | + grafreed = this; |
---|
62 | 134 | } |
---|
63 | 135 | |
---|
64 | 136 | /**/ |
---|
.. | .. |
---|
603 | 675 | |
---|
604 | 676 | public static void main(String argv[]) |
---|
605 | 677 | { |
---|
606 | | - String osArch = System.getProperty("os.arch"); |
---|
| 678 | + String osArch = System.getProperty("os.arch"); |
---|
| 679 | + if (Globals.DEBUG) |
---|
607 | 680 | System.out.println("os.arch = " + osArch); |
---|
608 | 681 | |
---|
609 | 682 | if (argv.length == 0) |
---|
.. | .. |
---|
808 | 881 | // try{Thread.sleep(5000);}catch(Exception e){} |
---|
809 | 882 | // PlayAudio("/Users/nbriere/Downloads/Footsteps-6.wav", 4, 1); |
---|
810 | 883 | |
---|
811 | | - |
---|
812 | 884 | /**/ |
---|
813 | | - if (NIMBUSLAF) |
---|
| 885 | + if (Globals.NIMBUSLAF) |
---|
814 | 886 | { |
---|
815 | 887 | try |
---|
816 | 888 | { |
---|
817 | | - Object o = UIManager.getInstalledLookAndFeels(); |
---|
| 889 | + //Object o = UIManager.getInstalledLookAndFeels(); |
---|
818 | 890 | |
---|
819 | 891 | javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme()); |
---|
820 | 892 | //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.beigeTheme)); |
---|
821 | | - UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel()); |
---|
| 893 | + //UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel()); |
---|
822 | 894 | |
---|
823 | 895 | UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); |
---|
824 | 896 | //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); |
---|
825 | 897 | //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); |
---|
826 | 898 | //UIManager.put("nimbusBase", new Color(0,0,0)); |
---|
| 899 | + |
---|
| 900 | + javax.swing.UIDefaults ui = UIManager.getDefaults(); |
---|
| 901 | + |
---|
| 902 | + ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(0,8,0,0)); |
---|
| 903 | + |
---|
| 904 | + for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();) |
---|
| 905 | + { |
---|
| 906 | + Object key = e.nextElement(); |
---|
| 907 | + System.out.println(key + " --> " + ui.get(key)); |
---|
| 908 | + } |
---|
827 | 909 | } |
---|
828 | 910 | catch (Exception e) |
---|
829 | 911 | { |
---|
.. | .. |
---|
833 | 915 | { |
---|
834 | 916 | try |
---|
835 | 917 | { |
---|
836 | | - MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); |
---|
837 | | - MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme)); |
---|
| 918 | + //Object o = UIManager.getInstalledLookAndFeels(); |
---|
| 919 | + |
---|
| 920 | + MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme()); |
---|
| 921 | + //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme)); |
---|
| 922 | + //UIManager.put("ScrollBar.background", new javax.swing.plaf.ColorUIResource(100,0,0)); |
---|
| 923 | + UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); |
---|
| 924 | + |
---|
| 925 | + javax.swing.UIDefaults ui = UIManager.getDefaults(); |
---|
| 926 | + |
---|
| 927 | + Object x = ui.get("TabbedPane.background"); |
---|
| 928 | + |
---|
838 | 929 | UIManager.setLookAndFeel(new MetalLookAndFeel()); |
---|
839 | | - //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); |
---|
840 | 930 | //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); |
---|
| 931 | + //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); |
---|
841 | 932 | //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); |
---|
| 933 | + |
---|
| 934 | + ui = UIManager.getDefaults(); |
---|
| 935 | + |
---|
| 936 | + x = ui.get("RadioButton.icon"); |
---|
| 937 | + |
---|
| 938 | + ArrayList gradient = new java.util.ArrayList(5); |
---|
| 939 | + gradient.add(1.0); |
---|
| 940 | + gradient.add(0.0); |
---|
| 941 | + gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255)); |
---|
| 942 | + gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192)); |
---|
| 943 | + gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0)); |
---|
| 944 | + |
---|
| 945 | + ui.put("Button.gradient", gradient); |
---|
| 946 | + |
---|
| 947 | + //ui.put("RadioButton.icon", new CheckBox()); //ObjEditor.GetIcon("icons/white-sphere-icon.png"))); |
---|
| 948 | + ui.put("CheckBox.icon", new CheckBox()); //ObjEditor.GetIcon("icons/white-sphere-icon.png"))); |
---|
| 949 | + //ui.put("CheckBoxMenuItem.checkIcon", ObjEditor.GetIcon("icons/white-sphere-icon.png")); |
---|
| 950 | + |
---|
| 951 | + ui.put("Slider.foreground", new javax.swing.plaf.ColorUIResource(0,0,0)); |
---|
| 952 | + ui.put("Slider.horizontalThumbIcon", ObjEditor.GetIcon("icons/white-sphere-icon.png")); |
---|
| 953 | + |
---|
| 954 | + /* |
---|
| 955 | +TabbedPane.unselectedBackground Color |
---|
| 956 | +TabbedPane.unselectedTabBackground Color |
---|
| 957 | +TabbedPane.unselectedTabForeground Color |
---|
| 958 | +TabbedPane.unselectedTabHighlight Color |
---|
| 959 | +TabbedPane.unselectedTabShadow |
---|
| 960 | + */ |
---|
| 961 | +// ui.put("TabbedPane.contentAreaColor", new javax.swing.plaf.ColorUIResource(0,100,0)); |
---|
| 962 | + //ui.put("TabbedPane.selected", new javax.swing.plaf.ColorUIResource(200,0,200)); |
---|
| 963 | + |
---|
| 964 | + ui.put("TabbedPane.background", new javax.swing.plaf.ColorUIResource(150,150,150)); |
---|
| 965 | + ui.put("TabbedPane.foreground", new javax.swing.plaf.ColorUIResource(50,50,50)); |
---|
| 966 | + ui.put("TabbedPane.light", new javax.swing.plaf.ColorUIResource(255,255,255)); |
---|
| 967 | + ui.put("TabbedPane.selectedForeground", new javax.swing.plaf.ColorUIResource(0,0,0)); |
---|
| 968 | + ui.put("TabbedPane.selectHighlight", new javax.swing.plaf.ColorUIResource(255,255,255)); |
---|
| 969 | + ui.put("TabbedPane.darkShadow", new javax.swing.plaf.ColorUIResource(0,0,0)); |
---|
| 970 | + |
---|
| 971 | +// ui.put("TabbedPane.shadow", new javax.swing.plaf.ColorUIResource(200,0,0)); |
---|
| 972 | +// ui.put("TabbedPane.tabAreaBackground", new javax.swing.plaf.ColorUIResource(0,200,0)); |
---|
| 973 | +// ui.put("TabbedPane.unselectedBackground", new javax.swing.plaf.ColorUIResource(200,200,0)); |
---|
| 974 | +// ui.put("TabbedPane.unselectedTabBackground", new javax.swing.plaf.ColorUIResource(0,0,200)); |
---|
| 975 | +// ui.put("TabbedPane.unselectedTabForeground", new javax.swing.plaf.ColorUIResource(200,0,200)); |
---|
| 976 | +// ui.put("TabbedPane.unselectedTabHighlight", new javax.swing.plaf.ColorUIResource(0,200,200)); |
---|
| 977 | +// ui.put("TabbedPane.unselectedTabShadow", new javax.swing.plaf.ColorUIResource(200,200,200)); |
---|
| 978 | + |
---|
| 979 | + ui.put("TabbedPane.textIconGap", 0); |
---|
| 980 | + ui.put("TabbedPane.contentBorderInsets", new javax.swing.plaf.InsetsUIResource(0,0,0,0)); |
---|
| 981 | + ui.put("TabbedPane.tabAreaInsets", new javax.swing.plaf.InsetsUIResource(1,1,0,0)); |
---|
| 982 | + ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(0,8,0,0)); |
---|
| 983 | + |
---|
| 984 | + Object openIcon2 = ui.get("Tree.openIcon"); |
---|
| 985 | + |
---|
| 986 | + ui.put("Tree.openIcon", ObjEditor.GetIcon("icons/folderopen.png")); |
---|
| 987 | + ui.put("Tree.closedIcon", ObjEditor.GetIcon("icons/folderclose.png")); |
---|
| 988 | + ui.put("Tree.leafIcon", ObjEditor.GetIcon("icons/file.png")); |
---|
| 989 | + |
---|
| 990 | + //javax.swing.plaf.metal.MetalIconFactory.getHorizontalSliderThumbIcon(). |
---|
| 991 | + Object o = ui.get("Slider.horizontalThumbIcon"); |
---|
| 992 | + |
---|
| 993 | + gradient = new java.util.ArrayList(5); |
---|
| 994 | + gradient.add(1.0); |
---|
| 995 | + gradient.add(0.0); |
---|
| 996 | + gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192)); |
---|
| 997 | + gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255)); |
---|
| 998 | + gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0)); |
---|
| 999 | + |
---|
| 1000 | + ui.put("ToggleButton.gradient", gradient); |
---|
| 1001 | + //ui.put("Button[MouseOver].backgroundPainter", new com.sun.java.swing.plaf.nimbus.ButtonPainter()); |
---|
| 1002 | + //ui.put("Button.highlight", new javax.swing.plaf.ColorUIResource(155,155,155)); |
---|
| 1003 | + |
---|
| 1004 | + for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();) |
---|
| 1005 | + { |
---|
| 1006 | + Object key = e.nextElement(); |
---|
| 1007 | + //System.out.println(key + " --> " + ui.get(key)); |
---|
| 1008 | + } |
---|
842 | 1009 | } catch (Exception e) |
---|
843 | 1010 | { |
---|
844 | 1011 | } |
---|
.. | .. |
---|
849 | 1016 | |
---|
850 | 1017 | //Monitor mon=MonitorFactory.start("myFirstMonitor"); |
---|
851 | 1018 | standAlone = true; |
---|
852 | | - grafreeD = new Grafreed(); |
---|
853 | | - grafreeD.universe = new cGroup(); |
---|
854 | | - grafreeD.universe.name = "Grafreed"; |
---|
855 | | - grafreeD.universe.material = new cMaterial(); |
---|
| 1019 | + |
---|
| 1020 | + grafreed = new Grafreed(); |
---|
| 1021 | + |
---|
| 1022 | + grafreed.materials = ReadGFD(grafreed.getClass().getClassLoader().getResourceAsStream("gfd/materials.gfd")); |
---|
| 1023 | + |
---|
| 1024 | + grafreed.universe = new cGroup(); |
---|
| 1025 | + grafreed.universe.name = "Grafreed"; |
---|
| 1026 | + grafreed.universe.material = new cMaterial(); |
---|
| 1027 | + grafreed.universe.skyboxname = "cubemaps/penguins-skyboxes/yonder"; |
---|
| 1028 | + grafreed.universe.skyboxext = "jpg"; |
---|
| 1029 | + |
---|
856 | 1030 | // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE; |
---|
857 | 1031 | |
---|
858 | | - grafreeD.universe.root = true; |
---|
859 | | - grafreeD.universe.openEditWindow(null, true); //, true); |
---|
| 1032 | + grafreed.universe.root = true; |
---|
| 1033 | + grafreed.universe.openEditWindow(null, true); //, true); |
---|
860 | 1034 | //mon.stop(); |
---|
861 | 1035 | //System.out.println(mon); |
---|
862 | 1036 | //timeflow.app.TimeflowAppLauncher.GetTimeFlow(); |
---|
| 1037 | + |
---|
| 1038 | + javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS); |
---|
863 | 1039 | } |
---|
864 | 1040 | |
---|
| 1041 | + static class CheckBox extends javax.swing.plaf.metal.MetalCheckBoxIcon |
---|
| 1042 | + { |
---|
| 1043 | + java.awt.image.BufferedImage image; |
---|
| 1044 | + |
---|
| 1045 | + CheckBox() |
---|
| 1046 | + { |
---|
| 1047 | + try |
---|
| 1048 | + { |
---|
| 1049 | + image = javax.imageio.ImageIO.read(ObjEditor.class.getClassLoader().getResourceAsStream("icons/checkbox.png")); |
---|
| 1050 | + } |
---|
| 1051 | + catch (Exception e) |
---|
| 1052 | + { |
---|
| 1053 | + } |
---|
| 1054 | + } |
---|
| 1055 | + |
---|
| 1056 | + protected void drawCheck(Component c, Graphics g, int x, int y) |
---|
| 1057 | + { |
---|
| 1058 | + super.drawCheck(c, g, x, y); |
---|
| 1059 | + } |
---|
| 1060 | + |
---|
| 1061 | + public void paintIcon(Component c, Graphics g, int x, int y) |
---|
| 1062 | + { |
---|
| 1063 | + g.drawImage(image, x-1, y-1, 19, 19, null); |
---|
| 1064 | + super.paintIcon(c, g, x+2, y+2); |
---|
| 1065 | + } |
---|
| 1066 | + } |
---|
| 1067 | + |
---|
| 1068 | + static Object3D materials; |
---|
| 1069 | + |
---|
| 1070 | + static Object3D ReadGFD(java.io.InputStream istream) |
---|
| 1071 | + { |
---|
| 1072 | + Object3D readobj = null; |
---|
| 1073 | + |
---|
| 1074 | + try |
---|
| 1075 | + { |
---|
| 1076 | + // Try compressed version first. |
---|
| 1077 | + java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream); |
---|
| 1078 | + java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream); |
---|
| 1079 | + |
---|
| 1080 | + readobj = (Object3D) p.readObject(); |
---|
| 1081 | + p.close(); |
---|
| 1082 | + zstream.close(); |
---|
| 1083 | + istream.close(); |
---|
| 1084 | + |
---|
| 1085 | + readobj.ResetDisplayList(); |
---|
| 1086 | + } catch (Exception e) |
---|
| 1087 | + { |
---|
| 1088 | + if (!e.toString().contains("GZIP")) |
---|
| 1089 | + e.printStackTrace(); |
---|
| 1090 | + |
---|
| 1091 | + try |
---|
| 1092 | + { |
---|
| 1093 | + java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream); |
---|
| 1094 | + |
---|
| 1095 | + readobj = (Object3D) p.readObject(); |
---|
| 1096 | + p.close(); |
---|
| 1097 | + istream.close(); |
---|
| 1098 | + |
---|
| 1099 | + readobj.ResetDisplayList(); |
---|
| 1100 | + } catch (Exception e2) |
---|
| 1101 | + { |
---|
| 1102 | + e2.printStackTrace(); |
---|
| 1103 | + } |
---|
| 1104 | + } |
---|
| 1105 | + |
---|
| 1106 | + return readobj; |
---|
| 1107 | + } |
---|
| 1108 | + |
---|
865 | 1109 | // Timer callback |
---|
866 | 1110 | public void actionPerformed(ActionEvent e) |
---|
867 | 1111 | { |
---|
.. | .. |
---|
876 | 1120 | static int depth = 0; |
---|
877 | 1121 | static java.util.Stack stack = new java.util.Stack(); |
---|
878 | 1122 | static boolean traceoff = false; // true; |
---|
879 | | - static float[] colorV = new float[5]; |
---|
| 1123 | + static float[] colorV = new float[4]; // 5]; |
---|
880 | 1124 | |
---|
881 | 1125 | static void traceon() |
---|
882 | 1126 | { |
---|
.. | .. |
---|
983 | 1227 | |
---|
984 | 1228 | static public Object clone(Object o) |
---|
985 | 1229 | { |
---|
| 1230 | + if (o instanceof Object3D) |
---|
| 1231 | + { |
---|
| 1232 | + assert(((Object3D)o).parent == null); |
---|
| 1233 | + } |
---|
| 1234 | + |
---|
986 | 1235 | if (o == null) |
---|
987 | 1236 | return null; |
---|
988 | 1237 | |
---|
.. | .. |
---|
1085 | 1334 | } while (avail > 0 && numRead >= 0); |
---|
1086 | 1335 | return new String(data, 0, pos, "US-ASCII"); |
---|
1087 | 1336 | } |
---|
1088 | | - public static Grafreed grafreeD; |
---|
| 1337 | + public static Grafreed grafreed; |
---|
1089 | 1338 | public static boolean standAlone = true; |
---|
1090 | 1339 | public Composite universe; |
---|
1091 | 1340 | public static Object3D clipboard = new Object3D(); |
---|