Package org.openstreetmap.josm.gui.util
Class GuiHelper
java.lang.Object
org.openstreetmap.josm.gui.util.GuiHelper
basic gui utils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidThis function fails if it was not called from the EDT thread.static voiddestroyComponents(Component component, boolean destroyItself) Destroys recursively allDestroyablecomponents of a given container, and optionnally the container itself.static JScrollPaneEmbeds the given component into a new vertical-only scrollableJScrollPane.static voidAdd a task to the main worker that will block the worker and run in the GUI thread.static voidExtends tooltip dismiss delay to a default value of 1 minute for the given component.static voidextendTooltipDelay(Component c, int delay) Extends tooltip dismiss delay to the specified value for the given component.static StrokegetCustomizedStroke(String code) Return s new BasicStroke object with given thickness and stylestatic ImageIcongetDisabledIcon(ImageIcon icon) Replies the disabled (grayed) version of the specified icon.static ImagegetDisabledImage(Image image) Replies the disabled (grayed) version of the specified image.static FramegetFrameForComponent(Component parentComponent) Returns the specified component'sFramewithout throwing exception in headless mode.static DimensionGets the size of the screen.static FontgetMonospacedFont(JComponent component) Gets the font used to display monospaced text in a component, if possible.static DimensionGets the size of the screen.static FontGets the font used to display JOSM title in about dialog and splash screen.static WindowReturns the firstWindowancestor of event source, ornullif event source is not a component contained inside aWindow.(package private) static voidHandle exceptions in the EDT.static voidnotifyUserHtmlError(Component parent, String title, String message, String html) Notifies user about an error received from an external source as an HTML page.static ComponentprepareResizeableOptionPane(Component pane, Dimension minDimension) Attaches aHierarchyListenerto the specifiedComponentthat will set its parent dialog resizeable.static voidExecutes asynchronously a runnable in Event Dispatch Thread, except if we're already in the EDT: in this case the runnable is executed synchronously.static voidrunInEDTAndWait(Runnable task) Executes synchronously a runnable in Event Dispatch Thread.static <V> VrunInEDTAndWaitAndReturn(Callable<V> callable) Executes synchronously a callable in Event Dispatch Thread and return a value.static voidExecutes synchronously a runnable in Event Dispatch Thread.static TimerscheduleTimer(int initialDelay, ActionListener actionListener, boolean repeats) Schedules a new Timer to be run in the future (once or several times).static voidsetBackgroundReadable(JComponent c, Color background) Sets the background color for this component, and adjust the foreground color so the text remains readable.static JScrollPaneSet the default unit increment for aJScrollPane.static voidsetEnabledRec(Container root, boolean enabled) disable / enable a component and all its child componentsstatic voidSets a global font for all UI, replacing default font of current look and feel.static voidSetup special font for Khmer script, as the default Java fonts do not display these characters.static voidLocalizations for file chooser dialog.static booleanWarns user about a dangerous action requiring confirmation.
-
Field Details
-
JAVA_INTERNAL_MESSAGE_KEYS
-
-
Constructor Details
-
GuiHelper
private GuiHelper()
-
-
Method Details
-
setEnabledRec
disable / enable a component and all its child components- Parameters:
root- componentenabled- enabled state
-
executeByMainWorkerInEDT
Add a task to the main worker that will block the worker and run in the GUI thread.- Parameters:
task- The task to run
-
runInEDT
Executes asynchronously a runnable in Event Dispatch Thread, except if we're already in the EDT: in this case the runnable is executed synchronously.- Parameters:
task- The runnable to execute- See Also:
-
handleEDTException
Handle exceptions in the EDT. This should only be used inGuiHelperandorg.openstreetmap.josm.testutils.mockers.EDTAssertionMocker.- Parameters:
t- The throwable to handle
-
runInEDTAndWait
Executes synchronously a runnable in Event Dispatch Thread.- Parameters:
task- The runnable to execute- See Also:
-
runInEDTAndWaitWithException
Executes synchronously a runnable in Event Dispatch Thread.Passes on the exception that was thrown to the thread calling this. The exception is wrapped using a
ReportedException.- Parameters:
task- The runnable to execute- Since:
- 10271
- See Also:
-
runInEDTAndWaitAndReturn
Executes synchronously a callable in Event Dispatch Thread and return a value.- Type Parameters:
V- the result type of methodcall- Parameters:
callable- The callable to execute- Returns:
- The computed result
- Since:
- 7204
-
assertCallFromEdt
This function fails if it was not called from the EDT thread.- Throws:
IllegalStateException- if called from wrong thread.- Since:
- 10271
-
warnUser
public static boolean warnUser(String title, String content, ImageIcon baseActionIcon, String continueToolTip) Warns user about a dangerous action requiring confirmation.- Parameters:
title- Title of dialogcontent- Content of dialogbaseActionIcon- Unused? FIXME why is this parameter unused?continueToolTip- Tooltip to display for "continue" button- Returns:
- true if the user wants to cancel, false if they want to continue
-
notifyUserHtmlError
Notifies user about an error received from an external source as an HTML page.- Parameters:
parent- Parent componenttitle- Title of dialogmessage- Message displayed at the top of the dialoghtml- HTML content to display (real error message)- Since:
- 7312
-
getDisabledImage
Replies the disabled (grayed) version of the specified image.- Parameters:
image- The image to disable- Returns:
- The disabled (grayed) version of the specified image, brightened by 20%.
- Since:
- 5484
-
getDisabledIcon
Replies the disabled (grayed) version of the specified icon.- Parameters:
icon- The icon to disable- Returns:
- The disabled (grayed) version of the specified icon, brightened by 20%.
- Since:
- 5484
-
prepareResizeableOptionPane
Attaches aHierarchyListenerto the specifiedComponentthat will set its parent dialog resizeable. Use it before a call to JOptionPane#showXXXXDialog to make it resizeable.- Parameters:
pane- The component that will be displayedminDimension- The minimum dimension that will be set for the dialog. Ignored if null- Returns:
pane- Since:
- 5493
-
scheduleTimer
Schedules a new Timer to be run in the future (once or several times).- Parameters:
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 event- Returns:
- The (started) timer.
- Since:
- 5735
-
getCustomizedStroke
Return s new BasicStroke object with given thickness and style- Parameters:
code- = 3.5 → thickness=3.5px; 3.5 10 5 → thickness=3.5px, dashed: 10px filled + 5px empty- Returns:
- stroke for drawing
- See Also:
-
getMonospacedFont
Gets the font used to display monospaced text in a component, if possible.- Parameters:
component- The component- Returns:
- the font used to display monospaced text in a component, if possible
- Since:
- 7896
-
getTitleFont
Gets the font used to display JOSM title in about dialog and splash screen.- Returns:
- title font
- Since:
- 5797
-
embedInVerticalScrollPane
Embeds the given component into a new vertical-only scrollableJScrollPane.- Parameters:
panel- The component to embed- Returns:
- the vertical scrollable
JScrollPane - Since:
- 6666
-
setDefaultIncrement
Set the default unit increment for aJScrollPane. This fixes slow mouse wheel scrolling when the content of theJScrollPaneis aJPanelor other component that does not implement theScrollableinterface. 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.- Parameters:
sp- the scroll pane- Returns:
- the scroll pane (same object) with fixed unit increment
- Throws:
IllegalArgumentException- if the component inside of the scroll pane implements theScrollableinterface (JTree,JLayer,JList,JTextComponentandJTable)
-
setUIFont
Sets a global font for all UI, replacing default font of current look and feel.- Parameters:
name- Font name. It is up to the caller to make sure the font exists- Throws:
IllegalArgumentException- if name is null- Since:
- 7896
-
setBackgroundReadable
Sets the background color for this component, and adjust the foreground color so the text remains readable.- Parameters:
c- componentbackground- background color- Since:
- 9223
-
getScreenSize
Gets the size of the screen. On systems with multiple displays, the primary display is used. This method returns always 800x600 in headless mode (useful for unit tests).- Returns:
- the size of this toolkit's screen, in pixels, or 800x600
- Since:
- 9576
- See Also:
-
getMaximumScreenSize
Gets the size of the screen. On systems with multiple displays, contrary togetScreenSize(), the biggest display is used. This method returns always 800x600 in headless mode (useful for unit tests).- Returns:
- the size of maximum screen, in pixels, or 800x600
- Since:
- 10470
- See Also:
-
getWindowAncestorFor
Returns the firstWindowancestor of event source, ornullif event source is not a component contained inside aWindow.- Parameters:
e- event object- Returns:
- a Window, or
null - Since:
- 9916
-
extendTooltipDelay
Extends tooltip dismiss delay to a default value of 1 minute for the given component.- Parameters:
c- component- Since:
- 10024
-
extendTooltipDelay
Extends tooltip dismiss delay to the specified value for the given component.- Parameters:
c- componentdelay- tooltip dismiss delay in milliseconds- Since:
- 10024
- See Also:
-
getFrameForComponent
Returns the specified component'sFramewithout throwing exception in headless mode.- Parameters:
parentComponent- theComponentto check for aFrame- Returns:
- the
Framethat contains the component, orgetRootFrameif the component isnull, or does not have a validFrameparent - Since:
- 10035
- See Also:
-
translateJavaInternalMessages
Localizations for file chooser dialog. For some locales (e.g. de, fr) translations are provided by Java, but not for others (e.g. ru, uk).- Since:
- 12644 (moved from I18n)
-
setupLanguageFonts
Setup special font for Khmer script, as the default Java fonts do not display these characters.- Since:
- 12644 (moved from I18n), 8282
-
destroyComponents
Destroys recursively allDestroyablecomponents of a given container, and optionnally the container itself.- Parameters:
component- the component to destroydestroyItself- whether to destroy the component itself- Since:
- 14463
-