Advertisement
Guest User

NotifyUtil

a guest
Jun 1st, 2010
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.85 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package org.metalklesk.utilities;
  7.  
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import org.openide.ErrorManager;
  11. import org.openide.awt.Notification;
  12. import org.openide.awt.NotificationDisplayer;
  13.  
  14. /**
  15.  *
  16.  * @author qbeukes.blogspot.com, used by metalklesk
  17.  */
  18. public class NotifyUtil {
  19.  
  20.     private NotifyUtil() {}
  21.  
  22.     /**
  23.     * Show message with the specified type and action listener
  24.     */
  25.     public static void show(String title, String message, MessageType type, ActionListener actionListener, boolean clear) {
  26.         Notification n = (Notification) NotificationDisplayer.getDefault().notify(title, type.getIcon(), message, actionListener);
  27.         if(clear == true)
  28.             n.clear();
  29.     }
  30.  
  31.     /**
  32.     * Show message with the specified type and a default action which displays the
  33.     * message using {@link MessageUtil} with the same message type
  34.     */
  35.     public static void show(String title, final String message, final MessageType type, boolean clear) {
  36.         ActionListener actionListener = new ActionListener() {
  37.             @Override
  38.             public void actionPerformed(ActionEvent e) {
  39.                 MessageUtil.show(message, type);
  40.             }
  41.         };
  42.  
  43.         show(title, message, type, actionListener, clear);
  44.     }
  45.  
  46.     /**
  47.     * Show an information notification
  48.     * @param message
  49.     */
  50.     public static void info(String title, String message, boolean clear) {
  51.         show(title, message, MessageType.INFO, clear);
  52.     }
  53.  
  54.     /**
  55.     * Show an error notification
  56.     * @param message
  57.     */
  58.     public static void error(String title, String message, boolean clear) {
  59.         show(title, message, MessageType.ERROR, clear);
  60.     }
  61.  
  62.     /**
  63.     * Show an error notification for an exception
  64.     * @param message
  65.     * @param exception
  66.     */
  67.     public static void error(String title, final String message, final Throwable exception , boolean clear) {
  68.         ActionListener actionListener = new ActionListener() {
  69.             @Override
  70.             public void actionPerformed(ActionEvent e) {
  71.                 ErrorManager.getDefault ().notify (exception);
  72.                 //MessageUtil.showException(message, exception);
  73.             }
  74.         };
  75.  
  76.         show(title, message, MessageType.ERROR, actionListener, clear);
  77.     }
  78.  
  79.     /**
  80.     * Show an warning notification
  81.     * @param message
  82.     */
  83.     public static void warn(String title, String message, boolean clear) {
  84.         show(title, message, MessageType.WARNING, clear);
  85.     }
  86.  
  87.     /**
  88.     * Show an plain notification
  89.     * @param message
  90.     */
  91.     public static void plain(String title, String message, boolean clear) {
  92.         show(title, message, MessageType.PLAIN, clear);
  93.     }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement