1 20 21 package org.jdesktop.jdic.tray; 22 23 24 import org.jdesktop.jdic.tray.internal.ServiceManager; 25 import org.jdesktop.jdic.tray.internal.TrayIconService; 26 27 import java.awt.Point ; 28 import javax.swing.Icon ; 29 import javax.swing.JPopupMenu ; 30 import java.awt.event.ActionListener ; 31 32 33 43 44 45 public class TrayIcon { 46 47 TrayIconService tis; 48 49 53 public TrayIcon(Icon i) { 54 this(i, null, null); 55 } 56 57 63 64 public TrayIcon(Icon icon, String caption) { 65 this(icon, caption, null); 66 } 67 68 75 public TrayIcon(Icon icon, String caption, JPopupMenu popup) { 76 tis = (TrayIconService) 77 ServiceManager.getService(ServiceManager.TRAY_ICON_SERVICE); 78 setIcon(icon); 79 setCaption(caption); 80 setPopupMenu(popup); 81 } 82 83 88 89 public void setIcon(Icon icon) { 90 if (tis != null) { 91 tis.setIcon(icon); 92 } 93 } 94 95 100 101 public void setPopupMenu(JPopupMenu popup) { 102 if (tis != null) { 103 tis.setPopupMenu(popup); 104 } 105 } 106 107 112 public void setToolTip(String tooltip) { 113 setCaption(tooltip); 114 } 115 116 122 public void addActionListener(ActionListener listener) { 123 if (tis != null) { 124 tis.addActionListener(listener); 125 } 126 } 127 128 134 public void removeActionListener(ActionListener listener) { 135 if (tis != null) { 136 tis.removeActionListener(listener); 137 } 138 } 139 140 145 public void setCaption(String caption) { 146 if (tis != null) { 147 tis.setCaption(caption); 148 } 149 } 150 151 158 public void setIconAutoSize(boolean autosize) { 159 if (tis != null) { 160 tis.setIconAutoSize(autosize); 161 } 162 } 163 164 TrayIconService getTrayIconService() { 165 return tis; 166 } 167 168 172 public Point getLocationOnScreen() { 173 Point p = null; 174 175 if (tis != null) { 176 p = tis.getLocationOnScreen(); 177 } 178 179 return p; 180 } 181 182 186 187 public static final int INFO_MESSAGE_TYPE = 0; 188 189 public static final int ERROR_MESSAGE_TYPE = 1; 190 191 public static final int WARNING_MESSAGE_TYPE = 2; 192 193 public static final int NONE_MESSAGE_TYPE = 3; 194 195 212 public void displayMessage(String caption, String text, int type)throws NullPointerException { 213 if(caption == null && text == null) 214 throw new NullPointerException ("Both caption and text are null."); 215 if(tis != null) 216 tis.showBalloonMessage(caption, text, type); 217 } 218 219 224 public void addBalloonActionListener(ActionListener listener) { 225 if (tis != null) { 226 tis.addBalloonActionListener(listener); 227 } 228 } 229 235 public void removeBalloonActionListener(ActionListener listener){ 236 if (tis != null) { 237 tis.removeBalloonActionListener(listener); 238 } 239 } 240 } 241 | Popular Tags |