Changeset 101150 for trunk/dports/java


Ignore:
Timestamp:
Jan 5, 2013, 11:25:31 AM (6 years ago)
Author:
nicos@…
Message:

jabref: update to 2.9.1, adding patches to use non-deprecated Java-OSX interface

Location:
trunk/dports/java/jabref
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/dports/java/jabref/Portfile

    r100763 r101150  
    55
    66name                jabref
    7 version             2.9
     7version             2.9.1
    88categories          java
    99platforms           darwin
     
    2020master_sites        sourceforge:project/jabref/jabref/${version}
    2121
    22 checksums           rmd160  71fc8ea61dd8baf983272f440220f227b12bb3cf \
    23                     sha256  1d1e31bccc4a5b8b850cbf96156faf6da9eae65374ba24dd2c16141d378522d4
     22checksums           rmd160  42c635c3c40c14f299eb04f57392c361bc20dc3f \
     23                    sha256  db609ba3c92f2d2dd12821ba837b6c7f1cb191580c40c334533bd0d0f9ba6699
    2424
    2525worksrcdir          ${name}-${version}
     
    3030                    port:jarbundler
    3131
    32 patchfiles          OSXAdapter.java.diff
     32patchfiles          OSXAdapter.java.diff \
     33                    JabRefFrame.java.diff
    3334
    3435use_configure       no
  • trunk/dports/java/jabref/files/OSXAdapter.java.diff

    r93175 r101150  
    1 --- src/osx/osxadapter/OSXAdapter.java.orig     2012-05-05 05:11:43.000000000 +0900
    2 +++ src/osx/osxadapter/OSXAdapter.java  2012-05-17 11:25:49.000000000 +0900
    3 @@ -52,7 +52,7 @@
    4      04092003  mdrance    added comments
    5  
    6  */
     1--- src/osx/osxadapter/OSXAdapter.java.orig     2013-01-01 14:36:56.000000000 +0900
     2+++ src/osx/osxadapter/OSXAdapter.java  2013-01-05 20:06:32.000000000 +0900
     3@@ -1,133 +1,203 @@
     4 /*
     5-  File:    OSXAdapter.java
     6-
     7-  Description:A single class with clear, static entry points for hooking existing preferences,
     8-        about, quit functionality from an existing Java app into handlers for the Mac OS X
     9-        application menu.  Useful for developers looking to support
     10-        multiple platforms with a single codebase, and support Mac OS X features with
     11-        minimal impact.
     12-
     13-        This sample is designed for Java 1.4.1 and later on Mac OS X.
     14-
     15-  Author:    mdrance
     16-
     17-  Copyright:   © Copyright 2003 Apple Computer, Inc. All rights reserved.
     18-
     19-  Disclaimer:  IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
     20-        ("Apple") in consideration of your agreement to the following terms, and your
     21-        use, installation, modification or redistribution of this Apple software
     22-        constitutes acceptance of these terms.  If you do not agree with these terms,
     23-        please do not use, install, modify or redistribute this Apple software.
     24-
     25-        In consideration of your agreement to abide by the following terms, and subject
     26-        to these terms, Apple grants you a personal, non-exclusive license, under Apple's
     27-        copyrights in this original Apple software (the "Apple Software"), to use,
     28-        reproduce, modify and redistribute the Apple Software, with or without
     29-        modifications, in source and/or binary forms; provided that if you redistribute
     30-        the Apple Software in its entirety and without modifications, you must retain
     31-        this notice and the following text and disclaimers in all such redistributions of
     32-        the Apple Software.  Neither the name, trademarks, service marks or logos of
     33-        Apple Computer, Inc. may be used to endorse or promote products derived from the
     34-        Apple Software without specific prior written permission from Apple.  Except as
     35-        expressly stated in this notice, no other rights or licenses, express or implied,
     36-        are granted by Apple herein, including but not limited to any patent rights that
     37-        may be infringed by your derivative works or by other works in which the Apple
     38-        Software may be incorporated.
     39-
     40-        The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
     41-        WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
     42-        WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     43-        PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
     44-        COMBINATION WITH YOUR PRODUCTS.
     45-
     46-        IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
     47-        CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     48-        GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     49-        ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
     50-        OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
     51-        (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
     52-        ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     53-
     54-  Change History (most recent first):
     55-    04092003  mdrance    added comments
     56-
     57-*/
    758-/*package osxadapter;
    8 +package osxadapter;
    9  
    10  import net.sf.jabref.JabRefFrame;
    11  import com.apple.eawt.*;
    12 @@ -99,7 +99,7 @@
    13        /  routine that chooses whether or not to quit, so the functionality is identical
    14        /  on all platforms.  This example simply cancels the AppleEvent-based quit and
    15        /  defers to that universal method.
     59-
     60-import net.sf.jabref.JabRefFrame;
     61-import com.apple.eawt.*;
     62-
     63-public class OSXAdapter extends ApplicationAdapter {
     64-
     65-  // pseudo-singleton model; no point in making multiple instances
     66-  // of the EAWT application or our adapter
     67-  private static OSXAdapter            theAdapter;
     68-  private static com.apple.eawt.Application    theApplication;
     69-
     70-  // reference to the app where the existing quit, about, prefs code is
     71-  private JabRefFrame mainApp;
     72-
     73-  private OSXAdapter (JabRefFrame inApp) {
     74-    mainApp = inApp;
     75-  }
     76-
     77-  // implemented handler methods.  These are basically hooks into existing
     78-  // functionality from the main app, as if it came over from another platform.
     79-  public void handleAbout(ApplicationEvent ae) {
     80-    if (mainApp != null) {
     81-      ae.setHandled(true);
     82-      mainApp.about();
     83-    } else {
     84-      throw new IllegalStateException("handleAbout: MyApp instance detached from listener");
     85-    }
     86-  }
     87-
     88-  public void handlePreferences(ApplicationEvent ae) {
     89-    if (mainApp != null) {
     90-      mainApp.preferences();
     91-      ae.setHandled(true);
     92-    } else {
     93-      throw new IllegalStateException("handlePreferences: MyApp instance detached from listener");
     94-    }
     95-  }
     96-
     97-  public void handleQuit(ApplicationEvent ae) {
     98-    if (mainApp != null) {
     99-      /*
     100-      /  You MUST setHandled(false) if you want to delay or cancel the quit.
     101-      /  This is important for cross-platform development -- have a universal quit
     102-      /  routine that chooses whether or not to quit, so the functionality is identical
     103-      /  on all platforms.  This example simply cancels the AppleEvent-based quit and
     104-      /  defers to that universal method.
    16105-      *//*
    17 +      */
    18        ae.setHandled(false);
    19        mainApp.quit();
    20      } else {
    21 @@ -130,4 +130,4 @@
    22      }
    23      theApplication.setEnabledPreferencesMenu(enabled);
    24    }
     106-      ae.setHandled(false);
     107-      mainApp.quit();
     108-    } else {
     109-      throw new IllegalStateException("handleQuit: MyApp instance detached from listener");
     110-    }
     111-  }
     112-
     113-
     114-  // The main entry-point for this functionality.  This is the only method
     115-  // that needs to be called at runtime, and it can easily be done using
     116-  // reflection (see MyApp.java)
     117-  public static void registerMacOSXApplication(JabRefFrame inApp) {
     118-    if (theApplication == null) {
     119-      theApplication = new com.apple.eawt.Application();
     120-    }
     121-
     122-    if (theAdapter == null) {
     123-      theAdapter = new OSXAdapter(inApp);
     124-    }
     125-    theApplication.addApplicationListener(theAdapter);
     126-  }
     127-
     128-  // Another static entry point for EAWT functionality.  Enables the
     129-  // "Preferences..." menu item in the application menu.
     130-  public static void enablePrefs(boolean enabled) {
     131-    if (theApplication == null) {
     132-      theApplication = new com.apple.eawt.Application();
     133-    }
     134-    theApplication.setEnabledPreferencesMenu(enabled);
     135-  }
    25136-}   */
    26 +}
     137+ File: OSXAdapter.java
     138+
     139+ Abstract: Hooks existing preferences/about/quit functionality from an
     140+     existing Java app into handlers for the Mac OS X application menu.
     141+     Uses a Proxy object to dynamically implement the
     142+     com.apple.eawt.ApplicationListener interface and register it with the
     143+     com.apple.eawt.Application object.  This allows the complete project
     144+     to be both built and run on any platform without any stubs or
     145+     placeholders. Useful for developers looking to implement Mac OS X
     146+     features while supporting multiple platforms with minimal impact.
     147+
     148+ Version: 2.0
     149+
     150+ Disclaimer: IMPORTANT:  This Apple software is supplied to you by
     151+ Apple Inc. ("Apple") in consideration of your agreement to the
     152+ following terms, and your use, installation, modification or
     153+ redistribution of this Apple software constitutes acceptance of these
     154+ terms.  If you do not agree with these terms, please do not use,
     155+ install, modify or redistribute this Apple software.
     156+
     157+ In consideration of your agreement to abide by the following terms, and
     158+ subject to these terms, Apple grants you a personal, non-exclusive
     159+ license, under Apple's copyrights in this original Apple software (the
     160+ "Apple Software"), to use, reproduce, modify and redistribute the Apple
     161+ Software, with or without modifications, in source and/or binary forms;
     162+ provided that if you redistribute the Apple Software in its entirety and
     163+ without modifications, you must retain this notice and the following
     164+ text and disclaimers in all such redistributions of the Apple Software.
     165+ Neither the name, trademarks, service marks or logos of Apple Inc.
     166+ may be used to endorse or promote products derived from the Apple
     167+ Software without specific prior written permission from Apple.  Except
     168+ as expressly stated in this notice, no other rights or licenses, express
     169+ or implied, are granted by Apple herein, including but not limited to
     170+ any patent rights that may be infringed by your derivative works or by
     171+ other works in which the Apple Software may be incorporated.
     172+
     173+ The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
     174+ MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
     175+ THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
     176+ FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
     177+ OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
     178+
     179+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
     180+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     181+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     182+ INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
     183+ MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
     184+ AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
     185+ STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
     186+ POSSIBILITY OF SUCH DAMAGE.
     187+
     188+ Copyright (C) 2003-2007 Apple, Inc., All Rights Reserved
     189+
     190+ */
     191+
     192+  package osxadapter;
     193+  import java.lang.reflect.*;
     194
     195
     196+  public class OSXAdapter implements InvocationHandler {
     197
     198+    protected Object targetObject;
     199+    protected Method targetMethod;
     200+    protected String proxySignature;
     201+
     202+    static Object macOSXApplication;
     203+
     204+    // Pass this method an Object and Method equipped to perform application shutdown logic
     205+    // The method passed should return a boolean stating whether or not the quit should occur
     206+    public static void setQuitHandler(Object target, Method quitHandler) {
     207+        setHandler(new OSXAdapter("handleQuit", target, quitHandler));
     208+    }
     209+
     210+    // Pass this method an Object and Method equipped to display application info
     211+    // They will be called when the About menu item is selected from the application menu
     212+    public static void setAboutHandler(Object target, Method aboutHandler) {
     213+        boolean enableAboutMenu = (target != null && aboutHandler != null);
     214+        if (enableAboutMenu) {
     215+            setHandler(new OSXAdapter("handleAbout", target, aboutHandler));
     216+        }
     217+        // If we're setting a handler, enable the About menu item by calling
     218+        // com.apple.eawt.Application reflectively
     219+        try {
     220+            Method enableAboutMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledAboutMenu", new Class[] { boolean.class });
     221+            enableAboutMethod.invoke(macOSXApplication, new Object[] { Boolean.valueOf(enableAboutMenu) });
     222+        } catch (Exception ex) {
     223+            System.err.println("OSXAdapter could not access the About Menu");
     224+            ex.printStackTrace();
     225+        }
     226+    }
     227+
     228+    // Pass this method an Object and a Method equipped to display application options
     229+    // They will be called when the Preferences menu item is selected from the application menu
     230+    public static void setPreferencesHandler(Object target, Method prefsHandler) {
     231+        boolean enablePrefsMenu = (target != null && prefsHandler != null);
     232+        if (enablePrefsMenu) {
     233+            setHandler(new OSXAdapter("handlePreferences", target, prefsHandler));
     234+        }
     235+        // If we're setting a handler, enable the Preferences menu item by calling
     236+        // com.apple.eawt.Application reflectively
     237+        try {
     238+            Method enablePrefsMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledPreferencesMenu", new Class[] { boolean.class });
     239+            enablePrefsMethod.invoke(macOSXApplication, new Object[] { Boolean.valueOf(enablePrefsMenu) });
     240+        } catch (Exception ex) {
     241+            System.err.println("OSXAdapter could not access the About Menu");
     242+            ex.printStackTrace();
     243+        }
     244+    }
     245+
     246+    // Pass this method an Object and a Method equipped to handle document events from the Finder
     247+    // Documents are registered with the Finder via the CFBundleDocumentTypes dictionary in the
     248+    // application bundle's Info.plist
     249+    public static void setFileHandler(Object target, Method fileHandler) {
     250+        setHandler(new OSXAdapter("handleOpenFile", target, fileHandler) {
     251+            // Override OSXAdapter.callTarget to send information on the
     252+            // file to be opened
     253+            public boolean callTarget(Object appleEvent) {
     254+                if (appleEvent != null) {
     255+                    try {
     256+                        Method getFilenameMethod = appleEvent.getClass().getDeclaredMethod("getFilename", (Class[])null);
     257+                        String filename = (String) getFilenameMethod.invoke(appleEvent, (Object[])null);
     258+                        this.targetMethod.invoke(this.targetObject, new Object[] { filename });
     259+                    } catch (Exception ex) {
     260+
     261+                    }
     262+                }
     263+                return true;
     264+            }
     265+        });
     266+    }
     267+
     268+    // setHandler creates a Proxy object from the passed OSXAdapter and adds it as an ApplicationListener
     269+    public static void setHandler(OSXAdapter adapter) {
     270+        try {
     271+            Class<?> applicationClass = Class.forName("com.apple.eawt.Application");
     272+            if (macOSXApplication == null) {
     273+                macOSXApplication = applicationClass.getConstructor((Class[])null).newInstance((Object[])null);
     274+            }
     275+            Class<?> applicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
     276+            Method addListenerMethod = applicationClass.getDeclaredMethod("addApplicationListener", new Class[] { applicationListenerClass });
     277+            // Create a proxy object around this handler that can be reflectively added as an Apple ApplicationListener
     278+            Object osxAdapterProxy = Proxy.newProxyInstance(OSXAdapter.class.getClassLoader(), new Class[] { applicationListenerClass }, adapter);
     279+            addListenerMethod.invoke(macOSXApplication, new Object[] { osxAdapterProxy });
     280+        } catch (ClassNotFoundException cnfe) {
     281+            System.err.println("This version of Mac OS X does not support the Apple EAWT.  ApplicationEvent handling has been disabled (" + cnfe + ")");
     282+        } catch (Exception ex) {  // Likely a NoSuchMethodException or an IllegalAccessException loading/invoking eawt.Application methods
     283+            System.err.println("Mac OS X Adapter could not talk to EAWT:");
     284+            ex.printStackTrace();
     285+        }
     286+    }
     287+
     288+    // Each OSXAdapter has the name of the EAWT method it intends to listen for (handleAbout, for example),
     289+    // the Object that will ultimately perform the task, and the Method to be called on that Object
     290+    protected OSXAdapter(String proxySignature, Object target, Method handler) {
     291+        this.proxySignature = proxySignature;
     292+        this.targetObject = target;
     293+        this.targetMethod = handler;
     294+    }
     295+
     296+    // Override this method to perform any operations on the event
     297+    // that comes with the various callbacks
     298+    // See setFileHandler above for an example
     299+    public boolean callTarget(Object appleEvent) throws InvocationTargetException, IllegalAccessException {
     300+        Object result = targetMethod.invoke(targetObject, (Object[])null);
     301+        if (result == null) {
     302+            return true;
     303+        }
     304+        return Boolean.valueOf(result.toString()).booleanValue();
     305+    }
     306+
     307+    // InvocationHandler implementation
     308+    // This is the entry point for our proxy object; it is called every time an ApplicationListener method is invoked
     309+    public Object invoke (Object proxy, Method method, Object[] args) throws Throwable {
     310+        if (isCorrectMethod(method, args)) {
     311+            boolean handled = callTarget(args[0]);
     312+            setApplicationEventHandled(args[0], handled);
     313+        }
     314+        // All of the ApplicationListener methods are void; return null regardless of what happens
     315+        return null;
     316+    }
     317+
     318+    // Compare the method that was called to the intended method when the OSXAdapter instance was created
     319+    // (e.g. handleAbout, handleQuit, handleOpenFile, etc.)
     320+    protected boolean isCorrectMethod(Method method, Object[] args) {
     321+        return (targetMethod != null && proxySignature.equals(method.getName()) && args.length == 1);
     322+    }
     323+
     324+    // It is important to mark the ApplicationEvent as handled and cancel the default behavior
     325+    // This method checks for a boolean result from the proxy method and sets the event accordingly
     326+    protected void setApplicationEventHandled(Object event, boolean handled) {
     327+        if (event != null) {
     328+            try {
     329+                Method setHandledMethod = event.getClass().getDeclaredMethod("setHandled", new Class[] { boolean.class });
     330+                // If the target method returns a boolean, use that as a hint
     331+                setHandledMethod.invoke(event, new Object[] { Boolean.valueOf(handled) });
     332+            } catch (Exception ex) {
     333+                System.err.println("OSXAdapter was unable to handle an ApplicationEvent: " + event);
     334+                ex.printStackTrace();
     335+            }
     336+        }
     337+    }
     338+}
Note: See TracChangeset for help on using the changeset viewer.