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