2009-07-21 04:39:18 -04:00
|
|
|
/*
|
|
|
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
|
|
|
* Copyright (C) 2009 Mickael Guessant
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2009-04-03 03:38:31 -04:00
|
|
|
package davmail.ui.tray;
|
2009-04-02 11:08:34 -04:00
|
|
|
|
2009-04-23 10:54:06 -04:00
|
|
|
import davmail.BundleMessage;
|
2009-05-17 18:24:43 -04:00
|
|
|
import davmail.DavGateway;
|
2010-05-13 15:38:12 -04:00
|
|
|
import davmail.ui.OSXAdapter;
|
|
|
|
import info.growl.Growl;
|
|
|
|
import info.growl.GrowlException;
|
|
|
|
import info.growl.GrowlUtils;
|
|
|
|
import org.apache.log4j.Level;
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.awt.image.RenderedImage;
|
2009-04-02 11:08:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extended Awt tray with OSX extensions.
|
|
|
|
*/
|
2012-08-24 05:19:54 -04:00
|
|
|
@SuppressWarnings("Since15")
|
2009-04-02 11:08:34 -04:00
|
|
|
public class OSXAwtGatewayTray extends AwtGatewayTray {
|
2009-12-20 05:51:02 -05:00
|
|
|
protected static final String OSX_TRAY_ACTIVE_PNG = "osxtray2.png";
|
|
|
|
protected static final String OSX_TRAY_PNG = "osxtray.png";
|
|
|
|
protected static final String OSX_TRAY_INACTIVE_PNG = "osxtrayinactive.png";
|
|
|
|
|
2010-05-13 15:38:12 -04:00
|
|
|
private static final Logger LOGGER = Logger.getLogger(OSXAwtGatewayTray.class);
|
|
|
|
|
2009-09-04 04:46:39 -04:00
|
|
|
/**
|
|
|
|
* Exit DavMail Gateway.
|
|
|
|
*
|
|
|
|
* @return true
|
|
|
|
*/
|
2009-12-20 05:51:02 -05:00
|
|
|
@SuppressWarnings({"SameReturnValue", "UnusedDeclaration"})
|
2009-04-02 11:08:34 -04:00
|
|
|
public boolean quit() {
|
2009-05-17 18:24:43 -04:00
|
|
|
DavGateway.stop();
|
|
|
|
// dispose frames
|
|
|
|
settingsFrame.dispose();
|
|
|
|
aboutFrame.dispose();
|
|
|
|
if (logBrokerMonitor != null) {
|
|
|
|
logBrokerMonitor.dispose();
|
|
|
|
}
|
2009-04-02 11:08:34 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void createAndShowGUI() {
|
|
|
|
System.setProperty("apple.laf.useScreenMenuBar", "true");
|
|
|
|
super.createAndShowGUI();
|
2009-07-06 09:54:58 -04:00
|
|
|
trayIcon.removeActionListener(settingsListener);
|
2009-04-02 11:08:34 -04:00
|
|
|
try {
|
|
|
|
OSXAdapter.setAboutHandler(this, AwtGatewayTray.class.getDeclaredMethod("about", (Class[]) null));
|
|
|
|
OSXAdapter.setPreferencesHandler(this, AwtGatewayTray.class.getDeclaredMethod("preferences", (Class[]) null));
|
|
|
|
OSXAdapter.setQuitHandler(this, OSXAwtGatewayTray.class.getDeclaredMethod("quit", (Class[]) null));
|
|
|
|
} catch (Exception e) {
|
2009-04-23 10:54:06 -04:00
|
|
|
DavGatewayTray.error(new BundleMessage("LOG_ERROR_LOADING_OSXADAPTER"), e);
|
2009-04-02 11:08:34 -04:00
|
|
|
}
|
|
|
|
}
|
2009-11-24 17:38:20 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getTrayIconPath() {
|
2009-12-20 05:51:02 -05:00
|
|
|
return OSXAwtGatewayTray.OSX_TRAY_PNG;
|
2009-11-24 17:38:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getTrayIconActivePath() {
|
2009-12-20 05:51:02 -05:00
|
|
|
return OSXAwtGatewayTray.OSX_TRAY_ACTIVE_PNG;
|
2009-11-24 17:38:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getTrayIconInactivePath() {
|
2009-12-20 05:51:02 -05:00
|
|
|
return OSXAwtGatewayTray.OSX_TRAY_INACTIVE_PNG;
|
2009-11-24 17:38:20 -05:00
|
|
|
}
|
2010-05-13 15:38:12 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void displayMessage(final String message, final Level level) {
|
|
|
|
if (!GrowlUtils.isGrowlLoaded()) {
|
|
|
|
super.displayMessage(message, level);
|
|
|
|
} else {
|
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (trayIcon != null) {
|
|
|
|
Icon icon = null;
|
|
|
|
if (level.equals(Level.INFO)) {
|
|
|
|
icon = UIManager.getIcon("OptionPane.informationIcon");
|
|
|
|
} else if (level.equals(Level.WARN)) {
|
|
|
|
icon = UIManager.getIcon("OptionPane.warningIcon");
|
|
|
|
} else if (level.equals(Level.ERROR)) {
|
|
|
|
icon = UIManager.getIcon("OptionPane.errorIcon");
|
|
|
|
}
|
|
|
|
|
2011-04-03 09:14:29 -04:00
|
|
|
if (icon != null && message != null && message.length() > 0) {
|
2010-05-13 15:38:12 -04:00
|
|
|
try {
|
|
|
|
String title = BundleMessage.format("UI_DAVMAIL_GATEWAY");
|
|
|
|
Growl growl = GrowlUtils.getGrowlInstance("DavMail");
|
|
|
|
growl.addNotification(title, true);
|
|
|
|
growl.register();
|
|
|
|
growl.sendNotification(title, title, message, (RenderedImage) getImageForIcon(icon));
|
|
|
|
} catch (GrowlException growlException) {
|
|
|
|
LOGGER.error(growlException);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trayIcon.setToolTip(BundleMessage.format("UI_DAVMAIL_GATEWAY") + '\n' + message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Image getImageForIcon(Icon icon) {
|
|
|
|
BufferedImage bufferedimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
|
|
|
Graphics g = bufferedimage.getGraphics();
|
|
|
|
icon.paintIcon(null, g, 0, 0);
|
|
|
|
g.dispose();
|
|
|
|
return bufferedimage;
|
|
|
|
}
|
2009-04-02 11:08:34 -04:00
|
|
|
}
|