1   package net.sf.jhylafax;
2   
3   import java.awt.AWTException;
4   import java.awt.PopupMenu;
5   import java.awt.SystemTray;
6   import java.awt.TrayIcon;
7   import java.awt.event.ActionEvent;
8   import java.awt.event.ActionListener;
9   
10  import javax.swing.ImageIcon;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  import org.xnap.commons.gui.util.IconHelper;
15  
16  public class FaxTray {
17  
18  	private final static Log logger = LogFactory.getLog(JHylaFAX.class);
19  	
20  	private TrayIcon trayIcon;
21  
22  	private PopupMenu popup = new PopupMenu();
23  
24  	private boolean supported = false;
25  	
26  	public FaxTray() {
27  		if (!SystemTray.isSupported()) {
28  			return;
29  		}
30  
31  		ImageIcon icon = IconHelper.getSystemTrayIcon("kdeprintfax.png");
32  		if (icon == null) {
33  			logger.warn("Could not find icon for system tray");
34  			return;
35  		}
36  
37  		SystemTray tray = SystemTray.getSystemTray();
38  		trayIcon = new TrayIcon(icon.getImage(), "JHylaFAX", popup);
39  
40  		ActionListener actionListener = new ActionListener() {
41  			public void actionPerformed(ActionEvent e) {
42  				JHylaFAX.getInstance().setVisible(true);
43  			}
44  		};
45  
46  		trayIcon.setImageAutoSize(true);
47  		trayIcon.addActionListener(actionListener);
48  
49  		try {
50  			tray.add(trayIcon);
51  		} catch (AWTException e) {
52  			logger.warn("Could not add icon to system tray", e);
53  			return;			
54  		}
55  		
56  		supported = true;
57  	}
58  	
59  	public boolean isSupported() {
60  		return supported;
61  	}
62  	
63  	public PopupMenu getPopupMenu() {
64  		return popup;
65  	}
66  
67  }