package urgrip.programnodes; import com.ur.urcap.api.contribution.ContributionProvider; import com.ur.urcap.api.contribution.program.swing.SwingProgramNodeView; import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardNumberInput; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import java.awt.Component; import java.awt.Dimension; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class GripperBlowoutNodeView implements SwingProgramNodeView{ private final Style style; private JTextField jtfDelay; public GripperBlowoutNodeView(Style style) { this.style = style; } @Override public void buildUI(JPanel jPanel, final ContributionProvider provider) { jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); jPanel.add(createVerticalSpacing(style.getVerticalSpacing())); jPanel.add(createInputSpeed(provider)); jPanel.add(createVerticalSpacing(style.getExtraLargeVerticalSpacing())); } private Box createInputSpeed(final ContributionProvider provider) { Box inputBox = Box.createHorizontalBox(); inputBox.setAlignmentX(Component.LEFT_ALIGNMENT); inputBox.add(new JLabel("Delay (ms):")); inputBox.add(createHorizontalSpacing()); jtfDelay = new JTextField(); jtfDelay.setFocusable(false); jtfDelay.setPreferredSize(style.getInputfieldSize()); jtfDelay.setMaximumSize(jtfDelay.getPreferredSize()); jtfDelay.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { KeyboardNumberInput keyboardInput = provider.get().getKeyboardForSpeedField(); keyboardInput.show(jtfDelay, provider.get().getCallbackForSpeedField()); } }); inputBox.add(jtfDelay); return inputBox; } private Component createVerticalSpacing(int height) { return Box.createRigidArea(new Dimension(0, height)); } private Component createHorizontalSpacing() { return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0)); } public void setDelay(Integer value) { jtfDelay.setText(value.toString()); } public Integer getDelay() { return Integer.parseInt(jtfDelay.getText()); } }