Skip to content

Commit

Permalink
Fix issue where images would be listed that don't actually belong
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Nov 13, 2023
1 parent 4421bb7 commit bec9d44
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,13 @@ public JSONObject resolveOrCreateInteractive(String name, String objectType, Str
// TODO: check compliance, does it really match well? We use "must", so let's hope so, but the resolution could still go wrong.
return (JSONObject) foundObjects.get(0);
} else {
log.info("Got != 1 " + objectType + " status. {}", results);
log.info("Got " + foundObjects.length() + " != 1 " + objectType + " status. {}", results);
// create / select correct
if (foundObjects.length() > 1) {
// first, loop objects to see whether we can find exactly one exact match
JSONObject bestMatch = findSimilarMatch(foundObjects, objectType, inner, !interactive);
if (bestMatch != null) {
log.info("Found 1 best match, using it.");
return bestMatch;
}
log.info("Asking user to select " + name + " (" + objectType + ") from results.", results);
Expand Down Expand Up @@ -1207,7 +1208,6 @@ public JSONObject addDefaultValuesForCreation(JSONObject inner, boolean omitPool
inner.put("_id", JSONObject.NULL);
inner.put("_version", 1);
return inner;

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.*;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

Expand Down Expand Up @@ -111,9 +108,7 @@ public class ImageDisplayFrame extends JFrame {

private JPanel jPanelImagePicker = null;

private JLabel jLabelImageCountTxt = null;

private JComboBox jComboBoxImagePicker = null;
private JComboBox<String> jComboBoxImagePicker = null;

private JLabel jLabelImageCountNr = null;

Expand Down Expand Up @@ -165,38 +160,43 @@ public void setTargetSpecimen(Specimen targetSpecimen) {
*/
public void loadImagesFromFiles(Set<ICImage> imageFiles) {
log.debug("Loading images from files with size {}", imageFiles.size());
ArrayList<String> fileNames = new ArrayList<String>();
Iterator<ICImage> i = imageFiles.iterator();
ICImage image = null;
int fileCount = imageFiles.size();
while (i.hasNext()) {
image = i.next();
jComboBoxImagePicker.addItem(image.getFilename());
fileNames.add(image.getFilename());
log.debug("Adding image to picklist: " + image.getPath() +
image.getFilename());
}
// TODO: stored path may need separator conversion for different systems.
// String startPointName =
// Singleton.getSingletonInstance().getProperties().getProperties().getProperty(ImageCaptureProperties.KEY_IMAGEBASE);
String path = image.getPath();
if (path == null) {
path = "";
}
// File fileToCheck = new File(startPointName + path + image.getFilename());
File fileToCheck = new File(
ImageCaptureProperties.assemblePathWithBase(path, image.getFilename()));

jLabelImageCountNr.setText("(" + fileCount + ")");
jLabelImageCountNr.setForeground(fileCount > 1 ? Color.RED : Color.BLACK);
jComboBoxImagePicker.setModel(new DefaultComboBoxModel<>(fileNames.toArray(new String[0])));
jComboBoxImagePicker.setEnabled(fileCount > 1);
jComboBoxImagePicker.setSelectedItem(image.getFilename());
ICImage finalImage = image;
(new Thread(() -> {
try {
PositionTemplate defaultTemplate = PositionTemplate.findTemplateForImage(finalImage);
loadImagesFromFileSingle(fileToCheck, defaultTemplate, finalImage);
} catch (ImageLoadException | BadTemplateException e) {
e.printStackTrace();
// File fileToCheck = new File(startPointName + path + image.getFilename());
if (image != null) {
String path = image.getPath();
if (path == null) {
path = "";
}
})).start();
File fileToCheck = new File(
ImageCaptureProperties.assemblePathWithBase(path, image.getFilename()));
ICImage finalImage = image;
jComboBoxImagePicker.setSelectedItem(image.getFilename());
(new Thread(() -> {
try {
PositionTemplate defaultTemplate = PositionTemplate.findTemplateForImage(finalImage);
loadImagesFromFileSingle(fileToCheck, defaultTemplate, finalImage);
} catch (ImageLoadException | BadTemplateException e) {
e.printStackTrace();
}
})).start();
}
jTabbedPane.setSelectedIndex(0); // move focus to full image tab
}

Expand Down Expand Up @@ -758,7 +758,7 @@ private JPanel getJPanelImagePicker() {
gridBagConstraints.gridy = 0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.gridx = 3;
jLabelImageCountTxt = new JLabel();
JLabel jLabelImageCountTxt = new JLabel();
jLabelImageCountTxt.setText("Images: ");
jPanelImagePicker = new JPanel();
GridBagLayout gbl_jPanelImagePicker = new GridBagLayout();
Expand Down

0 comments on commit bec9d44

Please sign in to comment.