]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/threedee/WindowFactory.java
Moved source into separate src directory due to popular request
[GpsPrune.git] / src / tim / prune / threedee / WindowFactory.java
diff --git a/src/tim/prune/threedee/WindowFactory.java b/src/tim/prune/threedee/WindowFactory.java
new file mode 100644 (file)
index 0000000..42ff8a4
--- /dev/null
@@ -0,0 +1,59 @@
+package tim.prune.threedee;
+
+import javax.swing.JFrame;
+
+/**
+ * Factory class for getting a Window
+ */
+public abstract class WindowFactory
+{
+       private static Java3DWindow _window = null;
+
+       /**
+        * Get a Window object
+        * @param inFrame parent frame
+        * @return object if available, otherwise null
+        */
+       public static ThreeDWindow getWindow(JFrame inFrame)
+       {
+               if (isJava3dEnabled())
+               {
+                       if (_window == null) {
+                               _window = new Java3DWindow(inFrame);
+                       }
+                       else {
+                               _window.dispose();
+                       }
+                       return _window;
+               }
+               return null;
+       }
+
+
+       /**
+        * @return true if 3d capability is installed
+        */
+       public static boolean isJava3dEnabled()
+       {
+               boolean has3d = false;
+               try
+               {
+                       Class<?> universeClass = Class.forName("com.sun.j3d.utils.universe.SimpleUniverse");
+                       has3d = (universeClass != null);
+               }
+               catch (ClassNotFoundException e)
+               {
+                       // no java3d classes available
+               }
+               catch (NoClassDefFoundError nfe)
+               {
+                       // no java3d classes available
+               }
+               catch (UnsatisfiedLinkError ule)
+               {
+                       // java3d classes found but no native components
+               }
+               return has3d;
+       }
+
+}