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=0bfca453cdf9eca2f76e17b9b71059b264c3f248;hp=e63a0f5cf96c006f0eac72d10788681e4fade1cc;hb=9a8d6d9fb7143f092e9cba98747814539d3cfaa0;hpb=a13899c5acad2f5e125abdae972b4c3d1e522f69 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 e63a0f5cf9..0bfca453cd 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java @@ -22,9 +22,17 @@ import java.util.List; import java.util.UUID; import java.util.Vector; +import javax.swing.DefaultListModel; import javax.swing.JComboBox; +import javax.swing.JList; import javax.swing.JOptionPane; +import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification; +import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdIdentification; +import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdVector; +import org.tianocore.frameworkwizard.packaging.PackageIdentification; +import org.tianocore.frameworkwizard.platform.PlatformIdentification; + /** The class is used to provides some useful interfaces @@ -44,6 +52,25 @@ public class Tools { **/ 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); } /** @@ -141,36 +168,56 @@ 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); + } + } + } + /** Get path only from a path - + @param filePath @return - - **/ + + **/ public static String getFilePathOnly(String filePath) { String path = filePath.substring(0, filePath.length() - getFileNameOnly(filePath).length()); if (path.endsWith(DataType.FILE_SEPARATOR)) { path = path.substring(0, path.length() - DataType.FILE_SEPARATOR.length()); } - + return path; } - - + /** Get file name from a path @param filePath @return - - **/ + + **/ public static String getFileNameOnly(String filePath) { File f = new File(filePath); return f.getAbsoluteFile().getName(); } - + public static String getFileNameWithoutExt(String filePath) { filePath = getFileNameOnly(filePath); filePath = filePath.substring(0, filePath.lastIndexOf(DataType.FILE_EXT_SEPARATOR)); @@ -256,6 +303,12 @@ public class Tools { if (type == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) { match = DataType.FILE_EXT_SEPARATOR + DataType.PLATFORM_SURFACE_AREA_EXT; } + 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; @@ -265,14 +318,215 @@ public class Tools { } return path; } - + /** Show a message box @param arg0 - - **/ + + **/ public static void showInformationMessage(String arg0) { JOptionPane.showConfirmDialog(null, arg0, "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); } + + /** + if the string doesn't end with a file separator, append it to the string + + @param arg0 + @return + + **/ + public static String addFileSeparator(String arg0) { + if (!arg0.endsWith(DataType.FILE_SEPARATOR)) { + arg0 = arg0 + DataType.FILE_SEPARATOR; + } + return arg0; + } + + /** + Sort all elements in the vector as the specific sort type + + @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); + } + } + } + } + } + + /** + Sort all elements of vector and return sorted sequence + + @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 + + **/ + public static Vector getVectorSortSequence(Vector v, int mode) { + Vector vSequence = new Vector(); + // + // Init sequence + // + if (v != null) { + for (int index = 0; index < v.size(); index++) { + vSequence.addElement(index); + } + } + + // + // sort and get new sequence + // + 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); + } + } + } + + return vSequence; + } + + /** + Sort all elements of vector as input sequence + + @param v The vector need to be sorted + @param vSequence The sort sequence should be followed + + **/ + 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); + } + } + } + + /** + Sort all modules + + @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); + } + } + } + } + } + + /** + Sort all packages + + @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); + } + } + } + } + } + + /** + Sort all pcd entries + + @param v + @param mode + + **/ + public static void sortPcds(PcdVector 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.getPcd(indexJ).getName().compareTo(v.getPcd(indexI).getName()) < 0 && mode == DataType.SORT_TYPE_ASCENDING) + || (v.getPcd(indexI).getName().compareTo(v.getPcd(indexJ).getName()) < 0 && mode == DataType.SORT_TYPE_DESCENDING)) { + PcdIdentification temp = v.getPcd(indexI); + v.setPcd(v.getPcd(indexJ), indexI); + v.setPcd(temp, indexJ); + } + } + } + } + } }