Advertisement
Guest User

MessageType

a guest
Jun 1st, 2010
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 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.net.URL;
  9. import javax.swing.Icon;
  10. import javax.swing.ImageIcon;
  11. import org.openide.NotifyDescriptor;
  12.  
  13. /**
  14.  *
  15.  * @author qbeukes.blogspot.com, used by metalklesk
  16.  */
  17. public enum MessageType {
  18.     PLAIN   (NotifyDescriptor.PLAIN_MESSAGE,       null),
  19.     INFO    (NotifyDescriptor.INFORMATION_MESSAGE, "info.png"),
  20.     QUESTION(NotifyDescriptor.QUESTION_MESSAGE,    "question.png"),
  21.     ERROR   (NotifyDescriptor.ERROR_MESSAGE,       "error.png"),
  22.     WARNING (NotifyDescriptor.WARNING_MESSAGE,     "warning.png");
  23.  
  24.     private int notifyDescriptorType;
  25.  
  26.     private Icon icon;
  27.  
  28.     private MessageType(int notifyDescriptorType, String resourceName) {
  29.         this.notifyDescriptorType = notifyDescriptorType;
  30.         if (resourceName == null) {
  31.             icon = new ImageIcon();
  32.         } else {
  33.             icon = loadIcon(resourceName);
  34.         }
  35.     }
  36.  
  37.     private static Icon loadIcon(String resourceName) {
  38.         URL resource = MessageType.class.getResource("images/" + resourceName);
  39.         System.out.println(resource);
  40.         if (resource == null) {
  41.             return new ImageIcon();
  42.         }
  43.        
  44.         return new ImageIcon(resource);
  45.     }
  46.  
  47.     int getNotifyDescriptorType() {
  48.         return notifyDescriptorType;
  49.     }
  50.  
  51.     Icon getIcon() {
  52.         return icon;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement