Set the dock icon on OS X.  Not perfect as it still shows the standard Java logo for a second or two, but better than nothing

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5151 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/java/com/tigervnc/vncviewer/Viewport.java b/java/com/tigervnc/vncviewer/Viewport.java
index a6ce355..e7d76a5 100644
--- a/java/com/tigervnc/vncviewer/Viewport.java
+++ b/java/com/tigervnc/vncviewer/Viewport.java
@@ -27,6 +27,7 @@
 import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsDevice;
 import java.awt.GraphicsEnvironment;
+import java.awt.Image;
 import java.awt.Window;
 import java.lang.reflect.*;
 import javax.swing.*;
@@ -41,7 +42,23 @@
     setTitle(name+" - TigerVNC");
     setFocusable(false);
     setFocusTraversalKeysEnabled(false);
-    setIconImage(VncViewer.frameIcon);
+    if (VncViewer.os.startsWith("mac os x")) {
+      try {
+        Class appClass = Class.forName("com.apple.eawt.Application");
+        Method getApplication = 
+          appClass.getMethod("getApplication", (Class[])null);
+        Object app = getApplication.invoke(appClass);
+        Class paramTypes[] = new Class[1];
+        paramTypes[0] = Image.class;
+        Method setDockIconImage = 
+          appClass.getMethod("setDockIconImage", paramTypes);
+        setDockIconImage.invoke(app, VncViewer.logoImage);
+      } catch (Exception e) {
+        vlog.debug("Could not set OS X dock icon: " + e.getMessage());
+      }
+    } else {
+      setIconImage(VncViewer.frameIcon);
+    }
     UIManager.getDefaults().put("ScrollPane.ancestorInputMap",
       new UIDefaults.LazyInputMap(new Object[]{}));
     sp = new JScrollPane();
@@ -133,7 +150,6 @@
     } catch (Exception e) {
       vlog.debug("Could not enable OS X 10.7+ full-screen mode: " +
                  e.getMessage());
-      
     }
   }