123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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.*;
- import java.awt.*;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class GripperGripNodeView implements SwingProgramNodeView<GripperGripNodeContribution>{
- private final Style style;
- private JTextField jtfPosition, jtfSpeed;
- public GripperGripNodeView(Style style) {
- this.style = style;
- }
- @Override
- public void buildUI(JPanel jPanel, final ContributionProvider<GripperGripNodeContribution> 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<GripperGripNodeContribution> 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());
- }
- }
|