public class DemoUtils
DemoUtils
In BBj 20.01 and higher, the DemoUtils
is a BBj Custom Class that provides commonly-used routines for demo programs
THROW
n Error Codes:
700
: Missing file. The specified file does not exist.705
: Error during file operation, such as reading in a source file to copy to target file.710
: Invalid BBjControl. The BBjControl is null(), invalid, does not exist, or does not implement required method.715
: Invalid control/object provided. The control or object is null(), invalid, does not exist, or is empty.720
: Error reading or writing a cookie. The get/setUserProperty() method failed with the provided error information.725
: Error getting the BBjThinClient.Modifier and Type | Field and Description |
---|---|
static BBjNumber | FONT_STYLE_BOLD |
static BBjNumber | FONT_STYLE_ITALIC |
static BBjNumber | FONT_STYLE_PLAIN |
static BBjNumber | FONT_STYLE_STRIKEOUT |
static BBjNumber | FONT_STYLE_UNDERLINE |
static BBjString | JQueryFileLocation$ A BBjString that defines the fully-qualified path to the jQuery library |
static BBjString | JQuerySlimFileLocation$ A BBjString that defines the fully-qualified path to the jQuery library's 'slim' build, which excludes the ajax and effects modules |
static BBjString | JQueryUIFileLocation$ A BBjString that defines the fully-qualified path to the jQuery UI library |
static BBjString | JQueryUITouchFileLocation$ A BBjString that defines the fully-qualified path to the jQueryUI Touch library |
Modifier and Type | Method and Description |
---|---|
static void | copyFile(BBjString p_source$, BBjString p_target$) Method to copy a file to another directory by providing the fully qualified path to both the source file and the target file. Note: The target path must include the target filename; it cannot be the directory in which the file will ultimately reside. |
static BBjFont | getBBjFont(Font p_font!) Method to get a BBjFont object from a Java Font object |
static BBjFont | getBBjFont(BBjString p_fontPath$, BBjNumber p_fontSize, BBjNumber p_fontStyle) Method to get a BBjFont object from a path to a TTF or OTF file |
static HashMap | getCookies(BBjString p_cookieKey$) Method to get multiple string-based user preferences in a HashMap to reduce client-server round trips The get/setCookies() methods offer a simple way to persist application setting via a HashMap. You save information by calling the setCookies() method providing a unique key value that's used to store the information (usually the app's name, but it can be virtually any string) and a HashMap filled with the information to store. You can then call the getCookies() method to retrieve the saved information in a HashMap. The methods bypass the effort of creating string templates and BBjTemplatedStrings as well as encoding information for safety and portability.
Both get/setCookies() methods throw errors, so you may want to add an |
static BBjString | getFileBaseName(BBjString p_source$) Method to return a file's base name by stripping its extension. If the file |
static BBjString | getFileBytes(BBjString p_source$) Method to get a file's contents in a BBjString variable, regardless of whether it's a text or binary file and without taking into account the character encoding. NOTE: This method read all bytes into memory in a single statement so do not use it to read large files (2GB), as it could results in an OutOfMemoryError. This method uses the Java Files::readAllBytes() method to get the contents of a file. The utility's getFileContents() method is similar, except that method uses BBj syntax to load the contents of a file. In practice, that method will be slower and will only return up to the first 10 megabytes of the file. In contrast, this method can be up to five times faster and it can read in over 1 gigabyte of data. However, if you provide a file that is too large, it will result in an out of memory error. |
static BBjString | getFileContents(BBjString p_source$) Method to get a file's contents in a BBjString variable - Note that this method reads in a maximum of 10 megabytes. |
static BBjString | getFileExtension(BBjString p_source$) Method to get a file's extension |
static BBjString | getFileNameFromFullPath(BBjString p_source$) Method to get a file's name from a fully-qualified path by stripping all the directories |
static BBjString | getFileNameWithoutExtensionFromFullPath(BBjString p_source$) Method to get a file's name without extension from a fully-qualified path by stripping all the directories, dot, and extension |
static BBjString | getFilePathWithEndSeparator(BBjString p_source$) |
static BBjString | getFilePathWithoutEndSeparator(BBjString p_source$) |
static BBjNumber | getIndexOfFileExtension(BBjString p_source$) Method to return the index of a file's extension separator which is a dot. If the file doesn't have an extension, which can also occur when a file contains a dot within its path but is later followed by the path separator character or slash, then the method will return -1. |
static Font | getJavaFont(BBjFont p_font!) Method to get a Java Font object from a BBjFont object |
static JsonObject | getJsonCSS(JsonObject p_jsonCSS!, BBjNumber p_fontSize, BBjNumber p_fontWeight) Method to get the CSS properties for a given BBjFont and return a Google JsonObject, typically used when themeing the BBjGridExWidget |
static JsonObject | getJsonCSSForBBjFont(BBjFont p_font!, BBjString p_altFamilies$) Method to get the CSS properties for a given BBjFont and return a Google JsonObject, typically used when themeing the BBjGridExWidget |
static BBjNumber | getScreenPixelRatio() Method to get the ratio of physical to logical pixels on the default client screen device. HiDPI (Retina) displays report values greater than 1, typically 2
Note that you can use the |
static BBjNumber | getScreenPixelRatio(BBjWindow p_window!) Method to get the ratio of physical to logical pixels on the specific client screen device. HiDPI (Retina) displays report values greater than 1, typically 2
Note that you can use the |
static void | injectCss(BBjString css!, BBjString location!, BBjString description!, BBjNumber removePrevious!, BBjHtmlView htmlView!) Injects the provided CSS string into the head or body of the HTML DOM (as specified by the location! parameter) in the specified BBjHtmlView, as well as providing the ability to tag the CSS and replace it in subsequent calls. |
static void | injectCssFile(BBjString cssPath!, BBjString location!, BBjString description!, BBjNumber removePrevious!, BBjHtmlView htmlView!) Injects the CSS contained in the specified file into the head or body of the HTML DOM (as specified by the location! parameter) in the specified BBjHtmlView, as well as providing the ability to tag the CSS and replace it in subsequent calls.
This is a convenience method that reads in the contents of the provided CSS file and injects it into the HtmlView control via the |
static void | injectJavaScriptLibrary(BBjString p_library$, BBjHtmlView p_htmlView!) Method to get the contents of a JavaScript library and inject it into the specified BBjHtmlView
Note that you can specify the full path to any JavaScript library, or use one of the built-in libraries like
When running your BBj application with JavaScript in GUI in a Chromium BBjHtmlView control, everything should behave as expected. However, things are shifted around slightly when running BUI due to BBj using the Google Web Toolkit (GWT) which uses the typical window and document objects. GWT executes the JavaScript included with BBj application via an implementation of JavaScript Native Interface (JSNI). Because of this, your JavaScript code that used to reference the window and document objects should instead reference $wnd and $doc. See this Stack Overflow post for a brief explanation. |
static void | injectJQuery(BBjHtmlView p_htmlView!) Method to get the contents of the jQuery library and inject it into the specified BBjHtmlView When running your BBj application with JavaScript in GUI in a Chromium BBjHtmlView control, everything should behave as expected. However, things are shifted around slightly when running BUI due to BBj using the Google Web Toolkit (GWT) which uses the typical window and document objects. GWT executes the JavaScript included with BBj application via an implementation of JavaScript Native Interface (JSNI). Because of this, your JavaScript code that used to reference the window and document objects should instead reference $wnd and $doc. See this Stack Overflow post for a brief explanation. |
static void | setCookies(BBjString p_cookieKey$, HashMap p_cookieHashMap!) Method to set multiple string-based user preferences via a HashMap to reduce client-server round trips
The get/setCookies() methods bypasses the effort of creating string templates and BBjTemplatedStrings as well as encoding
information for safety and portability. You only have to provide a unique key value that's used to
store the information (usually the app's name, but it can be virtually any string) and a HashMap filled
with the information to store. The method iterates through the HashMap's keys and builds a string
that consists of the HashMap's key/value pairs joined by the
Both get/setCookies() methods throw errors, so you may want to add an
The corresponding |
static BBjString | toTitleCase(BBjString string!) Method to convert a given string to Title Case, meaning that the first letter of each word is capitalized and the rest is set to lowercase Note that this is a convenience method to the more full-featured toTitleCase() method that allows you to optionally set whether the remainder strings are set to lowercase. |
static BBjString | toTitleCase(BBjString string!, BBjNumber forceLowerCase) Method to convert a given string to Title Case, meaning that the first letter of each word is capitalized and the rest is optionally set to lowercase |
public static BBjNumber FONT_STYLE_BOLD
public static BBjNumber FONT_STYLE_ITALIC
public static BBjNumber FONT_STYLE_PLAIN
public static BBjNumber FONT_STYLE_STRIKEOUT
public static BBjNumber FONT_STYLE_UNDERLINE
public static BBjString JQueryFileLocation$
A BBjString that defines the fully-qualified path to the jQuery library
public static BBjString JQuerySlimFileLocation$
A BBjString that defines the fully-qualified path to the jQuery library's 'slim' build, which excludes the ajax and effects modules
public static BBjString JQueryUIFileLocation$
A BBjString that defines the fully-qualified path to the jQuery UI library
public static BBjString JQueryUITouchFileLocation$
A BBjString that defines the fully-qualified path to the jQueryUI Touch library
public static void copyFile(BBjString p_source$, BBjString p_target$)
Method to copy a file to another directory by providing the fully qualified path to both the source file and the target file. Note: The target path must include the target filename; it cannot be the directory in which the file will ultimately reside.
p_source$
A BBjString with the full path to the source filep_target$
A BBjString with the full path to the target filepublic static BBjFont getBBjFont(Font p_font!)
Method to get a BBjFont object from a Java Font object
public static BBjFont getBBjFont(BBjString p_fontPath$, BBjNumber p_fontSize, BBjNumber p_fontStyle)
Method to get a BBjFont object from a path to a TTF or OTF file
p_fontPath$
A BBjString with the fully-qualified path to a TTF or OTF font filep_fontSize
A BBjNumber with the desired font size in pixelsp_fontStyle
A BBjNumber with the font style constant accessed from the BBjSysGui or BBjAPI object, or a static field from this class BBjFont for more information on the BBFont object
public static HashMap getCookies(BBjString p_cookieKey$)
Method to get multiple string-based user preferences in a HashMap to reduce client-server round trips
The get/setCookies() methods offer a simple way to persist application setting via a HashMap. You save information by calling the setCookies() method providing a unique key value that's used to store the information (usually the app's name, but it can be virtually any string) and a HashMap filled with the information to store. You can then call the getCookies() method to retrieve the saved information in a HashMap. The methods bypass the effort of creating string templates and BBjTemplatedStrings as well as encoding information for safety and portability.
Both get/setCookies() methods throw errors, so you may want to add an , err=
branch when
calling these methods. The getCookies() method will return a Hashmap filled with key/value pairs if
the cookie exists. If it does not exist, it will return null()
.
p_cookieKey$
A BBjString with the unique identifier for the saved cookie, such as the application's namepublic static BBjString getFileBaseName(BBjString p_source$)
Method to return a file's base name by stripping its extension. If the file
p_source$
A BBjString with either the filename or the full path to the source filepublic static BBjString getFileBytes(BBjString p_source$)
Method to get a file's contents in a BBjString variable, regardless of whether it's a text or binary file and without taking into account the character encoding. NOTE: This method read all bytes into memory in a single statement so do not use it to read large files (2GB), as it could results in an OutOfMemoryError.
This method uses the Java Files::readAllBytes() method to get the contents of a file. The utility's getFileContents() method is similar, except that method uses BBj syntax to load the contents of a file. In practice, that method will be slower and will only return up to the first 10 megabytes of the file. In contrast, this method can be up to five times faster and it can read in over 1 gigabyte of data. However, if you provide a file that is too large, it will result in an out of memory error.
p_source$
A BBjString with the full path to the source file Files::readString() documentation
BBj 23.00
public static BBjString getFileContents(BBjString p_source$)
Method to get a file's contents in a BBjString variable - Note that this method reads in a maximum of 10 megabytes.
p_source$
A BBjString with the full path to the source filepublic static BBjString getFileExtension(BBjString p_source$)
Method to get a file's extension
p_source$
A BBjString with either the filename or the full path to the source filepublic static BBjString getFileNameFromFullPath(BBjString p_source$)
Method to get a file's name from a fully-qualified path by stripping all the directories
p_source$
A BBjString with the full path to the source filepublic static BBjString getFileNameWithoutExtensionFromFullPath(BBjString p_source$)
Method to get a file's name without extension from a fully-qualified path by stripping all the directories, dot, and extension
p_source$
A BBjString with the full path to the source filepublic static BBjString getFilePathWithEndSeparator(BBjString p_source$)
public static BBjString getFilePathWithoutEndSeparator(BBjString p_source$)
public static BBjNumber getIndexOfFileExtension(BBjString p_source$)
Method to return the index of a file's extension separator which is a dot. If the file doesn't have an extension, which can also occur when a file contains a dot within its path but is later followed by the path separator character or slash, then the method will return -1.
p_source$
A BBjString with either the filename or the full path to the source filepublic static Font getJavaFont(BBjFont p_font!)
Method to get a Java Font object from a BBjFont object
public static JsonObject getJsonCSS(JsonObject p_jsonCSS!, BBjNumber p_fontSize, BBjNumber p_fontWeight)
Method to get the CSS properties for a given BBjFont and return a Google JsonObject, typically used when themeing the BBjGridExWidget
p_jsonCSS!
A pre-defined Google JsonObject filled with the font propertiesp_fontSize
The desired font-size that will replace the font-size parameter in the provided p_jsonCSS! parameterp_fontWeight
The desired font-weight that will replace the font-weight parameter in the provided p_jsonCSS! parameter. Valid weights are 100, 200, 300, 400, 500, 600, 700, 800, 900public static JsonObject getJsonCSSForBBjFont(BBjFont p_font!, BBjString p_altFamilies$)
Method to get the CSS properties for a given BBjFont and return a Google JsonObject, typically used when themeing the BBjGridExWidget
p_font!
A valid BBjFontp_altFamilies$
Any extra fonts for alternates, such as "Microsoft Sans Serif, Arial, Sans-serif", which will be added to the list of fonts. Pass in an empty string to exclude this parameter.public static BBjNumber getScreenPixelRatio()
Method to get the ratio of physical to logical pixels on the default client screen device. HiDPI (Retina) displays report values greater than 1, typically 2
Note that you can use the getScreenPixelRatio(BBjWindow p_window!)
method to get the pixel ratio of a particular screen associated with a BBjWindow
public static BBjNumber getScreenPixelRatio(BBjWindow p_window!)
Method to get the ratio of physical to logical pixels on the specific client screen device. HiDPI (Retina) displays report values greater than 1, typically 2
Note that you can use the getScreenPixelRatio()
method to get the pixel ratio of the default screen if you don't have a BBjWindow object avialable
p_window!
A valid BBjWindow, which is used to determine what screen is in usepublic static void injectCss(BBjString css!, BBjString location!, BBjString description!, BBjNumber removePrevious!, BBjHtmlView htmlView!)
Injects the provided CSS string into the head or body of the HTML DOM (as specified by the location! parameter) in the specified BBjHtmlView, as well as providing the ability to tag the CSS and replace it in subsequent calls.
BBjString
css! The CSS to inject into the BBjHtmlView's DOM.BBjString
location! The target for injection which can be 'head' or 'body'. If it's an empty string, it will default to 'body'.BBjString
description! The description of the CSS, which is used to replace it in subsequent calls.BBjNumber
removePrevious! A BBjNumber acting as a boolean that determines whether the CSS should replace existing CSS with the same description.BBjHtmlView
htmlView! The BBjHtmlView control that the CSS should be injected into. If null(), it will attempt to perform the injection via the BBjSysGui object, which is valid as of BBj 21.10. BBj 21.00
public static void injectCssFile(BBjString cssPath!, BBjString location!, BBjString description!, BBjNumber removePrevious!, BBjHtmlView htmlView!)
Injects the CSS contained in the specified file into the head or body of the HTML DOM (as specified by the location! parameter) in the specified BBjHtmlView, as well as providing the ability to tag the CSS and replace it in subsequent calls.
This is a convenience method that reads in the contents of the provided CSS file and injects it into the HtmlView control via the injectCss()
method.
BBjString
cssPath! A string representing the full path and filename of the file that contains the CSS to be injected.BBjString
location! The target for injection which can be 'head' or 'body'. If it's an empty string, it will default to 'body'.BBjString
description! The description of the CSS, which is used to replace it in subsequent calls.BBjNumber
removePrevious! A BBjNumber acting as a boolean that determines whether the CSS should replace existing CSS with the same description.BBjHtmlView
htmlView! The BBjHtmlView control that the CSS should be injected into. If null(), it will attempt to perform the injection via the BBjSysGui object, which is valid as of BBj 21.10. BBj 21.00
public static void injectJavaScriptLibrary(BBjString p_library$, BBjHtmlView p_htmlView!)
Method to get the contents of a JavaScript library and inject it into the specified BBjHtmlView
Note that you can specify the full path to any JavaScript library, or use one of the built-in libraries like
DemoUtils.getJQueryUIFileLocation()
for the first parameter.
When running your BBj application with JavaScript in GUI in a Chromium BBjHtmlView control, everything should behave as expected. However, things are shifted around slightly when running BUI due to BBj using the Google Web Toolkit (GWT) which uses the typical window and document objects. GWT executes the JavaScript included with BBj application via an implementation of JavaScript Native Interface (JSNI). Because of this, your JavaScript code that used to reference the window and document objects should instead reference $wnd and $doc. See this Stack Overflow post for a brief explanation.
p_library$
The full path to a JavaScript library, or use one of the pre-defined libraries like DemoUtils.getJQueryFileLocation()
or DemoUtils.getJQueryUIFileLocation()
p_htmlView!
The BBjHtmlView control that the jQuery library will be injected into. If null(), it will attempt to perform the injection via the BBjSysGui object, which is valid as of BBj 21.10. This StackOverflow post covering JSNI
How To Use the BBjHtmlView Control With Native JavaScript Events for more information about JSNI and integrating JavaScript with BBjHtmlView controls
public static void injectJQuery(BBjHtmlView p_htmlView!)
Method to get the contents of the jQuery library and inject it into the specified BBjHtmlView
When running your BBj application with JavaScript in GUI in a Chromium BBjHtmlView control, everything should behave as expected. However, things are shifted around slightly when running BUI due to BBj using the Google Web Toolkit (GWT) which uses the typical window and document objects. GWT executes the JavaScript included with BBj application via an implementation of JavaScript Native Interface (JSNI). Because of this, your JavaScript code that used to reference the window and document objects should instead reference $wnd and $doc. See this Stack Overflow post for a brief explanation.
p_htmlView!
The BBjHtmlView control that the jQuery library will be injected into. If null(), it will attempt to perform the injection via the BBjSysGui object, which is valid as of BBj 21.10. This StackOverflow post covering JSNI
How To Use the BBjHtmlView Control With Native JavaScript Events for more information about JSNI and integrating JavaScript with BBjHtmlView controls
public static void setCookies(BBjString p_cookieKey$, HashMap p_cookieHashMap!)
Method to set multiple string-based user preferences via a HashMap to reduce client-server round trips
The get/setCookies() methods bypasses the effort of creating string templates and BBjTemplatedStrings as well as encoding
information for safety and portability. You only have to provide a unique key value that's used to
store the information (usually the app's name, but it can be virtually any string) and a HashMap filled
with the information to store. The method iterates through the HashMap's keys and builds a string
that consists of the HashMap's key/value pairs joined by the "-, -"
characters in an
attempt to provide a reasonable separator that won't interfere with the stored data.
Both get/setCookies() methods throw errors, so you may want to add an , err=
branch when
calling these methods. The getCookies() method will return a Hashmap filled with key/value pairs if
the cookie exists. If it does not exist, it will return null()
.
The corresponding getCookies()
method is used to retrieve the stored information from the
client's computer (GUI) or browser (BUI). You only need to provide the unique key value when getting
the saved cookies, greatly simplifying the reading/writing of user properties
p_cookieKey$
A BBjString with the unique identifier for the saved cookie, such as the application's namep_cookieHashMap!
A HashMap filled with key/value pairs to be stored where the key is the field name and the value is the string value for that field HashMap for more information on the Java HashMap object
public static BBjString toTitleCase(BBjString string!)
Method to convert a given string to Title Case, meaning that the first letter of each word is capitalized and the rest is set to lowercase
Note that this is a convenience method to the more full-featured toTitleCase() method that allows you to optionally set whether the remainder strings are set to lowercase.
BBjString
string! A BBjString to be converted to Title Casepublic static BBjString toTitleCase(BBjString string!, BBjNumber forceLowerCase)
Method to convert a given string to Title Case, meaning that the first letter of each word is capitalized and the rest is optionally set to lowercase
BBjString
string! A BBjString to be converted to Title CaseBBjNumber
forceLowerCase A BBjNumber acting as a boolean that indicates whether the method should force all non-titlecase letters to lowercase (1) or not (0).