From d5d6485126da83b06645e90e3e4ce66659a56009 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sat, 17 Aug 2019 13:56:24 -0400 Subject: [PATCH] Reset transform, fix loop versioning. --- Grafreed.java | 200 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 187 insertions(+), 13 deletions(-) diff --git a/Grafreed.java b/Grafreed.java index 088a313..e0acda9 100644 --- a/Grafreed.java +++ b/Grafreed.java @@ -5,6 +5,7 @@ import java.io.*; +import java.util.ArrayList; import javax.swing.UIManager; import javax.swing.plaf.metal.MetalLookAndFeel; import javax.swing.plaf.ColorUIResource; @@ -15,7 +16,7 @@ //import com.jamonapi.*; public class Grafreed extends Applet implements ActionListener { - static boolean NIMBUSLAF = true; + static boolean NIMBUSLAF = false; // true; static int RENDERME = 0; @@ -23,6 +24,8 @@ static float epsvertex2 = 0.001f; static boolean linkUV = false; // not uniform at load time + static boolean smoothmode = false; + static Wav wav = new Wav("/Users/nbriere/0ut/wavs/monoformat"); // output"); static boolean hassound = false; static boolean savesound = false; @@ -47,6 +50,79 @@ } } + + public static String RemovePrefix(String s, String prefix) + { + if (s != null && prefix != null && s.startsWith(prefix)) + { + return s.substring(prefix.length()); + } + + return s; + } + + static void ParseFileSystem(java.io.File dir, iResourceCallBack callback, String prefix) + { + callback.ResourceCallBack(RemovePrefix(dir.toString(),prefix).split("/")); + File[] listFiles = dir.listFiles(); + if (listFiles != null) + { + for (java.io.File file : listFiles) + { + ParseFileSystem(file, callback, prefix); + } + } + } + + static interface iResourceCallBack + { + void ResourceCallBack(String[] path); + } + + static void ParseResources(String path, iResourceCallBack callback) + { + java.io.File jarFile = new java.io.File(Grafreed.class.getProtectionDomain().getCodeSource().getLocation().getPath()); + + if (jarFile.isFile()) + { + // Run with JAR file + try + { + java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile); + java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries(); //gives ALL entries in jar + while (entries.hasMoreElements()) + { + String name = entries.nextElement().getName(); + + if (name.startsWith(path + "/")) + callback.ResourceCallBack(RemovePrefix(name, path + "/").split("/")); + } + jar.close(); + } catch (Exception ex) + { + ex.printStackTrace(); + } + } else + { + // Run with IDE + final java.net.URL url = Object3D.class.getResource("/" + path); + if (url != null) + { + try + { + java.io.File apps = new java.io.File(url.toURI()); + ParseFileSystem(apps, callback, RemovePrefix(url.toString() + "/", "file:")); +// for (java.io.File app : apps.listFiles()) +// { +// //System.out.println(RemovePrefix(app.toString(), RemovePrefix(url.toString(), "file:") + "/")); +// } + } catch (Exception ex) + { + ex.printStackTrace(); + } + } + } + } public void init() { @@ -56,7 +132,7 @@ universe.material = new cMaterial(); //god.addChild(universe); universe.name = "Applet"; - grafreeD = this; + grafreed = this; } /**/ @@ -601,7 +677,8 @@ public static void main(String argv[]) { - String osArch = System.getProperty("os.arch"); + String osArch = System.getProperty("os.arch"); + if (Globals.DEBUG) System.out.println("os.arch = " + osArch); if (argv.length == 0) @@ -822,6 +899,13 @@ //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); //UIManager.put("nimbusBase", new Color(0,0,0)); + + javax.swing.UIDefaults ui = UIManager.getDefaults(); + for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();) + { + Object key = e.nextElement(); + System.out.println(key + " --> " + ui.get(key)); + } } catch (Exception e) { @@ -831,12 +915,49 @@ { try { - MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); - MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme)); + //Object o = UIManager.getInstalledLookAndFeels(); + + MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.DefaultMetalTheme()); + //MetalLookAndFeel.setCurrentTheme(new Theme(Constants.yellowTheme)); + //UIManager.put("ScrollBar.background", new javax.swing.plaf.ColorUIResource(100,0,0)); UIManager.setLookAndFeel(new MetalLookAndFeel()); //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); //UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); + //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + + javax.swing.UIDefaults ui = UIManager.getDefaults(); + ArrayList gradient = new java.util.ArrayList(5); + gradient.add(1.0); + gradient.add(0.0); + gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255)); + gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192)); + gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0)); + + ui.put("Button.gradient", gradient); + ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(0,8,0,0)); + ui.put("Slider.foreground", new javax.swing.plaf.ColorUIResource(0,0,0)); + ui.put("Slider.horizontalThumbIcon", ObjEditor.GetIcon("icons/white-sphere-icon.png")); + + //javax.swing.plaf.metal.MetalIconFactory.getHorizontalSliderThumbIcon(). + Object o = ui.get("Slider.horizontalThumbIcon"); + + gradient = new java.util.ArrayList(5); + gradient.add(1.0); + gradient.add(0.0); + gradient.add(new javax.swing.plaf.ColorUIResource(192,192,192)); + gradient.add(new javax.swing.plaf.ColorUIResource(255,255,255)); + gradient.add(new javax.swing.plaf.ColorUIResource(0,0,0)); + + ui.put("ToggleButton.gradient", gradient); + //ui.put("Button[MouseOver].backgroundPainter", new com.sun.java.swing.plaf.nimbus.ButtonPainter()); + //ui.put("Button.highlight", new javax.swing.plaf.ColorUIResource(155,155,155)); + + for (java.util.Enumeration e = ui.keys(); e.hasMoreElements();) + { + Object key = e.nextElement(); + //System.out.println(key + " --> " + ui.get(key)); + } } catch (Exception e) { } @@ -847,19 +968,67 @@ //Monitor mon=MonitorFactory.start("myFirstMonitor"); standAlone = true; - grafreeD = new Grafreed(); - grafreeD.universe = new cGroup(); - grafreeD.universe.name = "Grafreed"; - grafreeD.universe.material = new cMaterial(); + grafreed = new Grafreed(); + grafreed.materials = ReadGFD(grafreed.getClass().getClassLoader().getResourceAsStream("gfd/materials.gfd")); + + grafreed.universe = new cGroup(); + grafreed.universe.name = "Grafreed"; + grafreed.universe.material = new cMaterial(); + grafreed.universe.skyboxname = "cubemaps/penguins-skyboxes/yonder"; + grafreed.universe.skyboxext = "jpg"; + // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE; - grafreeD.universe.root = true; - grafreeD.universe.openEditWindow(null, true); //, true); + grafreed.universe.root = true; + grafreed.universe.openEditWindow(null, true); //, true); //mon.stop(); //System.out.println(mon); //timeflow.app.TimeflowAppLauncher.GetTimeFlow(); + + javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS); } + static Object3D materials; + + static Object3D ReadGFD(java.io.InputStream istream) + { + Object3D readobj = null; + + try + { + // Try compressed version first. + java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream); + java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream); + + readobj = (Object3D) p.readObject(); + p.close(); + zstream.close(); + istream.close(); + + readobj.ResetDisplayList(); + } catch (Exception e) + { + if (!e.toString().contains("GZIP")) + e.printStackTrace(); + + try + { + java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream); + + readobj = (Object3D) p.readObject(); + p.close(); + istream.close(); + + readobj.ResetDisplayList(); + } catch (Exception e2) + { + e2.printStackTrace(); + } + } + + return readobj; + } + // Timer callback public void actionPerformed(ActionEvent e) { @@ -874,7 +1043,7 @@ static int depth = 0; static java.util.Stack stack = new java.util.Stack(); static boolean traceoff = false; // true; - static float[] colorV = new float[5]; + static float[] colorV = new float[4]; // 5]; static void traceon() { @@ -981,6 +1150,11 @@ static public Object clone(Object o) { + if (o instanceof Object3D) + { + assert(((Object3D)o).parent == null); + } + if (o == null) return null; @@ -1083,7 +1257,7 @@ } while (avail > 0 && numRead >= 0); return new String(data, 0, pos, "US-ASCII"); } - public static Grafreed grafreeD; + public static Grafreed grafreed; public static boolean standAlone = true; public Composite universe; public static Object3D clipboard = new Object3D(); -- Gitblit v1.6.2