KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > metainf > SUtil


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.apisupport.project.metainf;
20
21 import java.awt.Component JavaDoc;
22 import java.awt.Dimension JavaDoc;
23 import java.awt.Toolkit JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29 import org.netbeans.modules.apisupport.project.NbModuleProject;
30 import org.netbeans.modules.apisupport.project.Util;
31 import org.openide.filesystems.FileObject;
32
33 /**
34  * Wrapper for testing purpose. I am too lazy to initialize NbModuleProject project in unittests
35  * so in order to I created special usecase when the project is null
36  * @author pzajac
37  */

38  class SUtil {
39     static final String JavaDoc LOG_SET_KEYS = "setting keys";
40     static final String JavaDoc LOG_COMPUTE_KEYS = "computing services keys";
41     static final String JavaDoc LOG_END_COMPUTE_KEYS = "compute keys finished";
42     static final String JavaDoc LOG_SERVICE_NODE_HANDLER_ADD_NOTIFY = "ServiceNodeHandler.addNotify()";
43     static Logger JavaDoc logger ;
44     
45     static FileObject projectDir;
46     static Set JavaDoc platformJars;
47     /** Creates a new instance of SUtil */
48     public SUtil() {
49     }
50
51     static Logger JavaDoc getLogger() {
52         if (logger == null) {
53          logger = Logger.getLogger("apisupport.meta-inf"); // NOI18N
54
logger.setLevel(Level.OFF);
55         }
56         return logger;
57     }
58     
59     static void log(String JavaDoc message) {
60         getLogger().log(Level.INFO, message);
61     }
62
63 // static String getCodeNameBase(NbModuleProject nbModuleProject) {
64
// return (nbModuleProject == null) ?
65
// codeBaseName :
66
// nbModuleProject.getCodeNameBase();
67
// }
68

69 // static FileObject getServicesFolder(NbModuleProject project) {
70
// FileObject dir = (project != null) ? project.getProjectDirectory() : projectDir;
71
// return (dir != null) ?
72
// dir.getFileObject("src/" + Service.META_INF_SERVICES):
73
// null;
74
// }
75

76    static FileObject getServicesFolder(NbModuleProject project,boolean create) throws IOException JavaDoc {
77         FileObject srcDir = project.getSourceDirectory();
78         if (srcDir != null) {
79             FileObject services = srcDir.getFileObject("META-INF/services"); //NOI18N
80
if (services == null && create) {
81                 FileObject fo = srcDir.getFileObject("META-INF"); //NOI18N
82
if (fo == null) {
83                     fo = srcDir.createFolder("META-INF"); //NOI18N
84
}
85                 services = fo.createFolder("services"); //NOI18N
86
}
87             return services;
88         } else {
89             Util.err.log(project.getProjectDirectory().getPath() + " doesn't contain source directory.");
90             return null;
91         }
92     }
93
94     static Set JavaDoc getPlatformJars() {
95     return (platformJars == null) ?
96         Collections.EMPTY_SET:
97         platformJars;
98     }
99
100        /**
101      * Centers the component <CODE>c</CODE> on the screen.
102      *
103      * @param c the component to center
104      * @see #centerComponent(Component, Component)
105      */

106     public static void centerComponent(Component JavaDoc c) {
107         centerComponent(c, null);
108     }
109  
110     /**
111      * Centers the component <CODE>c</CODE> on component <CODE>p</CODE>.
112      * If <CODE>p</CODE> is <CODE>null</CODE>, the component <CODE>c</CODE>
113      * will be centered on the screen.
114      *
115      * @param c the component to center
116      * @param p the parent component to center on or null for screen
117      * @see #centerComponent(Component)
118      */

119     public static void centerComponent(Component JavaDoc c, Component JavaDoc p) {
120         if(c == null) {
121             return;
122         }
123         Dimension JavaDoc d = (p != null ? p.getSize() :
124             Toolkit.getDefaultToolkit().getScreenSize()
125         );
126         c.setLocation(
127             Math.max(0, (d.getSize().width/2) - (c.getSize().width/2)),
128             Math.max(0, (d.getSize().height/2) - (c.getSize().height/2))
129         );
130     }
131
132 // public static Project getProject(Node[] nodes) {
133
// ArrayList dobjs = new ArrayList();
134
// Project prj = null;
135
// if (nodes.length == 1) {
136
// prj = (Project) nodes[0].getLookup().lookup(Project.class);
137
// }
138
// if (prj == null) {
139
// for(int n = 0 ; n < nodes.length ; n++) {
140
// DataObject dobj = (DataObject) nodes[n].getCookie(DataObject.class);
141
// if (dobj == null) {
142
// return null;
143
// }
144
// dobjs.add(dobj);
145
// }
146
// prj = getProject(dobjs);
147
// }
148
// return prj;
149
// }
150

151 }
152
Popular Tags