[med-svn] [Git][med-team/jam-lib][upstream] 2 commits: New upstream version 0.1+git20180106.740247a+dfsg

Andreas Tille gitlab at salsa.debian.org
Tue Jan 8 13:00:57 GMT 2019


Andreas Tille pushed to branch upstream at Debian Med / jam-lib


Commits:
1b9e90d6 by Andreas Tille at 2019-01-08T12:39:20Z
New upstream version 0.1+git20180106.740247a+dfsg
- - - - -
f485e0ec by Andreas Tille at 2019-01-08T12:54:52Z
New upstream version 0.1.git20180106.740247a+dfsg
- - - - -


7 changed files:

- + .gitignore
- build.xml
- src/jam/console/ConsoleApplication.java
- src/jam/framework/MultiDocApplication.java
- src/jam/framework/SingleDocApplication.java
- + src/jam/java9only/ApplicationAdapter.java
- src/jam/mac/Utils.java


Changes:

=====================================
.gitignore
=====================================
@@ -0,0 +1,5 @@
+# Created by .ignore support plugin (hsz.mobi)
+.gitignore
+JAM.iml
+JAM.ipr
+JAM.iws


=====================================
build.xml
=====================================
@@ -8,6 +8,7 @@
     <property name="src" location="src"/>
     <property name="build" location="build"/>
     <property name="build-mac-only" location="build-mac-only"/>
+    <property name="build-java9-only" location="build-java9-only"/>
 
     <property name="lib" location="lib"/>
     <property name="dist" location="dist"/>
@@ -19,6 +20,7 @@
         <tstamp/>
         <!-- Create the build directory structure used by compile -->
         <mkdir dir="${build}"/>
+        <mkdir dir="${build-java9-only}"/>
         <mkdir dir="${build-mac-only}"/>
         <mkdir dir="${dist}"/>
     </target>
@@ -29,9 +31,10 @@
         <condition property="isMac">
             <os family="mac"/>
         </condition>
-        <javac source="1.5" target="1.5" srcdir="${src}" destdir="${build}">
+        <javac source="1.6" target="1.6" srcdir="${src}" destdir="${build}">
             <include name="jam/**/*"/>
             <exclude name="jam/**/maconly/*"/>
+            <exclude name="jam/**/java9only/*"/>
             <!--<exclude name="org/**/maconly/*" unless = "isMac"/>-->
         </javac>
         <copy todir="${build}" verbose="true">
@@ -39,12 +42,32 @@
         </copy>
     </target>
 
+    <target name="compile-java9-only" depends="init">
+        <!-- Compile the java code from ${jamsrc} into ${build} -->
+        <condition property="isMac">
+            <os family="mac"/>
+        </condition>
+        <javac source="1.9" target="1.9" srcdir="${src}" destdir="${build-java9-only}">
+            <include name="jam/**/java9only/*"/>
+        </javac>
+    </target>
+
+    <target name="dist-java9-only" depends="compile-java9-only" description="generate the -java9-only distribution">
+        <!-- Create the distribution directory -->
+        <mkdir dir="${dist}"/>
+
+        <!-- create the mac-only jar file -->
+        <jar jarfile="${lib}/jam-java9-only.jar">
+            <fileset dir="${build-java9-only}" includes="**/mac*/**/*.class,*.properties"/>
+        </jar>
+    </target>
+
     <target name="compile-mac-only" depends="init">
         <!-- Compile the java code from ${jamsrc} into ${build} -->
         <condition property="isMac">
             <os family="mac"/>
         </condition>
-        <javac source="1.5" target="1.5" srcdir="${src}" destdir="${build-mac-only}">
+        <javac source="1.6" target="1.6" srcdir="${src}" destdir="${build-mac-only}">
             <include name="jam/**/maconly/*"/>
         </javac>
     </target>
@@ -59,8 +82,10 @@
         </jar>
     </target>
 
+    <!-- jam-mac-only.jar should be compiled using Java 6 and then is linked in here -->
+    <!-- jam-java9-only.jar should be compiled using Java 9 and then is linked in here -->
 
-    <target name="dist" depends="compile" description="generate the distribution">
+    <target name="dist" depends="compile, dist-java9-only, dist-mac-only" description="generate the distribution">
         <!-- Create the distribution directory -->
         <mkdir dir="${dist}"/>
         <delete file="${dist}/jam.jar"/>
@@ -68,6 +93,7 @@
         <jar jarfile="${dist}/jam.jar">
             <fileset dir="${build}" includes="**/*.class,**/*.properties,**/*.png"/>
             <zipgroupfileset dir="${lib}" includes="jam-mac-only.jar"/>
+            <zipgroupfileset dir="${lib}" includes="jam-java9-only.jar"/>
         </jar>
     </target>
 


=====================================
src/jam/console/ConsoleApplication.java
=====================================
@@ -20,25 +20,25 @@ import java.io.IOException;
 public class ConsoleApplication extends Application {
 
 	private ConsoleFrame consoleFrame = null;
-    private boolean dontAskSave;
+	private boolean dontAskSave;
 
-    public ConsoleApplication(String nameString, String aboutString, Icon icon, boolean dontAskSave) throws IOException {
-        this(new ConsoleMenuBarFactory(), nameString, aboutString, icon, dontAskSave);
-    }
+	public ConsoleApplication(String nameString, String aboutString, Icon icon, boolean dontAskSave) throws IOException {
+		this(new ConsoleMenuBarFactory(), nameString, aboutString, icon, dontAskSave);
+	}
 
-    public ConsoleApplication(String nameString, String titleString, String aboutString, Icon icon, boolean dontAskSave) throws IOException {
-        this(new ConsoleMenuBarFactory(), nameString, titleString, aboutString, icon, dontAskSave);
-    }
+	public ConsoleApplication(String nameString, String titleString, String aboutString, Icon icon, boolean dontAskSave) throws IOException {
+		this(new ConsoleMenuBarFactory(), nameString, titleString, aboutString, icon, dontAskSave);
+	}
 
-    public ConsoleApplication(MenuBarFactory menuBarFactory, String nameString, String aboutString, Icon icon, boolean dontAskSave) throws IOException {
-        this(menuBarFactory, nameString, nameString, aboutString, icon, dontAskSave);
-    }
+	public ConsoleApplication(MenuBarFactory menuBarFactory, String nameString, String aboutString, Icon icon, boolean dontAskSave) throws IOException {
+		this(menuBarFactory, nameString, nameString, aboutString, icon, dontAskSave);
+	}
 
-    public ConsoleApplication(MenuBarFactory menuBarFactory, String nameString, String titleString, String aboutString, Icon icon, boolean dontAskSave) throws IOException {
+	public ConsoleApplication(MenuBarFactory menuBarFactory, String nameString, String titleString, String aboutString, Icon icon, boolean dontAskSave) throws IOException {
 
 		super(menuBarFactory, nameString, titleString, aboutString, icon);
 
-        this.dontAskSave = dontAskSave;
+		this.dontAskSave = dontAskSave;
 
 		consoleFrame = new ConsoleFrame();
 		consoleFrame.initialize();
@@ -51,19 +51,18 @@ public class ConsoleApplication extends Application {
 			}
 		});
 
-        getOpenAction().setEnabled(false);
+		getOpenAction().setEnabled(false);
 	}
 
-    public void initialize() {
-        if (jam.mac.Utils.isMacOSX()) {
-            // If this is a Mac application then register it at this point.
-            // This will result in any events such as open file being executed
-            // due to files being double-clicked or dragged on to the application.
-            jam.mac.Utils.macOSXRegistration(this);
-        }
-    }
+	public void initialize() {
+		// Register the application with the OK. Prior to Java 1.9 this was just
+		// for Mac OS X. Now it uses java.desktop.Desktop to be cross platform
+		// This will result in any events such as open file being executed
+		// due to files being double-clicked or dragged on to the application.
+		jam.mac.Utils.registerDesktopApplication(this);
+	}
 
-    protected JFrame getDefaultFrame() { return consoleFrame; }
+	protected JFrame getDefaultFrame() { return consoleFrame; }
 
 	public DocumentFrame doNew() {
 		throw new RuntimeException("A ConsoleApplication cannot do a New command");
@@ -86,12 +85,12 @@ public class ConsoleApplication extends Application {
 		}
 	}
 
-    public void doPreferences() {
-    }
+	public void doPreferences() {
+	}
 
-    public void doStop() {
+	public void doStop() {
 		doQuit();
-    }
+	}
 
 	// Close the window when the close box is clicked
 	private void thisWindowClosing(java.awt.event.WindowEvent e) {


=====================================
src/jam/framework/MultiDocApplication.java
=====================================
@@ -14,7 +14,6 @@
 package jam.framework;
 
 import jam.mac.Utils;
-import jam.maconly.OSXAdapter;
 
 import javax.swing.*;
 import java.io.File;
@@ -35,7 +34,7 @@ public class MultiDocApplication extends Application {
 	}
 
 	public MultiDocApplication(String nameString, String aboutString, Icon icon,
-	                           String websiteURLString, String helpURLString) {
+							   String websiteURLString, String helpURLString) {
 
 		super(new MultiDocMenuBarFactory(), nameString, aboutString, icon, websiteURLString, helpURLString);
 	}
@@ -46,27 +45,23 @@ public class MultiDocApplication extends Application {
 	}
 
 	public MultiDocApplication(MenuBarFactory menuBarFactory, String nameString, String aboutString, Icon icon,
-	                           String websiteURLString, String helpURLString) {
+							   String websiteURLString, String helpURLString) {
 
 		super(menuBarFactory, nameString, aboutString, icon, websiteURLString, helpURLString);
 	}
 
-    public MultiDocApplication(MenuBarFactory menuBarFactory, String nameString, String titleString, String aboutString, Icon icon,
-                               String websiteURLString, String helpURLString) {
+	public MultiDocApplication(MenuBarFactory menuBarFactory, String nameString, String titleString, String aboutString, Icon icon,
+							   String websiteURLString, String helpURLString) {
 
-        super(menuBarFactory, nameString, titleString, aboutString, icon, websiteURLString, helpURLString);
-    }
+		super(menuBarFactory, nameString, titleString, aboutString, icon, websiteURLString, helpURLString);
+	}
 
 	public final void initialize() {
-        // The frameless default menubar is now handled by the OSXAdapter
-		// setupFramelessMenuBar();
-
-        if (jam.mac.Utils.isMacOSX()) {
-            // If this is a Mac application then register it at this point.
-            // This will result in any events such as open file being executed
-            // due to files being double-clicked or dragged on to the application.
-            jam.mac.Utils.macOSXRegistration(this);
-        }
+		// Register the application with the OK. Prior to Java 1.9 this was just
+		// for Mac OS X. Now it uses java.desktop.Desktop to be cross platform
+		// This will result in any events such as open file being executed
+		// due to files being double-clicked or dragged on to the application.
+		jam.mac.Utils.registerDesktopApplication(this);
 	}
 
 	public void setDocumentFrameFactory(DocumentFrameFactory documentFrameFactory) {
@@ -132,21 +127,21 @@ public class MultiDocApplication extends Application {
 		}
 	}
 
-    public DocumentFrame getUpperDocumentFrame() {
-        return upperDocumentFrame;
-    }
+	public DocumentFrame getUpperDocumentFrame() {
+		return upperDocumentFrame;
+	}
 
-    public DocumentFrame getDocumentFrame(File file) {
-        if (documents != null && documents.size() > 0) {
-            for (DocumentFrame doc : documents) {
-                if (doc != null && doc.getFile() == file) {
-                    return doc;
-                }
-            }
-        }
+	public DocumentFrame getDocumentFrame(File file) {
+		if (documents != null && documents.size() > 0) {
+			for (DocumentFrame doc : documents) {
+				if (doc != null && doc.getFile() == file) {
+					return doc;
+				}
+			}
+		}
 
-        return null;
-    }
+		return null;
+	}
 
 	private void documentFrameActivated(DocumentFrame documentFrame) {
 		upperDocumentFrame = documentFrame;
@@ -191,16 +186,16 @@ public class MultiDocApplication extends Application {
 		upperDocumentFrame = documentFrame;
 	}
 
-    /**
-     * Create an invisible dummy frame to host the default menu bar expected by the Mac OS X application
-     * This is now done in the OSXAdapter so this method is deprecated.
-     */
-    @Deprecated
+	/**
+	 * Create an invisible dummy frame to host the default menu bar expected by the Mac OS X application
+	 * This is now done in the OSXAdapter so this method is deprecated.
+	 */
+	@Deprecated
 	private void setupFramelessMenuBar() {
 		if (Utils.isMacOSX() &&
-                System.getProperty("apple.laf.useScreenMenuBar") != null &&
+				System.getProperty("apple.laf.useScreenMenuBar") != null &&
 				System.getProperty("apple.laf.useScreenMenuBar").equalsIgnoreCase("true")) {
-            if (invisibleFrame == null) {
+			if (invisibleFrame == null) {
 				// We use reflection here because the setUndecorated() method
 				// only exists in Java 1.4 and up
 				invisibleFrame = new AbstractFrame() {


=====================================
src/jam/framework/SingleDocApplication.java
=====================================
@@ -26,7 +26,7 @@ public class SingleDocApplication extends Application {
     }
 
     public SingleDocApplication(String nameString, String aboutString, Icon icon,
-    							String websiteURLString, String helpURLString) {
+                                String websiteURLString, String helpURLString) {
 
         super(new SingleDocMenuBarFactory(), nameString, aboutString, icon, websiteURLString, helpURLString);
     }
@@ -37,19 +37,18 @@ public class SingleDocApplication extends Application {
     }
 
     public SingleDocApplication(MenuBarFactory menuBarFactory, String nameString, String aboutString, Icon icon,
-    							String websiteURLString, String helpURLString) {
+                                String websiteURLString, String helpURLString) {
 
         super(menuBarFactory, nameString, aboutString, icon, websiteURLString, helpURLString);
     }
 
-	public final void initialize() {
-        if (jam.mac.Utils.isMacOSX()) {
-            // If this is a Mac application then register it at this point.
-            // This will result in any events such as open file being executed
-            // due to files being double-clicked or dragged on to the application.
-            jam.mac.Utils.macOSXRegistration(this);
-        }
-	}
+    public final void initialize() {
+        // Register the application with the OK. Prior to Java 1.9 this was just
+        // for Mac OS X. Now it uses java.desktop.Desktop to be cross platform
+        // This will result in any events such as open file being executed
+        // due to files being double-clicked or dragged on to the application.
+        jam.mac.Utils.registerDesktopApplication(this);
+    }
 
     public void setDocumentFrame(DocumentFrame documentFrame) {
 
@@ -66,9 +65,9 @@ public class SingleDocApplication extends Application {
         });
     }
 
-	protected JFrame getDefaultFrame() { return documentFrame; }
+    protected JFrame getDefaultFrame() { return documentFrame; }
 
-	protected String getDocumentExtension() { return ""; }
+    protected String getDocumentExtension() { return ""; }
 
     public DocumentFrame doNew() {
         throw new RuntimeException("A SingleDocApplication cannot do a New command");


=====================================
src/jam/java9only/ApplicationAdapter.java
=====================================
@@ -0,0 +1,96 @@
+package jam.java9only;
+
+import jam.framework.*;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.desktop.*;
+import java.io.File;
+
+public class ApplicationAdapter implements
+        AboutHandler,
+        PreferencesHandler,
+        OpenFilesHandler,
+        PrintFilesHandler,
+        QuitHandler {
+
+    private static ApplicationAdapter theAdapter;
+
+    // reference to the app where the existing quit, about, prefs code is
+    private jam.framework.Application application;
+
+    private ApplicationAdapter(jam.framework.Application application) {
+        this.application = application;
+    }
+
+    // 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.
+    public static void registerApplication(jam.framework.Application application) {
+//        if (theApplication == null) {
+//            theApplication = Application.getApplication();
+//        }
+
+        if (theAdapter == null) {
+            theAdapter = new ApplicationAdapter(application);
+        }
+        Desktop.getDesktop().setAboutHandler(theAdapter);
+        Desktop.getDesktop().setOpenFileHandler(theAdapter);
+        Desktop.getDesktop().setPreferencesHandler(theAdapter);
+        Desktop.getDesktop().setPrintFileHandler(theAdapter);
+        Desktop.getDesktop().setQuitHandler(theAdapter);
+
+        // Create a default menu bar that is shown when all windows are closed
+        JMenuBar defaultMenuBar = new JMenuBar();
+        if(jam.framework.Application.getMenuBarFactory() != null) {
+            jam.framework.Application.getMenuBarFactory().populateMenuBar(defaultMenuBar, null);
+            Desktop.getDesktop().setDefaultMenuBar(defaultMenuBar);
+        }
+
+    }
+
+    @Override
+    public void handleAbout(AboutEvent e) {
+        if (application != null) {
+            application.doAbout();
+        } else {
+            throw new IllegalStateException("handleAbout: Application instance detached from listener");
+        }
+    }
+
+    @Override
+    public void openFiles(OpenFilesEvent openFilesEvent) {
+        for (File file : openFilesEvent.getFiles()) {
+            application.doOpenFile(file);
+        }
+    }
+
+    @Override
+    public void handlePreferences(PreferencesEvent e) {
+        if (application != null) {
+            application.doPreferences();
+        } else {
+            throw new IllegalStateException("handlePreferences: Application instance detached from listener");
+        }
+    }
+
+    @Override
+    public void printFiles(PrintFilesEvent printFilesEvent) {
+        for (File file : printFilesEvent.getFiles()) {
+            DocumentFrame frame = application.doOpenFile(file);
+            if (frame != null) {
+                frame.doPrint();
+            }
+        }
+    }
+
+    @Override
+    public void handleQuitRequestWith(QuitEvent e, QuitResponse response) {
+        if (application != null) {
+            application.doQuit();
+        } else {
+            throw new IllegalStateException("handleQuit: Application instance detached from listener");
+        }
+
+    }
+}
\ No newline at end of file


=====================================
src/jam/mac/Utils.java
=====================================
@@ -15,16 +15,16 @@ import java.lang.reflect.Method;
 
 public class Utils {
 
-    protected static boolean MAC_OS_X;
-    protected static String MAC_OS_X_VERSION;
+    private static boolean MAC_OS_X;
+    private static String MAC_OS_X_VERSION;
 
     public static boolean isMacOSX() {
         return MAC_OS_X;
     }
 
-	public static String getMacOSXVersion() {
-		return MAC_OS_X_VERSION;
-	}
+    public static String getMacOSXVersion() {
+        return MAC_OS_X_VERSION;
+    }
 
     public static int getMacOSXMajorVersionNumber() {
         String[] bits = Utils.getMacOSXVersion().split("\\.");
@@ -35,49 +35,47 @@ public class Utils {
     }
 
 
-	public static void macOSXRegistration(jam.framework.Application application) {
-        if (MAC_OS_X) {
+    public static void registerDesktopApplication(jam.framework.Application application) {
+        Class adapter = null;
 
-            Class osxAdapter = null;
+        try {
+            adapter = Class.forName("jam.java9only.ApplicationAdapter");
+        } catch (Exception e) {
+            // do nothing...
+        }
 
+        if (adapter == null && MAC_OS_X) {
             try {
-                osxAdapter = Class.forName("jam.maconly.NewOSXAdapter");
+                // test if com.apple.eawt is present...
+                Class.forName("com.apple.eawt.AboutHandler");
+                adapter = Class.forName("jam.maconly.NewOSXAdapter");
             } catch (Exception e) {
-                System.err.println("This version of Mac OS X does not support the Apple EAWT.");
+                // do nothing...
             }
+        }
 
+        if (adapter != null) {
             try {
-                if (osxAdapter != null) {
-                    // Invoke this by reflection to avoid linking errors on other platforms...
-
-                    Class[] defArgs = {jam.framework.Application.class};
-                    Method registerMethod = osxAdapter.getDeclaredMethod("registerMacOSXApplication", defArgs);
-
-                    if (registerMethod != null) {
-                        Object[] args = {application};
-                        registerMethod.invoke(osxAdapter, args);
-                    }
-
-                    // This is slightly gross.  to reflectively access methods with boolean args,
-                    // use "boolean.class", then pass a Boolean object in as the arg, which apparently
-                    // gets converted for you by the reflection system.
-//                    defArgs[0] = boolean.class;
-//                    Method prefsEnableMethod = osxAdapter.getDeclaredMethod("enablePrefs", defArgs);
-//                    if (prefsEnableMethod != null) {
-//                        Object args[] = {Boolean.TRUE};
-//                        prefsEnableMethod.invoke(osxAdapter, args);
-//                    }
+                // Invoke this by reflection to avoid linking errors on other platforms...
+
+                Class[] defArgs = {jam.framework.Application.class};
+                Method registerMethod = adapter.getDeclaredMethod("registerApplication", defArgs);
+
+                if (registerMethod != null) {
+                    Object[] args = {application};
+                    registerMethod.invoke(adapter, args);
                 }
 
+
             } catch (Exception e) {
-                System.err.println("Exception while loading the OSXAdapter:");
+                System.err.println("Exception while loading the ApplicationAdapter:");
                 e.printStackTrace();
             }
-        }
+        } // if there is no adapter then just continue without registering...
     }
 
     static {
-	    MAC_OS_X = System.getProperty("os.name").toLowerCase().startsWith("mac os x");
+        MAC_OS_X = System.getProperty("os.name").toLowerCase().startsWith("mac os x");
         MAC_OS_X_VERSION = MAC_OS_X ? System.getProperty("os.version") : null;
     }
 }
\ No newline at end of file



View it on GitLab: https://salsa.debian.org/med-team/jam-lib/compare/8e0a33bdeeb084169c53f4d7e91fd15ed309079a...f485e0ecd81c85ebdf01f870c85d1446138c642f

-- 
View it on GitLab: https://salsa.debian.org/med-team/jam-lib/compare/8e0a33bdeeb084169c53f4d7e91fd15ed309079a...f485e0ecd81c85ebdf01f870c85d1446138c642f
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20190108/6bcdd9af/attachment-0001.html>


More information about the debian-med-commit mailing list