KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tools > generator > 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 package org.netbeans.modules.xml.tools.generator;
20
21 import java.awt.Font JavaDoc;
22 import java.awt.FontMetrics JavaDoc;
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 /**
30  *
31  * @author Libor Kramolis
32  * @version 0.2
33  */

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     /** Default and only one instance of this class. */
41     public static final Util THIS = new Util();
42
43     /** Nobody can create instance of it, just me. */
44     private Util () {
45     }
46
47     
48     /** A name checker interface. */
49     public static interface NameCheck {
50         public boolean checkName (String JavaDoc name);
51     }
52
53     /** Passes for java identifiers. */
54     public static class JavaIdentifierNameCheck implements NameCheck {
55         public boolean checkName (String JavaDoc name) {
56             return name.length() > 0 && org.openide.util.Utilities.isJavaIdentifier(name);
57         }
58     }
59
60     /** Passes for any non-empty string. */
61     public static class StringNameCheck implements NameCheck {
62         public boolean checkName (String JavaDoc name) {
63             return name.length() > 0;
64         }
65     }
66
67     /**
68      * Calculate JTable cell height for textual rows.
69      */

70     public static int getTextCellHeight(JTable table) {
71         JComboBox template = new JComboBox();
72         return template.getPreferredSize().height;
73     }
74     
75     /**
76      * Finds Java package name for the given folder.
77      * @return package name separated by dots or null if package name
78      * could not be find for the given file
79      */

80     public static String JavaDoc 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