Puck Loading Dialog
This commit is contained in:
@@ -13,6 +13,7 @@ import ch.psi.pshell.device.DeviceAdapter;
|
||||
import ch.psi.pshell.device.DeviceListener;
|
||||
import ch.psi.pshell.device.GenericDevice;
|
||||
import ch.psi.pshell.device.ReadbackDevice;
|
||||
import ch.psi.pshell.ui.App;
|
||||
import ch.psi.pshell.ui.Panel;
|
||||
import ch.psi.utils.Audio;
|
||||
import ch.psi.utils.State;
|
||||
@@ -54,6 +55,7 @@ public class Controller {
|
||||
Device puck_detection;
|
||||
JDialog dialogAskPuckDatamatrix;
|
||||
String currentMountedSample;
|
||||
PuckLoadingDialog dialogPuckLoading;
|
||||
|
||||
public static Controller getInstance() {
|
||||
return instance;
|
||||
@@ -62,7 +64,14 @@ public class Controller {
|
||||
static void createInstance(Panel mainFrame) {
|
||||
instance = new Controller(mainFrame);
|
||||
}
|
||||
|
||||
enum PuckMountMode{
|
||||
Direct,
|
||||
Dialog
|
||||
}
|
||||
|
||||
final PuckMountMode puckMountMode = App.hasArgument("direct") ? PuckMountMode.Direct : PuckMountMode.Dialog;
|
||||
|
||||
enum PuckSensorAccess {
|
||||
RaspberryPi,
|
||||
Esera;
|
||||
@@ -657,7 +666,7 @@ public class Controller {
|
||||
dialogAskPuckDatamatrix.setVisible(false);
|
||||
}
|
||||
puckLoading = value;
|
||||
getMainFrame().setPuckDatamatrix(null);
|
||||
onPuckScanned(null);
|
||||
Device reader = getPuckBarcodeReader();
|
||||
if (reader != null) {
|
||||
final String name = reader.getName();
|
||||
@@ -682,11 +691,12 @@ public class Controller {
|
||||
currentDetection = basePlate.getDetection();
|
||||
} else if (getState().isInitialized()) {
|
||||
getMainFrame().evalAsync(name + ".polling = 0; " + name + ".disable()", true).handle(errorHandler);
|
||||
getMainFrame().setPuckDatamatrix(null);
|
||||
onPuckScanned(null);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
errorHandler.apply(null, ex);
|
||||
}
|
||||
onPuckLoadingModeChange(puckLoading);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -705,22 +715,22 @@ public class Controller {
|
||||
Logger.getLogger(Controller.class.getName()).log(Level.FINE, null, ex);
|
||||
}
|
||||
}
|
||||
void onPuckBarcode(String datamatrix) {
|
||||
|
||||
public void onPuckBarcode(String datamatrix) {
|
||||
if (isPuckLoading()) {
|
||||
playSound("scanned");
|
||||
getMainFrame().setPuckDatamatrix(datamatrix);
|
||||
System.out.println("Detected Puck: " + datamatrix);
|
||||
onPuckScanned(datamatrix);
|
||||
}
|
||||
}
|
||||
|
||||
void onSampleBarcode(String datamatrix) {
|
||||
public void onSampleBarcode(String datamatrix) {
|
||||
getMainFrame().setSampleDatamatrix(datamatrix);
|
||||
System.out.println("Detected Sample: " + datamatrix);
|
||||
}
|
||||
|
||||
void onPuckDetectionChanged() {
|
||||
if (isPuckLoading()) {
|
||||
String datamatrix = getMainFrame().getPuckDatamatrix();
|
||||
Puck.Detection[] detection = basePlate.getDetection();
|
||||
for (int i = 0; i < Controller.NUMBER_OF_PUCKS; i++) {
|
||||
Puck puck = basePlate.getPucks()[i];
|
||||
@@ -729,16 +739,11 @@ public class Controller {
|
||||
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) {
|
||||
playSound("mounted");
|
||||
if (!datamatrix.isEmpty()) {
|
||||
getMainFrame().setPuckDatamatrix(null);
|
||||
linkPuckDatamatrix(puck, datamatrix);
|
||||
} else {
|
||||
askPuckDatamatrix(puck);
|
||||
}
|
||||
onPuckInserted(puck);
|
||||
|
||||
} else if (detectedPuckRemoved) {
|
||||
playSound("unmounted");
|
||||
linkPuckDatamatrix(puck, null);
|
||||
onPuckUnmounted(puck);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -746,8 +751,20 @@ public class Controller {
|
||||
currentDetection = detection;
|
||||
}
|
||||
}
|
||||
|
||||
public void onPuckInserted(Puck puck){
|
||||
playSound("mounted");
|
||||
String datamatrix = getMainFrame().getPuckDatamatrix();
|
||||
onPuckScanned(null);
|
||||
onPuckMounted(puck, datamatrix);
|
||||
}
|
||||
|
||||
public void onPuckRemoved(Puck puck){
|
||||
playSound("unmounted");
|
||||
onPuckUnmounted(puck);
|
||||
}
|
||||
|
||||
public void linkPuckDatamatrix(Puck puck, String datamatrix) {
|
||||
void linkPuckDatamatrix(Puck puck, String datamatrix, boolean showMessage) {
|
||||
// if ( ((puck.getId()==null) && (datamatrix!=null)) ||
|
||||
// (puck.getId()!=null) && (!puck.getId().equals(datamatrix))){
|
||||
String puckName = (puck == null) ? "" : puck.getName();
|
||||
@@ -756,8 +773,6 @@ public class Controller {
|
||||
}
|
||||
datamatrix = datamatrix.trim();
|
||||
|
||||
boolean showMessage = (puck != null) && !datamatrix.isEmpty();
|
||||
|
||||
System.out.println("Setting datamatrix '" + datamatrix + "' to puck: " + puckName);
|
||||
|
||||
try {
|
||||
@@ -768,7 +783,7 @@ public class Controller {
|
||||
basePlate.clearId(datamatrix);
|
||||
}
|
||||
|
||||
if (showMessage) {
|
||||
if (showMessage && (puck != null) && !datamatrix.isEmpty()) {
|
||||
SwingUtils.showMessage(getMainFrame(), "Puck loading",
|
||||
"Puck '" + datamatrix + "' set to position " + puckName,
|
||||
5000);
|
||||
@@ -790,7 +805,7 @@ public class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public void askPuckDatamatrix(Puck puck) {
|
||||
void askPuckDatamatrix(Puck puck) {
|
||||
if ((dialogAskPuckDatamatrix != null) && (dialogAskPuckDatamatrix.isShowing())) {
|
||||
dialogAskPuckDatamatrix.setVisible(false);
|
||||
}
|
||||
@@ -844,12 +859,77 @@ public class Controller {
|
||||
String dm = (row >= 0) ? String.valueOf(table.getValueAt(row, 0)) : null;
|
||||
dialogAskPuckDatamatrix.setVisible(false);
|
||||
if (dm != null) {
|
||||
linkPuckDatamatrix(puck, dm);
|
||||
linkPuckDatamatrix(puck, dm, true);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void showDialogPuckLoading (){
|
||||
if ((dialogPuckLoading!=null) && (dialogPuckLoading.isVisible())){
|
||||
return;
|
||||
}
|
||||
dialogPuckLoading = new PuckLoadingDialog(mainFrame.getTopLevel(), false);
|
||||
dialogPuckLoading.setLocationRelativeTo(mainFrame);
|
||||
dialogPuckLoading.setVisible(true);
|
||||
}
|
||||
|
||||
void hideDialogPuckLoading (){
|
||||
if (dialogPuckLoading!=null){
|
||||
dialogPuckLoading.setVisible(false);
|
||||
dialogPuckLoading.dispose();
|
||||
dialogPuckLoading = null;
|
||||
}
|
||||
}
|
||||
|
||||
void onPuckLoadingModeChange(boolean puckLoadMode) {
|
||||
if (puckMountMode == PuckMountMode.Dialog){
|
||||
if (puckLoadMode){
|
||||
showDialogPuckLoading();
|
||||
} else {
|
||||
hideDialogPuckLoading ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onPuckScanned(String datamatrix){
|
||||
if (isPuckLoading()) {
|
||||
getMainFrame().setPuckDatamatrix(datamatrix);
|
||||
if (puckMountMode == PuckMountMode.Dialog){
|
||||
showDialogPuckLoading();
|
||||
dialogPuckLoading.onPuckScanned(datamatrix);
|
||||
}
|
||||
} else{
|
||||
getMainFrame().setPuckDatamatrix(null);
|
||||
}
|
||||
}
|
||||
|
||||
void onPuckMounted(Puck puck, String datamatrix){
|
||||
if (isPuckLoading()) {
|
||||
if (puckMountMode == PuckMountMode.Dialog){
|
||||
showDialogPuckLoading();
|
||||
dialogPuckLoading.onPuckMounted(puck, datamatrix);
|
||||
} else {
|
||||
if (!datamatrix.isEmpty()) {
|
||||
linkPuckDatamatrix(puck, datamatrix, true);
|
||||
} else {
|
||||
askPuckDatamatrix(puck);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onPuckUnmounted(Puck puck){
|
||||
if (isPuckLoading()) {
|
||||
if (puckMountMode == PuckMountMode.Dialog){
|
||||
showDialogPuckLoading();
|
||||
dialogPuckLoading.onPuckUnmounted(puck);
|
||||
} else {
|
||||
linkPuckDatamatrix(puck, null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user