diff options
18 files changed, 816 insertions, 289 deletions
diff --git a/make/build.xml b/make/build.xml index b35641e43..5dce7d8ae 100644 --- a/make/build.xml +++ b/make/build.xml @@ -322,22 +322,9 @@ <!-- ================================================================== --> <!-- - - Set up java.home.dir appropriately on all platforms. - --> - <target name="setup.java.home.dir.nonmacosx" depends="load.user.properties" unless="isOSX"> - <!-- java home dir is up one directory as java.home points to '<java-install-dir>/jre' --> - <property name="java.home.dir" value="${java.home}/.." /> - </target> - <target name="setup.java.home.dir.macosx" depends="load.user.properties" if="isOSX"> - <property name="java.home.dir" value="/System/Library/Frameworks/JavaVM.framework/Home" /> - </target> - <target name="setup.java.home.dir" depends="setup.java.home.dir.nonmacosx,setup.java.home.dir.macosx"/> - - <!-- ================================================================== --> - <!-- - Declare all paths and user defined variables. --> - <target name="declare.common" description="Declare properties" depends="setup.java.home.dir, gluegen.cpptasks.detect.compiler"> + <target name="declare.common" description="Declare properties" depends="load.user.properties"> <!-- The location and name of the configuration ANT file that will - validate to ensure that all user-define variables are set. --> <property name="validate.user.properties" value="${make}/validate-properties.xml" /> @@ -427,35 +414,6 @@ <include name="cg-common-CustomJavaCode.java" /> </fileset> - <property name="java.includes.dir" value="${java.home.dir}/include" /> <!-- NOTE: this MUST be relative for FileSet --> - <property name="java.includes.dir.win32" value="${java.includes.dir}/win32" /> - <property name="java.includes.dir.linux" value="${java.includes.dir}/linux" /> - <property name="java.includes.dir.solaris" value="${java.includes.dir}/solaris" /> - <property name="java.includes.dir.macosx" value="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Headers" /> - <property name="java.includes.dir.freebsd" value="${java.includes.dir}/freebsd" /> - <property name="java.includes.dir.hpux" value="${java.includes.dir}/hp-ux" /> - <property name="java.lib.dir.win32" value="${java.home.dir}/lib" /> - <property name="java.lib.dir.linux" value="${java.home.dir}/jre/lib/i386" /> - <property name="java.lib.dir.linux.amd64" value="${java.home.dir}/jre/lib/amd64" /> - <property name="java.lib.dir.linux.ia64" value="${java.home.dir}/jre/lib/ia64" /> - <property name="java.lib.dir.hpux" value="${java.home.dir}/jre/lib/PA_RISC2.0" /> - <condition property="cpu" value="sparc"> - <os name="SunOS" arch="sparc" /> - </condition> - <condition property="cpu" value="sparcv9"> - <os name="SunOS" arch="sparcv9" /> - </condition> - <condition property="cpu" value="i386"> - <os name="SunOS" arch="x86" /> - </condition> - - <condition property="cpu" value="amd64"> - <os name="SunOS" arch="amd64" /> - </condition> - - <property name="java.lib.dir.solaris" value="${java.home.dir}/jre/lib/${cpu}" /> - <property name="java.lib.dir.macosx" value="/System/Library/Frameworks/JavaVM.framework/Libraries" /> - <!-- Create the classpath that includes GlueGen and - ANTLR. This requires the user-defined "antlr.jar" - property. --> @@ -531,34 +489,10 @@ <!-- - Platform specific declares - COMPILER --> - <target name="declare.win32.vc6" if="isVC6"> - <echo message="Win32.VC6" /> - <property name="compiler.cfg.id" value="compiler.cfg.win32.msvc" /> - <property name="linker.cfg.id.base" value="linker.cfg.win32.msvc" /> - <property name="linker.cfg.id.oswin" value="linker.cfg.win32.msvc.jogl" /> - <property name="linker.cfg.id.gl2" value="linker.cfg.win32.msvc.jogl" /> - </target> - - <target name="declare.win32.vc7" if="isVC7"> - <echo message="Win32.VC7" /> - <property name="compiler.cfg.id" value="compiler.cfg.win32.msvc" /> - <property name="linker.cfg.id.base" value="linker.cfg.win32.msvc" /> - <property name="linker.cfg.id.oswin" value="linker.cfg.win32.msvc.jogl" /> - <property name="linker.cfg.id.gl2" value="linker.cfg.win32.msvc.jogl" /> - </target> - - <target name="declare.win32.vc8" if="isVC8"> - <echo message="Win32.VC8" /> - <property name="compiler.cfg.id" value="compiler.cfg.win32.msvc" /> - <property name="linker.cfg.id.base" value="linker.cfg.win32.msvc" /> - <property name="linker.cfg.id.oswin" value="linker.cfg.win32.msvc.jogl" /> - <property name="linker.cfg.id.gl2" value="linker.cfg.win32.msvc.jogl" /> - </target> - - <target name="declare.win32.vc8_x64" if="isVC8_X64"> - <echo message="Win32.VC8_X64" /> + <target name="declare.win32.vc" if="isVCFamily"> + <echo message="Win32.VC" /> <property name="compiler.cfg.id" value="compiler.cfg.win32.msvc" /> - <property name="linker.cfg.id.base" value="linker.cfg.win32.msvc" /> + <property name="linker.cfg.id.core" value="linker.cfg.win32.msvc" /> <property name="linker.cfg.id.oswin" value="linker.cfg.win32.msvc.jogl" /> <property name="linker.cfg.id.gl2" value="linker.cfg.win32.msvc.jogl" /> </target> @@ -566,40 +500,31 @@ <target name="declare.win32.mingw" if="isMingW"> <echo message="Win32.MingW" /> <property name="compiler.cfg.id" value="compiler.cfg.win32.mingw" /> - <property name="linker.cfg.id.base" value="linker.cfg.win32.mingw" /> + <property name="linker.cfg.id.core" value="linker.cfg.win32.mingw" /> <property name="linker.cfg.id.oswin" value="linker.cfg.win32.mingw.jogl" /> <property name="linker.cfg.id.gl2" value="linker.cfg.win32.mingw.jogl" /> </target> <target name="declare.linux.x86" if="isLinuxX86"> <echo message="Linux.x86" /> - <property name="java.includes.dir.platform" value="${java.includes.dir.linux}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.linux}" /> - <property name="compiler.cfg.id" value="compiler.cfg.linux" /> - <property name="linker.cfg.id.base" value="linker.cfg.linux" /> + <property name="linker.cfg.id.core" value="linker.cfg.linux" /> <property name="linker.cfg.id.oswin" value="linker.cfg.linux.jogl.x11" /> <property name="linker.cfg.id.gl2" value="linker.cfg.linux.jogl.gl2" /> </target> <target name="declare.linux.amd64" if="isLinuxAMD64"> <echo message="Linux.AMD64" /> - <property name="java.includes.dir.platform" value="${java.includes.dir.linux}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.linux.amd64}" /> - <property name="compiler.cfg.id" value="compiler.cfg.linux.amd64" /> - <property name="linker.cfg.id.base" value="linker.cfg.linux.amd64" /> + <property name="linker.cfg.id.core" value="linker.cfg.linux.amd64" /> <property name="linker.cfg.id.oswin" value="linker.cfg.linux.amd64.jogl.x11" /> <property name="linker.cfg.id.gl2" value="linker.cfg.linux.amd64.jogl.gl2" /> </target> <target name="declare.linux.ia64" if="isLinuxIA64"> <echo message="Linux.IA64" /> - <property name="java.includes.dir.platform" value="${java.includes.dir.linux}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.linux.ia64}" /> - <property name="compiler.cfg.id" value="compiler.cfg.linux" /> - <property name="linker.cfg.id.base" value="linker.cfg.linux" /> + <property name="linker.cfg.id.core" value="linker.cfg.linux" /> <property name="linker.cfg.id.oswin" value="linker.cfg.linux.jogl.x11" /> <property name="linker.cfg.id.gl2" value="linker.cfg.linux.jogl.gl2" /> </target> @@ -608,11 +533,8 @@ <target name="declare.solaris32" depends="declare.x11" if="isSolaris32Bit"> <echo message="Solaris" /> - <property name="java.includes.dir.platform" value="${java.includes.dir.solaris}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.solaris}" /> - <property name="compiler.cfg.id" value="compiler.cfg.solaris" /> - <property name="linker.cfg.id.base" value="linker.cfg.solaris" /> + <property name="linker.cfg.id.core" value="linker.cfg.solaris" /> <property name="linker.cfg.id.oswin" value="linker.cfg.solaris.jogl.x11" /> <property name="linker.cfg.id.gl2" value="linker.cfg.solaris.jogl.gl2" /> </target> @@ -620,11 +542,8 @@ <target name="declare.solaris.sparcv9" depends="declare.x11" if="isSolarisSparcv9"> <echo message="SolarisSparcv9" /> - <property name="java.includes.dir.platform" value="${java.includes.dir.solaris}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.solaris}" /> - <property name="compiler.cfg.id" value="compiler.cfg.solaris.sparcv9" /> - <property name="linker.cfg.id.base" value="linker.cfg.solaris.sparcv9" /> + <property name="linker.cfg.id.core" value="linker.cfg.solaris.sparcv9" /> <property name="linker.cfg.id.oswin" value="linker.cfg.solaris.sparcv9.jogl.x11" /> <property name="linker.cfg.id.gl2" value="linker.cfg.solaris.sparcv9.jogl.gl2" /> </target> @@ -632,50 +551,35 @@ <target name="declare.solaris.amd64" depends="declare.x11" if="isSolarisAMD64"> <echo message="SolarisAMD64" /> - <property name="java.includes.dir.platform" value="${java.includes.dir.solaris}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.solaris}" /> - <property name="compiler.cfg.id" value="compiler.cfg.solaris.amd64" /> - <property name="linker.cfg.id.base" value="linker.cfg.solaris.amd64" /> + <property name="linker.cfg.id.core" value="linker.cfg.solaris.amd64" /> <property name="linker.cfg.id.oswin" value="linker.cfg.solaris.amd64.jogl.x11" /> <property name="linker.cfg.id.gl2" value="linker.cfg.solaris.amd64.jogl.gl2" /> </target> <target name="declare.freebsd" depends="declare.x11" if="isFreeBSD"> <echo message="FreeBSD" /> - <property name="java.includes.dir.platform" value="${java.includes.dir.freebsd}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.linux}" /> - <property name="compiler.cfg.id" value="compiler.cfg.freebsd.jogl" /> - <property name="linker.cfg.id.base" value="linker.cfg.linux" /> + <property name="linker.cfg.id.core" value="linker.cfg.linux" /> <property name="linker.cfg.id.oswin" value="linker.cfg.linux.jogl.x11" /> <property name="linker.cfg.id.gl2" value="linker.cfg.linux.jogl.gl2" /> </target> <target name="declare.hpux" depends="declare.x11" if="isHPUX"> <echo message="HP-UX" /> - <property name="java.includes.dir.platform" value="${java.includes.dir.hpux}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.hpux}" /> <property name="compiler.cfg.id" value="compiler.cfg.hpux" /> - <property name="linker.cfg.id.base" value="linker.cfg.hpux" /> + <property name="linker.cfg.id.core" value="linker.cfg.hpux" /> <property name="linker.cfg.id.oswin" value="linker.cfg.hpux.jogl.x11" /> <property name="linker.cfg.id.gl2" value="linker.cfg.hpux.jogl.gl2" /> </target> - <target name="declare.win32" depends="declare.win32.vc6,declare.win32.vc7,declare.win32.vc8,declare.win32.vc8_x64,declare.win32.mingw" if="isWindows"> - <property name="java.includes.dir.platform" value="${java.includes.dir.win32}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.win32}" /> - </target> + <target name="declare.win32" depends="declare.win32.vc,declare.win32.mingw" if="isWindows" /> - <target name="declare.x11" depends="init" if="isX11"> - </target> + <target name="declare.x11" depends="init" if="isX11" /> <target name="declare.macosx" depends="init" if="isOSX"> - <property name="java.includes.dir.platform" value="${java.includes.dir.macosx}" /> - <property name="java.lib.dir.platform" value="${java.lib.dir.macosx}" /> - <property name="compiler.cfg.id" value="compiler.cfg.macosx" /> - <property name="linker.cfg.id.base" value="linker.cfg.macosx" /> + <property name="linker.cfg.id.core" value="linker.cfg.macosx" /> <property name="linker.cfg.id.oswin" value="linker.cfg.macosx.jogl" /> <property name="linker.cfg.id.gl2" value="linker.cfg.macosx.jogl" /> </target> @@ -906,6 +810,7 @@ <target name="java.generate.window.system.es" if="window.es.cfg" unless="jogl.noes"> <echo message="Generating EGL implementation class" /> + <dirset id="stub.includes.fileset.platform" dir="." includes="${stub.includes.dir}/${window.es.system}/**" /> <gluegen src="${stub.includes.dir}/${window.es.system}/window-system.c" config="${window.es.cfg}" includeRefid="stub.includes.fileset.platform" @@ -950,12 +855,12 @@ <target name="java.generate.BufferUtil" depends="java.generate.BufferUtil.javase, java.generate.BufferUtil.javame_cdc_fp" /> <target name="java.generate.gl.platforms" > - <dirset id="stub.includes.fileset.platform" dir="." includes="${stub.includes.dir}/${window.os.system}/** ${stub.includes.dir}/${window.es.system}/** ${stub.includes.dir}/common/** ${stub.includes.dir}/opengl/**" /> + <dirset id="stub.includes.fileset.platform" dir="." includes="${stub.includes.dir}/${window.os.system}/** ${stub.includes.dir}/${window.es.system}/** ${stub.includes.dir}/common/** ${stub.includes.dir}/opengl/**" /> - <antcall target="java.generate.platform.glext" inheritRefs="true" /> - <antcall target="java.generate.window.lib" inheritRefs="true" /> - <antcall target="java.generate.window.system.os" inheritRefs="true" /> - <antcall target="java.generate.jawt" inheritRefs="true" /> + <antcall target="java.generate.platform.glext" inheritRefs="true" /> + <antcall target="java.generate.window.lib" inheritRefs="true" /> + <antcall target="java.generate.window.system.os" inheritRefs="true" /> + <antcall target="java.generate.jawt" inheritRefs="true" /> </target> <!-- @@ -977,7 +882,6 @@ <antcall target="java.generate.gl.all" inheritRefs="true" /> <!--antcall target="java.generate.gl.nsig" inheritRefs="true" /--> - <echo message="Generating EGL implementation class" /> <antcall target="java.generate.window.system.es" inheritRefs="true" /> <echo message="Generating platform-specifics: X11" /> @@ -1202,7 +1106,7 @@ - Compile the native C code for JOGL (and optionally the Cg binding). --> - <target name="c.configure" depends="gluegen.cpptasks.configure.compiler" unless="jogl.compiler.present"> + <target name="c.configure" depends="gluegen.cpptasks.setup.compiler" unless="jogl.compiler.present"> <!-- compiler configuration --> <!-- Note that we can use the base setups in the gluegen-cpptasks for most of these --> @@ -1283,6 +1187,14 @@ </linker> </target> + <target name="rename.mingw.dll" if="isMingW"> + <move file="${src}" tofile="${dest}" /> + </target> + + <target name="rename.dylib" if="isOSX"> + <move file="${src}" tofile="${dest}" /> + </target> + <target name="c.build" depends="c.configure"> <fail message="Requires '${c.compiler.src.files}'" unless="c.compiler.src.files"/> <fail message="Requires '${compiler.cfg.id}'" unless="compiler.cfg.id"/> @@ -1427,31 +1339,23 @@ <syslibset dir="${java.lib.dir.platform}/server" libs="jvm" if="c.compiler.needs-libjvm"/> </linker> </cc> - </target> - <target name="c.rename.jogl.libs.mingw" if="isMingW"> <!-- FIXME: this is a hack; the cpptask should have an option to change the - suffix or at least understand the override from .so to .dll --> - <move file="${obj}/libjogl_awt.so" tofile="${obj}/jogl_awt.dll" /> - <move file="${obj}/lib_newt.so" tofile="${obj}/newt.dll" /> - <move file="${obj}/libjogl_gl2.so" tofile="${obj}/jogl_gl2.dll" /> - <move file="${obj}/libjogl_es2.so" tofile="${obj}/jogl_es2.dll" /> - <move file="${obj}/libjogl_es1.so" tofile="${obj}/jogl_es1.dll" /> - <move file="${obj}/libjogl_cg.so" tofile="${obj}/jogl_cg.dll" failonerror="false" /> - </target> + suffix or at least understand the override from dylib to jnilib --> + <antcall target="rename.dylib" inheritRefs="true"> + <param name="src" value="${build}/obj/lib${output.lib.name}.dylib" /> + <param name="dest" value="${build}/obj/lib${output.lib.name}.jnilib" /> + </antcall> - <target name="c.rename.jogl.libs.macosx" if="isOSX"> <!-- FIXME: this is a hack; the cpptask should have an option to change the suffix or at least understand the override from dylib to jnilib --> - <move file="${obj}/libjogl_awt.dylib" tofile="${obj}/libjogl_awt.jnilib" /> - <move file="${obj}/libjogl_gl2.dylib" tofile="${obj}/libjogl_gl2.jnilib" /> - <move file="${obj}/libjogl_es2.dylib" tofile="${obj}/libjogl_es2.jnilib" /> - <move file="${obj}/libjogl_es1.dylib" tofile="${obj}/libjogl_es1.jnilib" /> - <move file="${obj}/libjogl_cg.dylib" tofile="${obj}/libjogl_cg.jnilib" failonerror="false" /> - <antcall target="c.fixup.jawt.version.macosx" inheritrefs="true" /> - </target> + <antcall target="rename.mingw.dll" inheritRefs="true"> + <param name="src" value="${build}/lib${output.lib.name}.so" /> + <param name="dest" value="${build}/${output.lib.name}.dll" /> + </antcall> + </target> - <target name="c.fixup.jawt.version.macosx" if="macosxfat"> + <target name="c.fixup.jawt.version.macosx" if="isOSX"> <!-- Edit the link to the JAWT version in the resulting jnilib file; this isn't strictly needed but seems to allow the universal binaries to work on 10.3 machines as well, which @@ -1513,7 +1417,7 @@ <param name="c.compiler.src.files" value="c.src.files.jogl.es2"/> <param name="c.compiler.use-es2" value="true"/> <param name="output.lib.name" value="jogl_es2"/> - <param name="linker.cfg.id" value="${linker.cfg.id.base}"/> + <param name="linker.cfg.id" value="${linker.cfg.id.core}"/> </antcall> </target> @@ -1522,7 +1426,7 @@ <param name="c.compiler.src.files" value="c.src.files.jogl.es1"/> <param name="c.compiler.use-es1" value="true"/> <param name="output.lib.name" value="jogl_es1"/> - <param name="linker.cfg.id" value="${linker.cfg.id.base}"/> + <param name="linker.cfg.id" value="${linker.cfg.id.core}"/> </antcall> </target> @@ -1559,8 +1463,7 @@ </target> <target name="c.build.jogl" depends="c.build.jogl.prepare,c.build.jogl.awt,c.build.newt,c.build.jogl.gl2,c.build.jogl.es2,c.build.jogl.es1,c.build.jogl.cg"> - <antcall target="c.rename.jogl.libs.mingw" inheritRefs="true" /> - <antcall target="c.rename.jogl.libs.macosx" inheritRefs="true" /> + <antcall target="c.fixup.jawt.version.macosx" inheritrefs="true" /> <antcall target="c.manifest" inheritRefs="true" /> </target> @@ -1698,7 +1601,7 @@ - on the platform specific build targets. To circumvent any - errors, ensure that the source is built first. --> - <target name="javadoc.nocg" depends="setup.java.home.dir,init" unless="jogl.cg"> + <target name="javadoc.nocg" depends="load.user.properties,init" unless="jogl.cg"> <!-- Build the general Javadoc --> <javadoc packagenames="${javadoc.packagenames}" excludepackagenames="${java.excludes.javadoc.packagenames}" @@ -1714,7 +1617,7 @@ </target> <!-- Same as above but with Cg directories added --> - <target name="javadoc.cg" depends="setup.java.home.dir,init" if="jogl.cg"> + <target name="javadoc.cg" depends="load.user.properties,init" if="jogl.cg"> <!-- Build the general Javadoc --> <javadoc packagenames="${javadoc.packagenames},com.sun.opengl.cg" excludepackagenames="${java.excludes.javadoc.packagenames}" @@ -1731,7 +1634,7 @@ <target name="javadoc" depends="javadoc.nocg,javadoc.cg" /> - <target name="javadoc.spec.nocg" depends="setup.java.home.dir,init" unless="jogl.cg"> + <target name="javadoc.spec.nocg" depends="load.user.properties,init" unless="jogl.cg"> <!-- Build the general Javadoc --> <javadoc packagenames="${javadoc.spec.packagenames}" excludepackagenames="${java.excludes.javadoc.packagenames}" @@ -1747,7 +1650,7 @@ </target> <!-- Same as above since Cg directories are not part of spec --> - <target name="javadoc.spec.cg" depends="setup.java.home.dir,init" if="jogl.cg"> + <target name="javadoc.spec.cg" depends="load.user.properties,init" if="jogl.cg"> <!-- Build the general Javadoc --> <javadoc packagenames="${javadoc.spec.packagenames}" excludepackagenames="${java.excludes.javadoc.packagenames}" @@ -1795,7 +1698,7 @@ </javadoc> </target> - <target name="javadoc.dev.all" depends="setup.java.home.dir,init,declare,javadoc.dev.nocg,javadoc.dev.cg" /> + <target name="javadoc.dev.all" depends="load.user.properties,init,declare,javadoc.dev.nocg,javadoc.dev.cg" /> <!-- ================================================================== --> <!-- @@ -2255,7 +2158,7 @@ <!-- - Build everything. --> - <target name="all" description="Build JOGL JAR file(s) and native libraries." depends="setup.java.home.dir,init,declare"> + <target name="all" description="Build JOGL JAR file(s) and native libraries." depends="load.user.properties,init,declare"> <!-- Generate, compile, and build the jar for the Java sources. --> <antcall target="jar" inheritRefs="true" /> diff --git a/make/jogl.properties b/make/jogl.properties index 59944f532..bb5e81f87 100644 --- a/make/jogl.properties +++ b/make/jogl.properties @@ -11,21 +11,6 @@ # # java.home.dir=C:/jdk1.4.2 -# If you are building on Windows and have the Microsoft Visual C++ -# compilers installed, you can choose an alternate compiler with which -# to build the JOGL native code. Valid strings here are "vc6", "vc7", -# "vc8", "vc8_x64", and "mingw". -win32.c.compiler=vc6 - -# If you are building on a Mac OS X system supporting -# cross-compilation and want to generate fat (PPC and x86) binaries, -# uncomment the property below -# macosxfat=true -# If you are building on a 64-bit Mac OS X system supporting -# cross-compilation and want to generate fat (PPC64 and x86_64) binaries, -# uncomment the property below -# macosx64fat=true - # # If you are building the Cg binding (by specifying -Djogl.cg=1 to the # Ant build) and have installed the Cg SDK in somewhere other than the @@ -34,4 +19,3 @@ win32.c.compiler=vc6 # windows.cg.lib=C:/Program Files/Nvidia Corporation/Cg/lib x11.cg.lib=/usr/lib - diff --git a/make/validate-properties.xml b/make/validate-properties.xml index 4a2d386c9..3afb12bd5 100644 --- a/make/validate-properties.xml +++ b/make/validate-properties.xml @@ -25,25 +25,6 @@ </target> <!-- - - Ensure that "java.home.dir" is set. - - NOTE: "java.home" is an internal property for ANT that is not - - typically set to what the build needs it to be. - --> - <target name="java.home.dir.validate" unless="java.home.dir"> - <fail> - - ************************************************************* - ** The property "java.home.dir" was not set in the JOGL ** - ** properties file ** - ** "${user.properties.file}" ** - ** (or this file was not found). ** - ** ** - ** Please set "java.home.dir" to your JAVA_HOME directory. ** - ************************************************************* - </fail> - </target> - - <!-- - Make sure that jogl.jar is not on the CLASSPATH; this can cause - builds to fail since if this Java process has the jar file open - we can not overwrite it. @@ -65,7 +46,7 @@ <!-- - Validate the required properties --> - <target name="validate" depends="antlr.jar.validate, java.home.dir.validate, java.class.path.validate" + <target name="validate" depends="antlr.jar.validate, java.class.path.validate" description="Validate required properties" /> </project> diff --git a/src/classes/com/sun/javafx/newt/Event.java b/src/classes/com/sun/javafx/newt/Event.java new file mode 100644 index 000000000..7d2b24ba5 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/Event.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public class Event { + private boolean isSystemEvent; + private int eventType; + private Window source; + private long when; + + Event(boolean isSystemEvent, int eventType, Window source, long when) { + this.isSystemEvent = isSystemEvent; + this.eventType = eventType; + this.source = source; + this.when = when; + } + + protected Event(int eventType, Window source, long when) { + this(false, eventType, source, when); + } + + /** Indicates whether this event was produced by the system or + generated by user code. */ + public final boolean isSystemEvent() { + return isSystemEvent; + } + + /** Returns the event type of this event. */ + public final int getEventType() { + return eventType; + } + + /** Returns the source Window which produced this Event. */ + public final Window getSource() { + return source; + } + + /** Returns the timestamp, in milliseconds, of this event. */ + public final long getWhen() { + return when; + } + + public String toString() { + return "Event[sys:"+isSystemEvent()+", source:"+getSource()+", when:"+getWhen()+"]"; + } +} diff --git a/src/classes/com/sun/javafx/newt/GLWindow.java b/src/classes/com/sun/javafx/newt/GLWindow.java new file mode 100644 index 000000000..93bb34fe0 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/GLWindow.java @@ -0,0 +1,389 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +import javax.media.opengl.*; +import com.sun.opengl.impl.GLDrawableHelper; + +/** + * An implementation of {@link Window} which is customized for OpenGL + * use, and which implements the {@link + * javax.media.opengl.GLAutoDrawable} interface. For convenience, this + * window class guarantees that its OpenGL context is current inside + * the various EventListeners' callbacks (MouseListener, KeyListener, + * etc.). + */ +public class GLWindow extends Window implements GLAutoDrawable { + private Window window; + + /** Constructor. Do not call this directly -- use {@link + create()} instead. */ + protected GLWindow(Window window, GLCapabilities caps) { + this.window = window; + this.caps = caps; + window.addWindowListener(new WindowListener() { + public void windowResized(WindowEvent e) { + sendReshape = true; + } + + public void windowMoved(WindowEvent e) { + } + }); + } + + /** Creates a new GLWindow on the local display, screen 0, with a + dummy visual ID, and with the default GLCapabilities. */ + public static GLWindow create() { + return create(null, null); + } + + /** Creates a new GLWindow referring to the given window. */ + public static GLWindow create(Window window) { + return create(window, null); + } + + /** Creates a new GLWindow on the local display, screen 0, with a + dummy visual ID, and with the given GLCapabilities. */ + public static GLWindow create(GLCapabilities caps) { + return create(null, caps); + } + + /** Creates a new GLWindow referring to the given window, and with the given GLCapabilities. */ + public static GLWindow create(Window window, GLCapabilities caps) { + if (window == null) { + Display display = NewtFactory.createDisplay(null); // local display + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + window = NewtFactory.createWindow(screen, 0); // dummy VisualID + } + if (caps == null) { + caps = new GLCapabilities(); + } + + return new GLWindow(window, caps); + } + + public boolean isTerminalObject() { + shouldNotCallThis(); + return false; + } + + protected void createNative() { + shouldNotCallThis(); + } + + protected void closeNative() { + shouldNotCallThis(); + } + + public void close() { + if (context != null) { + if (context == GLContext.getCurrent()) { + context.release(); + } + context.destroy(); + } + if (drawable != null) { + drawable.destroy(); + } + + window.close(); + } + + public int getDisplayWidth() { + return window.getDisplayWidth(); + } + + public int getDisplayHeight() { + return window.getDisplayHeight(); + } + + public void pumpMessages(int eventMask) { + pumpMessagesWithEventMaskAction.eventMask = eventMask; + pumpMessagesImpl(pumpMessagesWithEventMaskAction); + } + + class PumpMessagesWithEventMaskAction implements Runnable { + private int eventMask; + + public void run() { + window.pumpMessages(eventMask); + } + } + private PumpMessagesWithEventMaskAction pumpMessagesWithEventMaskAction = new PumpMessagesWithEventMaskAction(); + + public void pumpMessages() { + pumpMessagesImpl(pumpMessagesAction); + } + + class PumpMessagesAction implements Runnable { + public void run() { + window.pumpMessages(); + } + } + private PumpMessagesAction pumpMessagesAction = new PumpMessagesAction(); + + private void pumpMessagesImpl(Runnable pumpMessagesAction) { + // pumpMessagesAction.run(); + + boolean autoSwapBuffer = helper.getAutoSwapBufferMode(); + helper.setAutoSwapBufferMode(false); + try { + helper.invokeGL(drawable, context, pumpMessagesAction, initAction); + } finally { + helper.setAutoSwapBufferMode(autoSwapBuffer); + } + + } + + protected void dispatchMessages(int eventMask) { + shouldNotCallThis(); + } + + public void setVisible(boolean visible) { + window.setVisible(visible); + if (visible && context == null) { + factory = GLDrawableFactory.getFactory(window); + drawable = factory.createGLDrawable(window, caps, null); + window.setVisible(true); + drawable.setRealized(true); + context = drawable.createContext(null); + System.out.println("Created context"); + } + } + + public void setSize(int width, int height) { + window.setSize(width, height); + } + + public void setPosition(int x, int y) { + window.setPosition(x, y); + } + + public boolean setFullscreen(boolean fullscreen) { + return window.setFullscreen(fullscreen); + } + + public boolean isVisible() { + return window.isVisible(); + } + + public int getX() { + return window.getX(); + } + + public int getY() { + return window.getY(); + } + + public int getWidth() { + return window.getWidth(); + } + + public int getHeight() { + return window.getHeight(); + } + + public boolean isFullscreen() { + return window.isFullscreen(); + } + + public void addMouseListener(MouseListener l) { + window.addMouseListener(l); + } + + public void removeMouseListener(MouseListener l) { + window.removeMouseListener(l); + } + + public MouseListener[] getMouseListeners() { + return window.getMouseListeners(); + } + + public void addKeyListener(KeyListener l) { + window.addKeyListener(l); + } + + public void removeKeyListener(KeyListener l) { + window.removeKeyListener(l); + } + + public KeyListener[] getKeyListeners() { + return window.getKeyListeners(); + } + + public void addWindowListener(WindowListener l) { + window.addWindowListener(l); + } + + public void removeWindowListener(WindowListener l) { + window.removeWindowListener(l); + } + + public WindowListener[] getWindowListeners() { + return window.getWindowListeners(); + } + + //---------------------------------------------------------------------- + // OpenGL-related methods and state + // + + private GLDrawableFactory factory; + private GLCapabilities caps; + private GLDrawable drawable; + private GLContext context; + private GLDrawableHelper helper = new GLDrawableHelper(); + // To make reshape events be sent immediately before a display event + private boolean sendReshape; + + public GLDrawableFactory getFactory() { + return factory; + } + + public GLContext getContext() { + return context; + } + + public GL getGL() { + GLContext ctx = getContext(); + if (ctx == null) { + return null; + } + return ctx.getGL(); + } + + public void setGL(GL gl) { + GLContext ctx = getContext(); + if (ctx != null) { + ctx.setGL(gl); + } + } + + public void addGLEventListener(GLEventListener listener) { + helper.addGLEventListener(listener); + } + + public void removeGLEventListener(GLEventListener listener) { + helper.removeGLEventListener(listener); + } + + public void display() { + pumpMessages(); + helper.invokeGL(drawable, context, displayAction, initAction); + } + + public void setAutoSwapBufferMode(boolean onOrOff) { + helper.setAutoSwapBufferMode(onOrOff); + } + + public boolean getAutoSwapBufferMode() { + return helper.getAutoSwapBufferMode(); + } + + public void swapBuffers() { + drawable.swapBuffers(); + } + + class InitAction implements Runnable { + public void run() { + helper.init(GLWindow.this); + } + } + private InitAction initAction = new InitAction(); + + class DisplayAction implements Runnable { + public void run() { + if (sendReshape) { + int width = getWidth(); + int height = getHeight(); + getGL().glViewport(0, 0, width, height); + helper.reshape(GLWindow.this, 0, 0, width, height); + sendReshape = false; + } + + helper.display(GLWindow.this); + } + } + + private DisplayAction displayAction = new DisplayAction(); + + //---------------------------------------------------------------------- + // GLDrawable methods that are not really needed + // + + public GLContext createContext(GLContext shareWith) { + return drawable.createContext(shareWith); + } + + public void setRealized(boolean realized) { + } + + public void destroy() { + close(); + } + + public GLCapabilities getChosenGLCapabilities() { + if (drawable == null) + return null; + + return drawable.getChosenGLCapabilities(); + } + + public void setChosenGLCapabilities(GLCapabilities caps) { + drawable.setChosenGLCapabilities(caps); + } + + public NativeWindow getNativeWindow() { + return drawable.getNativeWindow(); + } + + public int lockSurface() throws GLException { + return drawable.lockSurface(); + } + + public void unlockSurface() { + drawable.unlockSurface(); + } + + public boolean isSurfaceLocked() { + return drawable.isSurfaceLocked(); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private void shouldNotCallThis() { + throw new RuntimeException("Should not call this"); + } +} diff --git a/src/classes/com/sun/javafx/newt/InputEvent.java b/src/classes/com/sun/javafx/newt/InputEvent.java index e8644f953..dc36be34d 100644 --- a/src/classes/com/sun/javafx/newt/InputEvent.java +++ b/src/classes/com/sun/javafx/newt/InputEvent.java @@ -33,7 +33,7 @@ package com.sun.javafx.newt; -public abstract class InputEvent +public abstract class InputEvent extends Event { public static int SHIFT_MASK = 1 << 0; public static int CTRL_MASK = 1 << 1; @@ -41,18 +41,12 @@ public abstract class InputEvent public static int ALT_MASK = 1 << 3; public static int ALT_GRAPH_MASK = 1 << 5; - protected InputEvent(boolean sysEvent, Window source, long when, int modifiers) { + protected InputEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers) { + super(sysEvent, eventType, source, when); this.consumed=false; - this.sysEvent=sysEvent; - this.source=source; - this.when=when; this.modifiers=modifiers; } - protected boolean isSysEvent() { - return sysEvent; - } - public void consume() { consumed=true; } @@ -63,9 +57,6 @@ public abstract class InputEvent public int getModifiers() { return modifiers; } - public long getWhen() { - return when; - } public boolean isAltDown() { return (modifiers&ALT_MASK)!=0; } @@ -83,13 +74,9 @@ public abstract class InputEvent } public String toString() { - return "InputEvent[sys:"+sysEvent+", source:"+source+", when:"+when+", modifiers:"+modifiers+"]"; + return "InputEvent[modifiers:"+modifiers+"]"; } - private boolean sysEvent, consumed; - private Window source; + private boolean consumed; private int modifiers; - private long when; - } - diff --git a/src/classes/com/sun/javafx/newt/KeyEvent.java b/src/classes/com/sun/javafx/newt/KeyEvent.java index 26e306687..92366bc93 100644 --- a/src/classes/com/sun/javafx/newt/KeyEvent.java +++ b/src/classes/com/sun/javafx/newt/KeyEvent.java @@ -35,9 +35,8 @@ package com.sun.javafx.newt; public class KeyEvent extends InputEvent { - protected KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { - super(sysEvent, source, when, modifiers); - this.eventType=eventType; + KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) { + super(sysEvent, eventType, source, when, modifiers); this.keyCode=keyCode; this.keyChar=keyChar; } @@ -45,9 +44,6 @@ public class KeyEvent extends InputEvent this(false, eventType, source, when, modifiers, keyCode, keyChar); } - public int getEventType() { - return eventType; - } public char getKeyChar() { return keyChar; } @@ -56,8 +52,8 @@ public class KeyEvent extends InputEvent } public String toString() { - return "KeyEvent["+getEventTypeString(eventType)+ - ", code "+keyCode+", char "+keyChar+", isActionKey "+isActionKey()+" "+super.toString(); + return "KeyEvent["+getEventTypeString(getEventType())+ + ", code "+keyCode+", char "+keyChar+", isActionKey "+isActionKey()+", "+super.toString()+"]"; } public static String getEventTypeString(int type) { @@ -65,7 +61,7 @@ public class KeyEvent extends InputEvent case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED"; - default: return "unknown"; + default: return "unknown (" + type + ")"; } } @@ -116,13 +112,12 @@ public class KeyEvent extends InputEvent return false; } - private int eventType; private int keyCode; private char keyChar; - public static final int EVENT_KEY_PRESSED = 1 << 0; - public static final int EVENT_KEY_RELEASED= 1 << 1; - public static final int EVENT_KEY_TYPED = 1 << 2; + public static final int EVENT_KEY_PRESSED = 300; + public static final int EVENT_KEY_RELEASED= 301; + public static final int EVENT_KEY_TYPED = 302; /* Virtual key codes. */ diff --git a/src/classes/com/sun/javafx/newt/MouseEvent.java b/src/classes/com/sun/javafx/newt/MouseEvent.java index 19b5f2b93..47d2803c0 100644 --- a/src/classes/com/sun/javafx/newt/MouseEvent.java +++ b/src/classes/com/sun/javafx/newt/MouseEvent.java @@ -41,8 +41,7 @@ public class MouseEvent extends InputEvent protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button) { - super(sysEvent, source, when, modifiers); - this.eventType=eventType; + super(sysEvent, eventType, source, when, modifiers); this.x=x; this.y=y; this.clickCount=clickCount; @@ -52,9 +51,6 @@ public class MouseEvent extends InputEvent this(false, eventType, source, when, modifiers, x, y, clickCount, button); } - public int getEventType() { - return eventType; - } public int getButton() { return button; } @@ -69,8 +65,8 @@ public class MouseEvent extends InputEvent } public String toString() { - return "MouseEvent["+getEventTypeString(eventType)+ - ", "+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString(); + return "MouseEvent["+getEventTypeString(getEventType())+ + ", "+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString()+"]"; } public static String getEventTypeString(int type) { @@ -82,19 +78,17 @@ public class MouseEvent extends InputEvent case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED"; case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; - default: return "unknown"; + default: return "unknown (" + type + ")"; } } - private int eventType, x, y, clickCount, button; - - public static final int EVENT_MOUSE_CLICKED = 1 << 0; - public static final int EVENT_MOUSE_ENTERED = 1 << 1; - public static final int EVENT_MOUSE_EXITED = 1 << 2; - public static final int EVENT_MOUSE_PRESSED = 1 << 3; - public static final int EVENT_MOUSE_RELEASED = 1 << 4; - public static final int EVENT_MOUSE_MOVED = 1 << 5; - public static final int EVENT_MOUSE_DRAGGED = 1 << 6; + private int x, y, clickCount, button; + public static final int EVENT_MOUSE_CLICKED = 200; + public static final int EVENT_MOUSE_ENTERED = 201; + public static final int EVENT_MOUSE_EXITED = 202; + public static final int EVENT_MOUSE_PRESSED = 203; + public static final int EVENT_MOUSE_RELEASED = 204; + public static final int EVENT_MOUSE_MOVED = 205; + public static final int EVENT_MOUSE_DRAGGED = 206; } - diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index 1486091e8..a5bdf0806 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -43,6 +43,7 @@ public abstract class Window implements NativeWindow { public static final boolean DEBUG_MOUSE_EVENT = false; public static final boolean DEBUG_KEY_EVENT = false; + public static final boolean DEBUG_WINDOW_EVENT = false; public static final boolean DEBUG_IMPLEMENTATION = false; private static Class getWindowClass(String type) @@ -131,9 +132,9 @@ public abstract class Window implements NativeWindow public void pumpMessages() { int em = 0; - //if(windowistener.size()>0) em |= EventListener.WINDOW; - if(mouseListener.size()>0) em |= EventListener.MOUSE; - if(keyListener.size()>0) em |= EventListener.KEY; + if(windowListeners.size()>0) em |= EventListener.WINDOW; + if(mouseListeners.size()>0) em |= EventListener.MOUSE; + if(keyListeners.size()>0) em |= EventListener.KEY; pumpMessages(em); } @@ -271,25 +272,25 @@ public abstract class Window implements NativeWindow if(l == null) { return; } - ArrayList newMouseListeners = (ArrayList) mouseListener.clone(); + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); newMouseListeners.add(l); - mouseListener = newMouseListeners; + mouseListeners = newMouseListeners; } public synchronized void removeMouseListener(MouseListener l) { if (l == null) { return; } - ArrayList newMouseListeners = (ArrayList) mouseListener.clone(); + ArrayList newMouseListeners = (ArrayList) mouseListeners.clone(); newMouseListeners.remove(l); - mouseListener = newMouseListeners; + mouseListeners = newMouseListeners; } public synchronized MouseListener[] getMouseListeners() { - return (MouseListener[]) mouseListener.toArray(); + return (MouseListener[]) mouseListeners.toArray(); } - private ArrayList mouseListener = new ArrayList(); + private ArrayList mouseListeners = new ArrayList(); private long lastMousePressed = 0; private int lastMouseClickCount = 0; public static final int ClickTimeout = 200; @@ -346,7 +347,7 @@ public abstract class Window implements NativeWindow ArrayList listeners = null; synchronized(this) { - listeners = mouseListener; + listeners = mouseListeners; } for(Iterator i = listeners.iterator(); i.hasNext(); ) { MouseListener l = (MouseListener) i.next(); @@ -389,21 +390,25 @@ public abstract class Window implements NativeWindow if(l == null) { return; } - keyListener.add(l); + ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); + newKeyListeners.add(l); + keyListeners = newKeyListeners; } public synchronized void removeKeyListener(KeyListener l) { if (l == null) { return; } - keyListener.remove(l); + ArrayList newKeyListeners = (ArrayList) keyListeners.clone(); + newKeyListeners.remove(l); + keyListeners = newKeyListeners; } public synchronized KeyListener[] getKeyListeners() { - return (KeyListener[]) keyListener.toArray(); + return (KeyListener[]) keyListeners.toArray(); } - private ArrayList keyListener = new ArrayList(); + private ArrayList keyListeners = new ArrayList(); protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(), @@ -411,7 +416,11 @@ public abstract class Window implements NativeWindow if(DEBUG_KEY_EVENT) { System.out.println("sendKeyEvent: "+e); } - for(Iterator i = keyListener.iterator(); i.hasNext(); ) { + ArrayList listeners = null; + synchronized(this) { + listeners = keyListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { KeyListener l = (KeyListener) i.next(); switch(eventType) { case KeyEvent.EVENT_KEY_PRESSED: @@ -428,5 +437,56 @@ public abstract class Window implements NativeWindow } } } -} + // + // WindowListener Support + // + + private ArrayList windowListeners = new ArrayList(); + + public synchronized void addWindowListener(WindowListener l) { + if(l == null) { + return; + } + ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); + newWindowListeners.add(l); + windowListeners = newWindowListeners; + } + + public synchronized void removeWindowListener(WindowListener l) { + if (l == null) { + return; + } + ArrayList newWindowListeners = (ArrayList) windowListeners.clone(); + newWindowListeners.remove(l); + windowListeners = newWindowListeners; + } + + public synchronized WindowListener[] getWindowListeners() { + return (WindowListener[]) windowListeners.toArray(); + } + + protected void sendWindowEvent(int eventType) { + WindowEvent e = new WindowEvent(true, eventType, this, System.currentTimeMillis()); + if(DEBUG_WINDOW_EVENT) { + System.out.println("sendWindowEvent: "+e); + } + ArrayList listeners = null; + synchronized(this) { + listeners = windowListeners; + } + for(Iterator i = listeners.iterator(); i.hasNext(); ) { + WindowListener l = (WindowListener) i.next(); + switch(eventType) { + case WindowEvent.EVENT_WINDOW_RESIZED: + l.windowResized(e); + break; + case WindowEvent.EVENT_WINDOW_MOVED: + l.windowMoved(e); + break; + default: + throw new RuntimeException("Unexpected window event type " + e.getEventType()); + } + } + } +} diff --git a/src/classes/com/sun/javafx/newt/WindowEvent.java b/src/classes/com/sun/javafx/newt/WindowEvent.java new file mode 100644 index 000000000..49cdb5497 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/WindowEvent.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public class WindowEvent extends Event { + public static final int EVENT_WINDOW_RESIZED = 100; + public static final int EVENT_WINDOW_MOVED = 101; + + public WindowEvent(int eventType, Window source, long when) { + this(false, eventType, source, when); + } + + WindowEvent(boolean isSystemEvent, int eventType, Window source, long when) { + super(isSystemEvent, eventType, source, when); + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_WINDOW_RESIZED: return "WINDOW_RESIZED"; + case EVENT_WINDOW_MOVED: return "WINDOW_MOVED"; + default: return "unknown (" + type + ")"; + } + } + public String toString() { + return "WindowEvent["+getEventTypeString(getEventType()) + + ", " + super.toString() + "]"; + } +} diff --git a/src/classes/com/sun/javafx/newt/WindowListener.java b/src/classes/com/sun/javafx/newt/WindowListener.java new file mode 100644 index 000000000..b76202f01 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/WindowListener.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package com.sun.javafx.newt; + +public interface WindowListener extends EventListener { + public void windowResized(WindowEvent e); + public void windowMoved(WindowEvent e); +} diff --git a/src/classes/com/sun/javafx/newt/awt/AWTWindow.java b/src/classes/com/sun/javafx/newt/awt/AWTWindow.java index 1e0f8d6ee..780d7f488 100644 --- a/src/classes/com/sun/javafx/newt/awt/AWTWindow.java +++ b/src/classes/com/sun/javafx/newt/awt/AWTWindow.java @@ -71,9 +71,11 @@ public class AWTWindow extends Window { canvas.addMouseListener(listener); canvas.addMouseMotionListener(listener); canvas.addKeyListener(listener); + canvas.addComponentListener(listener); frame.add(canvas, BorderLayout.CENTER); frame.setSize(width, height); frame.setLocation(x, y); + frame.addComponentListener(new MoveListener()); } }); } @@ -126,6 +128,8 @@ public class AWTWindow extends Window { } public void setPosition(final int x, final int y) { + this.x = x; + this.y = y; runOnEDT(new Runnable() { public void run() { frame.setLocation(x, y); @@ -153,18 +157,40 @@ public class AWTWindow extends Window { } } if (w != null) { - if (w.isMouseEvent()) { - if ((eventMask & com.sun.javafx.newt.EventListener.MOUSE) != 0) { - MouseEvent e = (MouseEvent) w.getEvent(); - sendMouseEvent(w.getType(), convertModifiers(e), - e.getX(), e.getY(), convertButton(e)); - } - } else { - if ((eventMask & com.sun.javafx.newt.EventListener.KEY) != 0) { - KeyEvent e = (KeyEvent) w.getEvent(); - sendKeyEvent(w.getType(), convertModifiers(e), - e.getKeyCode(), e.getKeyChar()); - } + switch (w.getType()) { + case com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_RESIZED: + case com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_MOVED: + if ((eventMask & com.sun.javafx.newt.EventListener.WINDOW) != 0) { + sendWindowEvent(w.getType()); + } + break; + + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_CLICKED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_ENTERED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_EXITED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_PRESSED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED: + case com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED: + if ((eventMask & com.sun.javafx.newt.EventListener.MOUSE) != 0) { + MouseEvent e = (MouseEvent) w.getEvent(); + sendMouseEvent(w.getType(), convertModifiers(e), + e.getX(), e.getY(), convertButton(e)); + } + break; + + case com.sun.javafx.newt.KeyEvent.EVENT_KEY_PRESSED: + case com.sun.javafx.newt.KeyEvent.EVENT_KEY_RELEASED: + case com.sun.javafx.newt.KeyEvent.EVENT_KEY_TYPED: + if ((eventMask & com.sun.javafx.newt.EventListener.KEY) != 0) { + KeyEvent e = (KeyEvent) w.getEvent(); + sendKeyEvent(w.getType(), convertModifiers(e), + e.getKeyCode(), e.getKeyChar()); + } + break; + + default: + throw new RuntimeException("Unknown event type " + w.getType()); } if(DEBUG_MOUSE_EVENT) { System.out.println("dispatchMessages: in event:"+w.getEvent()); @@ -205,31 +231,26 @@ public class AWTWindow extends Window { } } - private void enqueueEvent(boolean isMouseEvent, int type, InputEvent e) { - if(DEBUG_MOUSE_EVENT) { - System.out.println("enqueueEvent: mouse"+isMouseEvent+", event: "+e); - } - AWTEventWrapper wrapper = new AWTEventWrapper(isMouseEvent,type, e); + private void enqueueEvent(int type, InputEvent e) { + AWTEventWrapper wrapper = new AWTEventWrapper(type, e); synchronized(this) { events.add(wrapper); } } + private static final int WINDOW_EVENT = 1; + private static final int KEY_EVENT = 2; + private static final int MOUSE_EVENT = 3; + static class AWTEventWrapper { - boolean isMouseEvent; int type; InputEvent e; - AWTEventWrapper(boolean isMouseEvent, int type, InputEvent e) { - this.isMouseEvent = isMouseEvent; + AWTEventWrapper(int type, InputEvent e) { this.type = type; this.e = e; } - public boolean isMouseEvent() { - return isMouseEvent; - } - public int getType() { return type; } @@ -239,46 +260,79 @@ public class AWTWindow extends Window { } } - class Listener implements MouseListener, MouseMotionListener, KeyListener { + class MoveListener implements ComponentListener { + public void componentResized(ComponentEvent e) { + } + + public void componentMoved(ComponentEvent e) { + x = frame.getX(); + y = frame.getY(); + enqueueEvent(com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_MOVED, null); + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } + + } + + class Listener implements ComponentListener, MouseListener, MouseMotionListener, KeyListener { + public void componentResized(ComponentEvent e) { + width = canvas.getWidth(); + height = canvas.getHeight(); + enqueueEvent(com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_RESIZED, null); + } + + public void componentMoved(ComponentEvent e) { + } + + public void componentShown(ComponentEvent e) { + } + + public void componentHidden(ComponentEvent e) { + } + public void mouseClicked(MouseEvent e) { // We ignore these as we synthesize them ourselves out of // mouse pressed and released events } public void mouseEntered(MouseEvent e) { - enqueueEvent(true, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_ENTERED, e); + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_ENTERED, e); } public void mouseExited(MouseEvent e) { - enqueueEvent(true, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_EXITED, e); + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_EXITED, e); } public void mousePressed(MouseEvent e) { - enqueueEvent(true, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_PRESSED, e); + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_PRESSED, e); } public void mouseReleased(MouseEvent e) { - enqueueEvent(true, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED, e); + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_RELEASED, e); } public void mouseMoved(MouseEvent e) { - enqueueEvent(true, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED, e); + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_MOVED, e); } public void mouseDragged(MouseEvent e) { - enqueueEvent(true, com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED, e); + enqueueEvent(com.sun.javafx.newt.MouseEvent.EVENT_MOUSE_DRAGGED, e); } public void keyPressed(KeyEvent e) { - enqueueEvent(false, com.sun.javafx.newt.KeyEvent.EVENT_KEY_PRESSED, e); + enqueueEvent(com.sun.javafx.newt.KeyEvent.EVENT_KEY_PRESSED, e); } public void keyReleased(KeyEvent e) { - enqueueEvent(false, com.sun.javafx.newt.KeyEvent.EVENT_KEY_RELEASED, e); + enqueueEvent(com.sun.javafx.newt.KeyEvent.EVENT_KEY_RELEASED, e); } public void keyTyped(KeyEvent e) { - enqueueEvent(false, com.sun.javafx.newt.KeyEvent.EVENT_KEY_TYPED, e); + enqueueEvent(com.sun.javafx.newt.KeyEvent.EVENT_KEY_TYPED, e); } } } diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java index 00ecd5973..9e0df6c71 100755 --- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java +++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -154,11 +154,13 @@ public class WindowsWindow extends Window { private void sizeChanged(int newWidth, int newHeight) { width = newWidth; height = newHeight; + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); } private void positionChanged(int newX, int newY) { x = newX; y = newY; + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); } private void windowClosed() { diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java index 290b1e506..05d9abcb9 100755 --- a/src/classes/com/sun/javafx/newt/x11/X11Window.java +++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java @@ -138,6 +138,7 @@ public class X11Window extends Window { nfs_width=width; nfs_height=height; } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); } private void positionChanged(int newX, int newY) { @@ -147,6 +148,7 @@ public class X11Window extends Window { nfs_x=x; nfs_y=y; } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); } private void windowCreated(long visualID, long windowHandle) { diff --git a/src/classes/javax/media/opengl/GLAutoDrawable.java b/src/classes/javax/media/opengl/GLAutoDrawable.java index 688b78879..d4aff9107 100644 --- a/src/classes/javax/media/opengl/GLAutoDrawable.java +++ b/src/classes/javax/media/opengl/GLAutoDrawable.java @@ -81,10 +81,6 @@ public interface GLAutoDrawable extends GLDrawable { display} callback. */ public void display(); - /** Schedules a repaint of the component at some point in the - future. */ - public void repaint(); - /** Enables or disables automatic buffer swapping for this drawable. By default this property is set to true; when true, after all GLEventListeners have been called for a display() event, the diff --git a/src/classes/javax/media/opengl/GLDrawableFactory.java b/src/classes/javax/media/opengl/GLDrawableFactory.java index 50cf96a33..a6e382760 100644 --- a/src/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/classes/javax/media/opengl/GLDrawableFactory.java @@ -200,11 +200,11 @@ public abstract class GLDrawableFactory { throws GLException { if(null==GLProfile.getProfile()) { - throw new GLException("No choosen/preset profile"); + throw new GLException("No chosen/preset GLProfile"); } initializeNWFactory(); if(nwFactory == null) { - throw new GLException("Could not determine the NativeWindow-GLDrawableFactory"); + throw new GLException("Could not determine the NativeWindow GLDrawableFactory"); } return nwFactory; } diff --git a/src/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java b/src/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java index ef5a7f2d7..85163f0ff 100644 --- a/src/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java +++ b/src/classes/javax/media/opengl/awt/AWTGLAutoDrawable.java @@ -43,4 +43,7 @@ import javax.media.opengl.*; import javax.media.opengl.glu.*; public interface AWTGLAutoDrawable extends GLAutoDrawable, ComponentEvents { + /** Schedules a repaint of the component at some point in the + future. */ + public void repaint(); } diff --git a/src/native/newt/X11Window.c b/src/native/newt/X11Window.c index 1640a36fc..972bb72a7 100755 --- a/src/native/newt/X11Window.c +++ b/src/native/newt/X11Window.c @@ -407,6 +407,8 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_DispatchMessages break; } + // FIXME: support resize and window re-positioning events + switch(evt.type) { case ButtonPress: if(evt.xbutton.window==w) { |