public final class GuiHelper extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
JAVA_INTERNAL_MESSAGE_KEYS |
Modifier | Constructor and Description |
---|---|
private |
GuiHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
assertCallFromEdt()
This function fails if it was not called from the EDT thread.
|
static javax.swing.JScrollPane |
embedInVerticalScrollPane(java.awt.Component panel)
Embeds the given component into a new vertical-only scrollable
JScrollPane . |
static void |
executeByMainWorkerInEDT(java.lang.Runnable task)
Add a task to the main worker that will block the worker and run in the GUI thread.
|
static void |
extendTooltipDelay(java.awt.Component c)
Extends tooltip dismiss delay to a default value of 1 minute for the given component.
|
static void |
extendTooltipDelay(java.awt.Component c,
int delay)
Extends tooltip dismiss delay to the specified value for the given component.
|
static java.awt.Stroke |
getCustomizedStroke(java.lang.String code)
Return s new BasicStroke object with given thickness and style
|
static javax.swing.ImageIcon |
getDisabledIcon(javax.swing.ImageIcon icon)
Replies the disabled (grayed) version of the specified icon.
|
static java.awt.Image |
getDisabledImage(java.awt.Image image)
Replies the disabled (grayed) version of the specified image.
|
static java.awt.Frame |
getFrameForComponent(java.awt.Component parentComponent)
Returns the specified component's
Frame without throwing exception in headless mode. |
static java.awt.Dimension |
getMaximumScreenSize()
Gets the size of the screen.
|
static java.awt.Font |
getMonospacedFont(javax.swing.JComponent component)
Gets the font used to display monospaced text in a component, if possible.
|
static java.awt.Dimension |
getScreenSize()
Gets the size of the screen.
|
static java.awt.Font |
getTitleFont()
Gets the font used to display JOSM title in about dialog and splash screen.
|
static java.awt.Window |
getWindowAncestorFor(java.util.EventObject e)
Returns the first
Window ancestor of event source, or
null if event source is not a component contained inside a Window . |
private static void |
handleEDTException(java.lang.Throwable t) |
static void |
notifyUserHtmlError(java.awt.Component parent,
java.lang.String title,
java.lang.String message,
java.lang.String html)
Notifies user about an error received from an external source as an HTML page.
|
static java.awt.Component |
prepareResizeableOptionPane(java.awt.Component pane,
java.awt.Dimension minDimension)
Attaches a
HierarchyListener to the specified Component that
will set its parent dialog resizeable. |
static void |
runInEDT(java.lang.Runnable task)
Executes asynchronously a runnable in
Event Dispatch Thread.
|
static void |
runInEDTAndWait(java.lang.Runnable task)
Executes synchronously a runnable in
Event Dispatch Thread.
|
static <V> V |
runInEDTAndWaitAndReturn(java.util.concurrent.Callable<V> callable)
Executes synchronously a callable in
Event Dispatch Thread
and return a value.
|
static void |
runInEDTAndWaitWithException(java.lang.Runnable task)
Executes synchronously a runnable in
Event Dispatch Thread.
|
static javax.swing.Timer |
scheduleTimer(int initialDelay,
java.awt.event.ActionListener actionListener,
boolean repeats)
Schedules a new Timer to be run in the future (once or several times).
|
static void |
setBackgroundReadable(javax.swing.JComponent c,
java.awt.Color background)
Sets the background color for this component, and adjust the foreground color so the text remains readable.
|
static javax.swing.JScrollPane |
setDefaultIncrement(javax.swing.JScrollPane sp)
Set the default unit increment for a
JScrollPane . |
static void |
setEnabledRec(java.awt.Container root,
boolean enabled)
disable / enable a component and all its child components
|
static void |
setUIFont(java.lang.String name)
Sets a global font for all UI, replacing default font of current look and feel.
|
static void |
setupLanguageFonts()
Setup special font for Khmer script, as the default Java fonts do not display these characters.
|
static void |
translateJavaInternalMessages()
Localizations for file chooser dialog.
|
static boolean |
warnUser(java.lang.String title,
java.lang.String content,
javax.swing.ImageIcon baseActionIcon,
java.lang.String continueToolTip)
Warns user about a dangerous action requiring confirmation.
|
private static final java.lang.String[] JAVA_INTERNAL_MESSAGE_KEYS
private GuiHelper()
public static void setEnabledRec(java.awt.Container root, boolean enabled)
root
- componentenabled
- enabled statepublic static void executeByMainWorkerInEDT(java.lang.Runnable task)
task
- The task to runpublic static void runInEDT(java.lang.Runnable task)
task
- The runnable to executeSwingUtilities.invokeLater(java.lang.Runnable)
private static void handleEDTException(java.lang.Throwable t)
public static void runInEDTAndWait(java.lang.Runnable task)
task
- The runnable to executeSwingUtilities.invokeAndWait(java.lang.Runnable)
public static void runInEDTAndWaitWithException(java.lang.Runnable task)
Passes on the exception that was thrown to the thread calling this.
The exception is wrapped using a ReportedException
.
task
- The runnable to executeSwingUtilities.invokeAndWait(java.lang.Runnable)
public static <V> V runInEDTAndWaitAndReturn(java.util.concurrent.Callable<V> callable)
V
- the result type of method call
callable
- The callable to executepublic static void assertCallFromEdt()
java.lang.IllegalStateException
- if called from wrong thread.public static boolean warnUser(java.lang.String title, java.lang.String content, javax.swing.ImageIcon baseActionIcon, java.lang.String continueToolTip)
title
- Title of dialogcontent
- Content of dialogbaseActionIcon
- Unused? FIXME why is this parameter unused?continueToolTip
- Tooltip to display for "continue" buttonpublic static void notifyUserHtmlError(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String html)
parent
- Parent componenttitle
- Title of dialogmessage
- Message displayed at the top of the dialoghtml
- HTML content to display (real error message)public static java.awt.Image getDisabledImage(java.awt.Image image)
image
- The image to disablepublic static javax.swing.ImageIcon getDisabledIcon(javax.swing.ImageIcon icon)
icon
- The icon to disablepublic static java.awt.Component prepareResizeableOptionPane(java.awt.Component pane, java.awt.Dimension minDimension)
HierarchyListener
to the specified Component
that
will set its parent dialog resizeable. Use it before a call to JOptionPane#showXXXXDialog
to make it resizeable.pane
- The component that will be displayedminDimension
- The minimum dimension that will be set for the dialog. Ignored if nullpane
public static javax.swing.Timer scheduleTimer(int initialDelay, java.awt.event.ActionListener actionListener, boolean repeats)
initialDelay
- milliseconds for the initial and between-event delay if repeatableactionListener
- an initial listener; can be nullrepeats
- specify false to make the timer stop after sending its first action eventpublic static java.awt.Stroke getCustomizedStroke(java.lang.String code)
code
- = 3.5 -> thickness=3.5px; 3.5 10 5 -> thickness=3.5px, dashed: 10px filled + 5px emptyStrokeProperty
public static java.awt.Font getMonospacedFont(javax.swing.JComponent component)
component
- The componentpublic static java.awt.Font getTitleFont()
public static javax.swing.JScrollPane embedInVerticalScrollPane(java.awt.Component panel)
JScrollPane
.panel
- The component to embedJScrollPane
public static javax.swing.JScrollPane setDefaultIncrement(javax.swing.JScrollPane sp)
JScrollPane
.
This fixes slow mouse wheel scrolling when the content of the JScrollPane
is a JPanel
or other component that does not implement the Scrollable
interface.
The default unit increment is 1 pixel. Multiplied by the number of unit increments
per mouse wheel "click" (platform dependent, usually 3), this makes a very
sluggish mouse wheel experience.
This methods sets the unit increment to a larger, more reasonable value.sp
- the scroll panejava.lang.IllegalArgumentException
- if the component inside of the scroll pane
implements the Scrollable
interface (JTree
, JLayer
,
JList
, JTextComponent
and JTable
)public static void setUIFont(java.lang.String name)
name
- Font name. It is up to the caller to make sure the font existsjava.lang.IllegalArgumentException
- if name is nullpublic static void setBackgroundReadable(javax.swing.JComponent c, java.awt.Color background)
c
- componentbackground
- background colorpublic static java.awt.Dimension getScreenSize()
Toolkit.getScreenSize()
public static java.awt.Dimension getMaximumScreenSize()
getScreenSize()
, the biggest display is used.
This method returns always 800x600 in headless mode (useful for unit tests).Toolkit.getScreenSize()
public static java.awt.Window getWindowAncestorFor(java.util.EventObject e)
Window
ancestor of event source, or
null
if event source is not a component contained inside a Window
.e
- event objectnull
public static void extendTooltipDelay(java.awt.Component c)
c
- componentpublic static void extendTooltipDelay(java.awt.Component c, int delay)
c
- componentdelay
- tooltip dismiss delay in millisecondspublic static java.awt.Frame getFrameForComponent(java.awt.Component parentComponent)
Frame
without throwing exception in headless mode.parentComponent
- the Component
to check for a Frame
Frame
that contains the component, or getRootFrame
if the component is null
, or does not have a valid Frame
parentJOptionPane.getFrameForComponent(java.awt.Component)
,
GraphicsEnvironment.isHeadless()
public static void translateJavaInternalMessages()
public static void setupLanguageFonts()