Created application main panel and separated Controller class
This commit is contained in:
@@ -4,105 +4,25 @@
|
||||
|
||||
package ch.psi.mxsc;
|
||||
|
||||
import ch.psi.pshell.core.DevicePoolListener;
|
||||
import ch.psi.pshell.device.Device;
|
||||
import ch.psi.pshell.device.GenericDevice;
|
||||
import ch.psi.pshell.ui.Panel;
|
||||
import ch.psi.utils.swing.SwingUtils;
|
||||
import java.awt.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class MainPanel extends Panel {
|
||||
BasePlate basePlate;
|
||||
/** Creates new form Panel */
|
||||
static MainPanel instance;
|
||||
/** Creates new form Panel */
|
||||
|
||||
enum PuckSensorAccess{
|
||||
RaspberryPi,
|
||||
Esera;
|
||||
}
|
||||
|
||||
final PuckSensorAccess puckSensorAccess = PuckSensorAccess.RaspberryPi;
|
||||
|
||||
static String PUCK_ESERA_DEVICE = "onewire";
|
||||
|
||||
public static final int NUMBER_OF_PUCKS = 30;
|
||||
|
||||
final PuckState[] puckState;
|
||||
public PuckState[] getPuckStates(){
|
||||
return puckState;
|
||||
}
|
||||
EseraDetection detection;
|
||||
|
||||
//From 1 to PUCKS_NUMBER
|
||||
public PuckState getPuckState(int id) throws Exception{
|
||||
if ((id<=0) || (id>NUMBER_OF_PUCKS)){
|
||||
throw new Exception("invalid puck id: "+ id);
|
||||
}
|
||||
return getPuckStates()[id-1];
|
||||
}
|
||||
|
||||
public void clearPuckStates(){
|
||||
for (PuckState puck:getPuckStates()){
|
||||
puck.clear();
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
public static MainPanel getInstance(){
|
||||
return instance;
|
||||
}
|
||||
public MainPanel() {
|
||||
initComponents();
|
||||
instance = this;
|
||||
basePlate = new BasePlate();
|
||||
SwingUtils.setEnumCombo(comboMode, BasePlatePanel.Mode.class);
|
||||
comboMode.setSelectedItem(basePlatePanel.getMode());
|
||||
this.setPersistedComponents(new Component[]{comboMode});
|
||||
puckState = new PuckState[NUMBER_OF_PUCKS];
|
||||
for (int i=0; i<NUMBER_OF_PUCKS; i++ ){
|
||||
puckState[i] = new PuckState(i+1);
|
||||
}
|
||||
Controller.createInstance(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onInitialize(int runCount) {
|
||||
basePlatePanel.setDevice(basePlate);
|
||||
GenericDevice former = getDevice("BasePlate");
|
||||
if (former!=null){
|
||||
removeDevice(former);
|
||||
}
|
||||
addDevice(basePlate);
|
||||
clearPuckStates();
|
||||
|
||||
if (puckSensorAccess == PuckSensorAccess.Esera){
|
||||
getContext().getDevicePool().addListener(new DevicePoolListener() {
|
||||
@Override
|
||||
public void onDeviceAdded(GenericDevice dev) {
|
||||
if (dev.getName().equals(PUCK_ESERA_DEVICE)){
|
||||
detection = new EseraDetection((Device) dev);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onDeviceRemoved(GenericDevice dev) {
|
||||
if (dev.getName().equals(PUCK_ESERA_DEVICE)){
|
||||
detection.close();
|
||||
detection = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (detection != null){
|
||||
detection.close();
|
||||
detection = null;
|
||||
}
|
||||
if ((Device) getDevice(PUCK_ESERA_DEVICE) != null){
|
||||
detection = new EseraDetection((Device) getDevice(PUCK_ESERA_DEVICE));
|
||||
}
|
||||
}
|
||||
Controller.getInstance().onInitialize(runCount);
|
||||
basePlatePanel.setDevice((Device) getDevice("BasePlate"));
|
||||
}
|
||||
|
||||
|
||||
@@ -116,28 +36,16 @@ public class MainPanel extends Panel {
|
||||
private void initComponents() {
|
||||
|
||||
basePlatePanel = new ch.psi.mxsc.BasePlatePanel();
|
||||
comboMode = new javax.swing.JComboBox<>();
|
||||
|
||||
comboMode.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
|
||||
comboMode.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
comboModeActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout basePlatePanelLayout = new javax.swing.GroupLayout(basePlatePanel);
|
||||
basePlatePanel.setLayout(basePlatePanelLayout);
|
||||
basePlatePanelLayout.setHorizontalGroup(
|
||||
basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, basePlatePanelLayout.createSequentialGroup()
|
||||
.addGap(0, 386, Short.MAX_VALUE)
|
||||
.addComponent(comboMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(0, 442, Short.MAX_VALUE)
|
||||
);
|
||||
basePlatePanelLayout.setVerticalGroup(
|
||||
basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(basePlatePanelLayout.createSequentialGroup()
|
||||
.addComponent(comboMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 280, Short.MAX_VALUE))
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
@@ -152,14 +60,9 @@ public class MainPanel extends Panel {
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void comboModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboModeActionPerformed
|
||||
basePlatePanel.setMode((BasePlatePanel.Mode) comboMode.getSelectedItem());
|
||||
}//GEN-LAST:event_comboModeActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private ch.psi.mxsc.BasePlatePanel basePlatePanel;
|
||||
private javax.swing.JComboBox<String> comboMode;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user