public interface IUtils
To make everyone's life easier.
IGuiUtils
Modifier and Type | Method and Description |
---|---|
java.lang.String |
calculateFileMd5(java.nio.file.Path file)
Calculates the MD5 digest of a file.
|
java.lang.String |
calculateFileSha256(java.nio.file.Path file)
Calculates the SHA-256 digest of a file.
|
java.lang.String |
calculateStreamSha256(java.io.InputStream input,
long size)
Calculates the SHA-256 digest of data read from a stream.
|
boolean |
checkEmailSettings()
Checks the email settings, and returns
true if they are set and emails can be sent. |
java.lang.String |
concatenate(java.util.Collection<?> c)
Concatenates the elements of the specified collection to a comma separated string.
|
java.lang.String |
concatenate(int[] arr)
Concatenates the elements of the specified
int array to a semicolon separated string.Elements are separated with a semicolon and a space. |
boolean |
containsIngoreCase(java.lang.String text,
java.lang.String searchText)
Checks if the specified text contains the specified search text, performing a case-insensitive search.
|
void |
copyToClipboard(java.lang.String text)
Copies the specified text to the system clipboard.
|
java.util.concurrent.ExecutorService |
createExecutorService(java.lang.String parentThreadName)
Creates and returns an
ExecutorService which uses a thread pool with a size defined by the utilized CPU cores setting. |
boolean |
deletePath(java.nio.file.Path path)
Deletes the specified path, recursively.
|
IOpSys |
detectOs()
Returns the detected operating system (
IOpSys ). |
IPair<java.lang.String,java.lang.String> |
getFileNameAndExt(java.nio.file.Path file)
Returns the file name and extension parts of the name of the specified file.
|
java.lang.String |
getFileNameWithoutExt(java.nio.file.Path file)
Returns the file name of the specified file without its extension.
|
byte[] |
hexToBytes(java.lang.String hex)
Converts the specified hex string to bytes.
|
void |
launchReplay(java.nio.file.Path replayFile)
Starts playing a replay in StarCraft II.
|
<T> boolean |
moveBackward(java.util.List<T> list,
int[] indices)
Moves elements specified by their indices backward by 1.
|
<T> boolean |
moveForward(java.util.List<T> list,
int[] indices)
Moves elements specified by their indices forward by 1.
|
byte[] |
readFully(java.io.InputStream in,
byte[] buffer)
Reads a full byte array from the specified input stream.
|
java.lang.String |
safeForHtml(java.lang.String text)
Prepares a text for HTML rendering, to be included in HTML text.
|
void |
setEmailListValidator(IIndicatorTextField itf)
Sets an email list validator for the specified
IIndicatorTextField . |
void |
setEmailValidator(IIndicatorTextField itf)
Sets an email validator for the specified
IIndicatorTextField . |
void |
setMergedAccountsValidator(IIndicatorTextArea ita)
Sets a merged accounts validator (list of toon lists) for the specified
IndicatorTextArea . |
void |
setToonListValidator(IIndicatorTextField itf)
Sets a toon list validator for the specified
IIndicatorTextField . |
void |
showPathInFileBrowser(java.nio.file.Path path)
Opens the specified file or folder in the default file browser application of the user's OS.
|
void |
showURLInBrowser(java.net.URL url)
Opens the web page specified by the URL in the system's default browser.
|
boolean |
shutdownExecutorService(java.util.concurrent.ExecutorService es)
Shuts down properly the specified executor service.
|
void |
sortReversed(int[] a)
Sorts the specified int array in reversed order.
|
java.lang.String |
stripOffLeadingZeros(java.lang.String s)
Strips off leading zero characters from the specified string.
|
java.lang.String |
toBase64String(byte[] data)
Converts the specified data to base64 encoded string.
|
java.lang.String |
toCss(java.awt.Color color)
Converts the specified color to a CSS color sting.
|
java.lang.String |
toHexString(byte[] data)
Converts the specified data to hex string.
|
java.lang.String |
toHexString(byte[] data,
int offset,
int length)
Converts the specified data to hex string.
|
java.nio.file.Path |
uniqueFile(java.nio.file.Path file)
Generates and returns a unique path for the specified file that does not yet exist.
|
void showPathInFileBrowser(java.nio.file.Path path)
If a file is specified, on Windows it will also be selected.
path
- file or folder to be openedvoid showURLInBrowser(java.net.URL url)
url
- URL
to be openedvoid launchReplay(java.nio.file.Path replayFile)
Due to StarCraft II it only works if StarCraft II is not running at the time when this is called.
replayFile
- replay file to be launchedjava.lang.String safeForHtml(java.lang.String text)
text
- text to be preparedboolean deletePath(java.nio.file.Path path)
path
- path to be deletedjava.nio.file.Path uniqueFile(java.nio.file.Path file)
If the provided file does not exist, it is returned.
If it exists, an incrementing counter starting at 2 will be post-pended to the file name (keeping the extension) will be tried. (" (2)"
,
" (3)"
, etc.).
file
- file to return a unique path forjava.lang.String calculateFileMd5(java.nio.file.Path file)
file
- file whose MD5 to be calculatedjava.lang.String calculateFileSha256(java.nio.file.Path file)
file
- file whose SHA-256 to be calculatedjava.lang.String calculateStreamSha256(java.io.InputStream input, long size)
Note: the size
parameter is of type long
for convenience but is treated as int
which means its value cannot be
greater than Integer.MAX_VALUE
.
input
- input stream to read data fromsize
- number of bytes to read and calculate digest fromjava.lang.String toBase64String(byte[] data)
data
- data to be convertedjava.lang.String toHexString(byte[] data)
data
- data to be convertedtoHexString(byte[], int, int)
,
hexToBytes(String)
java.lang.String toHexString(byte[] data, int offset, int length)
data
- data to be convertedoffset
- offset of the first byte to be convertlength
- number of bytes to be convertedtoHexString(byte[])
,
hexToBytes(String)
byte[] hexToBytes(java.lang.String hex)
The hex string must be lower-cased, can only contain hex digits ('0'..'9'
and 'a'..'f'
) and spaces (which will be omitted), and
its length must be even.
hex
- hex string; a string containing hexadecimal numbersnull
if hex
is an invalid hex stringtoHexString(byte[])
,
toHexString(byte[], int, int)
boolean containsIngoreCase(java.lang.String text, java.lang.String searchText)
text
- text to search insearchText
- text to be searchedjava.lang.String concatenate(int[] arr)
int
array to a semicolon separated string.arr
- int
array whose elements to concatenatejava.lang.String concatenate(java.util.Collection<?> c)
c
- collection whose elements to concatenatevoid sortReversed(int[] a)
a
- array to be reverse-sortedjava.lang.String stripOffLeadingZeros(java.lang.String s)
Example: "\0\0S2"
=> "S2"
s
- string to strip off leading zero characters fromvoid copyToClipboard(java.lang.String text)
text
- text to be copied to the system clipboardjava.lang.String toCss(java.awt.Color color)
color
- color to be convertedjava.lang.String getFileNameWithoutExt(java.nio.file.Path file)
file
- file whose name without extension to be returnedIPair<java.lang.String,java.lang.String> getFileNameAndExt(java.nio.file.Path file)
If the name of the specified file does not have an extension (dot is not found in its name), the second part of the returned pair will be
null
.
file
- file whose name and extension to be returnedboolean checkEmailSettings()
true
if they are set and emails can be sent.
If email settings are not configured properly, an info dialog will be displayed informing the user about this, with a link to open the email settings page.
byte[] readFully(java.io.InputStream in, byte[] buffer) throws java.io.IOException
The problem with InputStream.read(byte[])
is that it does not guarantee that the passed array will be "fully populated" even if there are enough
data in the input stream (the returned number of bytes might be smaller than the array length). This method does guarantee it.
in
- input stream to read frombuffer
- array to be readjava.io.IOException
- if reading from the stream throws IOException
java.util.concurrent.ExecutorService createExecutorService(java.lang.String parentThreadName)
ExecutorService
which uses a thread pool with a size defined by the utilized CPU cores setting.parentThreadName
- parent thread nameExecutorService
with the proper thread pool sizeboolean shutdownExecutorService(java.util.concurrent.ExecutorService es)
es
- executor service to be shut down<T> boolean moveBackward(java.util.List<T> list, int[] indices)
If the specified indices contains 0, then nothing is moved (the first element cannot be moved backward).
Implementation note: the received indices array might be rearranged. If this is unwanted, pass a copy of the original array.
T
- type of the elements of the listlist
- list whose elements to moveindices
- indices of elements to be moved backward by 1moveForward(List, int[])
<T> boolean moveForward(java.util.List<T> list, int[] indices)
If the specified indices contains the index of the last element, then nothing is moved (the last element cannot be moved forward).
Implementation note: the received indices array might be rearranged. If this is unwanted, pass a copy of the original array.
T
- type of the elements of the listlist
- list whose elements to moveindices
- indices of elements to be moved backward by 1moveBackward(List, int[])
void setToonListValidator(IIndicatorTextField itf)
IIndicatorTextField
.itf
- IIndicatorTextField
to set a validator forvoid setMergedAccountsValidator(IIndicatorTextArea ita)
IndicatorTextArea
.ita
- IIndicatorTextArea
to set a validator forvoid setEmailValidator(IIndicatorTextField itf)
IIndicatorTextField
.itf
- IIndicatorTextField
to set a validator forvoid setEmailListValidator(IIndicatorTextField itf)
IIndicatorTextField
.itf
- IIndicatorTextField
to set a validator for
This API documentation is public and is intended for / allowed to be used by anyone.
Scelight home page: https://sites.google.com/site/scelight/
Scelight is a trademark of András Belicza. Copyright © András Belicza, 2013-2015. All rights reserved.