001package apps.plaf.macosx;
002
003import java.awt.Desktop;
004import jmri.util.SystemType;
005
006/**
007 * Wrapper for Apple provided extensions to Java that allow Java apps to feel
008 * more "Mac-like" on Mac OS X.
009 * <p>
010 * <b>NOTE</b> All use of this class must be wrapped in a conditional test that
011 * ensures that JMRI is not running on Mac OS X or in Try-Catch blocks. The
012 * easiest test is:
013 * <pre><code>
014 * if (SystemType.isMacOSX()) {
015 *     ...
016 * }
017 * </code></pre> A Try-Catch block will need to catch
018 * {@link java.lang.NoClassDefFoundError} Failure to use one of these methods
019 * will result in crashes.
020 *
021 * @author Randall Wood (c) 2011, 2016
022 * @see Jdk9Application
023 */
024abstract public class Application {
025
026    private static volatile Application sharedApplication = null;
027
028    public static Application getApplication() {
029        if (!SystemType.isMacOSX()) {
030            return null;
031        }
032        if (sharedApplication == null) {
033            try {
034                // test that Desktop supports AboutHandlers
035                if (Desktop.getDesktop().isSupported(Desktop.Action.valueOf("APP_ABOUT"))) { // NOI18N
036                    sharedApplication = new Jdk9Application();
037                }
038            } catch (IllegalArgumentException ex) {
039                log.error("failed to start desktop support");
040            }
041        }
042        return sharedApplication;
043    }
044
045    Application() {
046        // do nothing but require that subclass constructors are package private
047    }
048
049    abstract public void setAboutHandler(final AboutHandler handler);
050
051    abstract public void setPreferencesHandler(final PreferencesHandler handler);
052
053    abstract public void setQuitHandler(final QuitHandler handler);
054
055    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Application.class);
056}