Try to improve shutdown hook
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1980 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
5c337081b8
commit
e680c3e1ad
|
@ -173,6 +173,7 @@ public final class DavGateway {
|
||||||
// clear session cache
|
// clear session cache
|
||||||
ExchangeSessionFactory.reset();
|
ExchangeSessionFactory.reset();
|
||||||
DavGatewayTray.info(new BundleMessage("LOG_GATEWAY_STOP"));
|
DavGatewayTray.info(new BundleMessage("LOG_GATEWAY_STOP"));
|
||||||
|
DavGatewayTray.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,6 +37,7 @@ import java.awt.event.ActionListener;
|
||||||
/**
|
/**
|
||||||
* Tray icon handler based on java 1.6
|
* Tray icon handler based on java 1.6
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("Since15")
|
||||||
public class AwtGatewayTray implements DavGatewayTrayInterface {
|
public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||||
protected static final String TRAY_ACTIVE_PNG = "tray2.png";
|
protected static final String TRAY_ACTIVE_PNG = "tray2.png";
|
||||||
protected static final String TRAY_PNG = "tray.png";
|
protected static final String TRAY_PNG = "tray.png";
|
||||||
|
@ -163,6 +164,7 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||||
settingsFrame.reload();
|
settingsFrame.reload();
|
||||||
settingsFrame.setVisible(true);
|
settingsFrame.setVisible(true);
|
||||||
settingsFrame.toFront();
|
settingsFrame.toFront();
|
||||||
|
settingsFrame.repaint();
|
||||||
settingsFrame.requestFocus();
|
settingsFrame.requestFocus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -179,6 +181,17 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
SystemTray.getSystemTray().remove(trayIcon);
|
||||||
|
|
||||||
|
// dispose frames
|
||||||
|
settingsFrame.dispose();
|
||||||
|
aboutFrame.dispose();
|
||||||
|
if (logBrokerMonitor != null) {
|
||||||
|
logBrokerMonitor.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void createAndShowGUI() {
|
protected void createAndShowGUI() {
|
||||||
System.setProperty("swing.defaultlaf", UIManager.getSystemLookAndFeelClassName());
|
System.setProperty("swing.defaultlaf", UIManager.getSystemLookAndFeelClassName());
|
||||||
|
|
||||||
|
@ -241,14 +254,6 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
try {
|
try {
|
||||||
DavGateway.stop();
|
DavGateway.stop();
|
||||||
SystemTray.getSystemTray().remove(trayIcon);
|
|
||||||
|
|
||||||
// dispose frames
|
|
||||||
settingsFrame.dispose();
|
|
||||||
aboutFrame.dispose();
|
|
||||||
if (logBrokerMonitor != null) {
|
|
||||||
logBrokerMonitor.dispose();
|
|
||||||
}
|
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
DavGatewayTray.error(exc);
|
DavGatewayTray.error(exc);
|
||||||
}
|
}
|
||||||
|
@ -278,6 +283,7 @@ public class AwtGatewayTray implements DavGatewayTrayInterface {
|
||||||
if (Settings.isFirstStart()) {
|
if (Settings.isFirstStart()) {
|
||||||
settingsFrame.setVisible(true);
|
settingsFrame.setVisible(true);
|
||||||
settingsFrame.toFront();
|
settingsFrame.toFront();
|
||||||
|
settingsFrame.repaint();
|
||||||
settingsFrame.requestFocus();
|
settingsFrame.requestFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,4 +290,7 @@ public final class DavGatewayTray {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void dispose() {
|
||||||
|
davGatewayTray.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,4 +68,8 @@ public interface DavGatewayTrayInterface {
|
||||||
*/
|
*/
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* destroy frames
|
||||||
|
*/
|
||||||
|
void dispose();
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,6 +196,15 @@ public class FrameGatewayTray implements DavGatewayTrayInterface {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
// dispose frames
|
||||||
|
settingsFrame.dispose();
|
||||||
|
aboutFrame.dispose();
|
||||||
|
if (logBrokerMonitor != null) {
|
||||||
|
logBrokerMonitor.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void buildMenu() {
|
protected void buildMenu() {
|
||||||
// create a popup menu
|
// create a popup menu
|
||||||
JMenu menu = new JMenu(BundleMessage.format("UI_DAVMAIL_GATEWAY"));
|
JMenu menu = new JMenu(BundleMessage.format("UI_DAVMAIL_GATEWAY"));
|
||||||
|
@ -239,12 +248,6 @@ public class FrameGatewayTray implements DavGatewayTrayInterface {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
try {
|
try {
|
||||||
DavGateway.stop();
|
DavGateway.stop();
|
||||||
// dispose frames
|
|
||||||
settingsFrame.dispose();
|
|
||||||
aboutFrame.dispose();
|
|
||||||
if (logBrokerMonitor != null) {
|
|
||||||
logBrokerMonitor.dispose();
|
|
||||||
}
|
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
DavGatewayTray.error(exc);
|
DavGatewayTray.error(exc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,7 +312,6 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||||
exitItem.addListener(SWT.Selection, new Listener() {
|
exitItem.addListener(SWT.Selection, new Listener() {
|
||||||
public void handleEvent(Event event) {
|
public void handleEvent(Event event) {
|
||||||
DavGateway.stop();
|
DavGateway.stop();
|
||||||
shell.dispose();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -339,6 +338,32 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
} catch (Exception exc) {
|
||||||
|
DavGatewayTray.error(exc);
|
||||||
|
}
|
||||||
|
// make sure we do exit
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
while (true) {
|
||||||
|
// wait for SWT init
|
||||||
|
try {
|
||||||
|
synchronized (mainThread) {
|
||||||
|
if (isReady) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mainThread.wait(1000);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
DavGatewayTray.error(new BundleMessage("LOG_ERROR_WAITING_FOR_SWT_INIT"), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
shell.dispose();
|
||||||
if (trayItem != null) {
|
if (trayItem != null) {
|
||||||
trayItem.dispose();
|
trayItem.dispose();
|
||||||
trayItem = null;
|
trayItem = null;
|
||||||
|
@ -368,26 +393,5 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
||||||
logBrokerMonitor.dispose();
|
logBrokerMonitor.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception exc) {
|
|
||||||
DavGatewayTray.error(exc);
|
|
||||||
}
|
|
||||||
// make sure we do exit
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
while (true) {
|
|
||||||
// wait for SWT init
|
|
||||||
try {
|
|
||||||
synchronized (mainThread) {
|
|
||||||
if (isReady) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mainThread.wait(1000);
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
DavGatewayTray.error(new BundleMessage("LOG_ERROR_WAITING_FOR_SWT_INIT"), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue