1 19 20 package org.netbeans.modules.xml.wsdl.ui.wizard; 21 22 import java.awt.Component ; 23 import javax.swing.JComponent ; 24 import javax.swing.JLabel ; 25 import javax.swing.text.JTextComponent ; 26 import org.openide.WizardDescriptor; 27 28 32 public class Utilities { 33 34 public static String [] createSteps(String [] before, WizardDescriptor.Panel[] panels) { 35 int diff = 0; 38 if (before == null) { 39 before = new String [0]; 40 } else if (before.length > 0) { 41 diff = ("...".equals(before[before.length - 1])) ? 1 : 0; } 43 String [] res = new String [ (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 document, String replaceFrom, String replaceTo) { 55 javax.swing.text.AbstractDocument doc = (javax.swing.text.AbstractDocument )document; 56 int len = replaceFrom.length(); 57 try { 58 String 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 ex){} 66 } 67 68 71 public static JTextComponent findTextFieldForLabel(JComponent component, String text) { 72 JLabel label = findLabel(component, text); 73 if(label != null) { 74 Component comp = label.getLabelFor(); 75 if (comp!=null && (comp instanceof JTextComponent )) return (JTextComponent )comp; 76 } 77 return null; 78 } 79 80 private static JLabel findLabel(JComponent component, String text) { 81 Component [] components = component.getComponents(); 82 for (Component comp : components) { 83 if (comp instanceof JLabel ) { 84 if (((JLabel ) comp).getText().equals(text)) { 85 return (JLabel ) comp; 86 } 87 } else if (comp instanceof JComponent ){ 88 return findLabel((JComponent ) comp, text); 89 } 90 } 91 return null; 92 } 93 } 94 | Popular Tags |