FileChooser
com.jsmacrosce.jsmacros.client.gui.overlays.FileChooser
Browses native Java files with optional selection and edit callbacks. Construct the overlay, set root before opening when needed, then open it through its parent to initialize its controls. The root is a navigation reference, not a filesystem boundary; relative paths may escape it.
js
function openFileChooser(parent, font, directory, onSelect, onEdit) {
const FileChooser = Java.type('com.jsmacrosce.jsmacros.client.gui.overlays.FileChooser');
const chooser = new FileChooser(10, 10, 320, 180, font, directory, null, parent,
JavaWrapper.methodToJava(onSelect), JavaWrapper.methodToJava(onEdit));
chooser.root = directory;
parent.openOverlay(chooser);
return chooser;
}The caller supplies a listable native Java directory, native font, overlay parent and JavaScript callback functions.
Nested types
Constructors
new FileChooser
new FileChooser(int x, int y, int width, int height, Font textRenderer, File directory, File selected, IOverlayParent parent, Consumer<File> setFile, Consumer<File> editFile)#Stores the overlay geometry, browser state and callbacks; controls are registered when the parent opens and initializes this overlay.
Parameters:
x: left coordinate in GUI spacey: top coordinate in GUI spacewidth: width in GUI unitsheight: height in GUI unitstextRenderer: non-null native font for the controlsdirectory: non-null initial browse directory, listable or creatable during initializationselected: nullable file initially selected during initializationparent: non-null overlay hostsetFile: nullable callback invoked by the Select button when a selection is stored; null makes Select do nothing, and the overlay closes only after a normal callback returneditFile: callback invoked by the Edit button with the stored selection; it is not null-checked and does not close the overlay
Fields
root
Methods
addFile
Adds a row using the file's name as its literal button label. Requires initialized controls.
Parameters:
f: non-null native file or directory represented by the row
Appends and registers a row with the supplied literal label, using five columns and twelve-GUI-unit rows. Clicking it calls
selectFile; duplicate entries are not filtered. Requires an initialized scrollbar: the row is appended and registered before the scrollbar page-count update, so failures can leave partial effects. The page-count update can change scrollbar state and notify its callback, repositioning rows.Parameters:
f: file or directory represented by the rowbtnText: literal button label
confirmDelete
confirmDelete(FileChooser.fileObj f): void#Opens a confirmation overlay that calls
delete(f) only when confirmed; it does not delete immediately. Captures the mutable row record, not a snapshot of its fields. This method does not verify listing membership or require a regular file.Parameters:
f: row record captured by the confirmation callback
delete
delete(FileChooser.fileObj f): void#Removes the row from tracking and the parent, then attempts
File.delete() and repositions remaining rows. The delete result is ignored: a false result does not restore the row. Unchecked failures interrupt the remaining steps without rollback. Does not confirm, verify membership, require a regular file or recursively delete a directory. Selection and scrollbar page count are not updated.Parameters:
f: row record whose button and file are used
extractRenderState
extractRenderState(GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float delta): void#Submits this chooser's background, directory heading and separators, then delegates widget and child-overlay rendering before submitting popups for truncated hovered buttons. Popup eligibility uses each button's stored hover state and text-fit state; it does not check visibility or active state, and multiple buttons can qualify. Call after initialization so the directory heading is set.
Parameters:
drawContext: graphics context receiving the drawing operationsmouseX: GUI-space mouse x-coordinate forwarded to widgets and used for popup placementmouseY: GUI-space mouse y-coordinate forwarded to widgets and used for popup placementdelta: frame value forwarded to the superclass
init
init(): void#Clears local tracking, registers new controls and a scrollbar, resets the row origin to
y + 13, then rebuilds the directory listing. Opening through the parent calls this. The listing rebuild separately removes old file rows from the parent, but repeated initialization leaves prior non-row controls registered. A non-null initial selection is passed to selectFile, so a directory selection can navigate again; initialization does not notify the selection or edit consumers. Filesystem failures can leave partially initialized controls.onScrollbar
onScrollbar(double page): void#Sets the row origin to
y + 13 - (int) (page * (height - 27)) and repositions rows on every call. The page argument is not clamped; this changes row positions and visibility, not active flags, directory contents, page count or the scrollbar thumb.Parameters:
page: scrollbar amount in multiples ofheight - 27
selectFile
Navigates into a directory without clearing the stored file selection, or stores a non-directory file as the selection, then updates row highlighting against the supplied file. Does not require a listed or existing file, invoke either callback, confirm a choice or close the overlay.
Parameters:
f: file or directory to navigate to or select
setDir
Rebuilds the listing for
dir, attempting to create it when absent. Requires an initialized scrollbar and usable root; old rows are removed before filesystem checks. Failed creation recursively attempts root; there is no cycle guard if that directory cannot be created either. The heading is relative to the absolute root path, not a canonical containment check. Entries are sorted directories first, then by name. A null directory listing is not treated as empty; unchecked filesystem or path failures can leave a partial rebuild. Existing selection is retained. Row additions update scrollbar page count, which can reset the offset through its callback.Parameters:
dir: non-null directory to browse, listable or creatable and with a path compatible with the root for relativization
updateFilePos
updateFilePos(): void#Repositions and resizes existing rows in five columns of twelve-GUI-unit rows using current geometry and scroll position. A row is visible when its top lies between
y + 13 and y + height - 27, inclusive. Does not change active flags, create controls, rebuild the listing or update scrollbar page count.