DisplayedInformationPopUp.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. connectionCheckbox.setSelected(true);
  47. contentPanel.add(connectionCheckbox);
  48. objectEnergyCheckbox.setSelected(canvas.getShowedInformation()[1]);
  49. connectionCheckbox.setSelected(canvas.getShowedInformation()[0]);
  50. btnOk.addActionListener(actionEvent -> {
  51. setInformation(connectionCheckbox.isSelected(), objectEnergyCheckbox.isSelected(),
  52. colorizedBorderCheckbox.isSelected(), nodeOfnodeConnectionCheckbox.isSelected());
  53. controller.getSimManager().getFlexiblePane().recalculate();
  54. dispose();
  55. });
  56. btnOk.setBounds(174, 193, 82, 23);
  57. contentPanel.add(btnOk);
  58. JButton btnCancel = new JButton(Languages.getLanguage()[34]);
  59. btnCancel.setActionCommand(Languages.getLanguage()[34]);
  60. btnCancel.addActionListener(actionEvent -> dispose());
  61. btnCancel.setBounds(69, 193, 89, 23);
  62. contentPanel.add(btnCancel);
  63. colorizedBorderCheckbox = new JCheckBox("Display colorized Border for Objects");
  64. colorizedBorderCheckbox.setBounds(19, 96, 369, 23);
  65. contentPanel.add(colorizedBorderCheckbox);
  66. colorizedBorderCheckbox.setSelected(canvas.getShowedInformation()[3]);
  67. nodeOfnodeConnectionCheckbox = new JCheckBox("Display outside Connections in gouped Nodes");
  68. nodeOfnodeConnectionCheckbox.setBounds(19, 133, 369, 23);
  69. contentPanel.add(nodeOfnodeConnectionCheckbox);
  70. nodeOfnodeConnectionCheckbox.setSelected(canvas.getShowedInformation()[4]);
  71. }
  72. /**
  73. * Set the Information true or false.
  74. *
  75. * @param connection
  76. * conection Information
  77. * @param object
  78. * Object Information
  79. * @param nodeOfnode
  80. */
  81. private void setInformation(boolean connection, boolean object, boolean borders, boolean nodeOfnode) {
  82. canvas.setShowedInformation(connection, object, borders, nodeOfnode);
  83. canvas.repaint();
  84. toUpdate.updateUI();
  85. }
  86. }