]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java
1. Wrap text by word when showing a message box
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / Tools.java
index 26604d0d39a2d738c84e5d86765eb3651e2d8e95..59204a8adbf7778c60370198d8917b5b67103710 100644 (file)
@@ -336,4 +336,75 @@ public class Tools {
         }\r
         return arg0;\r
     }\r
+\r
+    /**\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
+     **/\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