1 19 package org.netbeans.modules.xml.tools.generator; 20 21 import java.awt.Font ; 22 import java.awt.FontMetrics ; 23 import javax.swing.*; 24 import org.netbeans.api.java.classpath.ClassPath; 25 26 import org.netbeans.modules.xml.core.lib.AbstractUtil; 27 import org.openide.filesystems.FileObject; 28 29 34 class Util extends AbstractUtil { 35 36 public static final NameCheck JAVA_CHECK = new JavaIdentifierNameCheck(); 37 38 public static final NameCheck NONEMPTY_CHECK = new StringNameCheck(); 39 40 41 public static final Util THIS = new Util(); 42 43 44 private Util () { 45 } 46 47 48 49 public static interface NameCheck { 50 public boolean checkName (String name); 51 } 52 53 54 public static class JavaIdentifierNameCheck implements NameCheck { 55 public boolean checkName (String name) { 56 return name.length() > 0 && org.openide.util.Utilities.isJavaIdentifier(name); 57 } 58 } 59 60 61 public static class StringNameCheck implements NameCheck { 62 public boolean checkName (String name) { 63 return name.length() > 0; 64 } 65 } 66 67 70 public static int getTextCellHeight(JTable table) { 71 JComboBox template = new JComboBox(); 72 return template.getPreferredSize().height; 73 } 74 75 80 public static String findJavaPackage(FileObject fo) { 81 assert fo.isFolder() : fo; 82 ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE); 83 if (cp == null) { 84 return null; 85 } 86 return cp.getResourceName(fo, '.', false); 87 } 88 89 } 90 | Popular Tags |