ShowedInformationPopUp.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package ui.view;
  2. import java.awt.BorderLayout;
  3. import javax.swing.JDialog;
  4. import javax.swing.JPanel;
  5. import javax.swing.border.EmptyBorder;
  6. import javax.swing.JCheckBox;
  7. import javax.swing.JButton;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.ActionEvent;
  10. /**
  11. * This Class represents a Popup to edit the shown Information.
  12. *
  13. * @author Gruppe14
  14. */
  15. public class ShowedInformationPopUp extends JDialog {
  16. private static final long serialVersionUID = 1L;
  17. private final JPanel contentPanel = new JPanel();
  18. private final JButton btnOk = new JButton("OK");
  19. private MyCanvas canvas;
  20. private JCheckBox objectEnergyCheckbox;
  21. private JCheckBox connectionCheckbox;
  22. /**
  23. * Constructor.
  24. *
  25. * @param canvas
  26. * the Canvas
  27. */
  28. public ShowedInformationPopUp(MyCanvas canvas) {
  29. super((java.awt.Frame) null, true);
  30. setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
  31. this.setTitle("Edit Showed Informations");
  32. setBounds(100, 100, 277, 169);
  33. getContentPane().setLayout(new BorderLayout());
  34. contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
  35. getContentPane().add(contentPanel, BorderLayout.CENTER);
  36. contentPanel.setLayout(null);
  37. this.canvas = canvas;
  38. objectEnergyCheckbox = new JCheckBox("Show Total Energy of Objects");
  39. objectEnergyCheckbox.setBounds(19, 19, 181, 23);
  40. contentPanel.add(objectEnergyCheckbox);
  41. connectionCheckbox = new JCheckBox("Show Connection Properties");
  42. connectionCheckbox.setBounds(19, 57, 181, 23);
  43. contentPanel.add(connectionCheckbox);
  44. objectEnergyCheckbox.setSelected(canvas.getShowedInformation()[1]);
  45. connectionCheckbox.setSelected(canvas.getShowedInformation()[0]);
  46. btnOk.addActionListener(new ActionListener() {
  47. public void actionPerformed(ActionEvent arg0) {
  48. setInformation(connectionCheckbox.isSelected(), objectEnergyCheckbox.isSelected());
  49. dispose();
  50. }
  51. });
  52. btnOk.setBounds(169, 98, 82, 23);
  53. contentPanel.add(btnOk);
  54. JButton btnCancel = new JButton("Cancel");
  55. btnCancel.setActionCommand("Cancel");
  56. btnCancel.addActionListener(new ActionListener() {
  57. public void actionPerformed(ActionEvent arg0) {
  58. dispose();
  59. }
  60. });
  61. btnCancel.setBounds(70, 98, 89, 23);
  62. contentPanel.add(btnCancel);
  63. }
  64. /**
  65. * Set the Information true or false.
  66. *
  67. * @param connection
  68. * conecction Information
  69. * @param object
  70. * Object Information
  71. */
  72. private void setInformation(boolean connection, boolean object) {
  73. canvas.setShowedInformation(connection, object);
  74. canvas.repaint();
  75. }
  76. }