2007-10-09 08:01:58 -04:00
|
|
|
package davmail.tray;
|
2007-05-09 19:37:24 -04:00
|
|
|
|
2008-01-31 18:40:26 -05:00
|
|
|
import davmail.Settings;
|
2007-05-09 19:37:24 -04:00
|
|
|
import org.apache.log4j.Priority;
|
2008-01-31 18:40:26 -05:00
|
|
|
import org.apache.log4j.Logger;
|
2007-05-09 19:37:24 -04:00
|
|
|
|
2007-10-20 14:35:02 -04:00
|
|
|
import java.awt.*;
|
2007-10-09 08:01:58 -04:00
|
|
|
|
2007-05-09 19:37:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tray icon handler
|
|
|
|
*/
|
|
|
|
public class DavGatewayTray {
|
2008-01-31 18:40:26 -05:00
|
|
|
protected static final Logger LOGGER = Logger.getLogger("davmail");
|
|
|
|
|
2007-05-09 19:37:24 -04:00
|
|
|
protected DavGatewayTray() {
|
|
|
|
}
|
|
|
|
|
2007-10-09 05:48:59 -04:00
|
|
|
protected static DavGatewayTrayInterface davGatewayTray;
|
2007-05-09 19:37:24 -04:00
|
|
|
|
|
|
|
public static void switchIcon() {
|
2008-01-31 18:40:26 -05:00
|
|
|
if (davGatewayTray != null) {
|
|
|
|
davGatewayTray.switchIcon();
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void resetIcon() {
|
2008-01-31 18:40:26 -05:00
|
|
|
if (davGatewayTray != null) {
|
|
|
|
davGatewayTray.resetIcon();
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static void displayMessage(String message, Priority priority) {
|
2008-01-31 18:40:26 -05:00
|
|
|
LOGGER.log(priority, message);
|
|
|
|
if (davGatewayTray != null) {
|
|
|
|
davGatewayTray.displayMessage(message, priority);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static void displayMessage(String message, Exception e, Priority priority) {
|
|
|
|
LOGGER.log(priority, message, e);
|
|
|
|
if (davGatewayTray != null) {
|
|
|
|
davGatewayTray.displayMessage(message + " " + e +" "+ e.getMessage(), priority);
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void debug(String message) {
|
|
|
|
displayMessage(message, Priority.DEBUG);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void info(String message) {
|
|
|
|
displayMessage(message, Priority.INFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void warn(String message) {
|
|
|
|
displayMessage(message, Priority.WARN);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void error(String message) {
|
|
|
|
displayMessage(message, Priority.ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void debug(String message, Exception e) {
|
2008-01-31 18:40:26 -05:00
|
|
|
displayMessage(message, e, Priority.DEBUG);
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void info(String message, Exception e) {
|
2008-01-31 18:40:26 -05:00
|
|
|
displayMessage(message, e, Priority.INFO);
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void warn(String message, Exception e) {
|
2008-01-31 18:40:26 -05:00
|
|
|
displayMessage(message, e, Priority.WARN);
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void error(String message, Exception e) {
|
2008-01-31 18:40:26 -05:00
|
|
|
displayMessage(message, e, Priority.ERROR);
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void init() {
|
2008-01-31 18:40:26 -05:00
|
|
|
if (!Settings.getBooleanProperty("davmail.server")) {
|
|
|
|
ClassLoader classloader = DavGatewayTray.class.getClassLoader();
|
|
|
|
// first try to load SWT
|
2007-10-09 05:48:59 -04:00
|
|
|
try {
|
2008-01-31 18:40:26 -05:00
|
|
|
// trigger ClassNotFoundException
|
|
|
|
classloader.loadClass("org.eclipse.swt.SWT");
|
|
|
|
// SWT available, create tray
|
|
|
|
davGatewayTray = new SwtGatewayTray();
|
|
|
|
davGatewayTray.init();
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
DavGatewayTray.info("SWT not available, fallback to JDK 1.6 system tray support");
|
|
|
|
}
|
|
|
|
// try java6 tray support
|
|
|
|
if (davGatewayTray == null) {
|
|
|
|
try {
|
|
|
|
if (SystemTray.isSupported()) {
|
|
|
|
davGatewayTray = new AwtGatewayTray();
|
|
|
|
davGatewayTray.init();
|
|
|
|
}
|
|
|
|
} catch (NoClassDefFoundError e) {
|
|
|
|
DavGatewayTray.info("JDK 1.6 needed for system tray support");
|
2007-08-02 09:34:10 -04:00
|
|
|
}
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
2008-01-31 18:40:26 -05:00
|
|
|
if (davGatewayTray == null) {
|
|
|
|
DavGatewayTray.warn("No system tray support found (tried SWT and native java)");
|
|
|
|
}
|
2007-10-09 05:48:59 -04:00
|
|
|
}
|
2007-05-09 19:37:24 -04:00
|
|
|
}
|
|
|
|
}
|