HelloWorldInstallationNodeView.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package urgrip.installation;
  2. import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeView;
  3. import com.ur.urcap.api.domain.io.IO;
  4. import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardTextInput;
  5. import urgrip.programnodes.Style;
  6. import javax.swing.*;
  7. import javax.swing.text.SimpleAttributeSet;
  8. import javax.swing.text.StyleConstants;
  9. import java.awt.Component;
  10. import java.awt.Dimension;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. import java.util.Collection;
  14. import java.util.Vector;
  15. import static urgrip.installation.HelloWorldInstallationNodeContribution.*;
  16. public class HelloWorldInstallationNodeView implements SwingInstallationNodeView<HelloWorldInstallationNodeContribution> {
  17. private final Style style;
  18. private JComboBox ddGrip;
  19. private JComboBox ddBlow;
  20. private JComboBox ddWaitFor;
  21. public HelloWorldInstallationNodeView(Style style) {
  22. this.style = style;
  23. }
  24. @Override
  25. public void buildUI(JPanel jPanel, final HelloWorldInstallationNodeContribution installationNode) {
  26. jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
  27. jPanel.add(createInfo());
  28. jPanel.add(createVerticalSpacing());
  29. // jPanel.add(createInput(installationNode));
  30. ddGrip = createDropdown(KEY_GRIP);
  31. jPanel.add(ddGrip);
  32. ddBlow = createDropdown(KEY_BLOWOUT);
  33. jPanel.add(ddBlow);
  34. ddWaitFor = createDropdown(KEY_WAITFOR);
  35. jPanel.add(ddWaitFor);
  36. }
  37. private JComboBox createDropdown(String key) {
  38. Box section = Box.createHorizontalBox();
  39. section.setAlignmentX(Component.LEFT_ALIGNMENT);
  40. JComboBox jcb = new JComboBox();
  41. jcb.setPreferredSize(style.getInputfieldSize());
  42. jcb.setMaximumSize(style.getInputfieldSize());
  43. jcb.setMinimumSize(style.getInputfieldSize());
  44. jcb.addActionListener(new ActionListener() {
  45. @Override
  46. public void actionPerformed(ActionEvent actionEvent) {
  47. }
  48. });
  49. section.add(new JLabel(key));
  50. section.add(jcb);
  51. return jcb;
  52. }
  53. private Box createInfo() {
  54. Box infoBox = Box.createVerticalBox();
  55. infoBox.setAlignmentX(Component.LEFT_ALIGNMENT);
  56. JTextPane pane = new JTextPane();
  57. pane.setBorder(BorderFactory.createEmptyBorder());
  58. SimpleAttributeSet attributeSet = new SimpleAttributeSet();
  59. StyleConstants.setLineSpacing(attributeSet, 0.5f);
  60. StyleConstants.setLeftIndent(attributeSet, 0f);
  61. pane.setParagraphAttributes(attributeSet, false);
  62. pane.setText("The popup title below is shared between all Hello World program nodes.\nThe title cannot be empty.");
  63. pane.setEditable(false);
  64. pane.setMaximumSize(pane.getPreferredSize());
  65. pane.setBackground(infoBox.getBackground());
  66. infoBox.add(pane);
  67. return infoBox;
  68. }
  69. private Component createHorizontalSpacing() {
  70. return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
  71. }
  72. private Component createVerticalSpacing() {
  73. return Box.createRigidArea(new Dimension(0, style.getVerticalSpacing()));
  74. }
  75. public void setIO(Collection<IO> ios) {
  76. Vector<IO> iov=new Vector<>();
  77. iov.addAll(ios);
  78. ddGrip.setModel(new DefaultComboBoxModel(iov));
  79. ddBlow.setModel(new DefaultComboBoxModel(iov));
  80. ddWaitFor.setModel(new DefaultComboBoxModel(iov));
  81. }
  82. }