mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-06 03:08:02 -05:00
From David Ashman : improve exceptions logging
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@116 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
dfeced6478
commit
52c50d30ed
@ -21,8 +21,6 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||
protected AwtGatewayTray() {
|
||||
}
|
||||
|
||||
protected static final Logger LOGGER = Logger.getLogger("davmail");
|
||||
|
||||
// LOCK for synchronized block
|
||||
protected static final Object LOCK = new Object();
|
||||
|
||||
@ -31,19 +29,19 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||
private static Image image2 = null;
|
||||
|
||||
public void switchIcon() {
|
||||
synchronized (LOCK) {
|
||||
if (trayIcon.getImage() == image) {
|
||||
trayIcon.setImage(image2);
|
||||
} else {
|
||||
trayIcon.setImage(image);
|
||||
}
|
||||
synchronized (LOCK) {
|
||||
if (trayIcon.getImage() == image) {
|
||||
trayIcon.setImage(image2);
|
||||
} else {
|
||||
trayIcon.setImage(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetIcon() {
|
||||
synchronized (LOCK) {
|
||||
trayIcon.setImage(image);
|
||||
}
|
||||
synchronized (LOCK) {
|
||||
trayIcon.setImage(image);
|
||||
}
|
||||
}
|
||||
|
||||
public void displayMessage(String message, Priority priority) {
|
||||
@ -62,7 +60,6 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||
}
|
||||
trayIcon.setToolTip("DavMail gateway \n" + message);
|
||||
}
|
||||
LOGGER.log(priority, message);
|
||||
}
|
||||
|
||||
}
|
||||
@ -72,7 +69,7 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Unable to set system look and feel");
|
||||
DavGatewayTray.warn("Unable to set system look and feel", e);
|
||||
}
|
||||
|
||||
// get the SystemTray instance
|
||||
@ -140,7 +137,7 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||
try {
|
||||
tray.add(trayIcon);
|
||||
} catch (AWTException e) {
|
||||
System.err.println(e);
|
||||
DavGatewayTray.warn("Unable to create tray", e);
|
||||
}
|
||||
|
||||
// display settings frame on first start
|
||||
|
@ -1,6 +1,8 @@
|
||||
package davmail.tray;
|
||||
|
||||
import davmail.Settings;
|
||||
import org.apache.log4j.Priority;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@ -9,26 +11,36 @@ import java.awt.*;
|
||||
* Tray icon handler
|
||||
*/
|
||||
public class DavGatewayTray {
|
||||
protected static final Logger LOGGER = Logger.getLogger("davmail");
|
||||
|
||||
protected DavGatewayTray() {
|
||||
}
|
||||
|
||||
protected static DavGatewayTrayInterface davGatewayTray;
|
||||
|
||||
public static void switchIcon() {
|
||||
if (davGatewayTray != null) {
|
||||
davGatewayTray.switchIcon();
|
||||
if (davGatewayTray != null) {
|
||||
davGatewayTray.switchIcon();
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetIcon() {
|
||||
if (davGatewayTray != null) {
|
||||
davGatewayTray.resetIcon();
|
||||
if (davGatewayTray != null) {
|
||||
davGatewayTray.resetIcon();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void displayMessage(String message, Priority priority) {
|
||||
if (davGatewayTray != null) {
|
||||
davGatewayTray.displayMessage(message, priority);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,47 +61,48 @@ public class DavGatewayTray {
|
||||
}
|
||||
|
||||
public static void debug(String message, Exception e) {
|
||||
debug(message + " " + e + " " + e.getMessage());
|
||||
displayMessage(message, e, Priority.DEBUG);
|
||||
}
|
||||
|
||||
public static void info(String message, Exception e) {
|
||||
info(message + " " + e + " " + e.getMessage());
|
||||
displayMessage(message, e, Priority.INFO);
|
||||
}
|
||||
|
||||
public static void warn(String message, Exception e) {
|
||||
warn(message + " " + e + " " + e.getMessage());
|
||||
displayMessage(message, e, Priority.WARN);
|
||||
}
|
||||
|
||||
public static void error(String message, Exception e) {
|
||||
error(message + " " + e + " " + e.getMessage());
|
||||
displayMessage(message, e, Priority.ERROR);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
ClassLoader classloader = DavGatewayTray.class.getClassLoader();
|
||||
// first try to load SWT
|
||||
try {
|
||||
// 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) {
|
||||
if (!Settings.getBooleanProperty("davmail.server")) {
|
||||
ClassLoader classloader = DavGatewayTray.class.getClassLoader();
|
||||
// first try to load SWT
|
||||
try {
|
||||
if (SystemTray.isSupported()) {
|
||||
davGatewayTray = new AwtGatewayTray();
|
||||
davGatewayTray.init();
|
||||
}
|
||||
} catch (NoClassDefFoundError e) {
|
||||
DavGatewayTray.info("JDK 1.6 needed for system tray support");
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
if (davGatewayTray == null) {
|
||||
DavGatewayTray.warn("No system tray support found (tried SWT and native java)");
|
||||
}
|
||||
}
|
||||
if (davGatewayTray == null) {
|
||||
DavGatewayTray.warn("No system tray support found (tried SWT and native java)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,6 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||
protected SwtGatewayTray() {
|
||||
}
|
||||
|
||||
protected static final Logger LOGGER = Logger.getLogger("davmail");
|
||||
|
||||
// LOCK for synchronized block
|
||||
protected static final Object LOCK = new Object();
|
||||
|
||||
@ -86,7 +84,6 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||
}
|
||||
});
|
||||
}
|
||||
LOGGER.log(priority, message);
|
||||
}
|
||||
|
||||
}
|
||||
@ -101,7 +98,7 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||
}
|
||||
UIManager.setLookAndFeel(lafClassName);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Unable to set look and feel");
|
||||
DavGatewayTray.warn("Unable to set look and feel");
|
||||
}
|
||||
|
||||
new Thread() {
|
||||
@ -123,14 +120,14 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||
image = new Image(display, imageUrl.openStream());
|
||||
awtImage = Toolkit.getDefaultToolkit().getImage(imageUrl);
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Unable to load image");
|
||||
DavGatewayTray.warn("Unable to load image", e);
|
||||
}
|
||||
|
||||
try {
|
||||
URL imageUrl2 = classloader.getResource("tray2.png");
|
||||
image2 = new Image(display, imageUrl2.openStream());
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Unable to load image");
|
||||
DavGatewayTray.warn("Unable to load image", e);
|
||||
}
|
||||
|
||||
trayItem.setImage(image);
|
||||
@ -171,7 +168,7 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||
display.asyncExec(
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
settingsFrame.setVisible(true);
|
||||
settingsFrame.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -238,4 +235,5 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user