[jsword-svn] r1290 - in trunk/common-aqua: . src src/main src/main/java src/main/java/org src/main/java/org/crosswire src/main/java/org/crosswire/common src/main/java/org/crosswire/common/aqua

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Sat Apr 21 14:15:39 MST 2007


Author: dmsmith
Date: 2007-04-21 14:15:39 -0700 (Sat, 21 Apr 2007)
New Revision: 1290

Added:
   trunk/common-aqua/.classpath
   trunk/common-aqua/.project
   trunk/common-aqua/README.txt
   trunk/common-aqua/build.xml
   trunk/common-aqua/src/
   trunk/common-aqua/src/main/
   trunk/common-aqua/src/main/java/
   trunk/common-aqua/src/main/java/org/
   trunk/common-aqua/src/main/java/org/crosswire/
   trunk/common-aqua/src/main/java/org/crosswire/common/
   trunk/common-aqua/src/main/java/org/crosswire/common/aqua/
   trunk/common-aqua/src/main/java/org/crosswire/common/aqua/OSXAdapter.java
Modified:
   trunk/common-aqua/
Log:
Add code to allow BibleDesktop to integrate better on the Mac.


Property changes on: trunk/common-aqua
___________________________________________________________________
Name: svn:ignore
   + target


Added: trunk/common-aqua/.classpath
===================================================================
--- trunk/common-aqua/.classpath	                        (rev 0)
+++ trunk/common-aqua/.classpath	2007-04-21 21:15:39 UTC (rev 1290)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/common-swing"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: trunk/common-aqua/.project
===================================================================
--- trunk/common-aqua/.project	                        (rev 0)
+++ trunk/common-aqua/.project	2007-04-21 21:15:39 UTC (rev 1290)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>common-aqua</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: trunk/common-aqua/README.txt
===================================================================
--- trunk/common-aqua/README.txt	                        (rev 0)
+++ trunk/common-aqua/README.txt	2007-04-21 21:15:39 UTC (rev 1290)
@@ -0,0 +1,6 @@
+The install ant target will put the constructed jar
+in the correct location in the bibledesktop project. This
+only needs to be done if the content changes
+
+Tbe Bibledesktop project should use the jar as provided
+and not depend upon this project.
\ No newline at end of file

Added: trunk/common-aqua/build.xml
===================================================================
--- trunk/common-aqua/build.xml	                        (rev 0)
+++ trunk/common-aqua/build.xml	2007-04-21 21:15:39 UTC (rev 1290)
@@ -0,0 +1,14 @@
+<project name="jsword-common-aqua" default="all">
+
+  <!-- This build uses the core build targets -->
+  <import file="../common/core.xml"/>
+  <property name="dependency" value="common-swing"/>
+  <property name="dependency.jar" value="../${dependency}/${target.jar}"/>
+
+  <target name="install"
+          depends="build"
+          unless="jar.uptodate"
+          description="Install the built project.">
+    <copy verbose="${verbose.copy}" todir="../bibledesktop/jar/${ant.project.name}-${release.version}" file="${target.jar}/${ant.project.name}-${release.version}.jar"/>
+  </target>
+</project>

Added: trunk/common-aqua/src/main/java/org/crosswire/common/aqua/OSXAdapter.java
===================================================================
--- trunk/common-aqua/src/main/java/org/crosswire/common/aqua/OSXAdapter.java	                        (rev 0)
+++ trunk/common-aqua/src/main/java/org/crosswire/common/aqua/OSXAdapter.java	2007-04-21 21:15:39 UTC (rev 1290)
@@ -0,0 +1,118 @@
+package org.crosswire.common.aqua;
+
+import org.crosswire.common.swing.Actionable;
+
+import com.apple.eawt.Application;
+import com.apple.eawt.ApplicationAdapter;
+import com.apple.eawt.ApplicationEvent;
+
+public class OSXAdapter extends ApplicationAdapter
+{
+
+	private OSXAdapter(Actionable actionable,
+                       String aboutAction,
+                       String prefAction,
+                       String quitAction)
+	{
+		this.actionable = actionable;
+		this.aboutAction = aboutAction;
+		this.prefAction = prefAction;
+		this.quitAction = quitAction;
+	}
+	
+	// The main entry-point for this functionality.  This is the only method
+	// that needs to be called at runtime, and it can easily be done using
+	// reflection (see MyApp.java) 
+	/**
+	 * Register the application so that About and Quit on the Application menu are hooked to the applications About and Quit choices.
+	 */
+	public static void registerMacOSXApplication(Actionable actionable, String aboutAction, String prefAction, String quitAction)
+	{
+		if (theApplication == null)
+		{
+			theApplication = new Application();
+		}
+
+		if (theAdapter == null)
+		{
+			theAdapter = new OSXAdapter(actionable, aboutAction, prefAction, quitAction);
+		}
+
+		theApplication.addApplicationListener(theAdapter);
+	}
+	
+	/**
+	 * Enables the Preferences menu item in the application menu.
+	 */
+	public static void enablePrefs(boolean enabled)
+	{
+		if (theApplication == null)
+		{
+			theApplication = new Application();
+		}
+		theApplication.setEnabledPreferencesMenu(enabled);
+	}
+
+	/* (non-Javadoc)
+	 * @see com.apple.eawt.ApplicationAdapter#handleAbout(com.apple.eawt.ApplicationEvent)
+	 */
+	public void handleAbout(ApplicationEvent ae)
+	{
+		handle(aboutAction, ae, true);
+	}
+	
+	/* (non-Javadoc)
+	 * @see com.apple.eawt.ApplicationAdapter#handlePreferences(com.apple.eawt.ApplicationEvent)
+	 */
+	public void handlePreferences(ApplicationEvent ae)
+	{
+		handle(prefAction, ae, true);
+	}
+	
+	/* (non-Javadoc)
+	 * @see com.apple.eawt.ApplicationAdapter#handleQuit(com.apple.eawt.ApplicationEvent)
+	 */
+	public void handleQuit(ApplicationEvent ae)
+	{
+		/*	
+		 * You MUST setHandled(false) if you want to delay or cancel the quit.
+		 * This is important for cross-platform development -- have a universal quit
+		 * routine that chooses whether or not to quit, so the functionality is identical
+		 * on all platforms.  This example simply cancels the AppleEvent-based quit and
+		 * defers to that universal method.
+		 */
+		handle(quitAction, ae, false);
+	}
+
+	private void handle(String action, ApplicationEvent ae, boolean handledState)
+	{
+		if (actionable != null)
+		{
+			ae.setHandled(handledState);
+			actionable.actionPerformed(action);
+			ae.setHandled(handledState);
+		}
+		else
+		{
+			throw new IllegalStateException("handleQuit: MyApp instance detached from listener");
+		}
+	}
+
+	/** This adapter is a singleton */
+	private static OSXAdapter		theAdapter;
+
+	/** The MacOSX notion of the application */
+	private static Application		theApplication;
+
+	/** The application providing about, preferences and quit. */
+	private Actionable				actionable;
+
+	/** The application's About action */
+	private String 					aboutAction;
+
+	/** The application's Preferences action */
+	private String 					prefAction;
+
+	/** The application's Quit action */
+	private String 					quitAction;	
+}
\ No newline at end of file




More information about the jsword-svn mailing list