Class GuiUtilities
- java.lang.Object
-
- com.biomatters.geneious.publicapi.utilities.GuiUtilities
-
public class GuiUtilities extends java.lang.Object
Provides utility methods for dealing with GUI (swing) components
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ACTION_MAP_KEY_COPY
Standard Java Action map key for Edit -> Copy.static java.lang.String
ACTION_MAP_KEY_CUT
Standard Java Action map key for Edit -> Cut.static java.lang.String
ACTION_MAP_KEY_DELETE
Standard Java Action map key for Edit -> Delete.static java.lang.String
ACTION_MAP_KEY_PASTE
Standard Java Action map key for Edit -> Paste.static java.lang.String
ACTION_MAP_KEY_REDO
Geneious Action map key for Edit -> Redo.static java.lang.String
ACTION_MAP_KEY_SELECT_ALL
Standard Java Action map key for Edit -> Select All on anything but a JTable.static java.lang.String
ACTION_MAP_KEY_SELECT_ALL_TABLE
Standard Java Action map key for Edit -> Select All on a JTable.static java.lang.String
ACTION_MAP_KEY_UNDO
Geneious Action map key for Edit -> Undo.static java.lang.String
ALT_KEY_STRING
System-dependent string used to represent the ALT keystatic java.awt.Color
CLEAR
Clear color,new Color(0,0,0,0)
static char
COMMAND_KEY_CHAR
The character used to represent the command key on Apple Macs (the "cloverleaf").static java.lang.String
CTRL_KEY_STRING
System-dependent string used to represent the CTRL keystatic java.awt.datatransfer.DataFlavor
DOCUMENT_LIST_FLAVOR
The DataFlavor that Geneious creates for drag-and-drop events containing Annotated Plugin Documents.static java.lang.String
ENTER_KEY_STRING
System-dependent string used to represent the ENTER/RETURN keystatic int
MENU_MASK
The key modifier for the Ctrl key on all operating systems except Mac OS, on which it is the Command key.static java.lang.String
META_KEY_STRING
System-dependent string used to represent the META keystatic java.lang.String
SHIFT_KEY_STRING
System-dependent string used to represent the SHIFT key
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addEditMenuSupport(javax.swing.text.JTextComponent component)
Links aJTextComponent
to the Edit menu actions Cut, Copy, Paste and Select All.static void
addPopupEditMenu(javax.swing.text.JTextComponent component)
Add a popup menu to aJTextComponent
which contains the standard Edit menu actions Cut, Copy, Paste, Select All, Undo and Redo.static void
addUndoSupport(javax.swing.text.JTextComponent component)
Add Undo and Redo capability to aJTextComponent
.static java.awt.Cursor
createCustomCursor(javax.swing.Icon icon, java.lang.String name, int hotspotx, int hotspoty)
Create a cursor from an icon.static GButton
createHelpButton()
static GButton
createHelpButton(boolean smallButton)
Deprecated.As of Geneious 2021.0.0, all help buttons are created as non-small buttons.static GButton
createHelpButton(boolean smallButton, java.lang.String title, java.lang.String message)
Deprecated.As of Geneious 2021.0.0, all help buttons are created as non-small buttons.static GButton
createHelpButton(java.lang.String title, java.lang.String message)
Creates a help style button that displays a help dialog with when clicked onstatic void
decorateAsDocumentViewerFooterPanel(javax.swing.JComponent statusBar)
Decorates the container as a footer bar in aDocumentViewer
.static java.awt.Rectangle
ensureRectangleIsWithinBounds(java.awt.Rectangle rectangle, java.awt.Rectangle maximumBounds)
If the given rectangle is not completely contained within maximumBounds then move it the smallest possible distance so that it is.static void
ensureWindowIsOnScreen(java.awt.Window window)
If the given window is not completely contained within a single screen then move it the smallest possible distance so that it is.static java.awt.Point
getAbsoluteMouseLocation()
Returns the Point that represents the coordinates of the mouse pointer on the screen.static javax.swing.JLabel
getAnimatedLoadingThrobber(int size)
Gets a JLabel containing an animated throbber icon (for displaying to a user while waiting for something to load) in the given size.static java.awt.Rectangle
getBoundsOfMonitorThatRectangleIsMostlyIn(java.awt.Rectangle rectangle)
Find the bounds of the monitor that the majority of the supplied rectangle intersects with and return that monitor's bounds, which excludes the task bar.static java.lang.Object
getClipboardContents(java.awt.datatransfer.DataFlavor flavor)
Get the data on the system clipboard for the given flavor or null if it's not available or there was a problem accessing the clipboard.static java.awt.datatransfer.Transferable
getClipboardTransferable()
Get the currentTransferable
on the system clipboard or null if there was a problem accessing the clipboard.static java.lang.String
getColorAsHtml(java.awt.Color c)
static java.lang.String
getCustomStyleSheetRules()
Supplies the custom CSS rules Geneious override on top ofHTMLEditorKit
stylesheet.static java.lang.String
getDialogHtmlHead()
Deprecated.As of Geneious 2021.0.0, Geneious applies the custom CSS formatting from this method across all HTML-formatted content to avoid formatting discrepancies.static java.awt.Color
getDisabledLabelForegroundColor()
Equivalent to calling UIManager.getColor("Label.disabledForeground") except that it returns Color.GRAY if the former would return nullstatic java.lang.String
getHtmlHead()
Get an HTML <head>...</head> block that can be included in displayed HTML pages.static java.lang.String
getHtmlStylesheet()
Get the CSS HTML stylesheet used throughout Geneious when displaying HTML.static java.awt.Point
getLocationRelativeToRootPane(java.awt.Component component)
Get the location of the given component relative to the root pane of the component.static org.virion.jam.framework.AbstractFrame
getMainFrame()
Get the main Geneious frame (which contains the service tree, document table etc).static int
getScaledValue(int value)
Deprecated.On Java 9 or above, the scale factor is always 1.static float
getScaleFactor()
Gets the scale factor to use when converting points to pixels in environments where this is not abstracted away for the programmer by Java.static java.awt.Font
getStandardDialogFont()
Get the standard font that is used to render text in dialogs.static java.lang.String
getStringForKeyStroke(javax.swing.KeyStroke shortcut)
Get a string representation for a KeyStroke which can be displayed to the user eg.static <T> T
getUIPropertyOrCrash(java.lang.String uiDefaultsKey)
Wrapper call toUIManager.get(Object)
, and returns a result casted to expected type.static <T> T
getUIPropertyOrDefault(java.lang.String uiDefaultsKey, T defaultValue)
Wrapper call toUIManager.get(Object)
, and returns a result casted to expected type.static <T> T
getUIPropertyOrNull(java.lang.String uiDefaultsKey)
Wrapper call toUIManager.get(Object)
, and returns a result casted to expected type.static java.awt.Color
getUserSelectedColor(java.awt.Color initialColor, javax.swing.JComponent preview, java.lang.String dialogTitle)
gets a color selected by the user in a color chooser dialog.static java.awt.Color
getUserSelectedColor(java.awt.Color initialColor, javax.swing.JComponent preview, java.lang.String dialogTitle, boolean showClearColorButton)
gets a color selected by the user in a color chooser dialog.static boolean
isDarkThemedUI()
static void
removeContainerComponents(java.awt.Container container)
Recursively removes all child components in a given container.static void
removeContainerComponents(java.awt.Container container, java.util.function.Consumer<java.awt.Component> computeForEachItem)
Removes all child components in a given container and runs additional code each item that is about to be removed.static java.lang.Boolean
setAntialiasing(java.awt.Graphics g, java.lang.Boolean on)
Get the current value and set a new value for antialiasing on the given graphics.static void
setGeneiousWindowIcon(java.awt.Window window)
Set the Geneious icon as the icon for a window.static void
setMainFrame(org.virion.jam.framework.AbstractFrame mainFrame)
Set the main Geneious frame.static java.lang.Boolean
setTextAntialiasing(java.awt.Graphics g, java.lang.Boolean on)
Get the current text antialiasing value and set a new value for it on the given graphics.static void
setWindowEnabled(java.awt.Window window, boolean enabledState)
When using Java 8 setting the enabled state of aWindow
usingComponent.setEnabled(boolean)
can cause flickering of the screen to occur.static void
traverseChildComponentsRecursive(java.awt.Container parentComponent, java.util.function.Consumer<java.awt.Component> componentConsumer)
Invokes the consumer for each component within parentComponent, including itself.
-
-
-
Field Detail
-
COMMAND_KEY_CHAR
public static final char COMMAND_KEY_CHAR
The character used to represent the command key on Apple Macs (the "cloverleaf"). This should only be used on MacOS.- See Also:
SystemUtilities.isMac()
, Constant Field Values
-
ALT_KEY_STRING
public static final java.lang.String ALT_KEY_STRING
System-dependent string used to represent the ALT key
-
CTRL_KEY_STRING
public static final java.lang.String CTRL_KEY_STRING
System-dependent string used to represent the CTRL key
-
SHIFT_KEY_STRING
public static final java.lang.String SHIFT_KEY_STRING
System-dependent string used to represent the SHIFT key
-
ENTER_KEY_STRING
public static final java.lang.String ENTER_KEY_STRING
System-dependent string used to represent the ENTER/RETURN key
-
META_KEY_STRING
public static final java.lang.String META_KEY_STRING
System-dependent string used to represent the META key
-
MENU_MASK
public static final int MENU_MASK
The key modifier for the Ctrl key on all operating systems except Mac OS, on which it is the Command key.
-
DOCUMENT_LIST_FLAVOR
public static final java.awt.datatransfer.DataFlavor DOCUMENT_LIST_FLAVOR
The DataFlavor that Geneious creates for drag-and-drop events containing Annotated Plugin Documents. The transfer data will be
List<? extends AnnotatedPluginDocument>
- Since:
- API 4.600 (Geneious 6.0.0)
-
ACTION_MAP_KEY_CUT
public static final java.lang.String ACTION_MAP_KEY_CUT
Standard Java Action map key for Edit -> Cut.- See Also:
- Constant Field Values
-
ACTION_MAP_KEY_COPY
public static final java.lang.String ACTION_MAP_KEY_COPY
Standard Java Action map key for Edit -> Copy.- See Also:
- Constant Field Values
-
ACTION_MAP_KEY_PASTE
public static final java.lang.String ACTION_MAP_KEY_PASTE
Standard Java Action map key for Edit -> Paste.- See Also:
- Constant Field Values
-
ACTION_MAP_KEY_DELETE
public static final java.lang.String ACTION_MAP_KEY_DELETE
Standard Java Action map key for Edit -> Delete.- See Also:
- Constant Field Values
-
ACTION_MAP_KEY_UNDO
public static final java.lang.String ACTION_MAP_KEY_UNDO
Geneious Action map key for Edit -> Undo.- See Also:
- Constant Field Values
-
ACTION_MAP_KEY_REDO
public static final java.lang.String ACTION_MAP_KEY_REDO
Geneious Action map key for Edit -> Redo.- See Also:
- Constant Field Values
-
ACTION_MAP_KEY_SELECT_ALL_TABLE
public static final java.lang.String ACTION_MAP_KEY_SELECT_ALL_TABLE
Standard Java Action map key for Edit -> Select All on a JTable.- See Also:
- Constant Field Values
-
ACTION_MAP_KEY_SELECT_ALL
public static final java.lang.String ACTION_MAP_KEY_SELECT_ALL
Standard Java Action map key for Edit -> Select All on anything but a JTable.- See Also:
- Constant Field Values
-
CLEAR
public static final java.awt.Color CLEAR
Clear color,new Color(0,0,0,0)
-
-
Method Detail
-
getHtmlStylesheet
public static java.lang.String getHtmlStylesheet()
Get the CSS HTML stylesheet used throughout Geneious when displaying HTML. This is the contents of the Geneious resources/documentSytle.css file. Most usages of this method should instead usegetHtmlHead()
which wraps the return value of this method in an HTML <head>...</head> block.- Returns:
- a css HTML stylesheet
- See Also:
getHtmlHead()
-
isDarkThemedUI
public static boolean isDarkThemedUI()
- Returns:
- true if this UI theme is dark. This value may change during Geneious runs or during printing.
- Since:
- API 4.202200 (Geneious 2022.0.0)
-
getHtmlHead
public static java.lang.String getHtmlHead()
Get an HTML <head>...</head> block that can be included in displayed HTML pages. This head block includes the standard Geneious stylesheet returned fromgetHtmlStylesheet()
.- Returns:
- an HTML <head>...</head> block
- See Also:
getHtmlStylesheet()
-
getDialogHtmlHead
@Deprecated public static java.lang.String getDialogHtmlHead()
Deprecated.As of Geneious 2021.0.0, Geneious applies the custom CSS formatting from this method across all HTML-formatted content to avoid formatting discrepancies.Get an HTML <head>...</head> block that should be used for any text pane shown in a dialog. The font will then match the standard dialog font.- Returns:
- an HTML <head>...</head> block
- Since:
- API 4.600 (Geneious 6.0.0)
- See Also:
getStandardDialogFont()
-
getCustomStyleSheetRules
public static java.lang.String getCustomStyleSheetRules()
Supplies the custom CSS rules Geneious override on top ofHTMLEditorKit
stylesheet. These rules are applied on startup so no special action is needed. For plugin development, this method only serves as a reference for the styles that have changed.- Returns:
- Custom CSS rules Geneious applies to the default HTML stylesheet.
- Since:
- API 4.202100 (Geneious 2021.0.0)
-
getStandardDialogFont
public static java.awt.Font getStandardDialogFont()
Get the standard font that is used to render text in dialogs. This is particularly useful for rendering HTML text in dialogs.- Returns:
- the standard font that is used to render text in dialogs
-
getDisabledLabelForegroundColor
public static java.awt.Color getDisabledLabelForegroundColor()
Equivalent to calling UIManager.getColor("Label.disabledForeground") except that it returns Color.GRAY if the former would return null- Returns:
- The color of disabled labels, will never be null
-
getLocationRelativeToRootPane
public static java.awt.Point getLocationRelativeToRootPane(java.awt.Component component)
Get the location of the given component relative to the root pane of the component. Eg. if the top left corner of the component is in the top left corner of the root pane then the location will be 0,0- Parameters:
component
- component to get location of- Returns:
- location of component relative to its root pane
-
getAnimatedLoadingThrobber
public static javax.swing.JLabel getAnimatedLoadingThrobber(int size)
Gets a JLabel containing an animated throbber icon (for displaying to a user while waiting for something to load) in the given size. High dpi and scaling are supported. The JLabel returned is guaranteed to contain an icon.- Parameters:
size
- the size (both width and height) in pixels. 16 is a size frequently used.- Returns:
- A JLabel with the default animated throbber icon at the specified size
- Since:
- API 4.202121 (Geneious 2021.2.1)
-
getBoundsOfMonitorThatRectangleIsMostlyIn
public static java.awt.Rectangle getBoundsOfMonitorThatRectangleIsMostlyIn(java.awt.Rectangle rectangle)
Find the bounds of the monitor that the majority of the supplied rectangle intersects with and return that monitor's bounds, which excludes the task bar. If rectangle does not intersect any monitor, returns the bounds of the primary monitor.- Parameters:
rectangle
- the rectangle the find which monitor it is mostly within- Returns:
- the bounds of the monitor (excluding any task bars) that mostly contains the rectangle.
-
ensureWindowIsOnScreen
public static void ensureWindowIsOnScreen(java.awt.Window window)
If the given window is not completely contained within a single screen then move it the smallest possible distance so that it is. If the window is too large to fit on the screen then this method will resize it fit on the screen. Eg. if the window is partially hidden beneath the Windows task bar, then then window will be moved upwards so it sits just above the task bar. Eg. if the window lies on the boundary between two screens (the user has multiple desktops) then the window will be moved so it sits at the edge of the screen which it previously lay mostly within.- Parameters:
window
- the window to ensure is on screen
-
ensureRectangleIsWithinBounds
public static java.awt.Rectangle ensureRectangleIsWithinBounds(java.awt.Rectangle rectangle, java.awt.Rectangle maximumBounds)
If the given rectangle is not completely contained within maximumBounds then move it the smallest possible distance so that it is. If the rectangle is too large to fit in maximumBounds then this method will resize it fit in maximumBounds.- Parameters:
rectangle
- the rectangle to ensure is within boundsmaximumBounds
- the maximum bounds to position the rectangle within- Returns:
- the adjusted rectangle
-
addUndoSupport
public static void addUndoSupport(javax.swing.text.JTextComponent component)
Add Undo and Redo capability to aJTextComponent
. These are invoked with Ctrl+Z and Ctrl+Shift+Z respectively. To have these linked to a popup menu, calladdPopupEditMenu(javax.swing.text.JTextComponent)
. The component is linked to Undo and Redo in the Edit menu by this method.- Parameters:
component
- Text component to add undo capability to.- See Also:
addEditMenuSupport(javax.swing.text.JTextComponent)
,(javax.swing.text.JTextComponent)
-
addEditMenuSupport
public static void addEditMenuSupport(javax.swing.text.JTextComponent component)
Links aJTextComponent
to the Edit menu actions Cut, Copy, Paste and Select All.- Parameters:
component
- Text Component to add Edit menu support to.- See Also:
addPopupEditMenu(javax.swing.text.JTextComponent)
,addUndoSupport(javax.swing.text.JTextComponent)
-
getClipboardContents
public static java.lang.Object getClipboardContents(java.awt.datatransfer.DataFlavor flavor)
Get the data on the system clipboard for the given flavor or null if it's not available or there was a problem accessing the clipboard. The returned object must be cast to the desired class.- Parameters:
flavor
- type of data to get- Since:
- API 4.1000 (Geneious 10.0.0)
-
getClipboardTransferable
public static java.awt.datatransfer.Transferable getClipboardTransferable()
Get the currentTransferable
on the system clipboard or null if there was a problem accessing the clipboard.- Since:
- API 4.1000 (Geneious 10.0.0)
-
addPopupEditMenu
public static void addPopupEditMenu(javax.swing.text.JTextComponent component)
Add a popup menu to aJTextComponent
which contains the standard Edit menu actions Cut, Copy, Paste, Select All, Undo and Redo. Undo and Redo are only added ifaddUndoSupport(javax.swing.text.JTextComponent)
has previously been called with this component.- Parameters:
component
- Text component to add a popup menu to.- See Also:
addEditMenuSupport(javax.swing.text.JTextComponent)
,addUndoSupport(javax.swing.text.JTextComponent)
-
setMainFrame
public static void setMainFrame(org.virion.jam.framework.AbstractFrame mainFrame)
Set the main Geneious frame. Should not be called by plugins- Parameters:
mainFrame
- The main Geneious frame
-
getMainFrame
public static org.virion.jam.framework.AbstractFrame getMainFrame()
Get the main Geneious frame (which contains the service tree, document table etc).- Returns:
- the main Geneious frame (which contains the service tree, document table etc).
-
getStringForKeyStroke
public static java.lang.String getStringForKeyStroke(javax.swing.KeyStroke shortcut)
Get a string representation for a KeyStroke which can be displayed to the user eg. "Ctrl+Shift+A"- Parameters:
shortcut
- KeyStroke to get the string representation of- Returns:
- String representation of the shortcut or empty String if null is passed in.
-
getUserSelectedColor
public static java.awt.Color getUserSelectedColor(java.awt.Color initialColor, javax.swing.JComponent preview, java.lang.String dialogTitle)
gets a color selected by the user in a color chooser dialog. returns null if the user clicked cancel.- Parameters:
initialColor
- the inital color for the dialog to display. If null is passed in, black will be used.preview
- an optional component that goes at the bottom of the dialog to show a preview of the color to the user. The chooser will callJComponent.setForeground(java.awt.Color)
on the component when the selected color has changed.dialogTitle
- the title of the dialog that will be displayed- Returns:
- the color that the user selected or null if canceled
-
getUserSelectedColor
public static java.awt.Color getUserSelectedColor(java.awt.Color initialColor, javax.swing.JComponent preview, java.lang.String dialogTitle, boolean showClearColorButton)
gets a color selected by the user in a color chooser dialog. returns null if the user clicked cancel.- Parameters:
initialColor
- the inital color for the dialog to display. If null is passed in, black will be used.preview
- an optional component that goes at the bottom of the dialog to show a preview of the color to the user. The chooser will callJComponent.setForeground(java.awt.Color)
on the component when the selected color has changed.dialogTitle
- the title of the dialog that will be displayedshowClearColorButton
- adds a "Clear Color" button to the dialog which meansCLEAR
will be returned immediately if this is clicked.- Returns:
- the color that the user selected,
CLEAR
if the clear button was present and was clicked or null if canceled - Since:
- API 4.41 (Geneious 5.4.1)
-
createCustomCursor
public static java.awt.Cursor createCustomCursor(javax.swing.Icon icon, java.lang.String name, int hotspotx, int hotspoty)
Create a cursor from an icon. Performs all sorts of hacks that are necessary to make this work on all platfroms.- Parameters:
icon
- Icon to create the cursor fromname
- a localized description of the cursor, for Java Accessibility usehotspotx
- hot spot's x position relative to top-left corner of the iconhotspoty
- hot spot's y position relative to top-left corner of the icon- Returns:
- the custom cursor or the default cursor if either the icon is null or if this platform doesn't support custom cursors
-
createHelpButton
public static GButton createHelpButton()
- Returns:
- a button suitable for a user to click on to show a help message. It is up to the caller to add an action listener to the button to actually do something. Or use
createHelpButton(String, String)
instead. - Since:
- API 4.702 (Geneious 7.0.2)
- See Also:
createHelpButton(String, String)
-
createHelpButton
@Deprecated public static GButton createHelpButton(boolean smallButton)
Deprecated.As of Geneious 2021.0.0, all help buttons are created as non-small buttons. UsecreateHelpButton()
instead.- Parameters:
smallButton
- true for the button to be smaller than a standard sized button- Returns:
- a button suitable for a user to click on to show a help message. It is up to the caller to add an action listener to the button to actually do something. Or use
createHelpButton(String, String)
instead. - Since:
- API 4.800 (Geneious 8.0.0)
- See Also:
createHelpButton(String, String)
-
createHelpButton
public static GButton createHelpButton(java.lang.String title, java.lang.String message)
Creates a help style button that displays a help dialog with when clicked on- Parameters:
title
- the title of the dialog to display when the button is clicked onmessage
- the contents of the dialog to display when the button is clicked on- Returns:
- a help style button that displays a help dialog with when clicked on
- Since:
- API 4.702 (Geneious 7.0.2)
- See Also:
createHelpButton()
-
createHelpButton
@Deprecated public static GButton createHelpButton(boolean smallButton, java.lang.String title, java.lang.String message)
Deprecated.As of Geneious 2021.0.0, all help buttons are created as non-small buttons. UsecreateHelpButton(String, String)
instead.Creates a help style button that displays a help dialog with when clicked on- Parameters:
smallButton
- true for the button to be smaller than a standard sized buttontitle
- the title of the dialog to display when the button is clicked onmessage
- the contents of the dialog to display when the button is clicked on. This may option begin with a tag <width=...> to override the maximum width of the dialog.- Returns:
- a help style button that displays a help dialog with when clicked on
- Since:
- API 4.800 (Geneious 8.0.0)
- See Also:
createHelpButton()
-
getAbsoluteMouseLocation
public static java.awt.Point getAbsoluteMouseLocation()
Returns the Point that represents the coordinates of the mouse pointer on the screen. SeeMouseInfo.getPointerInfo()
for more information about coordinate calculation for multi-screen systems.- Returns:
- the absolute mouse location, or null if we can't get the mouse location.
- Throws:
java.lang.IllegalStateException
- if this method isn't invoked from the Swing thread- Since:
- API 4.810 (Geneious 8.1.0)
-
setAntialiasing
public static java.lang.Boolean setAntialiasing(java.awt.Graphics g, java.lang.Boolean on)
Get the current value and set a new value for antialiasing on the given graphics. This is useful when you need to temporarily turn antialiasing on or off then turn it back to its previous state afterwards.- Parameters:
g
- graphics to set antialiasing on.on
- true to turn antialiasing on, false to turn it off, null to let the rendering pipeline decide (same asRenderingHints.VALUE_ANTIALIAS_DEFAULT
).- Returns:
- previous antialiasing state, as documented for the
on
parameter. - Since:
- API 4.903 (Geneious 9.0.3)
-
setTextAntialiasing
public static java.lang.Boolean setTextAntialiasing(java.awt.Graphics g, java.lang.Boolean on)
Get the current text antialiasing value and set a new value for it on the given graphics. This is useful when you need to temporarily turn text antialiasing on or off then turn it back to its previous state afterwards.- Parameters:
g
- graphics to set text antialiasing on.on
- true to turn text antialiasing on, false to turn it off, null to let the rendering pipeline decide (same asRenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT
).- Returns:
- previous text antialiasing state, as documented for the
on
parameter. - Since:
- API 4.202100 (Geneious 2021.0.0)
-
setWindowEnabled
public static void setWindowEnabled(java.awt.Window window, boolean enabledState)
When using Java 8 setting the enabled state of aWindow
usingComponent.setEnabled(boolean)
can cause flickering of the screen to occur. This method is designed to be used in place of those calls.- Parameters:
window
- window to enable/disable, usually the parent WindowenabledState
-true
if the window should be enabled,false
if it should be disabled.- Since:
- API 4.903 (Geneious 9.0.3)
-
getScaleFactor
public static float getScaleFactor()
Gets the scale factor to use when converting points to pixels in environments where this is not abstracted away for the programmer by Java.
On Mac OS X this will always return 1.0f because Java only deals with points and the underlying graphics pipeline takes care of everything else. For example calling getHeight() on the standard font will return the same value regardless of the current DPI setting.
On Windows under Java 9 and later, this method always returns 1.0
Consider using
SystemUtilities.getHighDPIScale(Graphics2D)
when needing to render high resolution images- Since:
- API 4.910 (Geneious 9.1.0)
-
getScaledValue
@Deprecated public static int getScaledValue(int value)
Deprecated.On Java 9 or above, the scale factor is always 1. Geneious ships with a bundled JRE that is always higher than Java 9, rendering this method effectively obsolete.- Returns:
- value scaled by
getScaleFactor()
and then rounded to the nearest integer - Since:
- API 4.911 (Geneious 9.1.1)
-
getColorAsHtml
public static java.lang.String getColorAsHtml(java.awt.Color c)
- Returns:
- the color formatted as a # followed by a 6 character hex string suitable for including in an html color tag.
- Since:
- API 4.202020 (Geneious 2020.2.0)
-
getUIPropertyOrNull
public static <T> T getUIPropertyOrNull(java.lang.String uiDefaultsKey)
Wrapper call toUIManager.get(Object)
, and returns a result casted to expected type. If noUIDefaults
value exists for this key, returns null instead. If a value exists but is of a different type than expected, throwsClassCastException
. For primitive type values, you must use the boxed type as return result since the returned value may be null.- Type Parameters:
T
- Expected type of value corresponding to this key.- Parameters:
uiDefaultsKey
- UI property key.- Returns:
- Value of this key casted to the expected type, or {@link null} if no value exists.
- Throws:
java.lang.ClassCastException
- If a value exists for this key but is a different type than expected.- Since:
- API 4.202100 (Geneious 2021.0.0)
-
getUIPropertyOrCrash
public static <T> T getUIPropertyOrCrash(java.lang.String uiDefaultsKey)
Wrapper call toUIManager.get(Object)
, and returns a result casted to expected type. If noUIDefaults
value exists for this key, or the result is an incompatible type, throwsNullPointerException
.- Type Parameters:
T
- Expected type of value corresponding to this key.- Parameters:
uiDefaultsKey
- UI property key.- Returns:
- Value of this key casted to the expected type, or {@link null} if no value exists.
- Throws:
java.lang.NullPointerException
- If no value corresponds to this key.java.lang.ClassCastException
- If a value exists for this key but is a different type than expected.- Since:
- API 4.202100 (Geneious 2021.0.0)
-
getUIPropertyOrDefault
public static <T> T getUIPropertyOrDefault(java.lang.String uiDefaultsKey, T defaultValue)
Wrapper call toUIManager.get(Object)
, and returns a result casted to expected type. If noUIDefaults
value exists for this key, returns the default value instead. If a value exists but is of the wrong type, throwsClassCastException
.- Type Parameters:
T
- Expected type of value corresponding to this key.- Parameters:
uiDefaultsKey
- UI property key.defaultValue
- Default value to return if no value corresponds to that key.- Returns:
- Value of this key casted to the expected type, or {@link null} if no value exists.
- Throws:
java.lang.ClassCastException
- If a value exists for this key but is a different type than expected.- Since:
- API 4.202100 (Geneious 2021.0.0)
-
decorateAsDocumentViewerFooterPanel
public static void decorateAsDocumentViewerFooterPanel(javax.swing.JComponent statusBar)
Decorates the container as a footer bar in aDocumentViewer
. This method should be called only after all the components have been added to the footer container, because child components are formatted as well.- Parameters:
statusBar
- Status bar container to decorate.- Since:
- API 4.202100 (Geneious 2021.0.0)
-
traverseChildComponentsRecursive
public static void traverseChildComponentsRecursive(java.awt.Container parentComponent, java.util.function.Consumer<java.awt.Component> componentConsumer)
Invokes the consumer for each component within parentComponent, including itself. If a child component is also a container, traverses all children inside it as well. This method is useful to apply some settings for all components within a container.- Parameters:
parentComponent
- Container component to traverse.componentConsumer
- Code to execute with a given child component.- Since:
- API 4.202100 (Geneious 2021.0.0)
-
setGeneiousWindowIcon
public static void setGeneiousWindowIcon(java.awt.Window window)
Set the Geneious icon as the icon for a window. Does nothing on Mac OS because windows shouldn't normally have icons on mac os.- Parameters:
window
- the window to set the Geneious icon on. Must not be null.- Since:
- API 4.202110 (Geneious 2021.1.0)
-
removeContainerComponents
public static void removeContainerComponents(java.awt.Container container)
Recursively removes all child components in a given container.- Parameters:
container
- The container to have its children removed.- Since:
- API 4.202200 (Geneious 2022.0.0)
-
removeContainerComponents
public static void removeContainerComponents(java.awt.Container container, java.util.function.Consumer<java.awt.Component> computeForEachItem)
Removes all child components in a given container and runs additional code each item that is about to be removed. This operation is not recursive, it will only remove the direct descendants of the container.- Parameters:
container
- The container to have its children removed.computeForEachItem
- Logic to execute for each item that is about to be removed- Since:
- API 4.202200 (Geneious 2022.0.0)
-
-