From: Kenneth B. R. <kbr...@us...> - 2008-03-02 20:21:27
|
Update of /cvsroot/jake2/jake2/src/jake2/sys In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv16186/src/jake2/sys Modified Files: JOGLKBD.java Sys.java Log Message: Changes to enable Jake2 to run well as an applet inside the next-generation Java Plug-In. Added Globals.appletMode, Globals.applet and Globals.sizeChangeListener to be able to easily pass around the knowledge that the system is running in applet mode, and the applet itself, which becomes the parent container for the output. Most changes were in Jsr231Driver to support putting the Display into a preexisting parent container rather than a new Frame each time. Changed JOGLKBD to allow manual initialization of the parent container rather than obtaining it from a CreateNotify or ConfigureNotify event since these will never be generated in the applet case. Removed various calls to System.exit(), although strictly speaking this is no longer necessary because it is expected that the separate_jvm parameter will be used in conjunction with the new Java Plug-In to create a fresh JVM instance for each run of Jake2. Video mode switching in applet mode is working; the applet resizes (via JavaScript) to accommodate the newly selected resolution. Full screen mode when running as an applet is not implemented at this point, as the intent was to show this inside the browser, though support could be added very straightforwardly. Index: JOGLKBD.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/sys/JOGLKBD.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** JOGLKBD.java 12 May 2007 15:15:32 -0000 1.12 --- JOGLKBD.java 2 Mar 2008 20:21:15 -0000 1.13 *************** *** 1,4 **** --- 1,5 ---- package jake2.sys; + import jake2.Globals; import jake2.client.Key; *************** *** 22,26 **** --- 23,29 ---- robot = new Robot(); } catch (AWTException e) { + if (!Globals.appletMode) { System.exit(1); + } } } *************** *** 29,32 **** --- 32,41 ---- } + // Used only for the applet case + public static void Init(Component component) { + c = component; + handleCreateAndConfigureNotify(component); + } + public void Update() { // get events *************** *** 86,107 **** case Jake2InputEvent.CreateNotify : case Jake2InputEvent.ConfigureNotify : ! Component c = ((ComponentEvent)event.ev).getComponent(); ! win_x = 0; ! win_y = 0; ! win_w2 = c.getWidth() / 2; ! win_h2 = c.getHeight() / 2; ! int left = 0; int top = 0; ! while (c != null) { ! if (c instanceof Container) { ! Insets insets = ((Container)c).getInsets(); ! left += insets.left; ! top += insets.top; ! } ! win_x += c.getX(); ! win_y += c.getY(); ! c = c.getParent(); ! } ! win_x += left; win_y += top; ! win_w2 -= left / 2; win_h2 -= top / 2; break; } --- 95,99 ---- case Jake2InputEvent.CreateNotify : case Jake2InputEvent.ConfigureNotify : ! handleCreateAndConfigureNotify(((ComponentEvent)event.ev).getComponent()); break; } *************** *** 114,117 **** --- 106,141 ---- } + private static void handleCreateAndConfigureNotify(Component component) { + // Probably could unify this code better, but for now just + // leave the two code paths separate + if (!Globals.appletMode) { + win_x = 0; + win_y = 0; + win_w2 = component.getWidth() / 2; + win_h2 = component.getHeight() / 2; + int left = 0; int top = 0; + while (component != null) { + if (component instanceof Container) { + Insets insets = ((Container)component).getInsets(); + left += insets.left; + top += insets.top; + } + win_x += component.getX(); + win_y += component.getY(); + component = component.getParent(); + } + win_x += left; win_y += top; + win_w2 -= left / 2; win_h2 -= top / 2; + } else { + win_x = 0; + win_y = 0; + win_w2 = component.getWidth() / 2; + win_h2 = component.getHeight() / 2; + Point p = component.getLocationOnScreen(); + win_x = p.x; + win_y = p.y; + } + } + // strange button numbering in java.awt.MouseEvent // BUTTON1(left) BUTTON2(center) BUTTON3(right) Index: Sys.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/sys/Sys.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Sys.java 1 Jul 2005 14:20:54 -0000 1.11 --- Sys.java 2 Mar 2008 20:21:15 -0000 1.12 *************** *** 46,50 **** //StackTrace(); new Exception(error).printStackTrace(); ! System.exit(1); } --- 46,52 ---- //StackTrace(); new Exception(error).printStackTrace(); ! if (!Globals.appletMode) { ! System.exit(1); ! } } *************** *** 52,56 **** CL.Shutdown(); ! System.exit(0); } --- 54,60 ---- CL.Shutdown(); ! if (!Globals.appletMode) { ! System.exit(0); ! } } *************** *** 241,243 **** } ! } \ No newline at end of file --- 245,247 ---- } ! } |