GripperNodeView.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package uraxis.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 GripperNodeView implements SwingProgramNodeView<GripperNodeContribution>{
  15. private final Style style;
  16. private JTextField jtfPosition, jtfSpeed;
  17. public GripperNodeView(Style style) {
  18. this.style = style;
  19. }
  20. @Override
  21. public void buildUI(JPanel jPanel, final ContributionProvider<GripperNodeContribution> provider) {
  22. jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
  23. jPanel.add(createVerticalSpacing(style.getVerticalSpacing()));
  24. jPanel.add(createInputPosition(provider));
  25. jPanel.add(createInputSpeed(provider));
  26. jPanel.add(createVerticalSpacing(style.getExtraLargeVerticalSpacing()));
  27. }
  28. private Box createInputPosition(final ContributionProvider<GripperNodeContribution> provider) {
  29. Box inputBox = Box.createHorizontalBox();
  30. inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
  31. inputBox.add(new JLabel("Move by:"));
  32. inputBox.add(createHorizontalSpacing());
  33. jtfPosition = new JTextField();
  34. jtfPosition.setFocusable(false);
  35. jtfPosition.setPreferredSize(style.getInputfieldSize());
  36. jtfPosition.setMaximumSize(jtfPosition.getPreferredSize());
  37. jtfPosition.addMouseListener(new MouseAdapter() {
  38. @Override
  39. public void mousePressed(MouseEvent e) {
  40. KeyboardNumberInput keyboardInput = provider.get().getKeyboardForPositionField();
  41. keyboardInput.show(jtfPosition, provider.get().getCallbackForPositionField());
  42. }
  43. });
  44. inputBox.add(jtfPosition);
  45. return inputBox;
  46. }
  47. private Box createInputSpeed(final ContributionProvider<GripperNodeContribution> provider) {
  48. Box inputBox = Box.createHorizontalBox();
  49. inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
  50. inputBox.add(new JLabel("Speed %:"));
  51. inputBox.add(createHorizontalSpacing());
  52. jtfSpeed = new JTextField();
  53. jtfSpeed.setFocusable(false);
  54. jtfSpeed.setPreferredSize(style.getInputfieldSize());
  55. jtfSpeed.setMaximumSize(jtfSpeed.getPreferredSize());
  56. jtfSpeed.addMouseListener(new MouseAdapter() {
  57. @Override
  58. public void mousePressed(MouseEvent e) {
  59. KeyboardNumberInput keyboardInput = provider.get().getKeyboardForSpeedField();
  60. keyboardInput.show(jtfSpeed, provider.get().getCallbackForSpeedField());
  61. }
  62. });
  63. inputBox.add(jtfSpeed);
  64. return inputBox;
  65. }
  66. private Component createVerticalSpacing(int height) {
  67. return Box.createRigidArea(new Dimension(0, height));
  68. }
  69. private Component createHorizontalSpacing() {
  70. return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
  71. }
  72. public void setPosition(Integer value) {
  73. jtfPosition.setText(value.toString());
  74. }
  75. public void setSpeed(Integer value) {
  76. jtfSpeed.setText(value.toString());
  77. }
  78. public Integer getPosition() {
  79. return Integer.parseInt(jtfPosition.getText());
  80. }
  81. public Integer getSpeed() {
  82. return Integer.parseInt(jtfSpeed.getText());
  83. }
  84. }