use of uk.ac.sussex.gdsc.smlm.ij.utils.ImageRoiPainter in project GDSC-SMLM by aherbert.
the class ImageJTablePeakResults method createResultsWindow.
/**
* Create the result window (if it is not available).
*/
private void createResultsWindow() {
final String header = createResultsHeader();
roiPainter = null;
for (final Frame f : WindowManager.getNonImageWindows()) {
if (f != null && tableTitle.equals(f.getTitle()) && f instanceof TextWindow) {
resultsWindow = (TextWindow) f;
// Check if the existing table matches the desired header
final String currentHeader = resultsWindow.getTextPanel().getColumnHeadings();
if (!currentHeader.startsWith(header)) {
resultsWindow = null;
continue;
}
roiPainter = map.get(resultsWindow.getTextPanel());
break;
}
}
newWindow = false;
if (!ImageJUtils.isShowing(resultsWindow)) {
newWindow = true;
resultsWindow = new TextWindow(tableTitle, header, "", 800, 300);
roiPainter = new ImageRoiPainter(resultsWindow.getTextPanel(), "", this);
// The ROI painter adds itself to the TextPanel as a mouse listener. However
// the TextPanel addMouseListener() adds to the private TextCanvas object so it
// cannot be retrieved. Store the painter in a global lookup table.
map.put(resultsWindow.getTextPanel(), roiPainter);
}
tp = resultsWindow.getTextPanel();
if (roiPainter != null && getSource() != null) {
roiPainter.setTitle(getSource().getOriginal().getName());
// Update the coordinate provider (avoids memory leaks with old objects lying around)
roiPainter.setCoordProvider(this);
// Get the headings for extracting the coordinates
final String[] headings = tp.getColumnHeadings().split("\t");
indexT = indexX = indexY = -1;
for (int i = 0; i < headings.length; i++) {
if (headings[i].equals(frameColumnName)) {
indexT = i;
continue;
}
// Allow for units
if (headings[i].equals("X") || headings[i].startsWith("X (")) {
indexX = i;
continue;
}
if (headings[i].equals("Y") || headings[i].startsWith("Y (")) {
indexY = i;
continue;
}
}
}
}
use of uk.ac.sussex.gdsc.smlm.ij.utils.ImageRoiPainter in project GDSC-SMLM by aherbert.
the class TraceMatchCalculator method refresh.
private static WindowAndPainter refresh(AtomicReference<WindowAndPainter> ref, boolean pairs, TextWindow resultsWindow, MemoryPeakResults results1) {
// Produce a pairs output
final WindowAndPainter wap = ConcurrencyUtils.refresh(ref, // Test the window is showing
w -> ImageJUtils.isShowing(w.textWindow), // Create
() -> {
final String title = TITLE + ((pairs) ? " Pairs" : " Triples");
final String header = pairs ? createPairsHeader() : createTriplesHeader();
final TextWindow window = new TextWindow(title, header, "", 900, 300);
// Position relative to results window
final Point p = resultsWindow.getLocation();
p.y += resultsWindow.getHeight();
window.setLocation(p);
final CoordinateProvider coordinateProvider = line -> {
// Extract the startT and x,y coordinates from the first pulse in the line
final int[] index = { 0, 5, 12 };
final String[] fields = line.split("\t");
for (final int i : index) {
if (i < fields.length) {
if (fields[i].equals("-")) {
continue;
}
final int startT = Integer.parseInt(fields[i]);
final double x = Double.parseDouble(fields[i + 2]);
final double y = Double.parseDouble(fields[i + 3]);
return new double[] { startT, x, y };
}
}
return null;
};
final ImageRoiPainter painter = new ImageRoiPainter(window.getTextPanel(), results1.getSource().getOriginal().getName(), coordinateProvider);
final WindowAndPainter result = new WindowAndPainter(window, painter);
// Free memory on close
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent event) {
ref.compareAndSet(result, null);
super.windowClosed(event);
}
});
return result;
});
wap.textWindow.getTextPanel().clear();
wap.painter.setTitle(results1.getSource().getOriginal().getName());
return wap;
}
Aggregations