-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Attempt At Loading Factory and Event Listeners
- Loading branch information
1 parent
b1b657c
commit b565b21
Showing
8 changed files
with
154 additions
and
88 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
view-simulation-results/src/main/java/org/vcell/N5/LoadingFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.vcell.N5; | ||
|
||
import ij.ImagePlus; | ||
import org.vcell.N5.UI.ImageIntoMemory; | ||
import org.vcell.N5.UI.N5ExportTable; | ||
import org.vcell.N5.UI.SimLoadingEventCreator; | ||
import org.vcell.N5.UI.SimLoadingListener; | ||
|
||
import javax.swing.*; | ||
import javax.swing.event.EventListenerList; | ||
import java.awt.*; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
public class LoadingFactory implements SimLoadingEventCreator{ | ||
private static final EventListenerList eventListenerList = new EventListenerList(); | ||
|
||
public void openN5FileDataset(ArrayList<SimResultsLoader> filesToOpen, boolean openInMemory){ | ||
N5ExportTable.enableCriticalButtons(false); | ||
N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.WAIT_CURSOR)); | ||
Thread openN5FileDataset = new Thread(() -> { | ||
try{ | ||
for(SimResultsLoader simResultsLoader: filesToOpen){ | ||
simResultsLoader.createS3ClientAndReader(); | ||
ImageIntoMemory imageIntoMemory; | ||
if (openInMemory){ | ||
ArrayList<Double> dimensions = simResultsLoader.getN5Dimensions(); | ||
imageIntoMemory = new ImageIntoMemory(dimensions.get(2), dimensions.get(3), dimensions.get(4), simResultsLoader); | ||
imageIntoMemory.displayRangeMenu(); | ||
} else{ | ||
ImagePlus imagePlus = simResultsLoader.getImgPlusFromN5File(); | ||
imagePlus.show(); | ||
} | ||
|
||
} | ||
} catch (Exception ex) { | ||
N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); | ||
N5ExportTable.enableCriticalButtons(true); | ||
throw new RuntimeException(ex); | ||
} finally { | ||
SwingUtilities.invokeLater(new Runnable() { | ||
@Override | ||
public void run() { | ||
if (!openInMemory) { | ||
N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); | ||
N5ExportTable.enableCriticalButtons(true); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
openN5FileDataset.setName("Open N5 File"); | ||
openN5FileDataset.start(); | ||
} | ||
|
||
public void openLocalN5FS(ArrayList<SimResultsLoader> filesToOpen){ | ||
N5ExportTable.enableCriticalButtons(true); | ||
JFileChooser fileChooser = new JFileChooser(); | ||
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | ||
fileChooser.setAcceptAllFileFilterUsed(false); | ||
int result = fileChooser.showOpenDialog(null); | ||
if (result == JFileChooser.APPROVE_OPTION){ | ||
File file = fileChooser.getSelectedFile(); | ||
N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.WAIT_CURSOR)); | ||
Thread openN5FileDataset = new Thread(() -> { | ||
try{ | ||
for(SimResultsLoader simResultsLoader: filesToOpen){ | ||
simResultsLoader.setSelectedLocalFile(file); | ||
ImagePlus imagePlus = simResultsLoader.getImgPlusFromLocalN5File(); | ||
imagePlus.show(); | ||
} | ||
} catch (IOException ex) { | ||
throw new RuntimeException(ex); | ||
} finally { | ||
SwingUtilities.invokeLater(new Runnable() { | ||
@Override | ||
public void run() { | ||
N5ExportTable.exportTableDialog.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); | ||
N5ExportTable.enableCriticalButtons(true); | ||
} | ||
}); | ||
} | ||
}); | ||
openN5FileDataset.start(); | ||
} | ||
} | ||
|
||
@Override | ||
public void addSimLoadingListener(SimLoadingListener simLoadingListener) { | ||
eventListenerList.add(SimLoadingListener.class, simLoadingListener); | ||
} | ||
|
||
@Override | ||
public void notifySimIsLoading(SimResultsLoader simResultsLoader) { | ||
for (SimLoadingListener simLoadingListener: eventListenerList.getListeners(SimLoadingListener.class)){ | ||
simLoadingListener.simIsLoading(simResultsLoader.rowNumber); | ||
} | ||
} | ||
|
||
@Override | ||
public void notifySimIsDoneLoading(SimResultsLoader simResultsLoader) { | ||
for (SimLoadingListener simLoadingListener: eventListenerList.getListeners(SimLoadingListener.class)){ | ||
simLoadingListener.simFinishedLoading(simResultsLoader.rowNumber); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
view-simulation-results/src/main/java/org/vcell/N5/UI/SimLoadingEventCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.vcell.N5.UI; | ||
|
||
import org.vcell.N5.SimResultsLoader; | ||
|
||
import javax.swing.event.EventListenerList; | ||
|
||
public interface SimLoadingEventCreator { | ||
public void addSimLoadingListener(SimLoadingListener simLoadingListener); | ||
|
||
public void notifySimIsLoading(SimResultsLoader simResultsLoader); | ||
|
||
public void notifySimIsDoneLoading(SimResultsLoader simResultsLoader); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
view-simulation-results/src/main/java/org/vcell/N5/UI/SimLoadingListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.vcell.N5.UI; | ||
|
||
import java.util.EventListener; | ||
|
||
public interface SimLoadingListener extends EventListener { | ||
|
||
public void simIsLoading(int itemRow); | ||
|
||
public void simFinishedLoading(int itemRow); | ||
|
||
} |