@@ -96,17 +96,27 @@ public enum State {READY, STARTED, ENDED, LOADED, STOPPED}
9696
9797
9898 /**
99- * Instantiates a new Fill Manager Dialog
99+ * Instantiates a new Fill Manager Dialog, with no owning {@link SNTUI} (e.g. scripts/tests
100+ * driving a headless-ish {@link SNT} instance that never called {@code startUI()}).
100101 *
101- * @param plugin the {@link SNT} instance to be associated
102- * with this FillManager. It is assumed that its {@link SNTUI} is
103- * available.
102+ * @param plugin the {@link SNT} instance to be associated with this FillManager.
104103 */
105104 public FillManagerUI (final SNT plugin ) {
106- super (plugin .getUI (), "Fill Manager" );
105+ this (plugin , null );
106+ }
107+
108+ /**
109+ * Instantiates a new Fill Manager Dialog owned by {@code ui}.
110+ *
111+ * @param plugin the {@link SNT} instance to be associated with this FillManager
112+ * @param ui the owning {@link SNTUI}, or null if none (see {@link #FillManagerUI(SNT)})
113+ */
114+ public FillManagerUI (final SNT plugin , final SNTUI ui ) {
115+ super (ui , "Fill Manager" );
107116 getRootPane ().putClientProperty ("JRootPane.menuBarEmbedded" , false );
108117
109118 this .plugin = plugin ;
119+ final boolean streamMode = ui != null && ui .isStreamMode ();
110120 pathAndFillManager = plugin .getPathAndFillManager ();
111121 pathAndFillManager .addPathAndFillListener (this );
112122 listModel = new DefaultListModel <>();
@@ -156,6 +166,7 @@ public FillManagerUI(final SNT plugin) {
156166
157167 // Row 1: Cursor threshold choice
158168 cursorThresholdChoice = new JRadioButton ("Set by clicking on traced structure (preferred)" );
169+ cursorThresholdChoice .setEnabled (!streamMode );
159170 distancePanel .add (cursorThresholdChoice , gdb );
160171 gdb .gridy ++;
161172
@@ -230,7 +241,7 @@ public void focusGained(java.awt.event.FocusEvent e) {
230241 transparentCheckbox = new JCheckBox ("Transparent overlay" );
231242 transparentCheckbox .setToolTipText ("Enabling this option allows you to better\n inspect fills, but may slow down filling" );
232243 transparentCheckbox .addActionListener (e -> plugin .setFillTransparent (transparentCheckbox .isSelected ()));
233-
244+ transparentCheckbox . setEnabled (! streamMode );
234245 final int prevLeftMargin = c .insets .left ;
235246 c .insets .left = MARGIN ;
236247 add (splitFillsCheckbox , c );
@@ -286,15 +297,13 @@ public void mousePressed(final MouseEvent e) {
286297 pack ();
287298 adjustListPlaceholder ();
288299 changeState (State .READY );
289- setLocationRelativeTo (plugin . getUI () );
300+ setLocationRelativeTo (ui );
290301 addWindowListener (new WindowAdapter () {
291302 @ Override
292303 public void windowClosing (final WindowEvent ignored ) {
293304 setVisible (false );
294305 }
295306 });
296-
297-
298307 }
299308
300309 private int [] getSelectedIndices (final String msg ) {
@@ -836,8 +845,19 @@ private void assembleExportFillsMenu() {
836845
837846 // Add image export actions
838847 for (ExportAction action : exportActions ) {
839- JMenuItem jmi = new JMenuItem (action .getMenuText ());
840- jmi .addActionListener (e -> action .execute ());
848+ final JMenuItem jmi = new JMenuItem (action .getMenuText ());
849+ jmi .addActionListener (e -> {
850+ try {
851+ action .execute ();
852+ } catch (final UnsupportedOperationException ex ) {
853+ final String msg = (plugin .getUI () != null && plugin .getUI ().isStreamMode ())
854+ ? "An error occurred: This operation likely requires the entire image to be loaded into memory (RAM)."
855+ : "An error occurred." ;
856+ gUtils .error (msg + " See Console for details." );
857+ if (plugin .getUI () != null ) plugin .getUI ().setEnableDebugMode (true );
858+ SNTUtils .error (action .getMenuText (), ex );
859+ }
860+ });
841861 exportFillsMenu .add (jmi );
842862 }
843863
0 commit comments