jhplot.utils
Class Util
- java.lang.Object
-
- jhplot.utils.Util
-
public final class Util extends java.lang.ObjectVarious useful functions of general purpose.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static voidbelowWithin(java.awt.Component parent, java.awt.Component child)static java.awt.PointbelowWithin(java.awt.Rectangle rec, java.awt.Dimension dim)static voidcentreWithin(java.awt.Component parent, java.awt.Component child)Centres the child component within its parent.static java.awt.PointcentreWithin(java.awt.Rectangle rec, java.awt.Dimension dim)Calculates the X and Y coordinates that a child component should have to be centered within its parent.static voidcopyFile(java.io.File inputFile, java.io.File outputFile)Copies the contents of any disk file to a specified output file.static booleancopyURLToFile(java.net.URL src, java.io.File dest)Generate a file from URL location.static booleandeleteDir(java.io.File dir)Deletes all files and subdirectories under dir.static booleanensureDirectory(java.io.File dir, java.io.File defaultDir)Ensures the existence of the directory specified by the parameter.static booleanensureFilePath(java.io.File file, java.io.File defaultDir)Ensures the existence of the directory which may be part of the path specification of parameterfile.static voidErrorMessage(java.lang.String a)Generate error message with long output.static voidErrorMessageLine(java.lang.String a)Generate error message as one line.static java.lang.StringfileNameOfPath(java.lang.String path)static java.lang.StringhtmlEncoded(java.lang.String text)Substitutes conflicting characters intextwith html masked expressions.static java.lang.StringpathNameOfPath(java.lang.String path)static voidrightWithin(java.awt.Component parent, java.awt.Component child)Puts to the rightstatic java.awt.PointrightWithin(java.awt.Rectangle rec, java.awt.Dimension dim)static java.lang.StringsubstituteText(java.lang.String text, java.lang.String token, java.lang.String substitute)Renders a string based ontextwhere any occurence oftokenis replaced bysubstitute.static java.lang.StringsubstituteTextS(java.lang.String text, java.lang.String token, java.lang.String substitute)Renders a string based ontextwhere any occurence oftokenis replaced bysubstitute.static inttextVariance(char[] ca)
-
-
-
Method Detail
-
centreWithin
public static java.awt.Point centreWithin(java.awt.Rectangle rec, java.awt.Dimension dim)Calculates the X and Y coordinates that a child component should have to be centered within its parent. This method does not try to constrain the calculation so that the point remains wholly onscreen.- Parameters:
rec- the bounding rectangle of the parent.dim- the dimensions of the child.- Returns:
- the X and Y coordinates the child should have.
-
rightWithin
public static java.awt.Point rightWithin(java.awt.Rectangle rec, java.awt.Dimension dim)
-
belowWithin
public static java.awt.Point belowWithin(java.awt.Rectangle rec, java.awt.Dimension dim)
-
centreWithin
public static void centreWithin(java.awt.Component parent, java.awt.Component child)Centres the child component within its parent.- Parameters:
parent- the parent component.child- the child component.
-
rightWithin
public static void rightWithin(java.awt.Component parent, java.awt.Component child)Puts to the right- Parameters:
parent- the parent component.child- the child component.
-
belowWithin
public static void belowWithin(java.awt.Component parent, java.awt.Component child)
-
fileNameOfPath
public static java.lang.String fileNameOfPath(java.lang.String path)
-
pathNameOfPath
public static java.lang.String pathNameOfPath(java.lang.String path)
-
substituteText
public static java.lang.String substituteText(java.lang.String text, java.lang.String token, java.lang.String substitute)Renders a string based ontextwhere any occurence oftokenis replaced bysubstitute.- Returns:
- String
-
substituteTextS
public static java.lang.String substituteTextS(java.lang.String text, java.lang.String token, java.lang.String substitute)Renders a string based ontextwhere any occurence oftokenis replaced bysubstitute.- Returns:
- String
-
htmlEncoded
public static java.lang.String htmlEncoded(java.lang.String text)
Substitutes conflicting characters intextwith html masked expressions. The returned string is displayable in html interpreting components.- Parameters:
text-- Returns:
-
copyFile
public static void copyFile(java.io.File inputFile, java.io.File outputFile) throws java.io.IOExceptionCopies the contents of any disk file to a specified output file. If the output file is a relative path, it is made absolute against the directory of the input file. The output file will be overwritten if it exist. A CRC32 check is performed to compare source and copy after the copy process and if results negative aStreamCorruptedExceptionis thrown. Function reports errors toSystem.err.- Parameters:
inputFile- a File objectoutputFile- a File object- Throws:
java.io.IOException- if the function could not be completed because of an IO or CRC check error
-
ensureFilePath
public static boolean ensureFilePath(java.io.File file, java.io.File defaultDir)Ensures the existence of the directory which may be part of the path specification of parameterfile. If the specified file is a relative path, it is made absolute againstdefaultDir. IfdefaultDiris null the System property "user.dir" is assumed as default directory.- Returns:
- true if and only if the parent directory of the specified file exists after this function terminates
-
ensureDirectory
public static boolean ensureDirectory(java.io.File dir, java.io.File defaultDir)Ensures the existence of the directory specified by the parameter. If the directory does not exist, an attempt is performed to create it including all necessary parent directories that may be implied by the specification.- Parameters:
dir- File specifying the intended directory; if the specified path is a relative path, it is made absolute againstdefaultDir. IfdefaultDiris null the System directory "user.dir" is assumed as default.- Returns:
- true if and only if the specified file exists and is a directory after this function terminates
-
textVariance
public static int textVariance(char[] ca)
-
deleteDir
public static boolean deleteDir(java.io.File dir)
Deletes all files and subdirectories under dir. Returns true if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.
-
ErrorMessage
public static void ErrorMessage(java.lang.String a)
Generate error message with long output.- Parameters:
a- Message
-
ErrorMessageLine
public static void ErrorMessageLine(java.lang.String a)
Generate error message as one line.- Parameters:
a- Message
-
copyURLToFile
public static boolean copyURLToFile(java.net.URL src, java.io.File dest) throws java.lang.ExceptionGenerate a file from URL location.- Parameters:
src- input URLdest- destination file- Throws:
java.lang.Exception
-
-
DMelt 3.0 © DataMelt by jWork.ORG