HelloWorldInstallationNodeView.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package at.acdp.opcur.ur;
  2. import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeView;
  3. import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardTextInput;
  4. import javax.swing.BorderFactory;
  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 javax.swing.JTextPane;
  11. import javax.swing.text.SimpleAttributeSet;
  12. import javax.swing.text.StyleConstants;
  13. import java.awt.Component;
  14. import java.awt.Dimension;
  15. import java.awt.event.MouseAdapter;
  16. import java.awt.event.MouseEvent;
  17. public class HelloWorldInstallationNodeView implements SwingInstallationNodeView<HelloWorldInstallationNodeContribution> {
  18. private final Style style;
  19. private JTextField jTextField;
  20. public HelloWorldInstallationNodeView(Style style) {
  21. this.style = style;
  22. }
  23. @Override
  24. public void buildUI(JPanel jPanel, final HelloWorldInstallationNodeContribution installationNode) {
  25. jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
  26. jPanel.add(createInfo());
  27. jPanel.add(createVerticalSpacing());
  28. jPanel.add(createInput(installationNode));
  29. }
  30. private Box createInfo() {
  31. Box infoBox = Box.createVerticalBox();
  32. infoBox.setAlignmentX(Component.LEFT_ALIGNMENT);
  33. JTextPane pane = new JTextPane();
  34. pane.setBorder(BorderFactory.createEmptyBorder());
  35. SimpleAttributeSet attributeSet = new SimpleAttributeSet();
  36. StyleConstants.setLineSpacing(attributeSet, 0.5f);
  37. StyleConstants.setLeftIndent(attributeSet, 0f);
  38. pane.setParagraphAttributes(attributeSet, false);
  39. pane.setText("The popup title below is shared between all Hello World program nodes.\nThe title cannot be empty.");
  40. pane.setEditable(false);
  41. pane.setMaximumSize(pane.getPreferredSize());
  42. pane.setBackground(infoBox.getBackground());
  43. infoBox.add(pane);
  44. return infoBox;
  45. }
  46. private Box createInput(final HelloWorldInstallationNodeContribution installationNode) {
  47. Box inputBox = Box.createHorizontalBox();
  48. inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
  49. inputBox.add(new JLabel("Popup title:"));
  50. inputBox.add(createHorizontalSpacing());
  51. jTextField = new JTextField();
  52. jTextField.setFocusable(false);
  53. jTextField.setPreferredSize(style.getInputfieldSize());
  54. jTextField.setMaximumSize(jTextField.getPreferredSize());
  55. jTextField.addMouseListener(new MouseAdapter() {
  56. @Override
  57. public void mousePressed(MouseEvent e) {
  58. KeyboardTextInput keyboardInput = installationNode.getInputForTextField();
  59. keyboardInput.show(jTextField, installationNode.getCallbackForTextField());
  60. }
  61. });
  62. inputBox.add(jTextField);
  63. return inputBox;
  64. }
  65. private Component createHorizontalSpacing() {
  66. return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
  67. }
  68. private Component createVerticalSpacing() {
  69. return Box.createRigidArea(new Dimension(0, style.getVerticalSpacing()));
  70. }
  71. public void setPopupText(String t) {
  72. jTextField.setText(t);
  73. }
  74. }