KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > wizard > Utilities


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.wizard;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.JComponent JavaDoc;
24 import javax.swing.JLabel JavaDoc;
25 import javax.swing.text.JTextComponent JavaDoc;
26 import org.openide.WizardDescriptor;
27
28 /**
29  *
30  * @author mkuchtiak
31  */

32 public class Utilities {
33     
34     public static String JavaDoc[] createSteps(String JavaDoc[] before, WizardDescriptor.Panel[] panels) {
35         //assert panels != null;
36
// hack to use the steps set before this panel processed
37
int diff = 0;
38         if (before == null) {
39             before = new String JavaDoc[0];
40         } else if (before.length > 0) {
41             diff = ("...".equals(before[before.length - 1])) ? 1 : 0; // NOI18N
42
}
43         String JavaDoc[] res = new String JavaDoc[ (before.length - diff) + panels.length];
44         for (int i = 0; i < res.length; i++) {
45             if (i < (before.length - diff)) {
46                 res[i] = before[i];
47             } else {
48                 res[i] = panels[i - before.length + diff].getComponent().getName();
49             }
50         }
51         return res;
52     }
53     
54     public static void replaceInDocument(javax.swing.text.Document JavaDoc document, String JavaDoc replaceFrom, String JavaDoc replaceTo) {
55         javax.swing.text.AbstractDocument JavaDoc doc = (javax.swing.text.AbstractDocument JavaDoc)document;
56         int len = replaceFrom.length();
57         try {
58             String JavaDoc content = doc.getText(0,doc.getLength());
59             int index = content.lastIndexOf(replaceFrom);
60             while (index>=0) {
61                 doc.replace(index,len,replaceTo,null);
62                 content=content.substring(0,index);
63                 index = content.lastIndexOf(replaceFrom);
64             }
65         } catch (javax.swing.text.BadLocationException JavaDoc ex){}
66     }
67     
68     /*
69      * Changes the text of a JLabel in component from oldLabel to newLabel
70      */

71     public static JTextComponent JavaDoc findTextFieldForLabel(JComponent JavaDoc component, String JavaDoc text) {
72         JLabel JavaDoc label = findLabel(component, text);
73         if(label != null) {
74             Component JavaDoc comp = label.getLabelFor();
75             if (comp!=null && (comp instanceof JTextComponent JavaDoc)) return (JTextComponent JavaDoc)comp;
76         }
77         return null;
78     }
79
80     private static JLabel JavaDoc findLabel(JComponent JavaDoc component, String JavaDoc text) {
81         Component JavaDoc[] components = component.getComponents();
82         for (Component JavaDoc comp : components) {
83             if (comp instanceof JLabel JavaDoc) {
84                 if (((JLabel JavaDoc) comp).getText().equals(text)) {
85                     return (JLabel JavaDoc) comp;
86                 }
87             } else if (comp instanceof JComponent JavaDoc){
88                 return findLabel((JComponent JavaDoc) comp, text);
89             }
90         }
91         return null;
92     }
93 }
94
Popular Tags