Java Image configureMacOSApplication(String appName, String dockImagePath)

Here you can find the source of configureMacOSApplication(String appName, String dockImagePath)

Description

Set common properties and dock image for the given application is we are running on Mac OS X

License

Open Source License

Parameter

Parameter Description
appName The name of the Application
dockImagePath The String path of the image to use as the dock icon

Declaration

public static void configureMacOSApplication(String appName, String dockImagePath) 

Method Source Code


//package com.java2s;
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Method;
import java.net.*;

public class Main {
    /**//from  w w  w  . j a v  a 2s.c o  m
     * Set a few common properties for the given application if we are running
     * under MacOS. Usage Example:
     *
     * <pre>
     * if (MacOSUtil.isMacOS()) {
     *   MacOSUtil.configureMacOSApplication(&quot;JabaDex&quot;);
     * }
     * </pre>
     *
     * @param appName -
     *            the name of the Application.
     */
    public static void configureMacOSApplication(String appName) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("apple.awt.showGrowBox", "true");
        //System.setProperty("apple.awt.fileDialogForDirectories", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", appName);
    }

    /**
     * Set common properties and dock image for the given application is we are running
     * on Mac OS X
     * @param appName The name of the Application
     * @param dockImagePath The String path of the image to use as the dock icon
     */
    public static void configureMacOSApplication(String appName, String dockImagePath) {
        configureMacOSApplication(appName);
        try {
            // Use reflection to invoke Apple's proprietary methods
            Class<?> clazz = Class.forName("com.apple.eawt.Application");
            Method method = clazz.getMethod("getApplication", null);
            Object application = method.invoke(null, null);
            Method method2 = application.getClass().getMethod("setDockIconImage", Image.class);
            URL dockImageURL = "".getClass().getResource(dockImagePath);
            Image dockImage = new ImageIcon(dockImageURL).getImage();
            method2.invoke(application, dockImage);
        } catch (Exception e) {
            // Do nothing
        }

    }
}

Related

  1. absoluteDifferenceImage(int[] rgb1, int[] rgb2, double scale)
  2. checkLosslessImageExt(Component parent, File f)
  3. CreateCopy(Image srcImg)
  4. createCursor(Image cursorImage, Point hotSpot, String name)
  5. createCursor(Image image, Point hotspot, String name)
  6. createMemoryImage(int width, int height, Color colour, JComponent someComponent)