Advertisement
Guest User

MessageUtil

a guest
Jun 1st, 2010
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 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 org.openide.DialogDisplayer;
  9. import org.openide.NotifyDescriptor;
  10.  
  11. /**
  12.  *
  13.  * @author qbeukes.blogspot.com, used by metalklesk
  14.  */
  15. public class MessageUtil {
  16.  
  17.     private MessageUtil() {}
  18.  
  19.     /**
  20.     * @return The dialog displayer used to show message boxes
  21.     */
  22.     public static DialogDisplayer getDialogDisplayer() {
  23.         return DialogDisplayer.getDefault();
  24.     }
  25.  
  26.     /**
  27.     * Show a message of the specified type
  28.     *
  29.     * @param message
  30.     * @param messageType As in {@link NotifyDescription} message type constants.
  31.     */
  32.     public static void show(String message, MessageType messageType) {
  33.         getDialogDisplayer().notify(new NotifyDescriptor.Message(message,
  34.         messageType.getNotifyDescriptorType()));
  35.     }
  36.  
  37.     /**
  38.     * Show an exception message dialog
  39.     *
  40.     * @param message
  41.     * @param exception
  42.     */
  43.     public static void showException(String message, Throwable exception) {
  44.         getDialogDisplayer().notify(new NotifyDescriptor.Exception(exception, message));
  45.     }
  46.  
  47.     /**
  48.     * Show an information dialog
  49.     * @param message
  50.     */
  51.     public static void info(String message) {
  52.         show(message, MessageType.INFO);
  53.     }
  54.  
  55.     /**
  56.     * Show an error dialog
  57.     * @param message
  58.     */
  59.     public static void error(String message) {
  60.         show(message, MessageType.ERROR);
  61.     }
  62.  
  63.     /**
  64.     * Show an error dialog for an exception
  65.     * @param message
  66.     * @param exception
  67.     */
  68.     public static void error(String message, Throwable exception) {
  69.         showException(message, exception);
  70.     }
  71.  
  72.     /**
  73.     * Show an question dialog
  74.     * @param message
  75.     */
  76.     public static void question(String message) {
  77.         show(message, MessageType.QUESTION);
  78.     }
  79.  
  80.     /**
  81.     * Show an warning dialog
  82.     * @param message
  83.     */
  84.     public static void warn(String message) {
  85.         show(message, MessageType.WARNING);
  86.     }
  87.  
  88.     /**
  89.     * Show an plain dialog
  90.     * @param message
  91.     */
  92.     public static void plain(String message) {
  93.         show(message, MessageType.PLAIN);
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement