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());
163 Get file name from a path
169 public static String
getFileNameOnly(String filePath
) {
170 File f
= new File(filePath
);
171 return f
.getAbsoluteFile().getName();
174 public static String
getFileNameWithoutExt(String filePath
) {
175 filePath
= getFileNameOnly(filePath
);
176 filePath
= filePath
.substring(0, filePath
.lastIndexOf(DataType
.FILE_EXT_SEPARATOR
));
185 @return wholePath - commonPath
188 public static String
getRelativePath(String wholePath
, String commonPath
) {
191 i
= wholePath
.indexOf(commonPath
);
193 i
= i
+ commonPath
.length();
197 path
= wholePath
.substring(i
);
199 // remove file separator of head
201 if (path
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == 0) {
202 path
= path
.substring(0 + DataType
.DOS_FILE_SEPARATOR
.length());
204 if (path
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == 0) {
205 path
= path
.substring(0 + DataType
.DOS_FILE_SEPARATOR
.length());
208 // remove file separator of rear
210 if (path
.indexOf(DataType
.DOS_FILE_SEPARATOR
) == path
.length() - DataType
.DOS_FILE_SEPARATOR
.length()) {
211 path
= path
.substring(0, path
.length() - DataType
.DOS_FILE_SEPARATOR
.length());
213 if (path
.indexOf(DataType
.UNIX_FILE_SEPARATOR
) == path
.length() - DataType
.UNIX_FILE_SEPARATOR
.length()) {
214 path
= path
.substring(0, path
.length() - DataType
.DOS_FILE_SEPARATOR
.length());
217 // convert to UNIX format
219 path
= Tools
.convertPathToUnixType(path
);
224 Convert List ot Vector
230 public static Vector
<String
> convertListToVector(List list
) {
231 Vector
<String
> v
= new Vector
<String
>();
232 if (list
!= null && list
.size() > 0) {
233 for (int index
= 0; index
< list
.size(); index
++) {
234 v
.addElement(list
.get(index
).toString());
241 If the input path missing ext, append the ext to the path
248 public static String
addPathExt(String path
, int type
) {
250 if (type
== DataType
.RETURN_TYPE_MODULE_SURFACE_AREA
) {
251 match
= DataType
.FILE_EXT_SEPARATOR
+ DataType
.MODULE_SURFACE_AREA_EXT
;
253 if (type
== DataType
.RETURN_TYPE_PACKAGE_SURFACE_AREA
) {
254 match
= DataType
.FILE_EXT_SEPARATOR
+ DataType
.PACKAGE_SURFACE_AREA_EXT
;
256 if (type
== DataType
.RETURN_TYPE_PLATFORM_SURFACE_AREA
) {
257 match
= DataType
.FILE_EXT_SEPARATOR
+ DataType
.PLATFORM_SURFACE_AREA_EXT
;
259 if (path
.length() <= match
.length()) {
263 if (!(path
.substring(path
.length() - match
.length())).equals(match
)) {
275 public static void showInformationMessage(String arg0
) {
276 JOptionPane
.showConfirmDialog(null, arg0
, "Error", JOptionPane
.DEFAULT_OPTION
, JOptionPane
.INFORMATION_MESSAGE
);