X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FFrameworkWizard%2Fsrc%2Forg%2Ftianocore%2Fframeworkwizard%2Fcommon%2FTools.java;h=e6647d24cc06010919be2c556025fa95214ae3c3;hp=021c2373a04cd8c1d52a91da232238331d239839;hb=3b7a9058fdf4e730963d20fc5ce57794ac2e6bc7;hpb=92e2937805abc97f7445217c77315cc1d51a8c60 diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java index 021c2373a0..e6647d24cc 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java @@ -15,6 +15,7 @@ package org.tianocore.frameworkwizard.common; +import java.awt.Component; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; @@ -27,6 +28,12 @@ import javax.swing.JComboBox; import javax.swing.JList; import javax.swing.JOptionPane; +import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea; +import org.tianocore.MsaHeaderDocument.MsaHeader; +import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea; +import org.tianocore.PlatformHeaderDocument.PlatformHeader; +import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea; +import org.tianocore.SpdHeaderDocument.SpdHeader; import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification; import org.tianocore.frameworkwizard.packaging.PackageIdentification; import org.tianocore.frameworkwizard.platform.PlatformIdentification; @@ -42,35 +49,6 @@ public class Tools { // public static String dirForNewSpd = null; - /** - Used for test - - @param args - - **/ - public static void main(String[] args) { - System.out.println(getCurrentDateTime()); -// Vector v = new Vector(); -// Vector v1 = new Vector(); -// -// v.addElement("CAC"); -// v1.addElement("1111"); -// v.addElement("1AC"); -// v1.addElement("2222"); -// v.addElement("ABC"); -// v1.addElement("3333"); -// v.addElement("0C"); -// v1.addElement("4444"); -// v.addElement("AAC"); -// v1.addElement("5555"); -// Vector vs = new Vector(); -// vs = Tools.getVectorSortSequence(v, DataType.Sort_Type_Ascending); -// Tools.sortVectorString(v1, Tools.getVectorSortSequence(v, DataType.Sort_Type_Ascending)); -// -// Tools.sortVectorString(v, DataType.Sort_Type_Ascending); -// Tools.sortVectorString(v, DataType.Sort_Type_Descending); - } - /** Get current date and time and format it as "yyyy-MM-dd HH:mm" @@ -166,27 +144,27 @@ public class Tools { } } } - + /** - Generate selection items for JList by input vector - - **/ - public static void generateListByVector(JList jl, Vector vector) { - if (jl != null) { - DefaultListModel listModel = (DefaultListModel) jl.getModel(); - listModel.removeAllElements(); - - if (vector != null) { - for (int index = 0; index < vector.size(); index++) { - listModel.addElement(vector.get(index)); - } - } - - if (listModel.size() > 0) { - jl.setSelectedIndex(0); - } - } - } + Generate selection items for JList by input vector + + **/ + public static void generateListByVector(JList jl, Vector vector) { + if (jl != null) { + DefaultListModel listModel = (DefaultListModel) jl.getModel(); + listModel.removeAllElements(); + + if (vector != null) { + for (int index = 0; index < vector.size(); index++) { + listModel.addElement(vector.get(index)); + } + } + + if (listModel.size() > 0) { + jl.setSelectedIndex(0); + } + } + } /** Get path only from a path @@ -304,6 +282,9 @@ public class Tools { if (type == DataType.RETURN_TYPE_TEXT) { match = DataType.FILE_EXT_SEPARATOR + DataType.TEXT_FILE_EXT; } + if (type == DataType.RETURN_TYPE_FAR_SURFACE_AREA) { + match = DataType.FILE_EXT_SEPARATOR + DataType.FAR_SURFACE_AREA_EXT; + } if (path.length() <= match.length()) { path = path + match; return path; @@ -321,7 +302,7 @@ public class Tools { **/ public static void showInformationMessage(String arg0) { - JOptionPane.showConfirmDialog(null, arg0, "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showConfirmDialog(null, arg0, "Info", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); } /** @@ -339,164 +320,333 @@ public class Tools { } /** - Sort all elements in the vector as the specific sort type + Wrap single line long input string to multiple short line string by word + + @param arg0 input string + @return wraped string - @param v The vector need to be sorted - @param mode Sort type DataType.Sort_Type_Ascendin and DataType.Sort_Type_Descending - **/ - public static void sortVectorString(Vector v, int mode) { - if (v != null) { - for (int indexI = 0; indexI < v.size(); indexI++) { - for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) { - if ((v.get(indexJ).compareTo(v.get(indexI)) < 0 && mode == DataType.SORT_TYPE_ASCENDING) - || (v.get(indexI).compareTo(v.get(indexJ)) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) { - String temp = v.get(indexI); - v.setElementAt(v.get(indexJ), indexI); - v.setElementAt(temp, indexJ); + public static String wrapStringByWord(String arg0) { + int intMaxLength = 40; + String strReturn = ""; + String strTemp = ""; + boolean isCopied = true; + + // + // Convert string to array by " " + // + String s[] = arg0.split(" "); + if (arg0.indexOf(" ") == -1) { + s[0] = arg0; + } + + // + // Add each string of array one by one + // + for (int index = 0; index < s.length; index++) { + String ss = s[index]; + isCopied = false; + // + // The word length > defined line length + // + if (ss.length() > intMaxLength) { + // + // Finish previous line + // + if (!isCopied) { + strReturn = strReturn + strTemp + DataType.UNIX_LINE_SEPARATOR; + strTemp = ""; + } + // + // Separater to short lines + // + while (ss.length() > 0) { + if (ss.length() > intMaxLength) { + strReturn = strReturn + s[index].substring(0, intMaxLength - 1) + DataType.UNIX_LINE_SEPARATOR; + ss = ss.substring(intMaxLength); + isCopied = true; + } else { + strTemp = ss; + ss = ""; + isCopied = false; } } + } else { + if ((strTemp + " " + ss).length() <= intMaxLength) { + strTemp = strTemp + " " + ss; + continue; + } else { + strReturn = strReturn + strTemp + DataType.UNIX_LINE_SEPARATOR; + strTemp = ss + " "; + isCopied = true; + } + } + } + + if (!isCopied) { + strReturn = strReturn + strTemp; + } + + return strReturn; + } + + public static String convertUnicodeHexStringToString(String str) { + // + // Handle if str is null or empty + // + if (str == null) { + return ""; + } + if (str.equals("")) { + return ""; + } + + String returnString = ""; + String[] strArray = str.split(" "); + for (int index = 0; index < strArray.length; index++) { + String s = strArray[index]; + if (s.length() == 6 && s.indexOf(DataType.HEX_STRING_HEADER) == 0) { + s = s.substring(DataType.HEX_STRING_HEADER.length()); + } else { + Log.err("convertUnicodeHexStringToString", "Incorrect input string: " + str); + continue; } + // + // Change hex to dec + // + int dec = Integer.parseInt(s, 16); + + returnString = returnString + (char) (dec); } + return returnString; } /** - Sort all elements of vector and return sorted sequence + Convert input string to unicode hex string - @param v The vector need to be sorted - @param mode Sort type DataType.Sort_Type_Ascendin and DataType.Sort_Type_Descending - @return Vector The sorted sequence + @param str input string + @return unicode hex string **/ - public static Vector getVectorSortSequence(Vector v, int mode) { - Vector vSequence = new Vector(); + public static String convertStringToUnicodeHexString(String str) { // - // Init sequence + // Handle if str is null or empty // - if (v != null) { - for (int index = 0; index < v.size(); index++) { - vSequence.addElement(index); - } + if (str == null) { + return ""; + } + if (str.equals("")) { + return ""; } // - // sort and get new sequence + // convert string to hex string // - for (int indexI = 0; indexI < v.size(); indexI++) { - for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) { - if ((v.get(indexJ).compareTo(v.get(indexI)) < 0 && mode == DataType.SORT_TYPE_ASCENDING) - || (v.get(indexI).compareTo(v.get(indexJ)) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) { - // - // Swap strings - // - String tempStr = v.get(indexI); - v.setElementAt(v.get(indexJ), indexI); - v.setElementAt(tempStr, indexJ); - - // - // Swap sequences - // - int tempInt = vSequence.get(indexI); - vSequence.setElementAt(vSequence.get(indexJ), indexI); - vSequence.setElementAt(tempInt, indexJ); - } + String hexString = ""; + for (int index = 0; index < str.length(); index++) { + int codePoint = str.codePointAt(index); + String s = Integer.toHexString(codePoint); + // + // Make the string to four length + // + if (s.length() == 3) { + s = "0" + s; + } else if (s.length() == 2) { + s = "00" + s; + } else if (s.length() == 1) { + s = "000" + s; } + + // + // Add the string to return hex string + // + hexString = hexString + DataType.HEX_STRING_HEADER + s + " "; + } + + // + // return hex string + // + return hexString.trim(); + } + + public static ModuleIdentification getId(String path, ModuleSurfaceArea msa) { + MsaHeader head = msa.getMsaHeader(); + String name = head.getModuleName(); + String guid = head.getGuidValue(); + String version = head.getVersion(); + ModuleIdentification id = new ModuleIdentification(name, guid, version, path); + return id; + } + + public static PackageIdentification getId(String path, PackageSurfaceArea spd) { + SpdHeader head = spd.getSpdHeader(); + String name = head.getPackageName(); + String guid = head.getGuidValue(); + String version = head.getVersion(); + PackageIdentification id = new PackageIdentification(name, guid, version, path); + return id; + } + + public static PlatformIdentification getId(String path, PlatformSurfaceArea fpd) { + PlatformHeader head = fpd.getPlatformHeader(); + String name = head.getPlatformName(); + String guid = head.getGuidValue(); + String version = head.getVersion(); + PlatformIdentification id = new PlatformIdentification(name, guid, version, path); + return id; + } + + /** + * To reset the width of input component via container width + * + * @param c + * @param containerWidth + * + */ + public static void resizeComponentWidth(Component c, int containerWidth, int preferredWidth) { + int newWidth = c.getPreferredSize().width + (containerWidth - preferredWidth); + if (newWidth < c.getPreferredSize().width) { + newWidth = c.getPreferredSize().width; + } + c.setSize(new java.awt.Dimension(newWidth, c.getHeight())); + c.validate(); + } + + /** + * To reset the height of input component via container height + * + * @param c + * @param containerHeight + * + */ + public static void resizeComponentHeight(Component c, int containerHeight, int preferredHeight) { + int newHeight = c.getPreferredSize().height + (containerHeight - preferredHeight); + if (newHeight < c.getPreferredSize().height) { + newHeight = c.getPreferredSize().height; + } + c.setSize(new java.awt.Dimension(c.getWidth(), newHeight)); + c.validate(); + } + + /** + * To reset the size of input component via container size + * + * @param c + * @param containerWidth + * @param containerHeight + * + */ + public static void resizeComponent(Component c, int containerWidth, int containerHeight, int preferredWidth, + int preferredHeight) { + resizeComponentWidth(c, containerWidth, preferredWidth); + resizeComponentHeight(c, containerHeight, preferredHeight); + } + + /** + * To relocate the input component + * + * @param c + * @param containerWidth + * @param spaceToRight + * + */ + public static void relocateComponentX(Component c, int containerWidth, int preferredWidth, int spaceToRight) { + int intGapToRight = spaceToRight + c.getPreferredSize().width; + int newLocationX = containerWidth - intGapToRight; + if (newLocationX < preferredWidth - intGapToRight) { + newLocationX = preferredWidth - intGapToRight; + } + c.setLocation(newLocationX, c.getLocation().y); + c.validate(); + } + + /** + * To relocate the input component + * + * @param c + * @param containerHeight + * @param spaceToBottom + * + */ + public static void relocateComponentY(Component c, int containerHeight, int preferredHeight, int spaceToBottom) { + int intGapToBottom = spaceToBottom + c.getPreferredSize().height; + int newLocationY = containerHeight - intGapToBottom; + if (newLocationY < preferredHeight - spaceToBottom) { + newLocationY = preferredHeight - spaceToBottom; } + c.setLocation(c.getLocation().x, newLocationY); + c.validate(); + } - return vSequence; + /** + * To relocate the input component + * + * @param c + * @param containerWidth + * @param containerHeight + * @param spaceToBottom + * @param spaceToRight + * + */ + public static void relocateComponent(Component c, int containerWidth, int containerHeight, int preferredWidht, + int preferredHeight, int spaceToRight, int spaceToBottom) { + relocateComponentX(c, containerWidth, preferredWidht, spaceToRight); + relocateComponentY(c, containerHeight, preferredHeight, spaceToBottom); } /** - Sort all elements of vector as input sequence + Move the component to the center of screen - @param v The vector need to be sorted - @param vSequence The sort sequence should be followed + @param c + @param width **/ - public static void sortVectorString(Vector v, Vector vSequence) { - if (v != null && vSequence != null && v.size() == vSequence.size()) { - Vector tempV = new Vector(); - for (int index = 0; index < v.size(); index++) { - tempV.addElement(v.get(index)); - } - for (int index = 0; index < v.size(); index++) { - v.setElementAt(tempV.get(vSequence.get(index)), index); - } - } + public static void centerComponent(Component c, int width) { + c.setLocation(width / 2 - c.getWidth() / 2, c.getLocation().y); + c.validate(); } - + /** - Sort all modules + Move the component to the center of screen and adjust the y location - @param v - @param mode - - **/ - public static void sortModules(Vector v, int mode) { - if (v != null) { - // - // sort by name - // - for (int indexI = 0; indexI < v.size(); indexI++) { - for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) { - if ((v.get(indexJ).getName().compareTo(v.get(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING) - || (v.get(indexI).getName().compareTo(v.get(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) { - ModuleIdentification temp = v.get(indexI); - v.setElementAt(v.get(indexJ), indexI); - v.setElementAt(temp, indexJ); - } - } - } - } + @param c + @param width + + **/ + public static void centerComponent(Component c, int width, int containerHeight, int preferredHeight, + int spaceToBottom) { + relocateComponentY(c, containerHeight, preferredHeight, spaceToBottom); + centerComponent(c, width); } - + /** - Sort all packages + Find the count of searchString in wholeString + + @param wholeString + @param searchString + @return + + **/ + public static int getSpecificStringCount(String wholeString, String searchString) { + int count = 0; + count = wholeString.split(searchString).length; + return count; + } - @param v - @param mode - - **/ - public static void sortPackages(Vector v, int mode) { - if (v != null) { - // - // sort by name - // - for (int indexI = 0; indexI < v.size(); indexI++) { - for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) { - if ((v.get(indexJ).getName().compareTo(v.get(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING) - || (v.get(indexI).getName().compareTo(v.get(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) { - PackageIdentification temp = v.get(indexI); - v.setElementAt(v.get(indexJ), indexI); - v.setElementAt(temp, indexJ); - } - } - } - } - } - - /** - Sort all platforms - - @param v - @param mode - - **/ - public static void sortPlatforms(Vector v, int mode) { - if (v != null) { - // - // sort by name - // - for (int indexI = 0; indexI < v.size(); indexI++) { - for (int indexJ = indexI + 1; indexJ < v.size(); indexJ++) { - if ((v.get(indexJ).getName().compareTo(v.get(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING) - || (v.get(indexI).getName().compareTo(v.get(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) { - PlatformIdentification temp = v.get(indexI); - v.setElementAt(v.get(indexJ), indexI); - v.setElementAt(temp, indexJ); - } - } - } - } - } + /** + * Check the input data is empty or not + * + * @param strValue + * The input data which need be checked + * + * @retval true - The input data is empty + * @retval fals - The input data is not empty + * + */ + public static boolean isEmpty(String strValue) { + if (strValue.length() > 0) { + return false; + } + return true; + } }