]> 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 d5d16b8d651d496d8ff6e1c7acddbf60f457552f..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,16 @@ 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
+\r
 /**\r
  The class is used to provides some useful interfaces  \r
  \r
@@ -378,7 +389,7 @@ public class Tools {
 \r
         return strReturn;\r
     }\r
-    \r
+\r
     public static String convertUnicodeHexStringToString(String str) {\r
         //\r
         // Handle if str is null or empty\r
@@ -397,15 +408,15 @@ public class Tools {
             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", "Wrong input string: " + str);\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
+            returnString = returnString + (char) (dec);\r
         }\r
         return returnString;\r
     }\r
@@ -457,4 +468,185 @@ public class Tools {
         //\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
+    /**\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
+     Move the component to the center of screen \r
+     \r
+     @param c\r
+     @param width\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
+     Move the component to the center of screen and adjust the y location \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
+     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
+    /**\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