]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Tools.java
1. Move resize funtions from IInternalFrame.java to Tools.java.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / Tools.java
index a5345019ea2bb20e616265591dbcb3f84453c124..983201f5a0f11444dcd15d254b314af7b262e835 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
@@ -494,4 +495,126 @@ public class Tools {
         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, int spaceToBottom) {\r
+       relocateComponentY(c, containerHeight, preferredHeight, spaceToBottom);\r
+       centerComponent(c, width);\r
+   }\r
 }\r