package ch.psi.mxsc; import ch.psi.pshell.core.DevicePoolListener; import ch.psi.pshell.device.Device; import ch.psi.pshell.device.DeviceAdapter; import ch.psi.pshell.device.GenericDevice; import ch.psi.pshell.swing.Led; import ch.psi.utils.State; import ch.psi.utils.swing.SwingUtils; import java.awt.Color; /** * */ public class DevicesPanel extends javax.swing.JPanel { GenericDevice robot; GenericDevice hexiposi; GenericDevice microscan; GenericDevice wago; GenericDevice laser; GenericDevice puck_detection; GenericDevice sm; GenericDevice img; GenericDevice gripper_cam; /** * Creates new form DevicesPanel */ public DevicesPanel() { initComponents(); } GenericDevice[] getDevices(){ return new GenericDevice[]{robot, hexiposi, microscan, wago, laser, puck_detection, sm}; } final DeviceAdapter deviceListener = new DeviceAdapter() { @Override public void onStateChanged(Device device, State state, State former) { update(); } }; void initialize(){ Controller.getInstance().getDevicePool().addListener(new DevicePoolListener() { @Override public void onDeviceAdded(GenericDevice dev) { updateDevices(); } @Override public void onDeviceRemoved(GenericDevice dev) { } }); updateDevices(); } void updateDevices(){ for (GenericDevice dev : getDevices()){ if (dev!=null){ dev.removeListener(deviceListener); } } robot = Controller.getInstance().getDevice("robot"); hexiposi = Controller.getInstance().getDevice("hexiposi"); microscan = Controller.getInstance().getDevice("microscan"); wago = Controller.getInstance().getDevice("wago"); laser = Controller.getInstance().getDevice("ue"); puck_detection = Controller.getInstance().getDevice("puck_detection"); img = Controller.getInstance().getDevice("img"); gripper_cam = Controller.getInstance().getDevice("gripper_cam"); sm = Controller.getInstance().getDevice("smart_magnet"); update(); for (GenericDevice dev : getDevices()){ if (dev!=null){ dev.addListener(deviceListener); } } } void update(){ setLedState(ledBarcodeReader, microscan); setLedState(ledCamera, img); setLedState(ledGripperImage, gripper_cam); setLedState(ledHexiposi, hexiposi); setLedState(ledLaser, laser); setLedState(ledPuckDetection, puck_detection); setLedState(ledRobot, robot); setLedState(ledWago, wago); setLedState(ledSmartMagnet, sm); } void setLedState(Led led, GenericDevice dev){ if ((dev==null) || (dev.getState()==null)){ led.setColor(Color.black); } else { switch (dev.getState()){ case Ready: led.setColor(Color.green); break; case Initializing: case Paused: case Busy: case Disabled: led.setColor(Color.orange); break; case Invalid: case Closing: case Fault: case Offline: led.setColor(Color.red); break; default: led.setColor(Color.darkGray); break; } } } void showDevicePanel(String device){ if (isActive()){ try{ Controller.getInstance().getMainFrame().showDevicePanel(device); } catch (Exception ex) { SwingUtils.showException(this, ex); } } } void showRenderer(String device){ if (isActive()){ try{ Controller.getInstance().getMainFrame().showRenderer(device); } catch (Exception ex) { SwingUtils.showException(this, ex); } } } boolean active = true; public void setActive(boolean value){ active = value; labelCamera.setActive(value); labelGripperImage.setActive(value); labelHexiposi.setActive(value); labelLaser.setActive(value); labelPuckDetection.setActive(value); labelReader.setActive(value); labelRobot.setActive(value); labelSmartMagnet.setActive(value); labelWago.setActive(value); } public boolean isActive(){ return active; } /** * 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") // //GEN-BEGIN:initComponents private void initComponents() { labelRobot = new ch.psi.mxsc.HyperlinkLabel(); ledRobot = new ch.psi.pshell.swing.Led(); ledWago = new ch.psi.pshell.swing.Led(); labelWago = new ch.psi.mxsc.HyperlinkLabel(); labelLaser = new ch.psi.mxsc.HyperlinkLabel(); ledLaser = new ch.psi.pshell.swing.Led(); labelCamera = new ch.psi.mxsc.HyperlinkLabel(); ledCamera = new ch.psi.pshell.swing.Led(); labelHexiposi = new ch.psi.mxsc.HyperlinkLabel(); ledHexiposi = new ch.psi.pshell.swing.Led(); labelReader = new ch.psi.mxsc.HyperlinkLabel(); ledBarcodeReader = new ch.psi.pshell.swing.Led(); labelPuckDetection = new ch.psi.mxsc.HyperlinkLabel(); ledPuckDetection = new ch.psi.pshell.swing.Led(); ledSmartMagnet = new ch.psi.pshell.swing.Led(); labelSmartMagnet = new ch.psi.mxsc.HyperlinkLabel(); ledGripperImage = new ch.psi.pshell.swing.Led(); labelGripperImage = new ch.psi.mxsc.HyperlinkLabel(); labelRobot.setText("Robot"); labelRobot.setActive(true); labelRobot.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ledRobotMouseClicked(evt); } }); ledRobot.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ledRobotMouseClicked(evt); } }); ledWago.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelWagoMouseClicked(evt); } }); labelWago.setText("Wago"); labelWago.setActive(true); labelWago.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelWagoMouseClicked(evt); } }); labelLaser.setText("Laser"); labelLaser.setActive(true); labelLaser.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ledLaserMouseClicked(evt); } }); ledLaser.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ledLaserMouseClicked(evt); } }); labelCamera.setText("Camera"); labelCamera.setActive(true); labelCamera.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ledCameraMouseClicked(evt); } }); ledCamera.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ledCameraMouseClicked(evt); } }); labelHexiposi.setText("Hexiposi"); labelHexiposi.setActive(true); labelHexiposi.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelHexiposiMouseClicked(evt); } }); ledHexiposi.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelHexiposiMouseClicked(evt); } }); labelReader.setText("Barcode Reader"); labelReader.setActive(true); labelReader.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelReaderMouseClicked(evt); } }); ledBarcodeReader.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelReaderMouseClicked(evt); } }); labelPuckDetection.setText("Puck Detection"); labelPuckDetection.setActive(true); labelPuckDetection.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ledPuckDetectionMouseClicked(evt); } }); ledPuckDetection.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ledPuckDetectionMouseClicked(evt); } }); ledSmartMagnet.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelSmartMagnetMouseClicked(evt); } }); labelSmartMagnet.setText("Smart Magnet"); labelSmartMagnet.setActive(true); labelSmartMagnet.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelSmartMagnetMouseClicked(evt); } }); ledGripperImage.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelGripperImageMouseClicked(evt); } }); labelGripperImage.setText("Gripper Image"); labelGripperImage.setActive(true); labelGripperImage.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { labelGripperImageMouseClicked(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.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() .addComponent(ledRobot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelRobot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(ledWago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelWago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(ledLaser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelLaser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(ledCamera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelCamera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(ledHexiposi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelHexiposi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(ledBarcodeReader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelReader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(ledPuckDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelPuckDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(ledSmartMagnet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelSmartMagnet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(ledGripperImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(labelGripperImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledRobot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelRobot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledWago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelWago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledLaser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelLaser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledCamera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelCamera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledHexiposi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelHexiposi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledBarcodeReader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelReader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledPuckDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelPuckDetection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledSmartMagnet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelSmartMagnet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ledGripperImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(labelGripperImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// //GEN-END:initComponents private void labelHexiposiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelHexiposiMouseClicked showDevicePanel("hexiposi"); }//GEN-LAST:event_labelHexiposiMouseClicked private void ledRobotMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ledRobotMouseClicked showDevicePanel("robot"); }//GEN-LAST:event_ledRobotMouseClicked private void labelSmartMagnetMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelSmartMagnetMouseClicked showDevicePanel("smart_magnet"); }//GEN-LAST:event_labelSmartMagnetMouseClicked private void ledCameraMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ledCameraMouseClicked showDevicePanel("img camera"); }//GEN-LAST:event_ledCameraMouseClicked private void ledLaserMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ledLaserMouseClicked showDevicePanel("ue"); }//GEN-LAST:event_ledLaserMouseClicked private void labelWagoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelWagoMouseClicked showDevicePanel("wago"); }//GEN-LAST:event_labelWagoMouseClicked private void labelReaderMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelReaderMouseClicked showDevicePanel("barcode_reader"); }//GEN-LAST:event_labelReaderMouseClicked private void ledPuckDetectionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ledPuckDetectionMouseClicked showDevicePanel("puck_detection"); }//GEN-LAST:event_ledPuckDetectionMouseClicked private void labelGripperImageMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelGripperImageMouseClicked showRenderer("gripper_cam"); }//GEN-LAST:event_labelGripperImageMouseClicked // Variables declaration - do not modify//GEN-BEGIN:variables private ch.psi.mxsc.HyperlinkLabel labelCamera; private ch.psi.mxsc.HyperlinkLabel labelGripperImage; private ch.psi.mxsc.HyperlinkLabel labelHexiposi; private ch.psi.mxsc.HyperlinkLabel labelLaser; private ch.psi.mxsc.HyperlinkLabel labelPuckDetection; private ch.psi.mxsc.HyperlinkLabel labelReader; private ch.psi.mxsc.HyperlinkLabel labelRobot; private ch.psi.mxsc.HyperlinkLabel labelSmartMagnet; private ch.psi.mxsc.HyperlinkLabel labelWago; private ch.psi.pshell.swing.Led ledBarcodeReader; private ch.psi.pshell.swing.Led ledCamera; private ch.psi.pshell.swing.Led ledGripperImage; private ch.psi.pshell.swing.Led ledHexiposi; private ch.psi.pshell.swing.Led ledLaser; private ch.psi.pshell.swing.Led ledPuckDetection; private ch.psi.pshell.swing.Led ledRobot; private ch.psi.pshell.swing.Led ledSmartMagnet; private ch.psi.pshell.swing.Led ledWago; // End of variables declaration//GEN-END:variables }