/**
* MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
* Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/******************************************************************************\
*
* This product was developed by
*
* SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
*
* a government company established under Brazilian law (5.615/70),
* at Department of Development of Porto Alegre.
*
\******************************************************************************/
package serpro.mailarchiver.util;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.util.ArrayList;
import java.util.List;
import serpro.mailarchiver.Version;
import javax.imageio.ImageIO;
public class TrayIconAdapter {
private static final serpro.mailarchiver.util.Logger log = serpro.mailarchiver.util.Logger.getLocalLogger();
private final TrayIcon trayIcon;
public TrayIconAdapter() {
if(SystemTray.isSupported()) {
TrayIcon ti;
try {
Image image = ImageIO.read(getClass().getResourceAsStream("/serpro/mailarchiver/resources/mailarchiver_icon.png"));
ti = new TrayIcon(image);
ti.setImageAutoSize(true);
SystemTray tray = SystemTray.getSystemTray();
tray.add(ti);
}
catch(Exception ex) {
log.error(ex, "TrayIcon could not be added.");
ti = null;
}
trayIcon = ti;
}
else {
log.error("System Tray is not supported by the current platform.");
trayIcon = null;
}
updateToolTip();
}
private List tooltips = new ArrayList();
public void addToolTip(String tooltip) {
tooltips.add(tooltip);
updateToolTip();
}
public void removeToolTip(String tooltip) {
tooltips.remove(tooltip);
updateToolTip();
}
private void updateToolTip() {
StringBuilder tooltip = new StringBuilder();
tooltip.append(Version.FULL);
for(String tt : tooltips) {
tooltip.append("\n").append(tt);
}
String s = tooltip.toString();
if(trayIcon != null) {
trayIcon.setToolTip(s);
}
log.info("updateToolTip:%n%n%s", s);
}
}