DisplayedInformationPopUp.java 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package ui.view;
  2. import ui.controller.Control;
  3. import javax.swing.*;
  4. import javax.swing.border.EmptyBorder;
  5. import java.awt.*;
  6. /**
  7. * This Class represents a Popup to edit the shown Information.
  8. *
  9. * @author Gruppe14
  10. */
  11. public class DisplayedInformationPopUp extends JDialog {
  12. private static final long serialVersionUID = 1L;
  13. private final JPanel contentPanel = new JPanel();
  14. private final JButton btnOk = new JButton("OK");
  15. private MyCanvas canvas;
  16. private Control controller;
  17. private JCheckBox objectEnergyCheckbox;
  18. private JCheckBox connectionCheckbox;
  19. private JCheckBox colorizedBorderCheckbox;
  20. private JCheckBox nodeOfnodeConnectionCheckbox;
  21. private JPanel toUpdate;
  22. /**
  23. * Constructor.
  24. *
  25. * @param canvas
  26. * the Canvas
  27. */
  28. public DisplayedInformationPopUp(MyCanvas canvas, JPanel update, Control cont, JFrame parentFrame) {
  29. super((java.awt.Frame) null, true);
  30. setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
  31. this.setTitle("Edit Displayed Informations");
  32. setBounds(100, 100, 400, 276);
  33. setLocationRelativeTo(parentFrame);
  34. getContentPane().setLayout(new BorderLayout());
  35. contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
  36. getContentPane().add(contentPanel, BorderLayout.CENTER);
  37. contentPanel.setLayout(null);
  38. this.canvas = canvas;
  39. this.toUpdate = update;
  40. controller = cont;
  41. objectEnergyCheckbox = new JCheckBox("Display Total Energy of Objects");
  42. objectEnergyCheckbox.setBounds(19, 19, 300, 23);
  43. contentPanel.add(objectEnergyCheckbox);
  44. connectionCheckbox = new JCheckBox("Display Connection Properties");
  45. connectionCheckbox.setBounds(19, 57, 300, 23);
  46. contentPanel.add(connectionCheckbox);
  47. objectEnergyCheckbox.setSelected(canvas.getShowedInformation()[1]);
  48. connectionCheckbox.setSelected(canvas.getShowedInformation()[0]);
  49. btnOk.addActionListener(actionEvent -> {
  50. setInformation(connectionCheckbox.isSelected(), objectEnergyCheckbox.isSelected(),
  51. colorizedBorderCheckbox.isSelected(), nodeOfnodeConnectionCheckbox.isSelected());
  52. controller.getSimManager().getFlexiblePane().recalculate();
  53. dispose();
  54. });
  55. btnOk.setBounds(174, 193, 82, 23);
  56. contentPanel.add(btnOk);
  57. JButton btnCancel = new JButton(Languages.getLanguage()[34]);
  58. btnCancel.setActionCommand(Languages.getLanguage()[34]);
  59. btnCancel.addActionListener(actionEvent -> dispose());
  60. btnCancel.setBounds(69, 193, 89, 23);
  61. contentPanel.add(btnCancel);
  62. colorizedBorderCheckbox = new JCheckBox("Display colorized Border for Objects");
  63. colorizedBorderCheckbox.setBounds(19, 96, 369, 23);
  64. contentPanel.add(colorizedBorderCheckbox);
  65. colorizedBorderCheckbox.setSelected(canvas.getShowedInformation()[3]);
  66. nodeOfnodeConnectionCheckbox = new JCheckBox("Display outside Connections in gouped Nodes");
  67. nodeOfnodeConnectionCheckbox.setBounds(19, 133, 369, 23);
  68. contentPanel.add(nodeOfnodeConnectionCheckbox);
  69. nodeOfnodeConnectionCheckbox.setSelected(canvas.getShowedInformation()[4]);
  70. }
  71. /**
  72. * Set the Information true or false.
  73. *
  74. * @param connection
  75. * conection Information
  76. * @param object
  77. * Object Information
  78. * @param nodeOfnode
  79. */
  80. private void setInformation(boolean connection, boolean object, boolean borders, boolean nodeOfnode) {
  81. canvas.setShowedInformation(connection, object, borders, nodeOfnode);
  82. canvas.repaint();
  83. toUpdate.updateUI();
  84. }
  85. }