Skip to content

Commit

Permalink
Small fixes (#9)
Browse files Browse the repository at this point in the history
* Fixed null client causing exception when closing
* Adjusted users order in list
* Added code to store local input preferences
  • Loading branch information
ppouchin authored Dec 16, 2021
1 parent 9c4109f commit ad4d79c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import fr.igred.omero.repository.ImageWrapper;
import fr.igred.omero.repository.ProjectWrapper;
import ij.IJ;
import ij.Prefs;
import ij.plugin.frame.PlugInFrame;
import loci.plugins.config.SpringUtilities;

Expand Down Expand Up @@ -225,6 +226,7 @@ public OMEROBatchPlugin() {
JButton inputFolderBtn = new JButton(browse);
inputFolderLabel.setLabelFor(inputFolder);
inputFolder.setMaximumSize(maxTextSize);
inputFolder.setName("omero.batch.dir.input");
input2.add(inputFolderLabel);
input2.add(inputFolder);
input2.add(inputFolderBtn);
Expand All @@ -246,6 +248,7 @@ public OMEROBatchPlugin() {
JButton macroBtn = new JButton(browse);
JButton argsBtn = new JButton("Set arguments");
macroLabel.setLabelFor(macro);
macro.setName("omero.batch.macro");
macro.setMaximumSize(maxTextSize);
macro1.add(macroLabel);
macro1.add(macro);
Expand Down Expand Up @@ -326,6 +329,7 @@ public OMEROBatchPlugin() {
JButton directoryBtn = new JButton(browse);
outputFolderLabel.setLabelFor(outputFolder);
outputFolder.setMaximumSize(maxTextSize);
outputFolder.setName("omero.batch.dir.output");
output3b.add(outputFolderLabel);
output3b.add(outputFolder);
output3b.add(directoryBtn);
Expand Down Expand Up @@ -411,7 +415,12 @@ public static void errorWindow(String message) {
* @param textField The related text field.
*/
private static void chooseDirectory(JTextField textField) {
JFileChooser outputChoice = new JFileChooser(textField.getText());
String pref = textField.getName();
if(pref.isEmpty()) pref = "omero.batch." + Prefs.DIR_IMAGE;
String previousDir = textField.getText();
if(previousDir.isEmpty()) previousDir = Prefs.get(pref, previousDir);

JFileChooser outputChoice = new JFileChooser(previousDir);
outputChoice.setDialogTitle("Choose the directory");
outputChoice.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = outputChoice.showOpenDialog(null);
Expand All @@ -421,6 +430,7 @@ private static void chooseDirectory(JTextField textField) {
.getAbsolutePath());
if (absDir.exists() && absDir.isDirectory()) {
textField.setText(absDir.toString());
Prefs.set(pref, absDir.toString());
} else {
////find a way to prevent JFileChooser closure?
errorWindow(String.format("Output:%nThe directory doesn't exist"));
Expand Down Expand Up @@ -638,6 +648,7 @@ private void updateGroup(ItemEvent e) {
} catch (ExecutionException | ServiceException | AccessException exception) {
LOGGER.warning(exception.getMessage());
}
users.sort(Comparator.comparing(ExperimenterWrapper::getUserName));
userList.removeAllItems();

userList.addItem("All members");
Expand Down Expand Up @@ -690,14 +701,20 @@ private void updateInput(ItemEvent e) {
* Displays a dialog to select the macro to run.
*/
private void chooseMacro() {
JFileChooser macroChoice = new JFileChooser(macro.getText());
String pref = macro.getName().isEmpty() ? "omero.batch.macro" : macro.getName();
String previousMacro = macro.getText();
if(previousMacro.isEmpty()) {
previousMacro = Prefs.get(pref, previousMacro);
}
JFileChooser macroChoice = new JFileChooser(previousMacro);
macroChoice.setDialogTitle("Choose the macro file");
macroChoice.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = macroChoice.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File absFile = new File(macroChoice.getSelectedFile().getAbsolutePath());
if (absFile.exists() && !absFile.isDirectory()) {
macro.setText(absFile.toString());
Prefs.set(pref, absFile.toString());
} else {
//find a way to prevent JFileChooser closure?
warningWindow(String.format("Macro:%nThe file doesn't exist"));
Expand Down Expand Up @@ -1120,7 +1137,8 @@ private class ClientDisconnector extends WindowAdapter {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
client.disconnect();
Client c = client;
if(c != null) c.disconnect();
}

}
Expand Down

0 comments on commit ad4d79c

Please sign in to comment.