GripperGripNodeView.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.*;
  6. import java.awt.*;
  7. import java.awt.event.MouseAdapter;
  8. import java.awt.event.MouseEvent;
  9. public class GripperGripNodeView implements SwingProgramNodeView<GripperGripNodeContribution>{
  10. private final Style style;
  11. private JTextField jtfPosition, jtfSpeed;
  12. public GripperGripNodeView(Style style) {
  13. this.style = style;
  14. }
  15. @Override
  16. public void buildUI(JPanel jPanel, final ContributionProvider<GripperGripNodeContribution> provider) {
  17. jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
  18. jPanel.add(createVerticalSpacing(style.getVerticalSpacing()));
  19. jPanel.add(createInputSpeed(provider));
  20. jPanel.add(createVerticalSpacing(style.getExtraLargeVerticalSpacing()));
  21. }
  22. private Box createInputSpeed(final ContributionProvider<GripperGripNodeContribution> provider) {
  23. Box inputBox = Box.createHorizontalBox();
  24. inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
  25. inputBox.add(new JLabel("Speed %:"));
  26. inputBox.add(createHorizontalSpacing());
  27. jtfSpeed = new JTextField();
  28. jtfSpeed.setFocusable(false);
  29. jtfSpeed.setPreferredSize(style.getInputfieldSize());
  30. jtfSpeed.setMaximumSize(jtfSpeed.getPreferredSize());
  31. jtfSpeed.addMouseListener(new MouseAdapter() {
  32. @Override
  33. public void mousePressed(MouseEvent e) {
  34. KeyboardNumberInput keyboardInput = provider.get().getKeyboardForSpeedField();
  35. keyboardInput.show(jtfSpeed, provider.get().getCallbackForSpeedField());
  36. }
  37. });
  38. inputBox.add(jtfSpeed);
  39. return inputBox;
  40. }
  41. private Component createVerticalSpacing(int height) {
  42. return Box.createRigidArea(new Dimension(0, height));
  43. }
  44. private Component createHorizontalSpacing() {
  45. return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
  46. }
  47. public void setPosition(Integer value) {
  48. jtfPosition.setText(value.toString());
  49. }
  50. public void setSpeed(Integer value) {
  51. jtfSpeed.setText(value.toString());
  52. }
  53. public Integer getPosition() {
  54. return Integer.parseInt(jtfPosition.getText());
  55. }
  56. public Integer getSpeed() {
  57. return Integer.parseInt(jtfSpeed.getText());
  58. }
  59. }