X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FPlatform.java;h=6e76b3f4e5f7509552b8b55afbd3fcd3901467c7;hb=16c24a73c1c1b2955db0bbbaf5a940215329bca1;hp=efc27316aeb2eb63195ca6c6243b4ba0b387433a;hpb=a1595b93f1dd8d55aa892cb7db82b45591ff6c28;p=org.ibex.core.git
diff --git a/src/org/xwt/Platform.java b/src/org/xwt/Platform.java
index efc2731..6e76b3f 100644
--- a/src/org/xwt/Platform.java
+++ b/src/org/xwt/Platform.java
@@ -1,10 +1,11 @@
-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt;
import java.lang.reflect.*;
import java.net.*;
import java.io.*;
import java.util.*;
+import org.xwt.js.*;
import org.xwt.util.*;
/**
@@ -17,39 +18,26 @@ import org.xwt.util.*;
* it in the org.xwt.plat package, and add code to this file's static
* block to detect the new platform.
*/
-public class Platform {
+public abstract class Platform {
- // Static Data /////////////////////////////////////////////////////////////////////////////////////
-
- /**
- * set to true during the delivery of a KeyPressed:C-v/A-v or Press3; it is safe to use a
- * 'global' here, since message delivery is single-threaded and non-preemptable
- */
- static boolean clipboardReadEnabled = false;
-
- /** The appropriate Platform object for this JVM */
- static Platform platform = null;
+ public Platform() { platform = this; }
- /** true if proxy autodetection has already been run */
- static boolean alreadyDetectedProxy = false;
-
- /** the result of proxy autodetection */
- static org.xwt.HTTP.Proxy cachedProxyInfo = null;
+ // Static Data /////////////////////////////////////////////////////////////////////////////////////
- /** the current build */
- public static String build = "unknown";
+ static boolean clipboardReadEnabled = false; ///< true iff inside a C-v/A-v/Press3 trap handler
+ static Platform platform = null; ///< The appropriate Platform object for this JVM
+ static boolean alreadyDetectedProxy = false; ///< true if proxy autodetection has already been run
+ static org.xwt.HTTP.Proxy cachedProxyInfo = null; ///< the result of proxy autodetection
+ public static String build = "unknown"; ///< the current build
// VM Detection Logic /////////////////////////////////////////////////////////////////////
- /** do-nothing method that forces <clinit> to run */
- public static void forceLoad() { }
-
// If you create a new subclass of Platform, you should add logic
// here to detect it. Do not reference your class directly -- use
// reflection.
- static {
- System.err.println("Detecting JVM...");
+ public static void forceLoad() {
+ System.err.print("Detecting JVM...");
try {
String vendor = System.getProperty("java.vendor", "");
String version = System.getProperty("java.version", "");
@@ -57,85 +45,87 @@ public class Platform {
String os_version = System.getProperty("os.version", "");
String platform_class = null;
- if (os_name.startsWith("Darwin")) platform_class = "Darwin";
- else if (vendor.startsWith("Free Software Foundation")) {
+ if (vendor.startsWith("Free Software Foundation")) {
if (os_name.startsWith("Window")) platform_class = "Win32";
+ else if (os_name.startsWith("Linux")) platform_class = "Linux";
+ else if (os_name.startsWith("SunOS")) platform_class = "Solaris";
+ else if (os_name.startsWith("Solaris")) platform_class = "Solaris";
else platform_class = "X11";
- } else if (version.startsWith("1.1") && vendor.startsWith("Netscape")) platform_class = "Netscape";
- else if (version.startsWith("1.1") && vendor.startsWith("Microsoft")) platform_class = "Microsoft";
+ }
else if (!version.startsWith("1.0") && !version.startsWith("1.1")) platform_class = "Java2";
- /*
- // Disable 2d hardware acceleration on Jaguar
- if (os_name.equals("Mac OS X") && os_version.startsWith("10.2")) System.setProperty("com.apple.hwaccel", "false");
- */
- System.setProperty("com.apple.hwaccel", "true");
-
- if (platform_class != null) {
- platform = (Platform)Class.forName("org.xwt.plat." + platform_class).newInstance();
- platform.init();
+ if (platform_class == null) {
+ Log.error(Platform.class, "Unable to detect JVM");
+ criticalAbort("Unable to detect JVM");
+ }
+
+ System.err.println(" " + os_name + " ==> org.xwt.plat." + platform_class);
+ try {
+ if (platform_class != null) Class.forName("org.xwt.plat." + platform_class).newInstance();
+ } catch (InstantiationException e) {
+ throw e.getCause();
}
+ String term = Platform.getEnv("TERM");
+ Log.color = term != null && term.length() != 0 && !term.equals("cygwin");
+
try {
build = (String)Class.forName("org.xwt.Build").getField("build").get(null);
+ Log.diag(Platform.class, "XWT build: " + build);
} catch (ClassNotFoundException cnfe) {
+ Log.warn(Platform.class, "XWT build: unknown");
} catch (Exception e) {
- if (Log.on) Log.log(Platform.class, "exception while detecting build:");
- if (Log.on) Log.log(Platform.class, e);
+ Log.info(Platform.class, "exception while detecting build:");
+ Log.info(Platform.class, e);
}
- if (Log.on) Log.log(Platform.class, "XWT build: " + build);
-
- if (Log.on) Log.log(Platform.class, "XWT VM detection: vendor = " + vendor);
- if (Log.on) Log.log(Platform.class, " version = " + version);
- if (Log.on) Log.log(Platform.class, " os = " + os_name + " [version " + os_version + "]");
- if (platform_class == null) {
- if (Log.on) Log.log(Platform.class, "Unable to detect JVM");
- new Platform().criticalAbort("Unable to detect JVM");
- }
-
- if (Log.on) Log.log(Platform.class, " platform = " + platform.getDescriptiveName());
- if (Log.on) Log.log(Platform.class, " class = " + platform.getClass().getName());
+ Log.diag(Platform.class, "XWT VM detection: vendor = " + vendor);
+ Log.diag(Platform.class, " version = " + version);
+ Log.diag(Platform.class, " os = " + os_name + " [version " + os_version + "]");
+ Log.diag(Platform.class, " platform = " + platform.getDescriptiveName());
+ Log.diag(Platform.class, " class = " + platform.getClass().getName());
platform.postInit();
- } catch (Exception e) {
- if (Log.on) Log.log(Platform.class, "Exception while trying to detect JVM");
- if (Log.on) Log.log(Platform.class, e);
- new Platform().criticalAbort("Unable to detect JVM");
+ } catch (Throwable e) {
+ Log.error(Platform.class, "Exception while trying to detect JVM");
+ Log.error(Platform.class, e);
+ criticalAbort("Unable to detect JVM");
}
}
- // Methods to be Overridden ////////////////////////////////////////////////////////////////////
+ // Methods to be Overridden ///////////////////////////////////////////////////////////////////
- /** a string describing the VM */
- protected String getDescriptiveName() { return "Generic Java 1.1 VM"; }
-
- /** this initializes the platform; code in here can invoke methods on Platform since Platform.platform has already been set */
- protected void init() { }
- protected void postInit() { }
+ protected Surface _createSurface(Box b, boolean framed) { return null; }
+ protected Picture _createPicture(JS r) { return null; }
+ protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return null; }
+ protected Font.Glyph _createGlyph(org.xwt.Font f, char c) { return new DefaultGlyph(f, c); }
- /** creates and returns a doublebuffer 'belonging' to owner; we need to associate PixelBuffers to surfaces
- * due to AWT 1.1 requirements (definately for Navigator, possibly also for MSJVM).
- */
public static PixelBuffer createPixelBuffer(int w, int h, Surface s) { return platform._createPixelBuffer(w, h, s); }
- protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return null; }
-
- /** creates and returns a picture */
- public static Picture createPicture(int[] data, int w, int h) { return platform._createPicture(data, w, h); }
- public static Picture createAlphaOnlyPicture(byte[] data, int w, int h) { return platform._createAlphaOnlyPicture(data, w, h); }
-
- protected Picture _createPicture(int[] b, int w, int h) { return null; }
- protected Picture _createAlphaOnlyPicture(byte[] b, int w, int h) {
- int[] b2 = new int[b.length];
- for(int i=0;i