mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-08 12:18:07 -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 AwtGatewayTray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final Logger LOGGER = Logger.getLogger("davmail");
|
|
||||||
|
|
||||||
// LOCK for synchronized block
|
// LOCK for synchronized block
|
||||||
protected static final Object LOCK = new Object();
|
protected static final Object LOCK = new Object();
|
||||||
|
|
||||||
@ -31,19 +29,19 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
private static Image image2 = null;
|
private static Image image2 = null;
|
||||||
|
|
||||||
public void switchIcon() {
|
public void switchIcon() {
|
||||||
synchronized (LOCK) {
|
synchronized (LOCK) {
|
||||||
if (trayIcon.getImage() == image) {
|
if (trayIcon.getImage() == image) {
|
||||||
trayIcon.setImage(image2);
|
trayIcon.setImage(image2);
|
||||||
} else {
|
} else {
|
||||||
trayIcon.setImage(image);
|
trayIcon.setImage(image);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetIcon() {
|
public void resetIcon() {
|
||||||
synchronized (LOCK) {
|
synchronized (LOCK) {
|
||||||
trayIcon.setImage(image);
|
trayIcon.setImage(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayMessage(String message, Priority priority) {
|
public void displayMessage(String message, Priority priority) {
|
||||||
@ -62,7 +60,6 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
}
|
}
|
||||||
trayIcon.setToolTip("DavMail gateway \n" + message);
|
trayIcon.setToolTip("DavMail gateway \n" + message);
|
||||||
}
|
}
|
||||||
LOGGER.log(priority, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -72,7 +69,7 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
} catch (Exception e) {
|
} 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
|
// get the SystemTray instance
|
||||||
@ -140,7 +137,7 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
try {
|
try {
|
||||||
tray.add(trayIcon);
|
tray.add(trayIcon);
|
||||||
} catch (AWTException e) {
|
} catch (AWTException e) {
|
||||||
System.err.println(e);
|
DavGatewayTray.warn("Unable to create tray", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// display settings frame on first start
|
// display settings frame on first start
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package davmail.tray;
|
package davmail.tray;
|
||||||
|
|
||||||
|
import davmail.Settings;
|
||||||
import org.apache.log4j.Priority;
|
import org.apache.log4j.Priority;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@ -9,6 +11,8 @@ import java.awt.*;
|
|||||||
* Tray icon handler
|
* Tray icon handler
|
||||||
*/
|
*/
|
||||||
public class DavGatewayTray {
|
public class DavGatewayTray {
|
||||||
|
protected static final Logger LOGGER = Logger.getLogger("davmail");
|
||||||
|
|
||||||
protected DavGatewayTray() {
|
protected DavGatewayTray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,19 +20,27 @@ public class DavGatewayTray {
|
|||||||
|
|
||||||
public static void switchIcon() {
|
public static void switchIcon() {
|
||||||
if (davGatewayTray != null) {
|
if (davGatewayTray != null) {
|
||||||
davGatewayTray.switchIcon();
|
davGatewayTray.switchIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetIcon() {
|
public static void resetIcon() {
|
||||||
if (davGatewayTray != null) {
|
if (davGatewayTray != null) {
|
||||||
davGatewayTray.resetIcon();
|
davGatewayTray.resetIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void displayMessage(String message, Priority priority) {
|
protected static void displayMessage(String message, Priority priority) {
|
||||||
|
LOGGER.log(priority, message);
|
||||||
if (davGatewayTray != null) {
|
if (davGatewayTray != null) {
|
||||||
davGatewayTray.displayMessage(message, priority);
|
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) {
|
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) {
|
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) {
|
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) {
|
public static void error(String message, Exception e) {
|
||||||
error(message + " " + e + " " + e.getMessage());
|
displayMessage(message, e, Priority.ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
ClassLoader classloader = DavGatewayTray.class.getClassLoader();
|
if (!Settings.getBooleanProperty("davmail.server")) {
|
||||||
// first try to load SWT
|
ClassLoader classloader = DavGatewayTray.class.getClassLoader();
|
||||||
try {
|
// first try to load SWT
|
||||||
// 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 {
|
try {
|
||||||
if (SystemTray.isSupported()) {
|
// trigger ClassNotFoundException
|
||||||
davGatewayTray = new AwtGatewayTray();
|
classloader.loadClass("org.eclipse.swt.SWT");
|
||||||
davGatewayTray.init();
|
// SWT available, create tray
|
||||||
}
|
davGatewayTray = new SwtGatewayTray();
|
||||||
} catch (NoClassDefFoundError e) {
|
davGatewayTray.init();
|
||||||
DavGatewayTray.info("JDK 1.6 needed for system tray support");
|
} 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 SwtGatewayTray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final Logger LOGGER = Logger.getLogger("davmail");
|
|
||||||
|
|
||||||
// LOCK for synchronized block
|
// LOCK for synchronized block
|
||||||
protected static final Object LOCK = new Object();
|
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);
|
UIManager.setLookAndFeel(lafClassName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn("Unable to set look and feel");
|
DavGatewayTray.warn("Unable to set look and feel");
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@ -123,14 +120,14 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
image = new Image(display, imageUrl.openStream());
|
image = new Image(display, imageUrl.openStream());
|
||||||
awtImage = Toolkit.getDefaultToolkit().getImage(imageUrl);
|
awtImage = Toolkit.getDefaultToolkit().getImage(imageUrl);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.warn("Unable to load image");
|
DavGatewayTray.warn("Unable to load image", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL imageUrl2 = classloader.getResource("tray2.png");
|
URL imageUrl2 = classloader.getResource("tray2.png");
|
||||||
image2 = new Image(display, imageUrl2.openStream());
|
image2 = new Image(display, imageUrl2.openStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.warn("Unable to load image");
|
DavGatewayTray.warn("Unable to load image", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
trayItem.setImage(image);
|
trayItem.setImage(image);
|
||||||
@ -171,7 +168,7 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
display.asyncExec(
|
display.asyncExec(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
settingsFrame.setVisible(true);
|
settingsFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -238,4 +235,5 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user