GripperBlowoutNodeView.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package urgrip.programnodes;
  2. import com.ur.urcap.api.contribution.ContributionProvider;
  3. import com.ur.urcap.api.contribution.program.swing.SwingProgramNodeView;
  4. import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardNumberInput;
  5. import javax.swing.Box;
  6. import javax.swing.BoxLayout;
  7. import javax.swing.JLabel;
  8. import javax.swing.JPanel;
  9. import javax.swing.JTextField;
  10. import java.awt.Component;
  11. import java.awt.Dimension;
  12. import java.awt.event.MouseAdapter;
  13. import java.awt.event.MouseEvent;
  14. public class GripperBlowoutNodeView implements SwingProgramNodeView<GripperBlowoutNodeContribution>{
  15. private final Style style;
  16. private JTextField jtfDelay;
  17. public GripperBlowoutNodeView(Style style) {
  18. this.style = style;
  19. }
  20. @Override
  21. public void buildUI(JPanel jPanel, final ContributionProvider<GripperBlowoutNodeContribution> provider) {
  22. jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
  23. jPanel.add(createVerticalSpacing(style.getVerticalSpacing()));
  24. jPanel.add(createInputSpeed(provider));
  25. jPanel.add(createVerticalSpacing(style.getExtraLargeVerticalSpacing()));
  26. }
  27. private Box createInputSpeed(final ContributionProvider<GripperBlowoutNodeContribution> provider) {
  28. Box inputBox = Box.createHorizontalBox();
  29. inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
  30. inputBox.add(new JLabel("Delay (ms):"));
  31. inputBox.add(createHorizontalSpacing());
  32. jtfDelay = new JTextField();
  33. jtfDelay.setFocusable(false);
  34. jtfDelay.setPreferredSize(style.getInputfieldSize());
  35. jtfDelay.setMaximumSize(jtfDelay.getPreferredSize());
  36. jtfDelay.addMouseListener(new MouseAdapter() {
  37. @Override
  38. public void mousePressed(MouseEvent e) {
  39. KeyboardNumberInput keyboardInput = provider.get().getKeyboardForSpeedField();
  40. keyboardInput.show(jtfDelay, provider.get().getCallbackForSpeedField());
  41. }
  42. });
  43. inputBox.add(jtfDelay);
  44. return inputBox;
  45. }
  46. private Component createVerticalSpacing(int height) {
  47. return Box.createRigidArea(new Dimension(0, height));
  48. }
  49. private Component createHorizontalSpacing() {
  50. return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
  51. }
  52. public void setDelay(Integer value) {
  53. jtfDelay.setText(value.toString());
  54. }
  55. public Integer getDelay() {
  56. return Integer.parseInt(jtfDelay.getText());
  57. }
  58. }