Interface GUI
public interface GUI
Factory of host-styled Swing components for plugins, plus static Swing helpers.
The host application (e.g., emuStudio) implements the factory methods and provides the instance via
ApplicationApi.getGUI(). Panel layout constraints are MigLayout strings.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classContainer listener propagating a key listener to added children and removing it from removed ones. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddKeyListenerRecursively(Component component, KeyListener listener) Adds a KeyListener to the component and all its descendants, including children added later.Creates a button; add listeners withAbstractButton.addActionListener(ActionListener).buttonMakePrimary(JButton button) Styles a button as the primary (default) button of a dialog.Creates a plain label.Creates a bold label.static FontloadFontResource(String path, Class<?> resourceClass, int size) Loads and registers a plain true-type font with kerning enabled.static ImageIconLoads an icon from a resource.Creates a panel with MigLayout.static voidrelayoutOnShow(Window window) Relayouts a window using its actual native insets whenever it becomes showing.static voidremoveKeyListenerRecursively(Component component, KeyListener listener) Removes a KeyListener added byaddKeyListenerRecursively(Component, KeyListener)from the component and its descendants.scrollPane(Component view) Creates a borderless scroll pane.Creates a panel with MigLayout and a titled border.static StringshortenToFit(String text, Component component, int width) Shortens text to fit the given width when rendered with the component's font.Creates a split pane.voidstyleTable(JTable table) Applies the host's table styling.textAreaReadOnly(int rows, int columns) Creates a non-editable text area.Creates a text field.toolBar()Creates a horizontal, non-floatable toolbar.toolbarButton(Action action) Creates a toolbar button from an action.
-
Method Details
-
relayoutOnShow
Relayouts a window using its actual native insets whenever it becomes showing. This prevents stale decoration spacing from the layout performed before native show. The hierarchy notification runs synchronously, including before a modal dialog's event loop. The listener remains installed when the window is hidden or disposed, so reopening is covered.Call once on the Swing event-dispatch thread before the window is first shown.
- Parameters:
window- window whose layout should be refreshed on show
-
loadIcon
Loads an icon from a resource. If a matching resource with@2xbefore the file extension exists (e.g.icon@2x.pngforicon.png), it is used for high-resolution rendering.- Parameters:
resource- resource path; relative paths are resolved againstresourceClassresourceClass- class whose classloader is used for resource lookup- Returns:
- loaded icon, or null if the base resource could not be found
-
loadFontResource
Loads and registers a plain true-type font with kerning enabled.- Parameters:
path- resource path; relative paths are resolved againstresourceClassresourceClass- class whose classloader is used for resource lookupsize- font size- Returns:
- loaded font, or a plain
Font.MONOSPACEDfont if the font could not be loaded
-
shortenToFit
Shortens text to fit the given width when rendered with the component's font.The text is cut in the middle, keeping a prefix and suffix around "..."; Unicode characters (grapheme clusters) are kept intact. If even "..." does not fit, only the dots that fit are returned.
- Parameters:
text- text to shortencomponent- component whose font is used for measuringwidth- available width in pixels; non-positive widths produce an empty string- Returns:
- text, or its shortened form that fits the width
-
addKeyListenerRecursively
Adds a KeyListener to the component and all its descendants, including children added later. Adding the same listener twice has no effect.- Parameters:
component- GUI componentlistener- KeyListener object
-
removeKeyListenerRecursively
Removes a KeyListener added byaddKeyListenerRecursively(Component, KeyListener)from the component and its descendants.- Parameters:
component- GUI componentlistener- KeyListener object
-
toolbarButton
Creates a toolbar button from an action. The action provides the icon (Action.SMALL_ICON), tooltip and accessible name (Action.SHORT_DESCRIPTION) and enabled state; the text is hidden.- Parameters:
action- button action- Returns:
- the toolbar button
-
label
-
labelBold
-
button
Creates a button; add listeners withAbstractButton.addActionListener(ActionListener).- Parameters:
text- button text- Returns:
- the button
-
buttonMakePrimary
-
textField
Creates a text field.- Parameters:
text- initial textcolumns- number of columns- Returns:
- the text field
-
textAreaReadOnly
Creates a non-editable text area.- Parameters:
rows- number of rowscolumns- number of columns- Returns:
- the text area
-
toolBar
JToolBar toolBar()Creates a horizontal, non-floatable toolbar. UseJToolBar.setOrientation(int)for a vertical one.- Returns:
- the toolbar
-
splitPane
Creates a split pane.- Parameters:
orientation-JSplitPane.HORIZONTAL_SPLIT(left to right) orJSplitPane.VERTICAL_SPLIT(top to bottom)first- left or top componentsecond- right or bottom componentresizeWeight- how extra space is distributed (0 = all to second, 1 = all to first)- Returns:
- the split pane
-
scrollPane
Creates a borderless scroll pane.- Parameters:
view- the scrolled component- Returns:
- the scroll pane
-
panel
-
section
JPanel section(String title, String layoutConstraints, String colConstraints, String rowConstraints) Creates a panel with MigLayout and a titled border.- Parameters:
title- section titlelayoutConstraints- layout constraintscolConstraints- column constraintsrowConstraints- row constraints- Returns:
- the titled panel
-
styleTable
Applies the host's table styling. Reapplying the style must not keep increasing row heights.- Parameters:
table- the table
-