EditEdgesPopUp.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package ui.view;
  2. import classes.AbstractCanvasObject;
  3. import classes.Edge;
  4. import classes.GroupNode;
  5. import ui.controller.Control;
  6. import javax.swing.*;
  7. import javax.swing.border.EmptyBorder;
  8. import java.awt.*;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. /**
  12. * Popup for Editing Edges.
  13. *
  14. * @author Gruppe14
  15. */
  16. public class EditEdgesPopUp extends JDialog {
  17. private static final long serialVersionUID = 1L;
  18. private final JPanel contentPanel = new JPanel();
  19. private JTextField capacityField;
  20. private float capacity;
  21. private JRadioButton rdbtnChangeForAll;
  22. private JRadioButton rdbtnChangeForNew;
  23. private JRadioButton rdbtnChangeForAll1;
  24. private Control controller;
  25. private MyCanvas canvas;
  26. private JLabel lblenterinfiniteFor;
  27. /**
  28. * Launch the application.
  29. *
  30. * @param args
  31. * standard
  32. */
  33. /**
  34. * Constructor.
  35. */
  36. public EditEdgesPopUp(JFrame parentFrame) {
  37. super((java.awt.Frame) null, true);
  38. setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
  39. this.setTitle(Languages.getLanguage()[46]);
  40. setBounds(100, 100, 400, 220);
  41. setLocationRelativeTo(parentFrame);
  42. getContentPane().setLayout(new BorderLayout());
  43. contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
  44. getContentPane().add(contentPanel, BorderLayout.CENTER);
  45. contentPanel.setLayout(null);
  46. JLabel lblMaximumCapacity = new JLabel(Languages.getLanguage()[47]);
  47. lblMaximumCapacity.setFont(new Font("Tahoma", Font.PLAIN, 11));
  48. lblMaximumCapacity.setBounds(10, 11, 98, 14);
  49. contentPanel.add(lblMaximumCapacity);
  50. capacityField = new JTextField();
  51. capacityField.setBounds(107, 8, 120, 20);
  52. contentPanel.add(capacityField);
  53. capacityField.setColumns(10);
  54. rdbtnChangeForAll = new JRadioButton(Languages.getLanguage()[48]);
  55. rdbtnChangeForAll.setBounds(10, 39, 330, 23);
  56. contentPanel.add(rdbtnChangeForAll);
  57. rdbtnChangeForNew = new JRadioButton(Languages.getLanguage()[49]);
  58. rdbtnChangeForNew.setBounds(10, 65, 330, 23);
  59. contentPanel.add(rdbtnChangeForNew);
  60. rdbtnChangeForAll1 = new JRadioButton(Languages.getLanguage()[50]);
  61. rdbtnChangeForAll1.setBounds(10, 95, 400, 23);
  62. contentPanel.add(rdbtnChangeForAll1);
  63. JButton btnCancel = new JButton(Languages.getLanguage()[51]);
  64. btnCancel.setActionCommand("Cancel");
  65. btnCancel.addActionListener(new ActionListener() {
  66. public void actionPerformed(ActionEvent arg0) {
  67. dispose();
  68. }
  69. });
  70. btnCancel.setBounds(285, 147, 89, 23);
  71. contentPanel.add(btnCancel);
  72. JButton btnOk1 = new JButton("OK");
  73. btnOk1.addActionListener(new ActionListener() {
  74. public void actionPerformed(ActionEvent e) {
  75. try {
  76. capacity = Float.parseFloat(capacityField.getText().toString());
  77. if (capacity < 0) {
  78. throw new NumberFormatException();
  79. }
  80. if (rdbtnChangeForAll.isSelected()) {
  81. changeForExisting(capacity);
  82. dispose();
  83. } else if (rdbtnChangeForNew.isSelected()) {
  84. changeForNew(capacity);
  85. dispose();
  86. } else if (rdbtnChangeForAll1.isSelected()) {
  87. changeForExAndNew(capacity);
  88. dispose();
  89. } else {
  90. JOptionPane.showMessageDialog(new JFrame(), Languages.getLanguage()[52]);
  91. }
  92. } catch (NumberFormatException eex) {
  93. JOptionPane.showMessageDialog(new JFrame(), Languages.getLanguage()[53]);
  94. }
  95. }
  96. });
  97. btnOk1.setBounds(186, 147, 89, 23);
  98. contentPanel.add(btnOk1);
  99. this.setTitle(Languages.getLanguage()[54]);
  100. ButtonGroup bG = new ButtonGroup();
  101. bG.add(rdbtnChangeForAll1);
  102. bG.add(rdbtnChangeForNew);
  103. bG.add(rdbtnChangeForAll);
  104. }
  105. /**
  106. * Set the Canvas.
  107. *
  108. * @param can
  109. * the Canvas
  110. */
  111. public void setCanvas(MyCanvas can) {
  112. canvas = can;
  113. }
  114. /**
  115. * set the Controller.
  116. *
  117. * @param cont
  118. * the Controller
  119. */
  120. public void setController(Control cont) {
  121. controller = cont;
  122. }
  123. /**
  124. * set edge capacity for new edges.
  125. *
  126. * @param cap
  127. * the capacity
  128. */
  129. public void changeForNew(float cap) {
  130. controller.setMaxCapacity(cap);
  131. controller.resetSimulation();
  132. }
  133. /**
  134. * Set Capacity for all existing Edges.
  135. *
  136. * @param cap
  137. * the Capacity
  138. */
  139. public void changeForExisting(float cap) {
  140. /*
  141. * for(SubNet sn: controller.getSimManager().getSubNets()){ for(CpsEdge
  142. * edge: sn.getEdges()){ edge.setCapacity(cap); } } for(CpsEdge edge:
  143. * controller.getSimManager().getBrokenEdges()){ edge.setCapacity(cap);
  144. * }
  145. */
  146. for (Edge edge : controller.getModel().getEdgesOnCanvas()) {
  147. edge.setCapacity(cap);
  148. }
  149. controller.resetSimulation();
  150. controller.calculateStateAndVisualForCurrentTimeStep();
  151. canvas.repaint();
  152. }
  153. /**
  154. * Set the Capacity for all existing and new edges.
  155. *
  156. * @param cap
  157. * the capacity
  158. */
  159. public void changeForExAndNew(float cap) {
  160. changeForNew(cap);
  161. changeForExisting(cap);
  162. }
  163. }