PickOrPlaceProgramNodeView.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package com.ur.urcap.examples.pickorplaceswing.pickorplace;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import javax.swing.Box;
  6. import javax.swing.BoxLayout;
  7. import javax.swing.JButton;
  8. import javax.swing.JPanel;
  9. import com.ur.urcap.api.contribution.ContributionProvider;
  10. import com.ur.urcap.api.contribution.program.swing.SwingProgramNodeView;
  11. public class PickOrPlaceProgramNodeView implements SwingProgramNodeView<PickOrPlaceProgramNodeContribution> {
  12. private final Style style;
  13. private JButton placeButton;
  14. private JButton pickButton;
  15. private JButton resetButton;
  16. public PickOrPlaceProgramNodeView(Style style) {
  17. this.style = style;
  18. }
  19. @Override
  20. public void buildUI(final JPanel panel, final ContributionProvider<PickOrPlaceProgramNodeContribution> provider) {
  21. panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
  22. panel.add(createMakeSection(provider));
  23. panel.add(createResetSection(provider));
  24. }
  25. private Component createMakeSection(final ContributionProvider<PickOrPlaceProgramNodeContribution> provider) {
  26. Box section = style.createSection(BoxLayout.PAGE_AXIS);
  27. Box infoSection = style.createSection(BoxLayout.PAGE_AXIS);
  28. infoSection.add(style.createInfo("Choose Pick or Place:"));
  29. infoSection.add(style.createVerticalSpacing());
  30. section.add(infoSection);
  31. Box buttonSection = style.createSection(BoxLayout.LINE_AXIS);
  32. buttonSection.add(style.createHorizontalIndent());
  33. this.pickButton = style.createButton("Pick");
  34. this.pickButton.addActionListener(new ActionListener() {
  35. @Override
  36. public void actionPerformed(ActionEvent e) {
  37. provider.get().createPick();
  38. }
  39. });
  40. buttonSection.add(pickButton, FlowLayout.LEFT);
  41. buttonSection.add(style.createHorizontalSpacing());
  42. this.placeButton = style.createButton("Place");
  43. this.placeButton.addActionListener(new ActionListener() {
  44. @Override
  45. public void actionPerformed(ActionEvent e) {
  46. provider.get().createPlace();
  47. }
  48. });
  49. buttonSection.add(placeButton);
  50. section.add(buttonSection);
  51. return section;
  52. }
  53. private Component createResetSection(final ContributionProvider<PickOrPlaceProgramNodeContribution> provider) {
  54. Box section = style.createSection(BoxLayout.PAGE_AXIS);
  55. section.add(style.createVerticalSpacing());
  56. Box infoSection = style.createSection(BoxLayout.PAGE_AXIS);
  57. infoSection.add(style.createVerticalSpacing());
  58. infoSection.add(style.createInfo("Tap the button to reset your selection."));
  59. infoSection.add(style.createVerticalSpacing());
  60. infoSection.add(style.createInfo("This removes the program tree and clears all configuration data."));
  61. infoSection.add(style.createVerticalSpacing());
  62. section.add(infoSection);
  63. Box buttonSection = style.createSection(BoxLayout.LINE_AXIS);
  64. buttonSection.add(style.createHorizontalIndent());
  65. this.resetButton = style.createButton("Reset");
  66. this.resetButton.addActionListener(new ActionListener() {
  67. @Override
  68. public void actionPerformed(ActionEvent e) {
  69. provider.get().reset();
  70. }
  71. });
  72. buttonSection.add(this.resetButton, FlowLayout.LEFT);
  73. section.add(buttonSection);
  74. return section;
  75. }
  76. void update(PickOrPlaceProgramNodeContribution contribution) {
  77. TemplateType templateType = contribution.getTemplateType();
  78. if (templateType == TemplateType.EMPTY) {
  79. pickButton.setEnabled(true);
  80. placeButton.setEnabled(true);
  81. resetButton.setEnabled(false);
  82. } else {
  83. pickButton.setEnabled(false);
  84. placeButton.setEnabled(false);
  85. resetButton.setEnabled(true);
  86. }
  87. }
  88. }