Class FileDialogs

java.lang.Object
edu.cnu.mdi.dialog.FileDialogs

public final class FileDialogs extends Object
Centralized open/save dialogs for MDI applications.

The service consistently configures filters, remembers the last directory independently for each caller-supplied purpose, appends save extensions, and confirms overwrites. Methods return Optional.empty() when the user cancels, allowing action handlers to avoid chooser result-code boilerplate.

Purpose keys

A purpose is a stable application-defined identifier such as "problem-json" or "plot-export". Open and save share one remembered directory per purpose (not separate ones) -- in practice a file of a given kind is saved and reopened from the same folder far more often than not, so splitting the two would make the common case worse. A caller that genuinely wants independent histories can already get that by using distinct purpose strings for each (e.g. "shapefile-import" vs. "shapefile-export").

The remembered directory is persisted (via Preferences) across JVM restarts, keyed by purpose -- see lastDirectory(String) and rememberDirectory(String, Path), which are also available to callers that build their own JFileChooser (for filtering a caller cannot express as a simple extension list) but still want to participate in the same per-purpose directory memory. Before a purpose has any history (or its remembered directory no longer exists), Environment's data directory is used as the initial location -- this is purely a developer-configured default (see Environment.setDataDirectory(java.lang.String), typically set once at startup from a command-line argument or environment variable) and is not updated by every dialog use, so it stays whatever the developer intended rather than drifting to wherever the user last happened to browse.

Threading

Like other modal Swing dialogs, openFile(java.awt.Component, java.lang.String, java.lang.String, edu.cnu.mdi.dialog.FileType) and saveFile(java.awt.Component, java.lang.String, java.lang.String, java.lang.String, edu.cnu.mdi.dialog.FileType) must be invoked on the EDT. An IllegalStateException is thrown otherwise so an accidental worker thread call cannot create platform-dependent UI behavior. lastDirectory(String) and rememberDirectory(String, Path) have no such requirement.