View Javadoc
1   /*
2    * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
3    * Copyright (C) 2009  Mickael Guessant
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the 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 General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  package davmail.ui.tray;
20  
21  import davmail.BundleMessage;
22  import org.apache.log4j.Level;
23  
24  import javax.swing.*;
25  import java.awt.*;
26  import java.awt.image.BufferedImage;
27  import java.util.ArrayList;
28  
29  /**
30   * Extended Awt tray with OSX extensions.
31   */
32  public class OSXAwtGatewayTray extends AwtGatewayTray implements OSXTrayInterface {
33      protected static final String OSX_TRAY_ACTIVE_PNG = "osxtray2.png";
34      protected static final String OSX_TRAY_PNG = "osxtray.png";
35      protected static final String OSX_TRAY_INACTIVE_PNG = "osxtrayinactive.png";
36  
37      @Override
38      protected void loadIcons() {
39          image = DavGatewayTray.adjustTrayIcon(DavGatewayTray.loadImage(OSX_TRAY_PNG));
40          activeImage = DavGatewayTray.adjustTrayIcon(DavGatewayTray.loadImage(OSX_TRAY_ACTIVE_PNG));
41          inactiveImage = DavGatewayTray.adjustTrayIcon(DavGatewayTray.loadImage(OSX_TRAY_INACTIVE_PNG));
42  
43          frameIcons = new ArrayList<>();
44          frameIcons.add(DavGatewayTray.loadImage(AwtGatewayTray.TRAY128_PNG));
45          frameIcons.add(DavGatewayTray.loadImage(AwtGatewayTray.TRAY_PNG));
46      }
47  
48  
49      @Override
50      protected void createAndShowGUI() {
51          System.setProperty("apple.laf.useScreenMenuBar", "true");
52          super.createAndShowGUI();
53          trayIcon.removeActionListener(settingsListener);
54          try {
55              new OSXHandler(this);
56          } catch (Exception e) {
57              DavGatewayTray.error(new BundleMessage("LOG_ERROR_LOADING_OSXADAPTER"), e);
58          }
59      }
60  
61      @Override
62      public void displayMessage(final String message, final Level level) {
63          super.displayMessage(message, level);
64      }
65  
66      protected Image getImageForIcon(Icon icon) {
67          BufferedImage bufferedimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
68          Graphics g = bufferedimage.getGraphics();
69          icon.paintIcon(null, g, 0, 0);
70          g.dispose();
71          return bufferedimage;
72      }
73  }