Skip to content

Commit 3edafac

Browse files
committed
add IJ macro commands run sequentially
1 parent 130d05d commit 3edafac

4 files changed

Lines changed: 85 additions & 47 deletions

File tree

src/main/java/bigtrace/BigTrace.java

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javax.swing.JLabel;
2424
import javax.swing.JOptionPane;
2525
import javax.swing.JPanel;
26+
import javax.swing.SwingUtilities;
2627
import javax.swing.UIManager;
2728
import javax.swing.WindowConstants;
2829

@@ -561,24 +562,47 @@ public IntervalView<T> getTraceInterval(boolean bClippedInterval)
561562

562563
return Views.interval(full_int, full_int);
563564
}
564-
565-
public synchronized void setLockMode(boolean bLockMode)
566-
{
567-
TaskBT.runOnEDT( () ->
565+
566+
public void setLockMode(final boolean bLockMode)
567+
{
568+
if(!this.btMacro.bMacroMode)
569+
{
570+
synchronized ( BigTrace.this )
571+
{
572+
lockGUI(bLockMode);
573+
//System.out.println("regular lock " + bLockMode);
574+
}
575+
}
576+
else
568577
{
569-
boolean bState = !bLockMode;
578+
setLockModeMacro(bLockMode);
579+
//System.out.println("macro lock"+ bLockMode);
580+
}
581+
}
570582

571-
GuiMisc.setPanelStatusAllComponents(roiManager, bState);
572-
GuiMisc.setPanelStatusAllComponents(btPanel.roiMeasure, bState);
573-
GuiMisc.setPanelStatusAllComponents(btPanel.btTracksPanel, bState);
574-
GuiMisc.setPanelStatusAllComponents(btPanel.btAniPanel, bState);
575-
btPanel.voxelSizePanel.allowVoxelSizeChange(bState);
583+
public void setLockModeMacro(final boolean bLockMode)
584+
{
585+
SwingUtilities.invokeLater(()->
586+
{
587+
lockGUI(bLockMode);
588+
});
589+
}
590+
void lockGUI(final boolean bLockMode)
591+
{
592+
boolean bState = !bLockMode;
593+
594+
GuiMisc.setPanelStatusAllComponents(roiManager, bState);
595+
GuiMisc.setPanelStatusAllComponents(btPanel.roiMeasure, bState);
596+
GuiMisc.setPanelStatusAllComponents(btPanel.btTracksPanel, bState);
597+
GuiMisc.setPanelStatusAllComponents(btPanel.btAniPanel, bState);
598+
btPanel.voxelSizePanel.allowVoxelSizeChange(bState);
599+
600+
btPanel.clipPanel.butExtractClipped.setEnabled( bState );
601+
//keep it on
602+
roiManager.butShowAll.setEnabled(true);
576603

577-
btPanel.clipPanel.butExtractClipped.setEnabled( bState );
578-
//keep it on
579-
roiManager.butShowAll.setEnabled(true);
580-
});
581604
}
605+
582606

583607
/** turn on Trace Box mode **/
584608
public void getSemiAutoTrace(RealPoint target)

src/main/java/bigtrace/BigTraceMacro.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ public BigTraceMacro(final BigTrace<T> bt_)
8080

8181
}
8282

83-
public synchronized CompletableFuture<Void> enqueue(Runnable task)
83+
public synchronized void enqueue(Runnable task)
8484
{
85+
8586
tail = tail
8687
.exceptionally(ex -> {
8788
ex.printStackTrace();
@@ -95,8 +96,9 @@ public synchronized CompletableFuture<Void> enqueue(Runnable task)
9596
throw e;
9697
}
9798
}, executor);
98-
99-
return tail;
99+
tail.join();
100+
return;
101+
// return tail;
100102
}
101103

102104
public String handleExtension(String name, Object[] args)
@@ -191,6 +193,7 @@ public String handleExtension(String name, Object[] args)
191193

192194
if (name.equals("btRunFullAutoTrace"))
193195
{
196+
194197
enqueue (()->
195198
{
196199
int nFirstTPi = 0;
@@ -271,7 +274,7 @@ public String handleExtension(String name, Object[] args)
271274
{
272275
enqueue (()->
273276
{
274-
macroCloseBT();
277+
macroClose();
275278
});
276279
}
277280

@@ -288,6 +291,7 @@ public String handleExtension(String name, Object[] args)
288291
* in case of timelapse data, the last frame to trace **/
289292
public void macroRunFullAutoTrace(final Double dMinIntensity, final Integer nMinNumPoints, final Integer nFirstFrame, final Integer nLastFrame)
290293
{
294+
291295
int nFirstTP = 0;
292296
int nLastTP = 0;
293297
bMacroMode = true;
@@ -877,16 +881,12 @@ public void macroOpenNext(final String sFilename)
877881
bt.bvvFrame.setTitle( sFilename );
878882
});
879883

880-
// TaskBT.runOnEDTAndWait(()->
881-
// {
882-
// IJ.log("BigTrace macro: opened new file " + sFilename + ".");
883-
// });
884884
bt.bInputLock = false;
885885
bMacroMode = false;
886886
}
887887

888888
/** macro function closes BigTrace **/
889-
public void macroCloseBT()
889+
public void macroClose()
890890
{
891891
bt.closeWindows();
892892
TaskBT.runOnEDTAndWait(()->

src/main/java/bigtrace/gui/PanelFullAutoTrace.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javax.swing.JOptionPane;
1616
import javax.swing.JPanel;
1717
import javax.swing.JTabbedPane;
18+
import javax.swing.SwingUtilities;
1819

1920
import net.imglib2.type.NativeType;
2021
import net.imglib2.type.numeric.RealType;
@@ -193,12 +194,23 @@ public void launchFullAutoTrace(final double dAutoMinStartTrace, final int nAuto
193194
bt.bInputLock = true;
194195
bt.setLockMode( true );
195196
fullAutoTrace.addPropertyChangeListener( bt.btPanel );
196-
TaskBT.runOnEDT( ()->
197+
198+
if(bt.btMacro.bMacroMode)
197199
{
198-
butAuto.setEnabled( true );
199-
butAuto.setIcon( tabIconCancel );
200-
butAuto.setToolTipText( "Stop auto trace" );
201-
});
200+
SwingUtilities.invokeLater(()->
201+
{
202+
butAuto.setEnabled( true );
203+
butAuto.setIcon( tabIconCancel );
204+
butAuto.setToolTipText( "Stop auto trace" );
205+
});
206+
}
207+
else
208+
{
209+
butAuto.setEnabled( true );
210+
butAuto.setIcon( tabIconCancel );
211+
butAuto.setToolTipText( "Stop auto trace" );
212+
}
213+
202214
fullAutoTrace.butAuto = butAuto;
203215
fullAutoTrace.tabIconRestore = tabIconAuto;
204216
if( !bt.btMacro.bMacroMode )
@@ -207,8 +219,11 @@ public void launchFullAutoTrace(final double dAutoMinStartTrace, final int nAuto
207219
}
208220
else
209221
{
210-
fullAutoTrace.runFullAutoTrace();
222+
fullAutoTrace.runFullAutoTrace();
223+
TaskBT.runOnEDTAndWait( () ->
224+
{
211225
fullAutoTrace.wrapUp();
226+
});
212227
}
213228
}
214229

src/main/java/bigtrace/math/FullAutoTrace.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import bigtrace.BigTrace;
1515
import bigtrace.BigTraceBGWorker;
16-
import bigtrace.gui.TaskBT;
1716
import bigtrace.rois.LineTrace3D;
1817
import ij.IJ;
1918

@@ -187,25 +186,25 @@ public void done()
187186

188187
public void wrapUp()
189188
{
190-
TaskBT.runOnEDT( () ->
189+
if(butAuto != null && tabIconRestore != null)
191190
{
192-
if(butAuto != null && tabIconRestore != null)
193-
{
194-
butAuto.setIcon( tabIconRestore );
195-
butAuto.setToolTipText( "Full auto tracing" );
196-
}
197-
bt.visualBoxes.bShowTraceBox = false;
198-
oneClickTrace.releaseMultiThread();
191+
butAuto.setIcon( tabIconRestore );
192+
butAuto.setToolTipText( "Full auto tracing" );
193+
}
194+
bt.visualBoxes.bShowTraceBox = false;
195+
oneClickTrace.releaseMultiThread();
196+
197+
//unlock user interaction
198+
bt.bInputLock = false;
199+
200+
bt.setLockMode(false);
201+
202+
if(bt.btMacro.bMacroMode)
203+
{
204+
bt.roiManager.updateRoiListModel();
205+
IJ.log( "Macro auto trace is finished with " +Integer.toString( nCount )+" new ROIs." );
206+
}
199207

200-
//unlock user interaction
201-
bt.bInputLock = false;
202-
bt.setLockMode(false);
203-
if(bt.btMacro.bMacroMode)
204-
{
205-
bt.roiManager.updateRoiListModel();
206-
IJ.log( "Macro auto trace is finished with " +Integer.toString( nCount )+" new ROIs." );
207-
}
208-
});
209208
}
210209

211210
}

0 commit comments

Comments
 (0)