Puck Loading Dialog

This commit is contained in:
2019-03-14 08:21:27 +01:00
parent d558687827
commit 075e76fc4e
6 changed files with 736 additions and 37 deletions

View File

@@ -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);
}
}
}
}

View File

@@ -13,6 +13,7 @@ import ch.psi.pshell.imaging.Source;
import ch.psi.pshell.scripting.ViewPreference;
import ch.psi.pshell.ui.App;
import ch.psi.pshell.ui.Panel;
import ch.psi.pshell.ui.StatusBar;
import ch.psi.utils.Chrono;
import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
@@ -24,12 +25,10 @@ import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Window;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
@@ -51,6 +50,7 @@ public class MainPanel extends Panel {
Boolean manualMode;
Boolean roomTemperature;
public final String PUCK_LOADING_STATUS = "Puck loading";
StatusBar statusBar;
public enum BasePlateLayout {
normal,
@@ -128,7 +128,7 @@ public class MainPanel extends Panel {
showException(ex);
}
}
});
});
}
@Override
@@ -139,6 +139,11 @@ public class MainPanel extends Panel {
}
basePlatePanel.setSelectionMode(SelectionMode.Pucks);
basePlatePanel.setDevice(Controller.getInstance().basePlate);
try{
statusBar = (StatusBar) SwingUtils.getComponentsByType(getTopLevel(), StatusBar.class)[0];
} catch (Exception ex){
}
}
@Override
@@ -228,7 +233,7 @@ public class MainPanel extends Panel {
public void onStateChange(State state, State former) {
Controller.getInstance().onStateChange(state, former);
}
@Override
protected void onTimer() {
try {
@@ -273,17 +278,23 @@ public class MainPanel extends Panel {
String status;
void setStatus(String status) {
if (!status.equals(this.status)) {
String current = current = (statusBar==null) ? this.status : statusBar.getStatusLabel().getText();
if (!status.equals(current)) {
getContext().setPreference(ViewPreference.STATUS, status);
this.status = status;
}
this.status = status;
}
volatile boolean refreshing;
void refresh() {
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(() -> {
refresh();
});
if (!refreshing){
refreshing = true;
SwingUtilities.invokeLater(() -> {
refreshing = false;
refresh();
});
}
return;
}
repaint();

View File

@@ -90,16 +90,21 @@ public class PuckDetection extends DeviceBase {
setState(State.Ready);
if (isSimulated()) {
while (!Thread.currentThread().isInterrupted()) {
boolean changed = false;
for (int address = 1; address <= Controller.NUMBER_OF_PUCKS; address++) {
Integer indDetector = ((address <= 6) || (address==30)) ? 1 : 0;
Integer mecDetector = ((address <= 6) || (address==29)) ? 1 : 0;
int index = Controller.getInstance().getPuckIndex(address);
PuckState puck = Controller.getInstance().getPuckState(index);
puck.set(mecDetector, indDetector);
if (puck.set(mecDetector, indDetector)){
changed = true;
}
}
if (changed){
if (Controller.getInstance() != null) {
Controller.getInstance().updateView();
}
}
if (Controller.getInstance() != null) {
Controller.getInstance().updateView();
}
chrono = new Chrono();
Thread.sleep(2000);
}

View File

@@ -0,0 +1,191 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.6" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="buttonSet" min="-2" pref="201" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Component id="labelSuggestion" max="32767" attributes="0"/>
<Component id="jScrollPane1" pref="484" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" linkSize="1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="textScannedDatamatrix" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="jLabel2" linkSize="1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="textDetectedPuck" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Component id="labelStatus" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="labelSuggestion" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="textScannedDatamatrix" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="textDetectedPuck" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="249" max="32767" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Component id="buttonSet" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="labelStatus" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="18" style="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="11"/>
<Property name="text" type="java.lang.String" value="Scanned Dartamatrix:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="textScannedDatamatrix">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="24" style="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="table">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="28" style="0"/>
</Property>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="2" rowCount="0">
<Column editable="false" title="Datamatrix" type="java.lang.String"/>
<Column editable="false" title="Puck Position" type="java.lang.String"/>
</Table>
</Property>
<Property name="rowHeight" type="int" value="40"/>
<Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor">
<JTableSelectionModel selectionMode="0"/>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="false" resizingAllowed="false"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="buttonSet">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="24" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="Set"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonSetActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="labelSuggestion">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="24" style="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="Scan, Insert or Remove Pucks"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelStatus">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="24" style="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="Waiting for Puck Detection"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder/>
</Border>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="18" style="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="11"/>
<Property name="text" type="java.lang.String" value="Detected Puck:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="textDetectedPuck">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Lucida Grande" size="24" style="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
</Component>
</SubComponents>
</Form>

View File

@@ -0,0 +1,407 @@
package ch.psi.mxsc;
import ch.psi.pshell.core.Context;
import ch.psi.pshell.swing.DataPanel;
import ch.psi.utils.swing.MainFrame;
import ch.psi.utils.swing.SwingUtils;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;
/**
*
*/
public class PuckLoadingDialog extends JDialog {
Path dialogPersistPath;
DefaultTableModel model;
/**
* Creates new form PuckLoadingDialog
*/
public PuckLoadingDialog(java.awt.Frame parent, boolean modal) {
super(parent, "Puck Loading", modal);
initComponents();
this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
this.setName("PuckLoadingDialog");
dialogPersistPath = Paths.get(Context.getInstance().getSetup().getContextPath(), getClass().getSimpleName());
setStatusLabel(null,-1);
setSugestionLabel(null,-1);
model = (DefaultTableModel) table.getModel();
table.getTableHeader().setFont(table.getTableHeader().getFont().deriveFont(20.0f));
}
@Override
public void setVisible(boolean value){
boolean visible = isVisible();
if (visible && !value){
try {
MainFrame.save(PuckLoadingDialog.this, dialogPersistPath);
} catch (Exception ex) {
Logger.getLogger(DataPanel.class.getName()).log(Level.WARNING, null, ex);
}
}
super.setVisible(value);
if (!visible && value){
try {
MainFrame.restore(PuckLoadingDialog.this, dialogPersistPath);
} catch (Exception ex) {
Logger.getLogger(DataPanel.class.getName()).log(Level.WARNING, null, ex);
}
update();
}
}
void update() {
Map dms = Controller.getInstance().getPuckDatamatrix();
if (dms == null) {
dms = new HashMap();
}
Object[] keys = dms.keySet().toArray();
Arrays.sort(keys);
if (keys.length != model.getRowCount()){
model.setRowCount(keys.length);
}
for (int i=0; i< keys.length; i++) {
model.setValueAt(keys[i], i, 0);
model.setValueAt(dms.get(keys[i]), i, 1);
}
}
void onPuckScanned(String datamatrix){
textScannedDatamatrix.setText((datamatrix == null) ? "" : datamatrix.trim());
if ((datamatrix != null) && (!datamatrix.isEmpty())){
setStatusLabel("Scanned puck " + datamatrix, 5000);
makeVisible(datamatrix);
} else {
setStatusLabel(null, -1);
}
setSugestionLabel(null, -1);
buttonSet.setEnabled(false);
detectedPuck = null;
textDetectedPuck.setText("");
}
Puck detectedPuck;
String detectedDatamatrix;
void onPuckMounted(Puck puck, String datamatrix){
if ((datamatrix != null) && (!datamatrix.isEmpty())) {
Controller.getInstance().linkPuckDatamatrix(puck, datamatrix, false);
setStatusLabel("Mounted puck " + datamatrix + " at " + puck.getName(), 5000);
setSugestionLabel(null, -1);
buttonSet.setEnabled(false);
textDetectedPuck.setText("");
detectedPuck = null;
} else {
setStatusLabel("Detected puck at " + puck.getName(), -1);
setSugestionLabel("Select the datamatrix and press 'Set'", -1);
detectedPuck = puck;
textDetectedPuck.setText(puck.getName());
buttonSet.setEnabled(true);
table.clearSelection();
}
update();
}
Timer timerClear;
void onPuckUnmounted(Puck puck){
if (puck == detectedPuck){
}
Controller.getInstance().linkPuckDatamatrix(puck, null, false);
setStatusLabel("Unmounted puck from "+ puck.getName(), 5000);
if (puck == detectedPuck){
buttonSet.setEnabled(false);
detectedPuck = null;
}
makeVisible(puck);
update();
}
void onManualSetPuckLocation(String datamatrix){
if (detectedPuck!=null){
Controller.getInstance().linkPuckDatamatrix(detectedPuck, datamatrix, false);
setStatusLabel("Set puck " + datamatrix + " at " + detectedPuck.getName(), 5000);
setSugestionLabel(null, -1);
buttonSet.setEnabled(false);
detectedPuck = null;
textDetectedPuck.setText("");
}
update();
}
Timer timerLabelStatus;
void setStatusLabel(String message, int delay){
final String defaultStatus = " "; //Waiting for Puck Detection";
if (timerLabelStatus!=null){
timerLabelStatus.stop();
timerLabelStatus = null;
}
labelStatus.setText(message==null ? defaultStatus : message);
if (delay>0){
timerLabelStatus = new Timer(delay, (e)->{
labelStatus.setText(defaultStatus);
});
timerLabelStatus.start();
}
}
Timer timerLabelSuggestion;
void setSugestionLabel(String message, int delay){
final String defaultSuggestion = "Scan, Insert or Remove Pucks"; //Waiting for Puck Detection";
if (timerLabelSuggestion!=null){
timerLabelSuggestion.stop();
timerLabelSuggestion = null;
}
labelSuggestion.setText(message==null ? defaultSuggestion : message);
if (delay>0){
timerLabelSuggestion = new Timer(delay, (e)->{
labelSuggestion.setText(defaultSuggestion);
});
timerLabelSuggestion.start();
}
}
void makeVisible(String datamatrix){
if (datamatrix!=null){
datamatrix = datamatrix.trim();
for (int i=0; i<model.getRowCount(); i++){
if (datamatrix.equals(model.getValueAt(i, 0))){
SwingUtils.scrollToVisible(table, i, 0);
table.setRowSelectionInterval(i, i);
break;
}
}
}
}
void makeVisible(Puck puck){
if (puck!=null){
for (int i=0; i<model.getRowCount(); i++){
if (puck.getName().equals(model.getValueAt(i, 1))){
SwingUtils.scrollToVisible(table, i, 0);
table.setRowSelectionInterval(i, i);
break;
}
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
textScannedDatamatrix = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
table = new javax.swing.JTable();
buttonSet = new javax.swing.JButton();
labelSuggestion = new javax.swing.JLabel();
labelStatus = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
textDetectedPuck = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel1.setText("Scanned Dartamatrix:");
textScannedDatamatrix.setEditable(false);
textScannedDatamatrix.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
textScannedDatamatrix.setHorizontalAlignment(javax.swing.JTextField.CENTER);
table.setFont(new java.awt.Font("Lucida Grande", 0, 28)); // NOI18N
table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Datamatrix", "Puck Position"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
table.setRowHeight(40);
table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
table.getTableHeader().setResizingAllowed(false);
table.getTableHeader().setReorderingAllowed(false);
jScrollPane1.setViewportView(table);
buttonSet.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
buttonSet.setText("Set");
buttonSet.setEnabled(false);
buttonSet.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSetActionPerformed(evt);
}
});
labelSuggestion.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
labelSuggestion.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
labelSuggestion.setText("Scan, Insert or Remove Pucks");
labelStatus.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
labelStatus.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
labelStatus.setText("Waiting for Puck Detection");
labelStatus.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel2.setText("Detected Puck:");
textDetectedPuck.setEditable(false);
textDetectedPuck.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
textDetectedPuck.setHorizontalAlignment(javax.swing.JTextField.CENTER);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(buttonSet, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(labelSuggestion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(textScannedDatamatrix))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(textDetectedPuck)))
.addContainerGap())
.addComponent(labelStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(labelSuggestion)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(textScannedDatamatrix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(textDetectedPuck, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(buttonSet)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(labelStatus))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void buttonSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSetActionPerformed
try {
int row = table.getSelectedRow();
String datamatrix = (row >= 0) ? String.valueOf(table.getValueAt(row, 0)) : null;
if (datamatrix != null) {
onManualSetPuckLocation(datamatrix);
}
} catch (Exception ex) {
SwingUtils.showException(this, ex);
}
}//GEN-LAST:event_buttonSetActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(PuckLoadingDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PuckLoadingDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PuckLoadingDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PuckLoadingDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
PuckLoadingDialog dialog = new PuckLoadingDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
javax.swing.JButton buttonSet;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel labelStatus;
private javax.swing.JLabel labelSuggestion;
javax.swing.JTable table;
javax.swing.JTextField textDetectedPuck;
javax.swing.JTextField textScannedDatamatrix;
// End of variables declaration//GEN-END:variables
}

View File

@@ -47,11 +47,15 @@ public class PuckState {
}
}
void set(int mecSwitch, int indSwitch) {
boolean set(int mecSwitch, int indSwitch) {
online = true;
//TODO: Handle -1 value: error
this.mecSwitch = SwitchState.fromInt(mecSwitch);
this.indSwitch = SwitchState.fromInt(indSwitch);
SwitchState mec = SwitchState.fromInt(mecSwitch);
SwitchState ind = SwitchState.fromInt(indSwitch);
boolean changed = (mec != this.mecSwitch) || (mec != this.mecSwitch);
this.mecSwitch = mec;
this.indSwitch = ind;
BasePlate basePlate = getBasePlate();
if (basePlate != null) {
Puck puck = basePlate.getPucks()[id - 1];
@@ -83,6 +87,7 @@ public class PuckState {
break;
}
}
return changed;
}
@Override