a13899c5 |
1 | /** @file\r |
2 | \r |
3 | The file is used to provides some useful interfaces \r |
4 | \r |
5 | Copyright (c) 2006, Intel Corporation\r |
6 | All rights reserved. This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r |
9 | http://opensource.org/licenses/bsd-license.php\r |
10 | \r |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
13 | \r |
14 | **/\r |
15 | \r |
16 | package org.tianocore.frameworkwizard.common;\r |
17 | \r |
8792f60f |
18 | import java.awt.Component;\r |
a13899c5 |
19 | import java.io.File;\r |
20 | import java.text.SimpleDateFormat;\r |
21 | import java.util.Date;\r |
22 | import java.util.List;\r |
23 | import java.util.UUID;\r |
24 | import java.util.Vector;\r |
25 | \r |
92e29378 |
26 | import javax.swing.DefaultListModel;\r |
a13899c5 |
27 | import javax.swing.JComboBox;\r |
92e29378 |
28 | import javax.swing.JList;\r |
a13899c5 |
29 | import javax.swing.JOptionPane;\r |
350785ff |
30 | import javax.swing.JTable;\r |
a13899c5 |
31 | \r |
739c6b04 |
32 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r |
33 | import org.tianocore.MsaHeaderDocument.MsaHeader;\r |
34 | import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r |
35 | import org.tianocore.PlatformHeaderDocument.PlatformHeader;\r |
36 | import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r |
37 | import org.tianocore.SpdHeaderDocument.SpdHeader;\r |
38 | import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r |
39 | import org.tianocore.frameworkwizard.packaging.PackageIdentification;\r |
40 | import org.tianocore.frameworkwizard.platform.PlatformIdentification;\r |
41 | \r |
a13899c5 |
42 | /**\r |
43 | The class is used to provides some useful interfaces \r |
44 | \r |
45 | **/\r |
46 | public class Tools {\r |
47 | \r |
48 | //\r |
49 | // The dir user selected to create new package in\r |
50 | //\r |
51 | public static String dirForNewSpd = null;\r |
52 | \r |
a13899c5 |
53 | /**\r |
54 | Get current date and time and format it as "yyyy-MM-dd HH:mm"\r |
55 | \r |
56 | @return formatted current date and time\r |
57 | \r |
58 | **/\r |
59 | public static String getCurrentDateTime() {\r |
60 | Date now = new Date(System.currentTimeMillis());\r |
61 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");\r |
62 | return sdf.format(now);\r |
63 | }\r |
64 | \r |
65 | /**\r |
66 | Generate a UUID\r |
67 | \r |
68 | @return the created UUID\r |
69 | \r |
70 | **/\r |
71 | public static String generateUuidString() {\r |
72 | return UUID.randomUUID().toString();\r |
73 | }\r |
74 | \r |
75 | /**\r |
76 | Use current file separator in the path\r |
77 | \r |
78 | @param strPath\r |
79 | @return\r |
80 | \r |
81 | **/\r |
82 | public static String convertPathToCurrentOsType(String strPath) {\r |
83 | strPath = strPath.replace(DataType.DOS_FILE_SEPARATOR, DataType.FILE_SEPARATOR);\r |
84 | strPath = strPath.replace(DataType.UNIX_FILE_SEPARATOR, DataType.FILE_SEPARATOR);\r |
85 | return strPath;\r |
86 | }\r |
87 | \r |
88 | /**\r |
89 | Use Unix file separator in the path\r |
90 | \r |
91 | @param strPath\r |
92 | @return\r |
93 | \r |
94 | **/\r |
95 | public static String convertPathToUnixType(String strPath) {\r |
96 | strPath = strPath.replace(DataType.DOS_FILE_SEPARATOR, DataType.UNIX_FILE_SEPARATOR);\r |
97 | return strPath;\r |
98 | }\r |
99 | \r |
100 | /**\r |
101 | Use Dos file separator in the path\r |
102 | \r |
103 | @param strPath\r |
104 | @return\r |
105 | \r |
106 | **/\r |
107 | public static String convertPathToDosType(String strPath) {\r |
108 | strPath = strPath.replace(DataType.UNIX_FILE_SEPARATOR, DataType.DOS_FILE_SEPARATOR);\r |
109 | return strPath;\r |
110 | }\r |
111 | \r |
112 | /**\r |
113 | Get all system properties and output to the console\r |
114 | \r |
115 | **/\r |
116 | public static void getSystemProperties() {\r |
117 | System.out.println(System.getProperty("java.class.version"));\r |
118 | System.out.println(System.getProperty("java.class.path"));\r |
119 | System.out.println(System.getProperty("java.ext.dirs"));\r |
120 | System.out.println(System.getProperty("os.name"));\r |
121 | System.out.println(System.getProperty("os.arch"));\r |
122 | System.out.println(System.getProperty("os.version"));\r |
123 | System.out.println(System.getProperty("file.separator"));\r |
124 | System.out.println(System.getProperty("path.separator"));\r |
125 | System.out.println(System.getProperty("line.separator"));\r |
126 | System.out.println(System.getProperty("user.name"));\r |
127 | System.out.println(System.getProperty("user.home"));\r |
128 | System.out.println(System.getProperty("user.dir"));\r |
129 | System.out.println(System.getProperty("PATH"));\r |
130 | \r |
131 | System.out.println(System.getenv("PROCESSOR_REVISION"));\r |
132 | }\r |
133 | \r |
134 | /**\r |
135 | Generate selection items for JComboBox by input vector\r |
136 | \r |
137 | **/\r |
138 | public static void generateComboBoxByVector(JComboBox jcb, Vector<String> vector) {\r |
139 | if (jcb != null) {\r |
140 | jcb.removeAllItems();\r |
141 | }\r |
142 | if (vector != null) {\r |
143 | for (int index = 0; index < vector.size(); index++) {\r |
144 | jcb.addItem(vector.elementAt(index));\r |
145 | }\r |
146 | }\r |
147 | }\r |
9a8d6d9f |
148 | \r |
92e29378 |
149 | /**\r |
9a8d6d9f |
150 | Generate selection items for JList by input vector\r |
151 | \r |
152 | **/\r |
153 | public static void generateListByVector(JList jl, Vector<String> vector) {\r |
154 | if (jl != null) {\r |
155 | DefaultListModel listModel = (DefaultListModel) jl.getModel();\r |
156 | listModel.removeAllElements();\r |
157 | \r |
158 | if (vector != null) {\r |
159 | for (int index = 0; index < vector.size(); index++) {\r |
160 | listModel.addElement(vector.get(index));\r |
161 | }\r |
162 | }\r |
163 | \r |
164 | if (listModel.size() > 0) {\r |
165 | jl.setSelectedIndex(0);\r |
166 | }\r |
167 | }\r |
168 | }\r |
79cb6fdb |
169 | \r |
a13899c5 |
170 | /**\r |
171 | Get path only from a path\r |
79cb6fdb |
172 | \r |
a13899c5 |
173 | @param filePath\r |
174 | @return\r |
79cb6fdb |
175 | \r |
176 | **/\r |
a13899c5 |
177 | public static String getFilePathOnly(String filePath) {\r |
178 | String path = filePath.substring(0, filePath.length() - getFileNameOnly(filePath).length());\r |
179 | if (path.endsWith(DataType.FILE_SEPARATOR)) {\r |
180 | path = path.substring(0, path.length() - DataType.FILE_SEPARATOR.length());\r |
181 | }\r |
79cb6fdb |
182 | \r |
a13899c5 |
183 | return path;\r |
184 | }\r |
79cb6fdb |
185 | \r |
a13899c5 |
186 | /**\r |
187 | Get file name from a path\r |
188 | \r |
189 | @param filePath\r |
190 | @return\r |
79cb6fdb |
191 | \r |
192 | **/\r |
a13899c5 |
193 | public static String getFileNameOnly(String filePath) {\r |
194 | File f = new File(filePath);\r |
195 | return f.getAbsoluteFile().getName();\r |
196 | }\r |
79cb6fdb |
197 | \r |
a13899c5 |
198 | public static String getFileNameWithoutExt(String filePath) {\r |
199 | filePath = getFileNameOnly(filePath);\r |
200 | filePath = filePath.substring(0, filePath.lastIndexOf(DataType.FILE_EXT_SEPARATOR));\r |
201 | return filePath;\r |
202 | }\r |
203 | \r |
204 | /**\r |
205 | Get relative path\r |
206 | \r |
207 | @param wholePath\r |
208 | @param commonPath\r |
209 | @return wholePath - commonPath \r |
210 | \r |
211 | **/\r |
212 | public static String getRelativePath(String wholePath, String commonPath) {\r |
213 | String path = "";\r |
214 | int i = 0;\r |
215 | i = wholePath.indexOf(commonPath);\r |
216 | if (i > -1) {\r |
217 | i = i + commonPath.length();\r |
218 | } else {\r |
219 | return "";\r |
220 | }\r |
221 | path = wholePath.substring(i);\r |
222 | //\r |
223 | // remove file separator of head\r |
224 | //\r |
225 | if (path.indexOf(DataType.DOS_FILE_SEPARATOR) == 0) {\r |
226 | path = path.substring(0 + DataType.DOS_FILE_SEPARATOR.length());\r |
227 | }\r |
228 | if (path.indexOf(DataType.UNIX_FILE_SEPARATOR) == 0) {\r |
229 | path = path.substring(0 + DataType.DOS_FILE_SEPARATOR.length());\r |
230 | }\r |
231 | //\r |
232 | // remove file separator of rear\r |
233 | //\r |
0915a2ce |
234 | if (path.length() > 0 && path.indexOf(DataType.DOS_FILE_SEPARATOR) == path.length() - DataType.DOS_FILE_SEPARATOR.length()) {\r |
a13899c5 |
235 | path = path.substring(0, path.length() - DataType.DOS_FILE_SEPARATOR.length());\r |
236 | }\r |
0915a2ce |
237 | if (path.length() > 0 && path.indexOf(DataType.UNIX_FILE_SEPARATOR) == path.length() - DataType.UNIX_FILE_SEPARATOR.length()) {\r |
a13899c5 |
238 | path = path.substring(0, path.length() - DataType.DOS_FILE_SEPARATOR.length());\r |
239 | }\r |
240 | //\r |
241 | // convert to UNIX format\r |
242 | //\r |
243 | path = Tools.convertPathToUnixType(path);\r |
244 | return path;\r |
245 | }\r |
246 | \r |
247 | /**\r |
248 | Convert List ot Vector\r |
249 | \r |
250 | @param list\r |
251 | @return\r |
252 | \r |
253 | **/\r |
254 | public static Vector<String> convertListToVector(List list) {\r |
255 | Vector<String> v = new Vector<String>();\r |
256 | if (list != null && list.size() > 0) {\r |
257 | for (int index = 0; index < list.size(); index++) {\r |
258 | v.addElement(list.get(index).toString());\r |
259 | }\r |
260 | }\r |
261 | return v;\r |
262 | }\r |
263 | \r |
264 | /**\r |
265 | If the input path missing ext, append the ext to the path\r |
266 | \r |
267 | @param path\r |
268 | @param type\r |
269 | @return\r |
270 | \r |
271 | **/\r |
272 | public static String addPathExt(String path, int type) {\r |
273 | String match = "";\r |
274 | if (type == DataType.RETURN_TYPE_MODULE_SURFACE_AREA) {\r |
275 | match = DataType.FILE_EXT_SEPARATOR + DataType.MODULE_SURFACE_AREA_EXT;\r |
276 | }\r |
277 | if (type == DataType.RETURN_TYPE_PACKAGE_SURFACE_AREA) {\r |
278 | match = DataType.FILE_EXT_SEPARATOR + DataType.PACKAGE_SURFACE_AREA_EXT;\r |
279 | }\r |
280 | if (type == DataType.RETURN_TYPE_PLATFORM_SURFACE_AREA) {\r |
281 | match = DataType.FILE_EXT_SEPARATOR + DataType.PLATFORM_SURFACE_AREA_EXT;\r |
282 | }\r |
92e29378 |
283 | if (type == DataType.RETURN_TYPE_TEXT) {\r |
284 | match = DataType.FILE_EXT_SEPARATOR + DataType.TEXT_FILE_EXT;\r |
285 | }\r |
5a24e806 |
286 | if (type == DataType.RETURN_TYPE_FAR_SURFACE_AREA) {\r |
55a2762d |
287 | match = DataType.FILE_EXT_SEPARATOR + DataType.FAR_SURFACE_AREA_EXT;\r |
288 | }\r |
a13899c5 |
289 | if (path.length() <= match.length()) {\r |
290 | path = path + match;\r |
291 | return path;\r |
292 | }\r |
293 | if (!(path.substring(path.length() - match.length())).equals(match)) {\r |
294 | path = path + match;\r |
295 | }\r |
296 | return path;\r |
297 | }\r |
79cb6fdb |
298 | \r |
a13899c5 |
299 | /**\r |
300 | Show a message box\r |
301 | \r |
302 | @param arg0\r |
79cb6fdb |
303 | \r |
304 | **/\r |
a13899c5 |
305 | public static void showInformationMessage(String arg0) {\r |
a929458e |
306 | JOptionPane.showConfirmDialog(null, arg0, "Info", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);\r |
a13899c5 |
307 | }\r |
92e29378 |
308 | \r |
309 | /**\r |
310 | if the string doesn't end with a file separator, append it to the string\r |
311 | \r |
312 | @param arg0\r |
313 | @return\r |
314 | \r |
315 | **/\r |
316 | public static String addFileSeparator(String arg0) {\r |
317 | if (!arg0.endsWith(DataType.FILE_SEPARATOR)) {\r |
318 | arg0 = arg0 + DataType.FILE_SEPARATOR;\r |
319 | }\r |
320 | return arg0;\r |
321 | }\r |
ed1665f2 |
322 | \r |
323 | /**\r |
324 | Wrap single line long input string to multiple short line string by word\r |
325 | \r |
326 | @param arg0 input string\r |
327 | @return wraped string\r |
328 | \r |
329 | **/\r |
330 | public static String wrapStringByWord(String arg0) {\r |
331 | int intMaxLength = 40;\r |
332 | String strReturn = "";\r |
333 | String strTemp = "";\r |
334 | boolean isCopied = true;\r |
335 | \r |
aa197375 |
336 | if (arg0 == null) {\r |
337 | return "";\r |
338 | }\r |
339 | if (arg0.length() <= 0) {\r |
340 | return "";\r |
341 | }\r |
342 | \r |
ed1665f2 |
343 | //\r |
344 | // Convert string to array by " "\r |
345 | //\r |
346 | String s[] = arg0.split(" ");\r |
347 | if (arg0.indexOf(" ") == -1) {\r |
348 | s[0] = arg0;\r |
349 | }\r |
350 | \r |
351 | //\r |
352 | // Add each string of array one by one\r |
353 | //\r |
354 | for (int index = 0; index < s.length; index++) {\r |
355 | String ss = s[index];\r |
356 | isCopied = false;\r |
357 | //\r |
358 | // The word length > defined line length\r |
359 | //\r |
360 | if (ss.length() > intMaxLength) {\r |
361 | //\r |
362 | // Finish previous line\r |
363 | //\r |
364 | if (!isCopied) {\r |
d933fc5f |
365 | strReturn = strReturn + strTemp + DataType.LINE_SEPARATOR;\r |
ed1665f2 |
366 | strTemp = "";\r |
367 | }\r |
368 | //\r |
369 | // Separater to short lines\r |
370 | //\r |
371 | while (ss.length() > 0) {\r |
372 | if (ss.length() > intMaxLength) {\r |
373 | strReturn = strReturn + s[index].substring(0, intMaxLength - 1) + DataType.UNIX_LINE_SEPARATOR;\r |
374 | ss = ss.substring(intMaxLength);\r |
375 | isCopied = true;\r |
376 | } else {\r |
377 | strTemp = ss;\r |
378 | ss = "";\r |
379 | isCopied = false;\r |
380 | }\r |
381 | }\r |
382 | } else {\r |
383 | if ((strTemp + " " + ss).length() <= intMaxLength) {\r |
384 | strTemp = strTemp + " " + ss;\r |
385 | continue;\r |
386 | } else {\r |
d933fc5f |
387 | strReturn = strReturn + strTemp + DataType.LINE_SEPARATOR;\r |
388 | if ((index == s.length - 1) && (!ss.equals(""))) {\r |
389 | strReturn = strReturn + ss;\r |
390 | } else {\r |
391 | strTemp = ss + " ";\r |
392 | }\r |
ed1665f2 |
393 | isCopied = true;\r |
394 | }\r |
395 | }\r |
396 | }\r |
397 | \r |
398 | if (!isCopied) {\r |
399 | strReturn = strReturn + strTemp;\r |
400 | }\r |
401 | \r |
402 | return strReturn;\r |
403 | }\r |
55e83b18 |
404 | \r |
43dc3851 |
405 | public static String convertUnicodeHexStringToString(String str) {\r |
406 | //\r |
407 | // Handle if str is null or empty\r |
408 | //\r |
409 | if (str == null) {\r |
410 | return "";\r |
411 | }\r |
412 | if (str.equals("")) {\r |
413 | return "";\r |
414 | }\r |
415 | \r |
416 | String returnString = "";\r |
417 | String[] strArray = str.split(" ");\r |
418 | for (int index = 0; index < strArray.length; index++) {\r |
419 | String s = strArray[index];\r |
420 | if (s.length() == 6 && s.indexOf(DataType.HEX_STRING_HEADER) == 0) {\r |
421 | s = s.substring(DataType.HEX_STRING_HEADER.length());\r |
422 | } else {\r |
af6afe48 |
423 | Log.err("convertUnicodeHexStringToString", "Incorrect input string: " + str);\r |
43dc3851 |
424 | continue;\r |
425 | }\r |
426 | //\r |
427 | // Change hex to dec\r |
428 | //\r |
429 | int dec = Integer.parseInt(s, 16);\r |
55e83b18 |
430 | \r |
431 | returnString = returnString + (char) (dec);\r |
43dc3851 |
432 | }\r |
433 | return returnString;\r |
434 | }\r |
435 | \r |
436 | /**\r |
437 | Convert input string to unicode hex string\r |
438 | \r |
439 | @param str input string\r |
440 | @return unicode hex string\r |
441 | \r |
442 | **/\r |
443 | public static String convertStringToUnicodeHexString(String str) {\r |
444 | //\r |
445 | // Handle if str is null or empty\r |
446 | //\r |
447 | if (str == null) {\r |
448 | return "";\r |
449 | }\r |
450 | if (str.equals("")) {\r |
451 | return "";\r |
452 | }\r |
453 | \r |
454 | //\r |
455 | // convert string to hex string\r |
456 | //\r |
457 | String hexString = "";\r |
458 | for (int index = 0; index < str.length(); index++) {\r |
459 | int codePoint = str.codePointAt(index);\r |
460 | String s = Integer.toHexString(codePoint);\r |
461 | //\r |
462 | // Make the string to four length\r |
463 | //\r |
464 | if (s.length() == 3) {\r |
465 | s = "0" + s;\r |
466 | } else if (s.length() == 2) {\r |
467 | s = "00" + s;\r |
468 | } else if (s.length() == 1) {\r |
469 | s = "000" + s;\r |
470 | }\r |
471 | \r |
472 | //\r |
473 | // Add the string to return hex string\r |
474 | //\r |
475 | hexString = hexString + DataType.HEX_STRING_HEADER + s + " ";\r |
476 | }\r |
477 | \r |
478 | //\r |
479 | // return hex string\r |
480 | //\r |
481 | return hexString.trim();\r |
482 | }\r |
55e83b18 |
483 | \r |
739c6b04 |
484 | public static ModuleIdentification getId(String path, ModuleSurfaceArea msa) {\r |
485 | MsaHeader head = msa.getMsaHeader();\r |
486 | String name = head.getModuleName();\r |
487 | String guid = head.getGuidValue();\r |
488 | String version = head.getVersion();\r |
489 | ModuleIdentification id = new ModuleIdentification(name, guid, version, path);\r |
490 | return id;\r |
491 | }\r |
492 | \r |
493 | public static PackageIdentification getId(String path, PackageSurfaceArea spd) {\r |
494 | SpdHeader head = spd.getSpdHeader();\r |
495 | String name = head.getPackageName();\r |
496 | String guid = head.getGuidValue();\r |
497 | String version = head.getVersion();\r |
498 | PackageIdentification id = new PackageIdentification(name, guid, version, path);\r |
499 | return id;\r |
500 | }\r |
501 | \r |
502 | public static PlatformIdentification getId(String path, PlatformSurfaceArea fpd) {\r |
503 | PlatformHeader head = fpd.getPlatformHeader();\r |
504 | String name = head.getPlatformName();\r |
505 | String guid = head.getGuidValue();\r |
506 | String version = head.getVersion();\r |
507 | PlatformIdentification id = new PlatformIdentification(name, guid, version, path);\r |
508 | return id;\r |
509 | }\r |
55e83b18 |
510 | \r |
8792f60f |
511 | /**\r |
512 | * To reset the width of input component via container width\r |
513 | * \r |
514 | * @param c\r |
515 | * @param containerWidth\r |
516 | * \r |
517 | */\r |
518 | public static void resizeComponentWidth(Component c, int containerWidth, int preferredWidth) {\r |
519 | int newWidth = c.getPreferredSize().width + (containerWidth - preferredWidth);\r |
520 | if (newWidth < c.getPreferredSize().width) {\r |
521 | newWidth = c.getPreferredSize().width;\r |
522 | }\r |
523 | c.setSize(new java.awt.Dimension(newWidth, c.getHeight()));\r |
524 | c.validate();\r |
525 | }\r |
526 | \r |
527 | /**\r |
528 | * To reset the height of input component via container height\r |
529 | * \r |
530 | * @param c\r |
531 | * @param containerHeight\r |
532 | * \r |
533 | */\r |
534 | public static void resizeComponentHeight(Component c, int containerHeight, int preferredHeight) {\r |
535 | int newHeight = c.getPreferredSize().height + (containerHeight - preferredHeight);\r |
536 | if (newHeight < c.getPreferredSize().height) {\r |
537 | newHeight = c.getPreferredSize().height;\r |
538 | }\r |
539 | c.setSize(new java.awt.Dimension(c.getWidth(), newHeight));\r |
540 | c.validate();\r |
541 | }\r |
542 | \r |
543 | /**\r |
544 | * To reset the size of input component via container size\r |
545 | * \r |
546 | * @param c\r |
547 | * @param containerWidth\r |
548 | * @param containerHeight\r |
549 | * \r |
550 | */\r |
551 | public static void resizeComponent(Component c, int containerWidth, int containerHeight, int preferredWidth,\r |
55e83b18 |
552 | int preferredHeight) {\r |
8792f60f |
553 | resizeComponentWidth(c, containerWidth, preferredWidth);\r |
554 | resizeComponentHeight(c, containerHeight, preferredHeight);\r |
555 | }\r |
350785ff |
556 | \r |
557 | /**\r |
558 | To adjust each column's width to meet the table's size\r |
559 | \r |
560 | @param t the table need to be adjusted\r |
561 | @param width the new width of the table\r |
562 | \r |
563 | **/\r |
564 | public static void resizeTableColumn(JTable t, int width) {\r |
565 | if (t != null) {\r |
566 | int columnCount = t.getColumnCount();\r |
567 | for (int index = 0; index < columnCount; index++) {\r |
568 | t.getColumn(t.getColumnName(index)).setPreferredWidth(width / columnCount);\r |
569 | }\r |
570 | }\r |
571 | }\r |
8792f60f |
572 | \r |
573 | /**\r |
574 | * To relocate the input component\r |
575 | * \r |
576 | * @param c\r |
577 | * @param containerWidth\r |
578 | * @param spaceToRight\r |
579 | * \r |
580 | */\r |
581 | public static void relocateComponentX(Component c, int containerWidth, int preferredWidth, int spaceToRight) {\r |
582 | int intGapToRight = spaceToRight + c.getPreferredSize().width;\r |
583 | int newLocationX = containerWidth - intGapToRight;\r |
584 | if (newLocationX < preferredWidth - intGapToRight) {\r |
585 | newLocationX = preferredWidth - intGapToRight;\r |
586 | }\r |
587 | c.setLocation(newLocationX, c.getLocation().y);\r |
588 | c.validate();\r |
589 | }\r |
590 | \r |
591 | /**\r |
592 | * To relocate the input component\r |
593 | * \r |
594 | * @param c\r |
595 | * @param containerHeight\r |
596 | * @param spaceToBottom\r |
597 | * \r |
598 | */\r |
599 | public static void relocateComponentY(Component c, int containerHeight, int preferredHeight, int spaceToBottom) {\r |
600 | int intGapToBottom = spaceToBottom + c.getPreferredSize().height;\r |
601 | int newLocationY = containerHeight - intGapToBottom;\r |
602 | if (newLocationY < preferredHeight - spaceToBottom) {\r |
603 | newLocationY = preferredHeight - spaceToBottom;\r |
604 | }\r |
605 | c.setLocation(c.getLocation().x, newLocationY);\r |
606 | c.validate();\r |
607 | }\r |
608 | \r |
609 | /**\r |
610 | * To relocate the input component\r |
611 | * \r |
612 | * @param c\r |
613 | * @param containerWidth\r |
614 | * @param containerHeight\r |
615 | * @param spaceToBottom\r |
616 | * @param spaceToRight\r |
617 | * \r |
618 | */\r |
619 | public static void relocateComponent(Component c, int containerWidth, int containerHeight, int preferredWidht,\r |
55e83b18 |
620 | int preferredHeight, int spaceToRight, int spaceToBottom) {\r |
8792f60f |
621 | relocateComponentX(c, containerWidth, preferredWidht, spaceToRight);\r |
622 | relocateComponentY(c, containerHeight, preferredHeight, spaceToBottom);\r |
623 | }\r |
55e83b18 |
624 | \r |
8792f60f |
625 | /**\r |
626 | Move the component to the center of screen \r |
55e83b18 |
627 | \r |
8792f60f |
628 | @param c\r |
629 | @param width\r |
55e83b18 |
630 | \r |
631 | **/\r |
8792f60f |
632 | public static void centerComponent(Component c, int width) {\r |
633 | c.setLocation(width / 2 - c.getWidth() / 2, c.getLocation().y);\r |
634 | c.validate();\r |
635 | }\r |
55e83b18 |
636 | \r |
8792f60f |
637 | /**\r |
55e83b18 |
638 | Move the component to the center of screen and adjust the y location \r |
639 | \r |
640 | @param c\r |
641 | @param width\r |
642 | \r |
643 | **/\r |
644 | public static void centerComponent(Component c, int width, int containerHeight, int preferredHeight,\r |
645 | int spaceToBottom) {\r |
646 | relocateComponentY(c, containerHeight, preferredHeight, spaceToBottom);\r |
647 | centerComponent(c, width);\r |
648 | }\r |
649 | \r |
650 | /**\r |
651 | Find the count of searchString in wholeString\r |
652 | \r |
653 | @param wholeString\r |
654 | @param searchString\r |
655 | @return\r |
656 | \r |
657 | **/\r |
658 | public static int getSpecificStringCount(String wholeString, String searchString) {\r |
659 | int count = 0;\r |
660 | count = wholeString.split(searchString).length;\r |
661 | return count;\r |
662 | }\r |
d933fc5f |
663 | \r |
3b7a9058 |
664 | /**\r |
665 | * Check the input data is empty or not\r |
666 | * \r |
667 | * @param strValue\r |
668 | * The input data which need be checked\r |
669 | * \r |
670 | * @retval true - The input data is empty\r |
671 | * @retval fals - The input data is not empty\r |
672 | * \r |
673 | */\r |
674 | public static boolean isEmpty(String strValue) {\r |
675 | if (strValue.length() > 0) {\r |
676 | return false;\r |
677 | }\r |
678 | return true;\r |
679 | }\r |
a13899c5 |
680 | }\r |