source: contrib/MailArchiver/sources/src/serpro/mailarchiver/util/TrayIconAdapter.java @ 6785

Revision 6785, 3.1 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
1/**
2 * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
3 * Copyright (C) 2012  Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/******************************************************************************\
20*
21*  This product was developed by
22*
23*        SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
24*
25*  a government company established under Brazilian law (5.615/70),
26*  at Department of Development of Porto Alegre.
27*
28\******************************************************************************/
29
30package serpro.mailarchiver.util;
31
32import java.awt.Image;
33import java.awt.SystemTray;
34import java.awt.TrayIcon;
35import java.util.ArrayList;
36import java.util.List;
37
38import serpro.mailarchiver.Version;
39
40import javax.imageio.ImageIO;
41
42public class TrayIconAdapter {
43
44    private static final serpro.mailarchiver.util.Logger log = serpro.mailarchiver.util.Logger.getLocalLogger();
45
46    private final TrayIcon trayIcon;
47
48    public TrayIconAdapter() {
49        if(SystemTray.isSupported()) {
50            TrayIcon ti;
51            try {
52                Image image = ImageIO.read(getClass().getResourceAsStream("/serpro/mailarchiver/resources/mailarchiver_icon.png"));
53
54                ti = new TrayIcon(image);
55                ti.setImageAutoSize(true);
56
57                SystemTray tray = SystemTray.getSystemTray();
58
59                tray.add(ti);
60            }
61            catch(Exception ex) {
62                log.error(ex, "TrayIcon could not be added.");
63                ti = null;
64            }
65
66            trayIcon = ti;
67        }
68        else {
69            log.error("System Tray is not supported by the current platform.");
70            trayIcon = null;
71        }
72
73        updateToolTip();
74    }
75
76    private List<String> tooltips = new ArrayList<String>();
77
78    public void addToolTip(String tooltip) {
79        tooltips.add(tooltip);
80        updateToolTip();
81    }
82
83    public void removeToolTip(String tooltip) {
84       tooltips.remove(tooltip);
85       updateToolTip();
86    }
87
88    private void updateToolTip() {
89        StringBuilder tooltip = new StringBuilder();
90        tooltip.append(Version.FULL);
91
92        for(String tt : tooltips) {
93            tooltip.append("\n").append(tt);
94        }
95
96        String s = tooltip.toString();
97
98        if(trayIcon != null) {
99            trayIcon.setToolTip(s);
100        }
101
102        log.info("updateToolTip:%n%n%s", s);
103    }
104}
Note: See TracBrowser for help on using the repository browser.