mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-05 10:47:59 -05:00
SWT: delayed AWT frames creation to reduce memory usage
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1675 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
c0cd134505
commit
eb912da404
@ -47,6 +47,9 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
protected SwtGatewayTray() {
|
protected SwtGatewayTray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsFrame settingsFrame;
|
||||||
|
AboutFrame aboutFrame;
|
||||||
|
|
||||||
private static TrayItem trayItem;
|
private static TrayItem trayItem;
|
||||||
private static java.awt.Image awtImage;
|
private static java.awt.Image awtImage;
|
||||||
private static Image image;
|
private static Image image;
|
||||||
@ -167,28 +170,35 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean lookAndFeelSet;
|
||||||
|
|
||||||
|
protected void setLookAndFeel() {
|
||||||
|
if (!lookAndFeelSet) {
|
||||||
|
lookAndFeelSet = true;
|
||||||
|
try {
|
||||||
|
String lafClassName = UIManager.getSystemLookAndFeelClassName();
|
||||||
|
// workaround for bug when SWT and AWT both try to access Gtk
|
||||||
|
if (lafClassName.indexOf("gtk") > 0) {
|
||||||
|
lafClassName = UIManager.getCrossPlatformLookAndFeelClassName();
|
||||||
|
// replace AWT event queue Gdk error handler to avoid application crash
|
||||||
|
Toolkit.getDefaultToolkit().getSystemEventQueue().push(new SwtAwtEventQueue());
|
||||||
|
SwtAwtEventQueue.registerErrorHandler();
|
||||||
|
UIManager.setLookAndFeel(lafClassName);
|
||||||
|
SwtAwtEventQueue.handleGdkError();
|
||||||
|
} else {
|
||||||
|
UIManager.setLookAndFeel(lafClassName);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
DavGatewayTray.warn(new BundleMessage("LOG_UNABLE_TO_SET_LOOK_AND_FEEL"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create tray icon and register frame listeners.
|
* Create tray icon and register frame listeners.
|
||||||
*/
|
*/
|
||||||
public void init() {
|
public void init() {
|
||||||
// set native look and feel
|
|
||||||
try {
|
|
||||||
String lafClassName = UIManager.getSystemLookAndFeelClassName();
|
|
||||||
// workaround for bug when SWT and AWT both try to access Gtk
|
|
||||||
if (lafClassName.indexOf("gtk") > 0) {
|
|
||||||
lafClassName = UIManager.getCrossPlatformLookAndFeelClassName();
|
|
||||||
// replace AWT event queue Gdk error handler to avoid application crash
|
|
||||||
Toolkit.getDefaultToolkit().getSystemEventQueue().push(new SwtAwtEventQueue());
|
|
||||||
SwtAwtEventQueue.registerErrorHandler();
|
|
||||||
UIManager.setLookAndFeel(lafClassName);
|
|
||||||
SwtAwtEventQueue.handleGdkError();
|
|
||||||
} else {
|
|
||||||
UIManager.setLookAndFeel(lafClassName);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
DavGatewayTray.warn(new BundleMessage("LOG_UNABLE_TO_SET_LOOK_AND_FEEL"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
new Thread("SWT") {
|
new Thread("SWT") {
|
||||||
@Override
|
@Override
|
||||||
@ -225,12 +235,15 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
|
|
||||||
MenuItem aboutItem = new MenuItem(popup, SWT.PUSH);
|
MenuItem aboutItem = new MenuItem(popup, SWT.PUSH);
|
||||||
aboutItem.setText(BundleMessage.format("UI_ABOUT"));
|
aboutItem.setText(BundleMessage.format("UI_ABOUT"));
|
||||||
final AboutFrame aboutFrame = new AboutFrame();
|
|
||||||
aboutItem.addListener(SWT.Selection, new Listener() {
|
aboutItem.addListener(SWT.Selection, new Listener() {
|
||||||
public void handleEvent(Event event) {
|
public void handleEvent(Event event) {
|
||||||
SwingUtilities.invokeLater(
|
SwingUtilities.invokeLater(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (aboutFrame == null) {
|
||||||
|
setLookAndFeel();
|
||||||
|
aboutFrame = new AboutFrame();
|
||||||
|
}
|
||||||
aboutFrame.update();
|
aboutFrame.update();
|
||||||
aboutFrame.setVisible(true);
|
aboutFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
@ -238,12 +251,16 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final SettingsFrame settingsFrame = new SettingsFrame();
|
|
||||||
trayItem.addListener(SWT.DefaultSelection, new Listener() {
|
trayItem.addListener(SWT.DefaultSelection, new Listener() {
|
||||||
public void handleEvent(Event event) {
|
public void handleEvent(Event event) {
|
||||||
SwingUtilities.invokeLater(
|
SwingUtilities.invokeLater(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// create frame on first call
|
||||||
|
if (settingsFrame == null) {
|
||||||
|
setLookAndFeel();
|
||||||
|
settingsFrame = new SettingsFrame();
|
||||||
|
}
|
||||||
settingsFrame.reload();
|
settingsFrame.reload();
|
||||||
settingsFrame.setVisible(true);
|
settingsFrame.setVisible(true);
|
||||||
// workaround for focus on first open
|
// workaround for focus on first open
|
||||||
@ -261,6 +278,11 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
SwingUtilities.invokeLater(
|
SwingUtilities.invokeLater(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// create frame on first call
|
||||||
|
if (settingsFrame == null) {
|
||||||
|
setLookAndFeel();
|
||||||
|
settingsFrame = new SettingsFrame();
|
||||||
|
}
|
||||||
settingsFrame.reload();
|
settingsFrame.reload();
|
||||||
settingsFrame.setVisible(true);
|
settingsFrame.setVisible(true);
|
||||||
// workaround for focus on first open
|
// workaround for focus on first open
|
||||||
@ -281,6 +303,7 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
Logger rootLogger = Logger.getRootLogger();
|
Logger rootLogger = Logger.getRootLogger();
|
||||||
LF5Appender lf5Appender = (LF5Appender) rootLogger.getAppender("LF5Appender");
|
LF5Appender lf5Appender = (LF5Appender) rootLogger.getAppender("LF5Appender");
|
||||||
if (lf5Appender == null) {
|
if (lf5Appender == null) {
|
||||||
|
setLookAndFeel();
|
||||||
logBrokerMonitor = new LogBrokerMonitor(LogLevel.getLog4JLevels()) {
|
logBrokerMonitor = new LogBrokerMonitor(LogLevel.getLog4JLevels()) {
|
||||||
@Override
|
@Override
|
||||||
protected void closeAfterConfirm() {
|
protected void closeAfterConfirm() {
|
||||||
@ -308,6 +331,11 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
|
|
||||||
// display settings frame on first start
|
// display settings frame on first start
|
||||||
if (Settings.isFirstStart()) {
|
if (Settings.isFirstStart()) {
|
||||||
|
// create frame on first call
|
||||||
|
if (settingsFrame == null) {
|
||||||
|
setLookAndFeel();
|
||||||
|
settingsFrame = new SettingsFrame();
|
||||||
|
}
|
||||||
settingsFrame.setVisible(true);
|
settingsFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
synchronized (mainThread) {
|
synchronized (mainThread) {
|
||||||
@ -341,8 +369,12 @@ public class SwtGatewayTray implements DavGatewayTrayInterface {
|
|||||||
// already disposed
|
// already disposed
|
||||||
}
|
}
|
||||||
// dispose AWT frames
|
// dispose AWT frames
|
||||||
settingsFrame.dispose();
|
if (settingsFrame != null) {
|
||||||
aboutFrame.dispose();
|
settingsFrame.dispose();
|
||||||
|
}
|
||||||
|
if (aboutFrame != null) {
|
||||||
|
aboutFrame.dispose();
|
||||||
|
}
|
||||||
if (logBrokerMonitor != null) {
|
if (logBrokerMonitor != null) {
|
||||||
logBrokerMonitor.dispose();
|
logBrokerMonitor.dispose();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user