package uraxis.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 GripperNodeView implements SwingProgramNodeView{ private final Style style; private JTextField jtfPosition, jtfSpeed; public GripperNodeView(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(createInputPosition(provider)); jPanel.add(createInputSpeed(provider)); jPanel.add(createVerticalSpacing(style.getExtraLargeVerticalSpacing())); } private Box createInputPosition(final ContributionProvider provider) { Box inputBox = Box.createHorizontalBox(); inputBox.setAlignmentX(Component.LEFT_ALIGNMENT); inputBox.add(new JLabel("Move by:")); inputBox.add(createHorizontalSpacing()); jtfPosition = new JTextField(); jtfPosition.setFocusable(false); jtfPosition.setPreferredSize(style.getInputfieldSize()); jtfPosition.setMaximumSize(jtfPosition.getPreferredSize()); jtfPosition.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { KeyboardNumberInput keyboardInput = provider.get().getKeyboardForPositionField(); keyboardInput.show(jtfPosition, provider.get().getCallbackForPositionField()); } }); inputBox.add(jtfPosition); return inputBox; } private Box createInputSpeed(final ContributionProvider provider) { Box inputBox = Box.createHorizontalBox(); inputBox.setAlignmentX(Component.LEFT_ALIGNMENT); inputBox.add(new JLabel("Speed %:")); inputBox.add(createHorizontalSpacing()); jtfSpeed = new JTextField(); jtfSpeed.setFocusable(false); jtfSpeed.setPreferredSize(style.getInputfieldSize()); jtfSpeed.setMaximumSize(jtfSpeed.getPreferredSize()); jtfSpeed.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { KeyboardNumberInput keyboardInput = provider.get().getKeyboardForSpeedField(); keyboardInput.show(jtfSpeed, provider.get().getCallbackForSpeedField()); } }); inputBox.add(jtfSpeed); 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 setPosition(Integer value) { jtfPosition.setText(value.toString()); } public void setSpeed(Integer value) { jtfSpeed.setText(value.toString()); } public Integer getPosition() { return Integer.parseInt(jtfPosition.getText()); } public Integer getSpeed() { return Integer.parseInt(jtfSpeed.getText()); } }