1 19 20 package org.netbeans.modules.j2ee.sun.ws7.ui; 21 22 import java.awt.Toolkit ; 23 24 import javax.swing.text.AttributeSet ; 25 import javax.swing.text.BadLocationException ; 26 import javax.swing.text.PlainDocument ; 27 import javax.swing.SwingUtilities ; 28 29 import org.openide.DialogDescriptor; 30 import org.openide.DialogDisplayer; 31 import org.openide.NotifyDescriptor; 32 import org.openide.WizardDescriptor; 33 import org.openide.awt.StatusDisplayer; 34 35 public class Util { 36 39 public Util() { 40 } 41 42 public static NumericDocument getNumericDocument() { 44 return new NumericDocument(); 45 } 46 47 public static class NumericDocument extends PlainDocument { 48 private Toolkit toolkit = Toolkit.getDefaultToolkit(); 49 50 public void insertString(int offs, String str, AttributeSet a) 51 throws BadLocationException { 52 char[] s = str.toCharArray(); 53 char[] r = new char[s.length]; 54 int j = 0; 55 for (int i = 0; i < r.length; i++) { 56 if (Character.isDigit(s[i])) { 57 r[j++] = s[i]; 58 } else { 59 toolkit.beep(); 60 } 61 } 62 super.insertString(offs, new String (r, 0, j), a); 63 } 64 } 66 public static void showInformation(String msg) { 67 internalShowMessage(msg, null, NotifyDescriptor.INFORMATION_MESSAGE); 68 } 69 70 public static void showInformation(String msg, String title) { 71 internalShowMessage(msg, title, NotifyDescriptor.INFORMATION_MESSAGE); 72 } 73 74 public static Object showWarning(final String msg) { 75 NotifyDescriptor d = new NotifyDescriptor.Confirmation(msg, NotifyDescriptor.OK_CANCEL_OPTION, 76 NotifyDescriptor.WARNING_MESSAGE); 77 return DialogDisplayer.getDefault().notify(d); 78 } 79 80 public static Object showWarning(final String msg, final String title) { 81 NotifyDescriptor d = new NotifyDescriptor.Confirmation(msg, title, NotifyDescriptor.OK_CANCEL_OPTION, 82 NotifyDescriptor.WARNING_MESSAGE); 83 return DialogDisplayer.getDefault().notify(d); 84 } 85 86 public static void showError(String msg) { 87 internalShowMessage(msg, null, NotifyDescriptor.ERROR_MESSAGE); 88 } 89 90 public static void showError(String msg, String title){ 91 internalShowMessage(msg, title, NotifyDescriptor.ERROR_MESSAGE); 92 } 93 94 public static void setStatusBar(final String msg) { 95 SwingUtilities.invokeLater(new Runnable () { 96 public void run() { 97 StatusDisplayer.getDefault().setStatusText(msg); 98 } 99 }); 100 } 101 102 private static void internalShowMessage(final String msg, final String title, final int type) { 103 SwingUtilities.invokeLater(new Runnable () { 104 public void run() { 105 NotifyDescriptor d = new NotifyDescriptor.Message(msg, type); 106 107 if (title != null) { 108 d.setTitle(title); 109 } 111 DialogDisplayer.getDefault().notify(d); 112 } 113 }); 114 } 115 } 116 | Popular Tags |