1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-08-13 16:53:51 -04:00

Improve Mac OSX Java6 support

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@498 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-04-02 15:08:34 +00:00
parent 94d3deb6b4
commit c0a7f59384
3 changed files with 78 additions and 21 deletions

View File

@ -21,6 +21,9 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
protected AwtGatewayTray() {
}
protected static AboutFrame aboutFrame;
protected static SettingsFrame settingsFrame;
private static TrayIcon trayIcon = null;
private static Image image = null;
private static Image image2 = null;
@ -68,20 +71,38 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
public void displayMessage(final String message, final Priority priority) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (trayIcon != null) {
TrayIcon.MessageType messageType = null;
if (priority == Priority.INFO) {
messageType = TrayIcon.MessageType.INFO;
} else if (priority == Priority.WARN) {
messageType = TrayIcon.MessageType.WARNING;
} else if (priority == Priority.ERROR) {
messageType = TrayIcon.MessageType.ERROR;
if (trayIcon != null) {
TrayIcon.MessageType messageType = null;
if (priority == Priority.INFO) {
messageType = TrayIcon.MessageType.INFO;
} else if (priority == Priority.WARN) {
messageType = TrayIcon.MessageType.WARNING;
} else if (priority == Priority.ERROR) {
messageType = TrayIcon.MessageType.ERROR;
}
if (messageType != null) {
trayIcon.displayMessage("DavMail gateway", message, messageType);
}
trayIcon.setToolTip("DavMail gateway \n" + message);
}
if (messageType != null) {
trayIcon.displayMessage("DavMail gateway", message, messageType);
}
trayIcon.setToolTip("DavMail gateway \n" + message);
}
});
}
public void about() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
aboutFrame.update();
aboutFrame.setVisible(true);
}
});
}
public void preferences() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
settingsFrame.reload();
settingsFrame.setVisible(true);
}
});
}
@ -94,7 +115,6 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
});
}
protected void createAndShowGUI() {
// set native look and feel
@ -113,12 +133,11 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
// create a popup menu
PopupMenu popup = new PopupMenu();
final AboutFrame aboutFrame = new AboutFrame();
aboutFrame = new AboutFrame();
// create an action settingsListener to listen for settings action executed on the tray icon
ActionListener aboutListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
aboutFrame.update();
aboutFrame.setVisible(true);
about();
}
};
// create menu item for the default action
@ -126,12 +145,11 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
aboutItem.addActionListener(aboutListener);
popup.add(aboutItem);
final SettingsFrame settingsFrame = new SettingsFrame();
settingsFrame = new SettingsFrame();
// create an action settingsListener to listen for settings action executed on the tray icon
ActionListener settingsListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
settingsFrame.reload();
settingsFrame.setVisible(true);
preferences();
}
};
// create menu item for the default action

View File

@ -127,7 +127,11 @@ public class DavGatewayTray {
if (davGatewayTray == null) {
try {
if (SystemTray.isSupported()) {
davGatewayTray = new AwtGatewayTray();
if (isOSX()) {
davGatewayTray = new OSXAwtGatewayTray();
} else {
davGatewayTray = new AwtGatewayTray();
}
davGatewayTray.init();
}
} catch (NoClassDefFoundError e) {
@ -135,7 +139,7 @@ public class DavGatewayTray {
}
}
if (davGatewayTray == null) {
if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
if (isOSX()) {
// MacOS
davGatewayTray = new OSXFrameGatewayTray();
} else {
@ -146,6 +150,15 @@ public class DavGatewayTray {
}
}
/**
* Test if running on OSX
*
* @return true on Mac OS X
*/
protected static boolean isOSX() {
return System.getProperty("os.name").toLowerCase().startsWith("mac os x");
}
/**
* Load image with current class loader.
*

View File

@ -0,0 +1,26 @@
package davmail.tray;
import davmail.ui.OSXAdapter;
/**
* Extended Awt tray with OSX extensions.
*/
public class OSXAwtGatewayTray extends AwtGatewayTray {
@SuppressWarnings({"SameReturnValue"})
public boolean quit() {
return true;
}
@Override
protected void createAndShowGUI() {
System.setProperty("apple.laf.useScreenMenuBar", "true");
super.createAndShowGUI();
try {
OSXAdapter.setAboutHandler(this, AwtGatewayTray.class.getDeclaredMethod("about", (Class[]) null));
OSXAdapter.setPreferencesHandler(this, AwtGatewayTray.class.getDeclaredMethod("preferences", (Class[]) null));
OSXAdapter.setQuitHandler(this, OSXAwtGatewayTray.class.getDeclaredMethod("quit", (Class[]) null));
} catch (Exception e) {
DavGatewayTray.error("Error while loading the OSXAdapter", e);
}
}
}