public class Utils extends FileUtils implements com.tplan.robot.remoteclient.rfb.RfbConstants
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
Modifier and Type | Field and Description |
---|---|
static NumberFormat |
fractionNumberFormat |
static NumberFormat |
numberFormat |
canCreateFileMap
BYTEMASK, CINIT_EXCLUSIVE_DESKTOP, CINIT_SHARE_DESKTOP, ENCODING_COMPRESSION_LEVEL_PSEUDO, ENCODING_COPY_RECT, ENCODING_CORRE, ENCODING_CURSOR_PSEUDO, ENCODING_DESKTOP_SIZE, ENCODING_GII_PSEUDO, ENCODING_HEXTILE, ENCODING_HEXTILE_ANY_SUBRECTS, ENCODING_HEXTILE_BG_SPECIFIED, ENCODING_HEXTILE_FG_SPECIFIED, ENCODING_HEXTILE_RAW, ENCODING_HEXTILE_SUBRECTS_COLORED, ENCODING_JPEG_FINE_GRAINED_PSEUDO, ENCODING_JPEG_SUBSAMPLING_PSEUDO, ENCODING_JPEGQLVL, ENCODING_LASTRECT_PSEUDO, ENCODING_POINTER_POSITION, ENCODING_RAW, ENCODING_RRE, ENCODING_TIGHT, ENCODING_X_CURSOR_PSEUDO, ENCODING_ZLIB, ENCODING_ZLIBHEX, MSG_C2S_CLIENT_CUT_TEXT, MSG_C2S_FIX_COLOR_MAP_ENTRIES, MSG_C2S_FRAMEBUFFER_UPDATE_REQUEST, MSG_C2S_KEY_EVENT, MSG_C2S_POINTER_EVENT, MSG_C2S_SET_ENCODINGS, MSG_C2S_SET_PIXEL_FORMAT, MSG_S2C_BELL, MSG_S2C_COMMUNICATION_ERROR, MSG_S2C_CONNECTED, MSG_S2C_CONNECTING, MSG_S2C_DISCONNECTED, MSG_S2C_DISCONNECTING, MSG_S2C_FRAMEBUFFER_UPDATE, MSG_S2C_SERVER_CUT_TEXT, MSG_S2C_SERVER_INIT, MSG_S2C_SET_COLOR_MAP_ENTRIES, PROTOCOL_VERSION_3_3, PROTOCOL_VERSION_3_7, PROTOCOL_VERSION_3_8, RFB_LISTEN_PORT_OFFSET, RFB_PORT_OFFSET, SECURITY_CDEAN, SECURITY_INVALID, SECURITY_MD5, SECURITY_NONE, SECURITY_RA2, SECURITY_RA2NE, SECURITY_RESPONSE_FAILED, SECURITY_RESPONSE_OK, SECURITY_RESPONSE_TOO_MANY_ATTEMPTS, SECURITY_SASL, SECURITY_TIGHT, SECURITY_TLS, SECURITY_TYPE_NAMES, SECURITY_TYPES, SECURITY_ULTRA, SECURITY_VENCRYPT, SECURITY_VNC_AUTH, SPECIAL_KEY_CODES, VAR_LISTEN, VK_CONTEXT_MENU, VK_WINDOWS
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static BufferedImage |
addAlpha(BufferedImage img) |
static void |
adjustSize(Window dlg) |
static void |
adjustSizeAndLocation(Window dlg)
Adjust size and location of a dialog.
|
static void |
centerOnScreen(Window win) |
static void |
checkOpacity(Component c) |
static boolean |
closeWindow(String fqcn) |
static boolean |
containsIgnoreCase(List l,
Object o)
Letter case tolerant contains() method for lists.
|
static boolean |
containsWhiteSpace(String s) |
static String |
convertLegacyHelpURL(String url)
Convert a legacy v4.x local help file URL to the new v5.x online one.
|
static String |
convertMultilineToString(String text) |
static String |
convertStringToMultiline(String text) |
static Document |
createDocument()
Create an empty XML document.
|
static JEditorPane |
createHTMLMessagePane(String message) |
static List<Point> |
createSmoothMoveCoords(int startX,
int startY,
int endX,
int endY,
int delta)
Create a list of points alongside the trajectory defined by the arguments.
|
static String |
createUID(String group,
String prefix) |
static void |
debugArray(byte[] array,
int length,
String desc)
Print out content of an integer array for debug purposes.
|
static void |
debugArray(int[] array,
String desc)
Print out content of an integer array for debug purposes.
|
static void |
debugArray(Object[] array,
String desc)
Print out content of an Object array for debug purposes.
|
static String |
encloseInDoubleQuotesIfNeeded(CharSequence s) |
static String |
encodeXmlAttribute(String str)
Encode an XML attribute value.
|
static String |
enforceMaxStringSize(Component owner,
String text,
int maxWidth)
Ensure that the argument text doesn't exceed the specified display width.
|
static String |
escapeHTML(String s)
Escape an HTML text so that it can be displayed in the body of another
HTML document.
|
static String |
escapeUnescapedDoubleQuotes(String s) |
static int |
execOpenURL(String url) |
static int |
execute(List<String> cmd,
StringBuilder stdOut,
StringBuilder errOut)
Execute an OS command.
|
static void |
exit(int exitCode)
Exit the JVM.
|
static void |
expandTree(JTree tree)
Expand the tree to display all nodes.
|
static void |
exportScriptToBBCode(Writer writer,
StyledDocument doc) |
static void |
exportScriptToHtml(Writer writer,
StyledDocument doc,
boolean addLineNumbers)
Export a test script as is displayed in the editor (with styles) to HTML.
|
File |
extractZip(File zip,
File targetDir)
Extract a zip file to the target directory.
|
static <T> List<T> |
findComponents(Container c,
Class<T> clazz)
Find all components of the specified class in a container (recursively).
|
static <T> List<T> |
findComponents(Container c,
Class<T> clazz,
boolean sameClass)
Find all components of the specified class in a container (recursively).
|
static String |
fixSingleBackSlashChars(String str) |
static Base64Support |
getBASE64Decoder() |
static Base64Support |
getBASE64Encoder() |
static BufferedImage |
getBufferedImage(Image image)
Create a
BufferedImage from an Image . |
static BufferedImage |
getBufferedImage(Image image,
Rectangle r,
boolean copy,
Integer type)
Method to get a BufferedImage or its part.
|
static long |
getCheckSum(InputStream is) |
static long |
getCheckSum(String text) |
static int[] |
getColorAt(int x,
int y,
BufferedImage image) |
static String |
getCopyright() |
static String |
getCurrentEnvironmentNetworkIp() |
static String |
getDateStamp(Date date) |
static String |
getDefaultOutputPath() |
static String |
getDefaultOutputPath(ScriptingContext ctx) |
static String |
getDefaultTemplatePath() |
static String |
getDefaultTemplatePath(TestScriptInterpret ti) |
static Point2D |
getDragTargetWithinBounds(Rectangle bounds,
Point2D dragSource,
Point2D dragTarget) |
static int |
getFreeLocalPort(int startFrom)
Find a free local port.
|
static File |
getHelpSetFile() |
static String |
getHintPattern(String url)
Get the hint pattern used to parse help files for fragments of text
displayed by the GUI as hints.
|
static String |
getHostName() |
static String |
getHostnameOrIP() |
static String |
getHTMLRed() |
static ImageObserver |
getImageObserver()
Get a simple implementation of the
ImageObserver interface for
image loading purposes. |
static InputStream |
getInputStream(String url,
URLConnection[] out,
Proxy proxy)
Connect to the argument HTTP URL and resolve eventual redirection.
|
static String |
getJavaDescription() |
static int[] |
getJavaSpecVersion() |
static int |
getKeyCode(String codeText) |
static Map<String,Integer> |
getKeyCodeTable() |
static String |
getKeyName(int keyCode) |
static KeyStroke |
getKeyStroke(String text) |
static KeyStroke |
getKeyStroke(String text,
boolean fixForMac) |
static String |
getKeyStrokeName(KeyStroke k) |
static String |
getLicenseText() |
static List |
getListOfStrings(String value)
Parse semicolon separated parameters as a list of String values.
|
static KeyStroke |
getMacAwareKeyStroke(KeyStroke k) |
static Rectangle |
getMaximumWindowSizeAt(int x,
int y)
Get the maximum window size and location at the screen belonging to the
specified coordinates.
|
static String |
getMouseCoordinateText(Point p,
BufferedImage image,
boolean shortVersion,
boolean isReadOnly,
boolean displayRelativeCoordinates) |
static int[] |
getPixels(Image img,
Rectangle r)
Get pixels of an image rectangle.
|
static String |
getProductNameAndVersion() |
static List<String> |
getPublicIPv4() |
static List<String> |
getRecentServersByProtocol(String protocol) |
static Date |
getReleaseDate() |
static List<Image> |
getRobotIcons() |
static int |
getRobotScreenNumber() |
static Insets |
getScreenInsets() |
static Rectangle |
getScreenSizeAtLocation(int x,
int y)
Get the screen rectangle for the given coordinates.
|
static String |
getStackTrace(Throwable t) |
static List<String> |
getStartCommand(String[] args) |
static List<String> |
getStartCommand(String[] args,
Boolean forceAbsolutePath,
File relativeTo) |
static List<String> |
getSupportedImageExtensions()
Get lower case list of image file extensions supported by this version
of Java.
|
static String |
getTimePeriodForDisplay(long miliseconds,
boolean longFormat) |
static String |
getTimePeriodForDisplay(long miliseconds,
boolean longFormat,
boolean showMiliseconds) |
static String |
getTimePeriodForDisplay(long miliseconds,
boolean longFormat,
boolean showMiliseconds,
boolean showMillisAsSecondFraction) |
static String |
getTimeStamp(Date date) |
static Window |
getTopmostWindow()
Get the topmost Robot window displayed on the screen.
|
static URI |
getURI(String uri) |
static int[] |
getVersion() |
static List<Window> |
getWindowHierarchy(Window w) |
static byte[] |
imageToBase64(Image img)
Convert an image to a Base64 encoded byte array.
|
static String |
imageToBase64String(Image img)
Convert an image to a Base64 encoded string.
|
static boolean |
implementsInterface(Class cl,
String interf)
Find out whether a class implements a particular interface.
|
static int |
indexOfIgnoreCase(List l,
Object o)
Letter case tolerant indexOf() method for lists.
|
static boolean |
isEncrypted(File zip)
Test out if a zip file is encrypted.
|
static boolean |
isHostEqual(String host,
int port,
RemoteDesktopClient client) |
static boolean |
isHTML(String text) |
static boolean |
isIPv4(String ip) |
static boolean |
isJava64Bit() |
static boolean |
isJava9() |
static boolean |
isJTattooLAF() |
static boolean |
isJVMExiting()
Indicate whether the JVM is being shut down through a call of
System.exit().
|
static boolean |
isLocalAddress(String address) |
static boolean |
isLocalPortInUse(int port)
Find out if the local port is being used or not.
|
static boolean |
isMac() |
static boolean |
isMacApp()
Test out if this Robot is a Mac application.
|
static boolean |
isOS64Bit() |
static boolean |
isWindows() |
static boolean |
isWindowsLocalhost(String host,
int port) |
static Rectangle |
modelToView(JTextComponent ed,
int position)
Get rectangle corresponding to the element at the argument position.This
method uses Reflection to invoke either JTextComponent.modelToView2D() on
Java 9+ or fall back to the obsoleted JTextComponent.modelToView() on
Java 8.
|
static void |
openHelp(String url)
Open the specified help URL in the web browser.
|
static void |
paintDefaultImage(Image image,
Image logoIcon,
String text)
Paint default image into a BufferedImage.
|
static int |
parseLegacyRfbPort(int portOffset,
String str) |
static String |
parseParamName(String str) |
static String |
parseParamValue(String str) |
static void |
printStack(String msg,
int level) |
static Map |
putAll(Map target,
Map source) |
static void |
registerComponentForEscape(JComponent comp,
JButton closeButton) |
static void |
registerDialogForEscape(JDialog dlg,
JButton closeButton) |
static void |
registerDialogForEscape(JFrame frame,
JButton closeButton) |
static CharSequence |
removeEnclosingDoubleQuotesIfNeeded(CharSequence s) |
static void |
restart(Window frame,
String[] args) |
static Map |
retrieveIntegrationParameters(Map options,
boolean remove)
Retrieve the T-Plan Professional integration parameters from the argument
map.
|
static boolean |
runOnAWTWithTimeout(Runnable r,
int timeoutMs)
Execute the specified runnable on the AWT dispatch thread.
|
static void |
setFixedWidth(Component component,
int width) |
static void |
setOpaque(boolean opaque,
Component c) |
static void |
setToolbarButtonsVisible(JToolBar toolBar,
String[] action,
boolean visible)
Set visibility of all created toolbar buttons.
|
static void |
setVisibilityOfComponents(Container c,
Object[] exclude,
boolean visible) |
static void |
setVisible(List<Window> list,
boolean visible) |
static int |
showCheckBoxMessageDialog(Component parentComponent,
String title,
String message,
String checkboxLabel,
Object[] options,
Icon[] icons,
int defaultBtnNo,
boolean[] selected,
boolean showResetHint) |
static int |
showConfigurableMessageDialog(Component parentComponent,
String title,
String message,
String checkboxLabel,
String configurationKey,
Object[] options,
Icon[] icons,
int defaultBtnNo,
boolean showResetHint) |
static int |
showConfigurableMessageDialog(Component parentComponent,
String title,
String message,
String checkboxLabel,
String configurationKey,
Object[] options,
int defaultBtnNo)
Display a warning message which contains a check box like 'Do not display this message again'.
|
static int |
showConfigurableMessageDialog(Component parentComponent,
String title,
String message,
String checkboxLabel,
String configurationKey,
Object[] options,
int defaultBtnNo,
boolean showResetHint) |
static void |
showErrorDialog(Component parentComponent,
String title,
String message,
Throwable ex)
Show an error window.
|
static void |
showErrorDialog(Component parentComponent,
String title,
String message,
Throwable ex,
boolean collapseThrowable)
Show an error window.This method avoids JOptionPane and creates its own
dialog.
|
static void |
showErrorOnWindowOpening(Window owner,
String title,
String message,
Throwable ex,
boolean collapseThrowable) |
static int |
showMessageDialog(Component parentComponent,
String title,
Object message,
Throwable ex,
String[] options,
Icon[] icons,
String defaultOption,
boolean collapseThrowable) |
static int |
showMessageDialog(Component parentComponent,
String title,
Object message,
Throwable ex,
String[] options,
Icon[] icons,
String defaultOption,
boolean collapseThrowable,
boolean showThrowableMessageOnly,
String throwableTickBox)
Show a message window with configurable list of buttons.It is basically a
replacement of JOptionPane which fixes a few annoyances and delivers new
functionality such as:
|
static int |
showMessageDialog(Component parentComponent,
String title,
String message,
Throwable ex,
String[] options,
Icon[] icons,
String defaultOption)
Show a message window with configurable list of buttons.
|
static String |
size2string(long fileSize)
Convert a size in bytes to a displayable string with one digit after the
floating point ("3.2 kB", "121.1 MB" etc.).
|
static void |
sleep(long millis)
An exception safe variant of the
Thread.sleep(long) method. |
static String[] |
splitCli(String s)
Split a line with CLI arguments into tokens.
|
static Map<String,List<String>> |
splitQuery(URI uri) |
static Map<String,List<String>> |
splitQuery(URL url) |
static String |
stripBOM(String data)
Strip the leading BOM character from the string.
|
static String |
stripHTML(String html)
Strip HTML code from an HTML document or fragment and return the plain
text.
|
static String |
stripHTMLFast(String html)
Strip HTML tags and entities (escaped char sequences) from the argument.
|
static String |
stripRTF(String rtf) |
static Document |
toDocument(File f,
boolean nameSpaceAware) |
static Document |
toDocument(String xmlContent,
boolean nameSpaceAware) |
static void |
toFrontOnMac() |
static boolean |
toggle(JSplitPane sp,
boolean collapse)
Simulate pressing of a
JSplitPane 's divider button to extend or
collapse it. |
static <T> Map<T,T> |
toMap(T[][] values) |
static String |
toPlainText(String text) |
static String |
toString(byte[] a,
int offset,
int length) |
static String |
unescapeJavaString(String st) |
static int |
viewToModel(JTextComponent ed,
Point p)
Determine document offset (text position) for the argument point.
|
static String |
wrap(String text,
int columns,
boolean html) |
static void |
writeLog(PrintStream writer,
String msg) |
static void |
writeXML(Document doc,
Object target,
int indent)
Write an XML document to the target stream or file.
|
canCreateNewFile, contains, copy, copy, copy, copyDirectoryContent, copyDirectoryContent, copyDirectoryContent, copyFile, delete, deleteEmptyDirs, extract, findFile, findFile, getExtension, getExtension, getFileFromURL, getFullPath, getInstallPath, getInstallPath, getJarFile, getJarFile, getJarManifestField, getRelativePath, isLink, isParent, moveOrCopy, parseFile, read, read, rename, write, write, writeSafely
public static final NumberFormat numberFormat
public static final NumberFormat fractionNumberFormat
public static boolean isJVMExiting()
public static void exit(int exitCode)
System.exit(int)
one but it saves a flag that it is an intentional exit.exitCode
- the process exit code.public static Base64Support getBASE64Decoder()
public static Base64Support getBASE64Encoder()
public static URI getURI(String uri) throws URISyntaxException
URISyntaxException
public static int parseLegacyRfbPort(int portOffset, String str)
public static String parseParamName(String str) throws StringIndexOutOfBoundsException
StringIndexOutOfBoundsException
public static String parseParamValue(String str) throws StringIndexOutOfBoundsException
StringIndexOutOfBoundsException
public static int[] getVersion()
public static Date getReleaseDate()
public static String getProductNameAndVersion()
public static String getCopyright()
public static String getLicenseText()
public static String getTimePeriodForDisplay(long miliseconds, boolean longFormat)
public static String getTimePeriodForDisplay(long miliseconds, boolean longFormat, boolean showMiliseconds)
public static String getTimePeriodForDisplay(long miliseconds, boolean longFormat, boolean showMiliseconds, boolean showMillisAsSecondFraction)
public static String getKeyName(int keyCode)
public static int getKeyCode(String codeText)
public static String encloseInDoubleQuotesIfNeeded(CharSequence s)
public static CharSequence removeEnclosingDoubleQuotesIfNeeded(CharSequence s)
public static String escapeHTML(String s)
s
- an HTML text.public static int[] getPixels(Image img, Rectangle r)
img
- an image.r
- rectangle to grab the pixels from.public static boolean isWindowsLocalhost(String host, int port)
public static boolean isWindows()
public static boolean isLocalAddress(String address) throws UnknownHostException, SocketException
UnknownHostException
SocketException
public static boolean isHostEqual(String host, int port, RemoteDesktopClient client)
public static String getCurrentEnvironmentNetworkIp() throws UnknownHostException
UnknownHostException
public static boolean isIPv4(String ip)
public static List<String> getPublicIPv4() throws UnknownHostException
UnknownHostException
public static String getHostnameOrIP()
public static boolean isLocalPortInUse(int port)
port
- a port number to test.public static int getFreeLocalPort(int startFrom)
startFrom
- the port to start from.public static void showErrorDialog(Component parentComponent, String title, String message, Throwable ex)
parentComponent
- parent component (owner). It should be either a
JFrame or JDialog instance or null.title
- message title. A default one will be provided if the argument is null.message
- error message text. A default one will be provided if the argument is null.ex
- an exception to display. May be null.public static void showErrorDialog(Component parentComponent, String title, String message, Throwable ex, boolean collapseThrowable)
parentComponent
- parent component (owner). It should be either a
JFrame or JDialog instance or null.title
- message title. A default one will be provided if the
argument is null.message
- error message text. A default one will be provided if the
argument is null.ex
- an exception to display. May be null.collapseThrowable
- true to collapse the throwable viewer.public static int showMessageDialog(Component parentComponent, String title, String message, Throwable ex, String[] options, Icon[] icons, String defaultOption)
Show a message window with configurable list of buttons. It is basically a replacement of JOptionPane which fixes a few annoyances and delivers new functionality such as:
JEditorPane
with attached
CustomHyperlinkListener
. This allows to display HTML text where
the standard HTTP links are opened in web browser and links of special
syntax supported by CustomHyperlinkListener
allow to trigger GUI
actions, such as for example open a help page or the Preferences window.err
argument contains a valid throwable, the window
displays its stack trace in a scrollable text pane.parentComponent
- parent component (owner).title
- window title.message
- message text. It may be either plain text or HTML.
HTML text must start with the "<html>" prefix to be recognized properly.ex
- an optional throwable to display the stack trace of.options
- optional list of button labels. The window will then display
with the corresponding list of closing buttons at the bottom. If this
parameter is null, the window will contain just the default "OK" button.icons
- optional icons for the buttons.defaultOption
- default button label (one from the options
list. It will have focus and it will also get selected when user presses Enter.public static int showMessageDialog(Component parentComponent, String title, Object message, Throwable ex, String[] options, Icon[] icons, String defaultOption, boolean collapseThrowable)
public static int showMessageDialog(Component parentComponent, String title, Object message, Throwable ex, String[] options, Icon[] icons, String defaultOption, boolean collapseThrowable, boolean showThrowableMessageOnly, String throwableTickBox)
Show a message window with configurable list of buttons.It is basically a replacement of JOptionPane which fixes a few annoyances and delivers new functionality such as:
JEditorPane
with attached
CustomHyperlinkListener
. This allows to display HTML text where
the standard HTTP links are opened in web browser and links of special
syntax supported by CustomHyperlinkListener
allow to trigger GUI
actions, such as for example open a help page or the Preferences window.err
argument contains a valid throwable, the window
displays its stack trace in a scrollable text pane.parentComponent
- parent component (owner).title
- window title.message
- message text. It may be either plain text or HTML.
HTML text must start with the "<html>" prefix to be recognized properly.ex
- an optional throwable to display the stack trace of.options
- optional list of button labels. The window will then display
with the corresponding list of closing buttons at the bottom. If this
parameter is null, the window will contain just the default "OK" button.icons
- optional icons for the buttons.defaultOption
- default button label (one from the options
list. It will have focus and it will also get selected when user presses Enter.collapseThrowable
- true to display the window with the view of
throwable collapsed.showThrowableMessageOnly
- true to show the throwable message returned
by Throwable.getMessage()
or false to display the whole stack trace.throwableTickBox
- optional custom name for the collapse/expand check
box.public static void setFixedWidth(Component component, int width)
public static int showConfigurableMessageDialog(Component parentComponent, String title, String message, String checkboxLabel, String configurationKey, Object[] options, int defaultBtnNo)
parentComponent
- parent component (must be a JFrame or JDialog)title
- message window titlemessage
- message to be displayedcheckboxLabel
- text of the check boxconfigurationKey
- configuration key of the check box option (should be an int option because
the method saves button index chosen by the user rather than a plain boolean)options
- an array of labels for buttonsdefaultBtnNo
- default button indexpublic static int showConfigurableMessageDialog(Component parentComponent, String title, String message, String checkboxLabel, String configurationKey, Object[] options, int defaultBtnNo, boolean showResetHint)
public static int showConfigurableMessageDialog(Component parentComponent, String title, String message, String checkboxLabel, String configurationKey, Object[] options, Icon[] icons, int defaultBtnNo, boolean showResetHint)
public static int showCheckBoxMessageDialog(Component parentComponent, String title, String message, String checkboxLabel, Object[] options, Icon[] icons, int defaultBtnNo, boolean[] selected, boolean showResetHint)
public static void registerDialogForEscape(JDialog dlg, JButton closeButton)
public static void registerDialogForEscape(JFrame frame, JButton closeButton)
public static void registerComponentForEscape(JComponent comp, JButton closeButton)
public static void writeLog(PrintStream writer, String msg)
public static List<String> getSupportedImageExtensions()
public static List getListOfStrings(String value)
value
- a string to parse.public static String getMouseCoordinateText(Point p, BufferedImage image, boolean shortVersion, boolean isReadOnly, boolean displayRelativeCoordinates)
public static int[] getColorAt(int x, int y, BufferedImage image)
public static void debugArray(int[] array, String desc)
array
- an integer arraydesc
- descriptionpublic static void debugArray(byte[] array, int length, String desc)
array
- an integer array.length
- the length of the items to print out.desc
- descriptionpublic static void debugArray(Object[] array, String desc)
array
- an Object arraydesc
- descriptionpublic static void paintDefaultImage(Image image, Image logoIcon, String text)
image
- an image.logoIcon
- the logo icon.text
- the text to be rendered.public static String convertLegacyHelpURL(String url)
url
- a legacy help file URL.public static String getHintPattern(String url)
url
- a URL of the help document that is to be parsed.public static void openHelp(String url)
url
- the help page URL.public static int execOpenURL(String url)
public static void setToolbarButtonsVisible(JToolBar toolBar, String[] action, boolean visible)
toolBar
- the tool bar.action
- actions to be processed or null to apply to all.visible
- true/false to set visible/invisible.public static void setVisibilityOfComponents(Container c, Object[] exclude, boolean visible)
public static <T> List<T> findComponents(Container c, Class<T> clazz)
T
- the component class name.c
- the container to search.clazz
- the component class.public static <T> List<T> findComponents(Container c, Class<T> clazz, boolean sameClass)
T
- the component class or interface name.c
- the container to search.clazz
- the component class or an interface it is supposed to implement.sameClass
- the value of true will look up all components which are
instances of clazz
. Otherwise the method returns all components
which are of the specified class, extend it or implement the clazz
interface.public static int getRobotScreenNumber()
public static boolean closeWindow(String fqcn)
public static void centerOnScreen(Window win)
public static void sleep(long millis)
Thread.sleep(long)
method.millis
- number of milliseconds to sleep for.public static List<String> getStartCommand(String[] args, Boolean forceAbsolutePath, File relativeTo)
public static Document toDocument(String xmlContent, boolean nameSpaceAware) throws ParserConfigurationException, SAXException, IOException
public static Document toDocument(File f, boolean nameSpaceAware) throws ParserConfigurationException, SAXException, IOException
public static String stripBOM(String data)
data
- a stringpublic static void writeXML(Document doc, Object target, int indent) throws IOException
doc
- a documenttarget
- a file, an output stream or a writer.indent
- whether to indent (format) the document. The value of 0 or
lower sets off indenting.IOException
- thrown by the transformer or the targetpublic static Document createDocument()
public static Rectangle modelToView(JTextComponent ed, int position) throws BadLocationException
ed
- a text componentposition
- document offsetBadLocationException
- if the position is out of
the document bounds.public static int viewToModel(JTextComponent ed, Point p)
ed
- a text componentp
- a pointpublic static String getDefaultTemplatePath()
public static String getDefaultOutputPath()
public static String getDefaultTemplatePath(TestScriptInterpret ti)
public static String getDefaultOutputPath(ScriptingContext ctx)
public static void exportScriptToHtml(Writer writer, StyledDocument doc, boolean addLineNumbers) throws IOException, BadLocationException
writer
- an output writer to write to.doc
- a styled document containing a test script with styles.addLineNumbers
- true turns on line numbering.IOException
- on an I/O error in the writer.BadLocationException
- on a wrong offset referenced
in the argument document.public static void exportScriptToBBCode(Writer writer, StyledDocument doc) throws IOException, BadLocationException
IOException
BadLocationException
public static boolean containsIgnoreCase(List l, Object o)
l
- a list.o
- a value to search for. If the value is a String, the list is
searched using String.equalsIgnoreCase().public static int indexOfIgnoreCase(List l, Object o)
l
- a list.o
- a value to search for. If the value is a String, the list is
searched using String.equalsIgnoreCase().public static <T> Map<T,T> toMap(T[][] values)
public static Insets getScreenInsets()
public static void adjustSizeAndLocation(Window dlg)
dlg
- a dialog to check the size and location of.public static void adjustSize(Window dlg)
public static Rectangle getScreenSizeAtLocation(int x, int y)
x
- an x coordinate.y
- an y coordinate.public static Rectangle getMaximumWindowSizeAt(int x, int y)
x
- an x coordinate.y
- an y coordinate.public static BufferedImage addAlpha(BufferedImage img)
public static BufferedImage getBufferedImage(Image image)
BufferedImage
from an Image
.image
- if the argument is already a BufferedImage the method
returns it without any changes. If the image is an Image
instance
the method creates a new BufferedImage (type
BufferedImage.TYPE_INT_RGB
) and copies the pixels in there. If
the argument is null the method returns null.public static BufferedImage getBufferedImage(Image image, Rectangle r, boolean copy, Integer type)
image
- an image.r
- the area to crop or null to return the full image.copy
- true will always create a copy of the source image.type
- the target BufferedImage type. If the argument is null the
image will be of the same type if the source is a BufferedImage. If the
source image is not a BufferedImage it will default to
BufferedImage.TYPE_INT_RGB
. If the argument is not null and the
target type doesn't match the source image type the method creates an
image copy.public static ImageObserver getImageObserver()
ImageObserver
interface for
image loading purposes.public static boolean isMac()
public static boolean isMacApp()
public static boolean isJTattooLAF()
public static File getHelpSetFile()
public static boolean implementsInterface(Class cl, String interf)
Class.getImplementedInterfaces()
the method also checks all
superclasses. It provides the same functionality as the "instanceof"
operator save that it avoids any class instantiation.cl
- a class to be checked for the implemented interface.interf
- an interface class.public static String getJavaDescription()
public static boolean isOS64Bit()
public static boolean isJava64Bit()
public static JEditorPane createHTMLMessagePane(String message)
public static void showErrorOnWindowOpening(Window owner, String title, String message, Throwable ex, boolean collapseThrowable)
public static String stripHTMLFast(String html)
stripHTML(java.lang.String)
one.html
- an HTML text.public static String stripHTML(String html)
html
- an HTML document or fragment.public static boolean isHTML(String text)
public static String[] splitCli(String s)
Split a line with CLI arguments into tokens. This is used for conversion
of a command with CLI arguments into an argument array for the use with
Runtime.exec(java.lang.String[])
. This addresses mainly Mac OS
where the Runtime.exec(java.lang.String)
doesn't work well with escaping.
For example, a line like:
diff "/tmp/my doc1.txt" "/tmp/my doc2.txt"
will be split to three tokens of "diff", "/tmp/my doc1.txt" and "/tmp/my doc2.txt".
s
- a CLI string.public static Map<String,List<String>> splitQuery(URI uri) throws UnsupportedEncodingException
UnsupportedEncodingException
public static Map<String,List<String>> splitQuery(URL url) throws UnsupportedEncodingException
UnsupportedEncodingException
public static long getCheckSum(String text) throws IOException
IOException
public static long getCheckSum(InputStream is) throws IOException
IOException
public static void printStack(String msg, int level)
public static boolean containsWhiteSpace(String s)
public static void setOpaque(boolean opaque, Component c)
public static void checkOpacity(Component c)
public static int[] getJavaSpecVersion()
public static int execute(List<String> cmd, StringBuilder stdOut, StringBuilder errOut) throws IOException, InterruptedException
cmd
- the list of command elements (the command itself plus the arguments/options).stdOut
- a buffer for the command standard output.errOut
- a buffer for the command error output.IOException
- on an I/O error.InterruptedException
- when interrupted while waiting for the process to finish.public static String toString(byte[] a, int offset, int length)
public static List<Point> createSmoothMoveCoords(int startX, int startY, int endX, int endY, int delta)
startX
- start X coordinate.startY
- start Y coordinate.endX
- end X coordinate.endY
- end Y coordinate.delta
- maximum distance between two subsequent point (granularity).
The lower the number is the more points will be created.public static String size2string(long fileSize)
fileSize
- a file size in bytespublic static Window getTopmostWindow()
public static void expandTree(JTree tree)
tree
- a JTree to expand.public static String getHostName()
public static String encodeXmlAttribute(String str)
str
- an attribute value.public static String enforceMaxStringSize(Component owner, String text, int maxWidth)
owner
- the component that is about to display this text (used to
retrieve the font and font metrics).text
- the text.maxWidth
- maximum text width in pixels.public static Map retrieveIntegrationParameters(Map options, boolean remove)
options
- a map with Robot's CLI options.remove
- true will remove the options from the source map.public static boolean toggle(JSplitPane sp, boolean collapse)
JSplitPane
's divider button to extend or
collapse it.sp
- a split pane.collapse
- true will collapse the right/bottom component, false will
expand it.public static boolean isJava9()
public static Point2D getDragTargetWithinBounds(Rectangle bounds, Point2D dragSource, Point2D dragTarget)
public static boolean runOnAWTWithTimeout(Runnable r, int timeoutMs) throws InterruptedException
r
- a runnabletimeoutMs
- the timeout in millisecondsInterruptedException
- on interruption.public static byte[] imageToBase64(Image img) throws IOException
img
- an image.IOException
- on an I/O error.public static String imageToBase64String(Image img) throws IOException
img
- an image.IOException
- on an I/O error.public static InputStream getInputStream(String url, URLConnection[] out, Proxy proxy) throws IOException
url
- a url (HTTP or HTTPS).out
- optional array to store the resulting connection to.proxy
- optional proxy.IOException
- on an I/O error.public static void toFrontOnMac()
public static String getHTMLRed()
public static boolean isEncrypted(File zip)
zip
- a zip file.public File extractZip(File zip, File targetDir) throws IOException
zip
- a zip file.targetDir
- the target directory.IOException
- on an I/O exception.