3 The file is used to provides some useful interfaces
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.frameworkwizard
.common
;
19 import java
.text
.SimpleDateFormat
;
20 import java
.util
.Date
;
21 import java
.util
.List
;
22 import java
.util
.UUID
;
23 import java
.util
.Vector
;
25 import javax
.swing
.JComboBox
;
26 import javax
.swing
.JOptionPane
;
29 The class is used to provides some useful interfaces
35 // The dir user selected to create new package in
37 public static String dirForNewSpd
= null;
45 public static void main(String
[] args
) {
46 System
.out
.println(getCurrentDateTime());
50 Get current date and time and format it as "yyyy-MM-dd HH:mm"
52 @return formatted current date and time
55 public static String
getCurrentDateTime() {
56 Date now
= new Date(System
.currentTimeMillis());
57 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd HH:mm");
58 return sdf
.format(now
);
64 @return the created UUID
67 public static String
generateUuidString() {
68 return UUID
.randomUUID().toString();
72 Use current file separator in the path
78 public static String
convertPathToCurrentOsType(String strPath
) {
79 strPath
= strPath
.replace(DataType
.DOS_FILE_SEPARATOR
, DataType
.FILE_SEPARATOR
);
80 strPath
= strPath
.replace(DataType
.UNIX_FILE_SEPARATOR
, DataType
.FILE_SEPARATOR
);
85 Use Unix file separator in the path
91 public static String
convertPathToUnixType(String strPath
) {
92 strPath
= strPath
.replace(DataType
.DOS_FILE_SEPARATOR
, DataType
.UNIX_FILE_SEPARATOR
);
97 Use Dos file separator in the path
103 public static String
convertPathToDosType(String strPath
) {
104 strPath
= strPath
.replace(DataType
.UNIX_FILE_SEPARATOR
, DataType
.DOS_FILE_SEPARATOR
);
109 Get all system properties and output to the console
112 public static void getSystemProperties() {
113 System
.out
.println(System
.getProperty("java.class.version"));
114 System
.out
.println(System
.getProperty("java.class.path"));
115 System
.out
.println(System
.getProperty("java.ext.dirs"));
116 System
.out
.println(System
.getProperty("os.name"));
117 System
.out
.println(System
.getProperty("os.arch"));
118 System
.out
.println(System
.getProperty("os.version"));
119 System
.out
.println(System
.getProperty("file.separator"));
120 System
.out
.println(System
.getProperty("path.separator"));
121 System
.out
.println(System
.getProperty("line.separator"));
122 System
.out
.println(System
.getProperty("user.name"));
123 System
.out
.println(System
.getProperty("user.home"));
124 System
.out
.println(System
.getProperty("user.dir"));
125 System
.out
.println(System
.getProperty("PATH"));
127 System
.out
.println(System
.getenv("PROCESSOR_REVISION"));
131 Generate selection items for JComboBox by input vector
134 public static void generateComboBoxByVector(JComboBox jcb
, Vector
<String
> vector
) {
136 jcb
.removeAllItems();
138 if (vector
!= null) {
139 for (int index
= 0; index
< vector
.size(); index
++) {
140 jcb
.addItem(vector
.elementAt(index
));
146 Get path only from a path
152 public static String
getFilePathOnly(String filePath
) {
153 String path
= filePath
.substring(0, filePath
.length() - getFileNameOnly(filePath
).length());
154 if (path
.endsWith(DataType
.FILE_SEPARATOR
)) {
155 path
= path
.substring(0, path
.length() - DataType
.FILE_SEPARATOR
.length());
162 Get file name from a path
168 public static String
getFileNameOnly(String filePath
) {
169 File f
= new File(filePath
);
170 return f
.getAbsoluteFile().getName();
173 public static String
getFileNameWithoutExt(String filePath
) {
174 filePath
= getFileNameOnly(filePath
);
175 filePath
= filePath
.substring(0, filePath
.lastIndexOf(DataType
.FILE_EXT_SEPARATOR
));
184 @return wholePath - commonPath
187 public static String
getRelativePath(String wholePath
, String commonPath
) {
190 i
= wholePath
.indexOf(commonPath
);
192 i
= i
+ commonPath
.length();
196 path
= wholePath
.substring(i
);
198 // remove file separator of head
200 if (path
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == 0) {
201 path
= path
.substring(0 + DataType
.DOS_FILE_SEPARATOR
.length());
203 if (path
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == 0) {
204 path
= path
.substring(0 + DataType
.DOS_FILE_SEPARATOR
.length());
207 // remove file separator of rear
209 if (path
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == path
.length() - DataType
.DOS_FILE_SEPARATOR
.length()) {
210 path
= path
.substring(0, path
.length() - DataType
.DOS_FILE_SEPARATOR
.length());
212 if (path
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == path
.length() - DataType
.UNIX_FILE_SEPARATOR
.length()) {
213 path
= path
.substring(0, path
.length() - DataType
.DOS_FILE_SEPARATOR
.length());
216 // convert to UNIX format
218 path
= Tools
.convertPathToUnixType(path
);
223 Convert List ot Vector
229 public static Vector
<String
> convertListToVector(List list
) {
230 Vector
<String
> v
= new Vector
<String
>();
231 if (list
!= null && list
.size() > 0) {
232 for (int index
= 0; index
< list
.size(); index
++) {
233 v
.addElement(list
.get(index
).toString());
240 If the input path missing ext, append the ext to the path
247 public static String
addPathExt(String path
, int type
) {
249 if (type
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
250 match
= DataType
.FILE_EXT_SEPARATOR
+ DataType
.MODULE_SURFACE_AREA_EXT
;
252 if (type
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
253 match
= DataType
.FILE_EXT_SEPARATOR
+ DataType
.PACKAGE_SURFACE_AREA_EXT
;
255 if (type
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
256 match
= DataType
.FILE_EXT_SEPARATOR
+ DataType
.PLATFORM_SURFACE_AREA_EXT
;
258 if (path
.length() <= match
.length()) {
262 if (!(path
.substring(path
.length() - match
.length())).equals(match
)) {
274 public static void showInformationMessage(String arg0
) {
275 JOptionPane
.showConfirmDialog(null, arg0
, "Error", JOptionPane
.DEFAULT_OPTION
, JOptionPane
.INFORMATION_MESSAGE
);
279 if the string doesn't end with a file separator, append it to the string
285 public static String
addFileSeparator(String arg0
) {
286 if (!arg0
.endsWith(DataType
.FILE_SEPARATOR
)) {
287 arg0
= arg0
+ DataType
.FILE_SEPARATOR
;