1 package org.lucane.applications.quicklaunch; 2 import java.awt.event.*; 3 4 import javax.swing.*; 5 6 import org.lucane.client.widgets.DialogBox; 7 8 import com.jeans.trayicon.*; 9 10 public class TrayIcon 11 { 12 private WindowsTrayIcon icon; 13 private SwingTrayPopup popup; 14 15 public TrayIcon(ImageIcon icon, String tooltip) 16 throws Exception 17 { 18 WindowsTrayIcon.initTrayIcon("lucane-client"); 19 20 int height = icon.getIconHeight(); 21 int width = icon.getIconWidth(); 22 23 this.icon = new WindowsTrayIcon(icon.getImage(), height, width); 24 this.icon.setToolTipText(tooltip); 25 26 popup = new SwingTrayPopup(); 27 popup.setTrayIcon(this.icon); 28 } 29 30 public void addMouseListener(MouseListener ml) 31 { 32 this.icon.addMouseListener(ml); 33 } 34 35 public void add(JMenuItem item) 36 { 37 this.popup.add(item); 38 } 39 40 public void addSeparator() 41 { 42 this.popup.addSeparator(); 43 } 44 45 public void setVisible(boolean visible) 46 { 47 this.icon.setVisible(visible); 48 } 49 50 private void showBalloon(String message, String title, int timeout, int flags) 51 throws TrayIconException 52 { 53 this.icon.showBalloon(message, title, timeout, flags); 54 } 55 56 public void showInfo(String message, String title) 57 { 58 try { 59 showBalloon(message, title, 5000, WindowsTrayIcon.BALLOON_INFO); 60 } catch (TrayIconException e) { 61 DialogBox.info(message); 62 } 63 } 64 65 public void showWarning(String message, String title) 66 { 67 try { 68 showBalloon(message, title, 5000, WindowsTrayIcon.BALLOON_WARNING); 69 } catch (TrayIconException e) { 70 DialogBox.error(message); 71 } 72 } 73 74 public void showError(String message, String title) 75 { 76 try { 77 showBalloon(message, title, 10000, WindowsTrayIcon.BALLOON_ERROR); 78 } catch (TrayIconException e) { 79 DialogBox.error(message); 80 } 81 } 82 } | Popular Tags |