Link samples table to GUI events

This commit is contained in:
2018-09-11 11:57:51 +02:00
parent 014116ba6f
commit 0cf9904929
3 changed files with 43 additions and 15 deletions

View File

@@ -15,6 +15,7 @@ import ch.psi.pshell.device.GenericDevice;
import ch.psi.pshell.device.ReadbackDevice;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -24,6 +25,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptException;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
/**
@@ -509,9 +511,10 @@ public class Controller {
////////////////////// Sample Info /////////////////////////////////
String samplesTableJson;
final Object samplesTableLock = new Object();
//final Object samplesTableLock = new Object();
void refreshSamplesTable() {
synchronized(samplesTableLock){
//synchronized(samplesTableLock){
SwingUtilities.invokeLater(()->{
try {
String json = (String) Context.getInstance().evalLineBackground("get_samples_info()");
if (!json.equals(samplesTableJson)) {
@@ -530,7 +533,8 @@ public class Controller {
clearSamplesTable();
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
//}
}
void clearSamplesTable() {
@@ -557,6 +561,7 @@ public class Controller {
} else if (getState().isInitialized()){
execute("barcode_reader.polling = 0", true);
execute("barcode_reader.disable()", true);
getMainFrame().setPuckDatamatrix(null);
}
}
}
@@ -575,18 +580,17 @@ public class Controller {
Puck.Detection[] detection = basePlate.getDetection();
for (int i=0; i< Controller.NUMBER_OF_PUCKS; i++){
Puck puck = basePlate.getPucks()[i];
//Only manage pucks for current hexiposi position
if (isSelectedPuck(puck)){
boolean detectedPuckInserted = (currentDetection[i] != Puck.Detection.Present) && (detection[i] == Puck.Detection.Present);
boolean detectedPuckInserted = (currentDetection[i] != Puck.Detection.Present) && (detection[i] == Puck.Detection.Present);
boolean detectedPuckRemoved = (currentDetection[i] != Puck.Detection.Empty) && (detection[i] == Puck.Detection.Empty);
if (detectedPuckInserted){
System.out.println("Detected puck at position: " + puck.getName() + " - Datamatrix: " + (datamatrix.isEmpty() ? null : datamatrix));
if (!datamatrix.isEmpty()){
getMainFrame().setPuckDatamatrix(null);
setPuckDatamatrix(puck, datamatrix);
linkPuckDatamatrix(puck, datamatrix);
}
} else if (detectedPuckRemoved){
System.out.println("Removed puck from position " + puck.getName() + " - Datamatrix: " + puck.getId());
setPuckDatamatrix(puck, null);
linkPuckDatamatrix(puck, null);
}
}
}
@@ -595,14 +599,24 @@ public class Controller {
}
}
void setPuckDatamatrix(Puck puck, String datamatrix){
if ( ((puck.getId()==null) && (datamatrix!=null)) ||
(puck.getId()!=null) && (!puck.getId().equals(datamatrix))){
public void linkPuckDatamatrix(Puck puck, String datamatrix){
// if ( ((puck.getId()==null) && (datamatrix!=null)) ||
// (puck.getId()!=null) && (!puck.getId().equals(datamatrix))){
System.out.println("Setting to: " + puck.getName() + " datamatrix: " + datamatrix);
puck.setId(datamatrix);
getMainFrame().refresh();
}
try {
Context.getInstance().evalLineBackground("set_puck_datamatrix('" + puck.getName() + "','" + datamatrix + "')");
puck.setId(datamatrix);
SwingUtils.showMessage(getMainFrame(), "Puck loading",
"Puck " + datamatrix + "set to position " + puck.getName(),
5000);
} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
}
refreshSamplesTable();
getMainFrame().refresh();
// }
}
}