public class UiUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
UiUtils.EscapeConverter
Converts valid escape sequences %XX to byte values.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FILE_PROTOCOL_PREFIX
file protocol prefix to construct file related URL.
|
static java.lang.String |
FILE_SCHEMA
Schema name for files
|
protected static java.util.logging.Logger |
LOG
Logger.
|
Constructor and Description |
---|
UiUtils() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
buildCanonicalUrl(java.io.File fCanon,
java.lang.String path,
boolean warn)
Build a canonical url for the given file.
|
static java.util.Optional<java.io.File> |
checkAndGetFile(java.lang.String fName)
Checks the file exists and isn't a directory, otherwise displays a error message and returns
an empty optional.
|
static java.util.Optional<java.io.File> |
checkAndGetFile(java.lang.String fName,
boolean warn,
boolean allowDirectory)
Checks the file exists and isn't a directory, otherwise displays a error message and returns
an empty optional.
|
static boolean |
checkEventList(EventList list)
Checks the given event list for global events.
|
static boolean |
containsFrames(Frame<?> frame,
Rectangle r)
Check if there are other frames in specified area.
|
static ButtonGuiImpl |
createButton(java.lang.String text,
java.lang.String action,
int width,
int height,
boolean def,
ActionListener listener)
Creates and initializes a customized button widget.
|
static SimpleLabel |
createSimpleLabel(CoordinatesConversion cc,
java.lang.String text,
int w,
int h,
boolean rightAlign)
Creates a customized
SimpleLabel . |
static SimpleLabel |
createSimpleLabel(CoordinatesConversion cc,
java.lang.String text,
int w,
int h,
boolean rightAlign,
WidgetId frameId)
Creates a customized
SimpleLabel . |
static WidgetConfig |
getConfig(Widget<?> w)
Returns config reference associated with the passed-in widget.
|
static <C extends WidgetConfig> |
getConfig(Widget<?> w,
java.lang.Class<C> clazz)
Returns config reference associated with the passed-in widget.
|
static Widget<?> |
getCurrentFocus()
Get the component which is in focus.
|
static Widget<?> |
getCurrentFocus(boolean legacy)
Get the component which is in focus.
|
static Widget<?> |
getCurrentFocus(boolean legacy,
boolean nonlegacy)
Get the component which is in focus.
|
static TitledWindow<?> |
getCurrentFocusWindow()
Get the component which is in focus.
|
static byte[] |
getData(java.io.InputStream is)
Gets the data array from input stream.
|
static byte[] |
getDataFromUrl(java.net.URL url)
Loads the binary data given by its URL and delegates the received data to the given consumer.
|
static Color |
getDColor(Color dcolor,
Widget<?> widget)
Get DCOLOR attribute for specified widget taking into account color
inheritance from parent to child widgets.
|
static Color |
getDColor(Widget<?> widget)
Get DCOLOR attribute for specified widget taking into account color
inheritance from parent to child widgets.
|
static NativePoint |
getDropDownPhysicalLocation(AbstractWidget<GuiOutputManager> owner,
AbstractWidget<GuiOutputManager> dropdown,
GuiDriver gd)
Calculates the drop down physical location based on the owner physical location taking
into account that the dropdown belongs to the different parent frame.
|
static java.util.Optional<TopLevelWindow<?>> |
getFirstOwner(TopLevelWindow<?> window,
java.util.function.Predicate<TopLevelWindow<?>> property)
Find the first window that satisfies the given property predicate searching through the set
of the given window and its owner hierarchy.
|
static int[] |
getFrameIDs(TopLevelWindow wnd)
Get IDs of all frames in the current window.
|
static Frame<?>[] |
getFramesAbove(Frame<?> frame)
Get all frames which are visible, overlap given frame and are above it
in Z-order.
|
static java.util.List<java.lang.Integer> |
getParentFrames(int widgetId)
Returns all parent frames up the root frame starting from the provided widget.
|
static java.util.List<Frame<?>> |
getParentFrames(Widget<?> widget)
Returns all parent frames up the root frame starting from the provided widget.
|
static Widget<?>[] |
getTopLevelComponents(TopLevelWindow wnd)
Convenience method to retrieve top level frames and other components
from the default window.
|
static Widget[] |
getVisibleComponents(Frame frame,
UIStatement stmt)
Get the non-hidden components from this frame and all child frames.
|
static WidgetId |
getWidgetId(Widget<?> w)
Get ID of specified widget.
|
static int |
getWidgetIdAsInt(Widget<?> widget)
Get ID of specified widget.
|
static java.lang.String |
getWidgetIdAsString(Widget<?> widget,
java.lang.String ifNull)
Get ID of specified widget formatted to string.
|
static boolean |
hasConfig(Widget<?> widget)
Check if widget has config.
|
static boolean |
hasFileSchema(java.lang.String urlString)
Check if a specific URL string is describing a local file.
|
static void |
hideDialogs(Window wnd,
java.util.Collection<Frame> except)
Hide all dialog frames, if not in the specified list.
|
static boolean[] |
hideFrames(Frame<?> current,
boolean streamed)
Hide frames which are marked as such that can be hidden.
|
static boolean |
isAllShowing(Widget<?> comp,
Frame<?>[] above)
Returns
true if the whole widget is not even partially
obscured by any frame from the specified array. |
static boolean |
isFocusable(Widget<?> comp)
Check if widget is focusable.
|
static boolean |
isNeedPause()
Check if any visible frame has
needPause flag set. |
static byte[] |
loadFromUrl(java.net.URL url)
Loads the binary resource to the client.
|
static AlertBox<?> |
locateAlertBox(Widget<?> widget)
Return the alert box which contains the specified widget.
|
static Frame<?> |
locateFrame(Widget<?> widget)
Return the frame which contains the specified widget.
|
static Frame<?> |
locateRootFrame(Widget<?> widget)
Return the root frame which contains the specified widget.
|
static WidgetId |
lookup4GLWidgetId(Widget<?> widget)
Get ID of the 4GL widget which has the input focus.
|
static int |
lookup4GLWidgetIdAsInt(Widget<?> widget)
Get ID of the 4GL widget which has the input focus.
|
static WidgetId |
lookupWidgetId(Widget<?> widget)
Get ID of the widget which has the input focus.
|
private static WidgetId |
lookupWidgetId(Widget<?> widget,
boolean progressOnly)
Get ID of the 4GL widget which has the input focus.
|
static int |
lookupWidgetIdAsInt(Widget<?> widget)
Get ID of the widget which has the input focus.
|
private static int |
lookupWidgetIdAsInt(Widget<?> widget,
boolean progressOnly)
Get ID of the 4GL widget which has the input focus.
|
static Widget<?> |
reconstructComponent(WidgetId id,
WidgetConfig cfg)
Instantiate component using type information provided in configuration.
|
static void |
resetNeedPause(TopLevelWindow<?> wnd)
Reset
needPause flag for all frames which are visible. |
static java.lang.String |
resolveLocalFileResource(java.lang.String urlString)
Resolve the specified string presentation of the target resource, so that it can be used to open it.
|
static java.lang.String |
resolveLocalFileResource(java.lang.String urlString,
boolean warn,
boolean allowDirectory)
Resolve the specified string presentation of the target resource, so that it can be used to open it.
|
static boolean |
showWindowForFrame(TopLevelWindow window,
Frame frame,
UIStatement stmt)
Check if the specified window can be implicitly shown by the UI statement targeting the
given frame.
|
static java.util.Optional<java.net.URL> |
toURL(java.lang.String spec)
It supposes that the input string represents URL and tries to convert it to URL and takes a care of
MalformedURLException.
|
static java.lang.String |
uriDecode(java.lang.String source)
Decode an uri string by substituting escaped characters for valid %hex1hex2 escape sequences.
|
static java.lang.String |
uriDecode(java.lang.String source,
java.nio.charset.Charset charset)
Decode an uri string by substituting escaped characters for valid %hex1hex2 escape sequences.
|
public static final java.lang.String FILE_PROTOCOL_PREFIX
public static final java.lang.String FILE_SCHEMA
protected static final java.util.logging.Logger LOG
public static java.lang.String resolveLocalFileResource(java.lang.String urlString)
urlString
- The string presentation of the target resource.public static java.lang.String resolveLocalFileResource(java.lang.String urlString, boolean warn, boolean allowDirectory)
urlString
- The string presentation of the target resource.warn
- Show an warning if a local file can't be resolved.allowDirectory
- This can also resolve to local directory resources.public static boolean hasFileSchema(java.lang.String urlString)
urlString
- The original string representation a resource.true
if this is identified as a local file.public static java.util.Optional<java.io.File> checkAndGetFile(java.lang.String fName)
fName
- The file pathpublic static java.util.Optional<java.io.File> checkAndGetFile(java.lang.String fName, boolean warn, boolean allowDirectory)
fName
- The file pathwarn
- Show an warning if a local file can't be resolved.allowDirectory
- If set to true
, this can also retrieve directories.public static Widget[] getVisibleComponents(Frame frame, UIStatement stmt)
frame
- The frame.stmt
- The current UI statement which uses this frame.public static boolean hasConfig(Widget<?> widget)
widget
- Widget to check.true
if widget is not null and has config.public static WidgetId getWidgetId(Widget<?> w)
w
- Component to for which ID is requested.null
if the widget doesn't have a config.public static int getWidgetIdAsInt(Widget<?> widget)
widget
- Component to for which ID is requested.public static java.lang.String getWidgetIdAsString(Widget<?> widget, java.lang.String ifNull)
widget
- Component to for which ID is requested.ifNull
- A value to be returned when the widget has no
assigned id.public static WidgetConfig getConfig(Widget<?> w)
w
- A widget reference or null
.null
if the widget has
no valid associated widget.public static <C extends WidgetConfig> C getConfig(Widget<?> w, java.lang.Class<C> clazz)
w
- A widget reference or null
.clazz
- The Java class representing the expected config type.null
if the widget has
no valid associated widget of the expected type.public static boolean containsFrames(Frame<?> frame, Rectangle r)
frame
- Frame to exclude.r
- Rectangle to check.true
if there are other frames in specified area.public static WidgetId lookupWidgetId(Widget<?> widget)
widget
- Event source.-1
public static WidgetId lookup4GLWidgetId(Widget<?> widget)
widget
- Event source.-1
public static int lookupWidgetIdAsInt(Widget<?> widget)
widget
- Event source.-1
if the widget doesn't have a config.public static int lookup4GLWidgetIdAsInt(Widget<?> widget)
widget
- Event source.-1
if the widget doesn't have a config.public static Widget<?> getCurrentFocus()
Component
instance which is in focus or
null
if there is no focused widget.public static Widget<?> getCurrentFocus(boolean legacy)
legacy
- Flag indicating if the legacy focus (which is reported via i.e. FOCUS) is returned
or the real focus.
Note: currently only editable BROWSE is handled.
Note 2: the "legacy" semantics of this method is different from the legacy widget of
Widget.getLegacyWidget()
. Consider BROWSE in edit mode, while the legacy focus
is the browse's column the legacy widget of the physically focused fill-in is the fill-in
itself.Component
instance which is in focus or
null
if there is no focused widget.public static Widget<?> getCurrentFocus(boolean legacy, boolean nonlegacy)
legacy
- Flag indicating if the legacy focus (which is reported via i.e. FOCUS) is returned
or the real focus.
Note: currently only editable BROWSE is handled.
Note 2: the "legacy" semantics of this method is different from the legacy widget of
Widget.getLegacyWidget()
. Consider BROWSE in edit mode, while the legacy focus
is the browse's column the legacy widget of the physically focused fill-in is the fill-in
itself.nonlegacy
- This parameter is considered only when legacy
is true
. When true
and no legacy widget has focus the method returns a non-legacy widget if such a widget is
focused.Component
instance which is in focus or
null
if there is no focused widget.public static TitledWindow<?> getCurrentFocusWindow()
null
if there is no focused window.public static boolean checkEventList(EventList list)
list
- event list to checktrue
if the list contains at least one global eventpublic static Frame<?> locateFrame(Widget<?> widget)
widget
- Widget for which to find the frame.null
if null
is passed as the parameter or the widget
is not placed in a frame.public static Frame<?> locateRootFrame(Widget<?> widget)
widget
- Widget for which to find the frame.null
if null
is passed as the paramete or the widget is
not placed in a frame.public static java.util.List<Frame<?>> getParentFrames(Widget<?> widget)
widget
- A widget. If null
an empty list is returned.public static java.util.Optional<TopLevelWindow<?>> getFirstOwner(TopLevelWindow<?> window, java.util.function.Predicate<TopLevelWindow<?>> property)
window
- The given top level windowproperty
- The given property predicatepublic static java.util.List<java.lang.Integer> getParentFrames(int widgetId)
widgetId
- A widget id.public static NativePoint getDropDownPhysicalLocation(AbstractWidget<GuiOutputManager> owner, AbstractWidget<GuiOutputManager> dropdown, GuiDriver gd)
owner
- The dropdown's owner: combobox, calendar widgetdropdown
- The dropdown widgetgd
- The GUI driverpublic static AlertBox<?> locateAlertBox(Widget<?> widget)
widget
- Widget for which to find the alert box.null
if the widget is not contained in an
alert box or null
is passed as the parameter.public static boolean isAllShowing(Widget<?> comp, Frame<?>[] above)
true
if the whole widget is not even partially
obscured by any frame from the specified array.comp
- widget to testabove
- array of visible frames to test against; normally obtained by
Screen.getFramesAbove() helpertrue
if it is not obscuredpublic static boolean isFocusable(Widget<?> comp)
comp
- Widget to check.true
if widget us focusable.public static void hideDialogs(Window wnd, java.util.Collection<Frame> except)
wnd
- Containing window.except
- The list of dialogs which should not be hidden.public static int[] getFrameIDs(TopLevelWindow wnd)
wnd
- Window containing frames, current window.public static Widget<?> reconstructComponent(WidgetId id, WidgetConfig cfg)
WARNING: at this time, Window
and AlertBox
cannot be reconstructed via this mechanism.
id
- The widget's ID.cfg
- Configuration data.null
in case of
failure.public static Frame<?>[] getFramesAbove(Frame<?> frame)
frame
- Reference frame.public static void resetNeedPause(TopLevelWindow<?> wnd)
needPause
flag for all frames which are visible.wnd
- target window pause.public static boolean isNeedPause()
needPause
flag set.true
if any of the frames on the screen has
needPause
flag set to true
.public static boolean[] hideFrames(Frame<?> current, boolean streamed)
Note that if there is an old instance of given frame (not the same frame, but frame with the same name), then method returns false as if there were no frames hidden at all. Logically this is correct because new instance will replace old one at the screen.
current
- The frame for which frame hiding is performed.streamed
- true
hide streamed frames, false
-
hide frames from interactive terminal.true
if at least one
frame other than given one was hidden and there were no old
instances of given frame.true
if one of hidden
frames has the same row as current frame.public static Widget<?>[] getTopLevelComponents(TopLevelWindow wnd)
wnd
- default windowpublic static Color getDColor(Widget<?> widget)
widget
- Widget.public static Color getDColor(Color dcolor, Widget<?> widget)
null
.dcolor
- Initial color.widget
- Widget.public static byte[] getData(java.io.InputStream is)
is
- The input stream to be read.null
in case of error.public static byte[] loadFromUrl(java.net.URL url) throws java.io.IOException
url
- The resource URLjava.io.IOException
- If the target IO operations are not succeeded.public static byte[] getDataFromUrl(java.net.URL url)
url
- The URL of the target binary datanull
otherwise.public static java.util.Optional<java.net.URL> toURL(java.lang.String spec)
spec
- The given stringpublic static SimpleLabel createSimpleLabel(CoordinatesConversion cc, java.lang.String text, int w, int h, boolean rightAlign)
SimpleLabel
.cc
- Coordinates conversion instance.text
- The text to be displayed.w
- The physical width of the label.h
- The physical height of the label.rightAlign
- Whether the text is right aligned.SimpleLabel
.public static SimpleLabel createSimpleLabel(CoordinatesConversion cc, java.lang.String text, int w, int h, boolean rightAlign, WidgetId frameId)
SimpleLabel
.cc
- Coordinates conversion instance.text
- The text to be displayed.w
- The physical width of the label.h
- The physical height of the label.rightAlign
- Whether the text is right aligned.frameId
- ID of the parent frame. Can be null
if you don't want to set the parent
frame.SimpleLabel
.public static ButtonGuiImpl createButton(java.lang.String text, java.lang.String action, int width, int height, boolean def, ActionListener listener)
text
- The text (label) displayed on the button.action
- The action to trigger when button is pressed.width
- The width of the button (native units).height
- The height of the button (native units).def
- true
if this is the default button for the frame.listener
- The listener for the button.ButtonGuiImpl
instance.public static boolean showWindowForFrame(TopLevelWindow window, Frame frame, UIStatement stmt)
If the frame is hidden, only the UIStatement.UPDATE
, UIStatement.SET
,
UIStatement.PROMPT_FOR
and UIStatement.VIEW
will show the window.
If the frame is not hidden, only the UIStatement.DISPLAY
, UIStatement.UPDATE
,
UIStatement.SET
, UIStatement.PROMPT_FOR
, UIStatement.VIEW
and
UIStatement.ENABLE
statements will show the window.
window
- The window which needs to be shown implicitly.frame
- The frame which targets this window.stmt
- The UI statement working with this frame.true
if the window needs to be shown implicitly.private static WidgetId lookupWidgetId(Widget<?> widget, boolean progressOnly)
widget
- Event source.progressOnly
- specifies if only 4GL widgets should be considered.-1
private static int lookupWidgetIdAsInt(Widget<?> widget, boolean progressOnly)
widget
- Event source.progressOnly
- specifies if only 4GL widgets should be considered.-1
if the widget doesn't have a config.public static java.lang.String uriDecode(java.lang.String source)
source
- The uri string with encoded characterspublic static java.lang.String uriDecode(java.lang.String source, java.nio.charset.Charset charset)
source
- The uri string with encoded characterscharset
- The given character set used for source decodingprivate static java.lang.String buildCanonicalUrl(java.io.File fCanon, java.lang.String path, boolean warn)
fCanon
- The given filepath
- The path of fCanon filewarn
- Show an warning if a local file can't be resolved.