KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > ui > Util


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.ws7.ui;
21
22 import java.awt.Toolkit JavaDoc;
23
24 import javax.swing.text.AttributeSet JavaDoc;
25 import javax.swing.text.BadLocationException JavaDoc;
26 import javax.swing.text.PlainDocument JavaDoc;
27 import javax.swing.SwingUtilities JavaDoc;
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     /**
37      * Creates a new instance of Util
38      */

39     public Util() {
40     }
41
42     ///Numeric Document
43
public static NumericDocument getNumericDocument() {
44         return new NumericDocument();
45     }
46
47     public static class NumericDocument extends PlainDocument JavaDoc {
48         private Toolkit JavaDoc toolkit = Toolkit.getDefaultToolkit();
49         
50         public void insertString(int offs, String JavaDoc str, AttributeSet JavaDoc a)
51             throws BadLocationException JavaDoc {
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 JavaDoc(r, 0, j), a);
63         }
64     } // class NumericDocument
65

66     public static void showInformation(String JavaDoc msg) {
67         internalShowMessage(msg, null, NotifyDescriptor.INFORMATION_MESSAGE);
68     }
69     
70     public static void showInformation(String JavaDoc msg, String JavaDoc title) {
71         internalShowMessage(msg, title, NotifyDescriptor.INFORMATION_MESSAGE);
72     }
73     
74     public static Object JavaDoc showWarning(final String JavaDoc 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 JavaDoc showWarning(final String JavaDoc msg, final String JavaDoc 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 JavaDoc msg) {
87         internalShowMessage(msg, null, NotifyDescriptor.ERROR_MESSAGE);
88     }
89     
90     public static void showError(String JavaDoc msg, String JavaDoc title){
91         internalShowMessage(msg, title, NotifyDescriptor.ERROR_MESSAGE);
92     }
93     
94     public static void setStatusBar(final String JavaDoc msg) {
95         SwingUtilities.invokeLater(new Runnable JavaDoc() {
96                 public void run() {
97                     StatusDisplayer.getDefault().setStatusText(msg);
98                 }
99             });
100     }
101
102     private static void internalShowMessage(final String JavaDoc msg, final String JavaDoc title, final int type) {
103         SwingUtilities.invokeLater(new Runnable JavaDoc() {
104                 public void run() {
105                     NotifyDescriptor d = new NotifyDescriptor.Message(msg, type);
106
107                     if (title != null) {
108                         d.setTitle(title);
109                     } // end of if (title != null)
110

111                     DialogDisplayer.getDefault().notify(d);
112                 }
113             });
114     }
115 }
116
Popular Tags