-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edf1260
commit 08c3154
Showing
5 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/com/watsontech/tools/sshcrab2/UIExtensionApple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.watsontech.tools.sshcrab2; | ||
|
||
import java.awt.*; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
/** | ||
* Created by Watson on 2021/2/21. | ||
*/ | ||
public class UIExtensionApple { | ||
// static com.apple.eawt.Application macApplication; | ||
static Object macApplication; | ||
static { | ||
// Replace: import com.apple.eawt.Application | ||
String className = "com.apple.eawt.Application"; | ||
Class<?> cls = null; | ||
try { | ||
cls = Class.forName(className); | ||
|
||
// Replace: Application application = Application.getApplication(); | ||
macApplication = cls.newInstance().getClass().getMethod("getApplication").invoke(null); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} catch (InstantiationException e) { | ||
e.printStackTrace(); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void setDockIconImage(Image image) { | ||
if(UIExtensionApple.macApplication==null) return; | ||
|
||
// Retrieve the Image object from the locally stored image file | ||
// "frame" is the name of my JFrame variable, and "filename" is the name of the image file | ||
// Image image = Toolkit.getDefaultToolkit().getImage(frame.getClass().getResource(fileName)); | ||
|
||
// Replace: application.setDockIconImage(image); | ||
try { | ||
UIExtensionApple.macApplication.getClass().getMethod("setDockIconImage", Image.class) | ||
.invoke(UIExtensionApple.macApplication, image); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void updateDockerWord(String word) { | ||
if(macApplication!=null) { | ||
try { | ||
macApplication.getClass().getMethod("setDockIconBadge", String.class) | ||
.invoke(macApplication, word); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// macApplication.setDockIconBadge(word); | ||
} | ||
} | ||
|
||
public static void requestForeground() { | ||
if(macApplication!=null) { | ||
try { | ||
macApplication.getClass().getMethod("requestForeground", boolean.class) | ||
.invoke(macApplication, true); | ||
macApplication.getClass().getMethod("requestUserAttention", boolean.class) | ||
.invoke(macApplication, true); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// macApplication.requestForeground(true); | ||
// macApplication.requestUserAttention(true); | ||
} | ||
} | ||
} |