123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package ui.view;
- import classes.AbstractCanvasObject;
- import classes.Edge;
- import classes.GroupNode;
- import ui.controller.Control;
- import javax.swing.*;
- import javax.swing.border.EmptyBorder;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- /**
- * Popup for Editing Edges.
- *
- * @author Gruppe14
- */
- public class EditEdgesPopUp extends JDialog {
- private static final long serialVersionUID = 1L;
- private final JPanel contentPanel = new JPanel();
- private JTextField capacityField;
- private float capacity;
- private JRadioButton rdbtnChangeForAll;
- private JRadioButton rdbtnChangeForNew;
- private JRadioButton rdbtnChangeForAll1;
- private Control controller;
- private MyCanvas canvas;
- private JLabel lblenterinfiniteFor;
- /**
- * Launch the application.
- *
- * @param args
- * standard
- */
- /**
- * Constructor.
- */
- public EditEdgesPopUp(JFrame parentFrame) {
- super((java.awt.Frame) null, true);
- setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
- this.setTitle(Languages.getLanguage()[46]);
- setBounds(100, 100, 400, 220);
- setLocationRelativeTo(parentFrame);
- getContentPane().setLayout(new BorderLayout());
- contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
- getContentPane().add(contentPanel, BorderLayout.CENTER);
- contentPanel.setLayout(null);
- JLabel lblMaximumCapacity = new JLabel(Languages.getLanguage()[47]);
- lblMaximumCapacity.setFont(new Font("Tahoma", Font.PLAIN, 11));
- lblMaximumCapacity.setBounds(10, 11, 98, 14);
- contentPanel.add(lblMaximumCapacity);
- capacityField = new JTextField();
- capacityField.setBounds(107, 8, 120, 20);
- contentPanel.add(capacityField);
- capacityField.setColumns(10);
- rdbtnChangeForAll = new JRadioButton(Languages.getLanguage()[48]);
- rdbtnChangeForAll.setBounds(10, 39, 330, 23);
- contentPanel.add(rdbtnChangeForAll);
- rdbtnChangeForNew = new JRadioButton(Languages.getLanguage()[49]);
- rdbtnChangeForNew.setBounds(10, 65, 330, 23);
- contentPanel.add(rdbtnChangeForNew);
- rdbtnChangeForAll1 = new JRadioButton(Languages.getLanguage()[50]);
- rdbtnChangeForAll1.setBounds(10, 95, 400, 23);
- contentPanel.add(rdbtnChangeForAll1);
- JButton btnCancel = new JButton(Languages.getLanguage()[51]);
- btnCancel.setActionCommand("Cancel");
- btnCancel.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- dispose();
- }
- });
- btnCancel.setBounds(285, 147, 89, 23);
- contentPanel.add(btnCancel);
- JButton btnOk1 = new JButton("OK");
- btnOk1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- capacity = Float.parseFloat(capacityField.getText().toString());
- if (capacity < 0) {
- throw new NumberFormatException();
- }
- if (rdbtnChangeForAll.isSelected()) {
- changeForExisting(capacity);
- dispose();
- } else if (rdbtnChangeForNew.isSelected()) {
- changeForNew(capacity);
- dispose();
- } else if (rdbtnChangeForAll1.isSelected()) {
- changeForExAndNew(capacity);
- dispose();
- } else {
- JOptionPane.showMessageDialog(new JFrame(), Languages.getLanguage()[52]);
- }
- } catch (NumberFormatException eex) {
- JOptionPane.showMessageDialog(new JFrame(), Languages.getLanguage()[53]);
- }
- }
- });
- btnOk1.setBounds(186, 147, 89, 23);
- contentPanel.add(btnOk1);
- this.setTitle(Languages.getLanguage()[54]);
- ButtonGroup bG = new ButtonGroup();
- bG.add(rdbtnChangeForAll1);
- bG.add(rdbtnChangeForNew);
- bG.add(rdbtnChangeForAll);
- }
- /**
- * Set the Canvas.
- *
- * @param can
- * the Canvas
- */
- public void setCanvas(MyCanvas can) {
- canvas = can;
- }
- /**
- * set the Controller.
- *
- * @param cont
- * the Controller
- */
- public void setController(Control cont) {
- controller = cont;
- }
- /**
- * set edge capacity for new edges.
- *
- * @param cap
- * the capacity
- */
- public void changeForNew(float cap) {
- controller.setMaxCapacity(cap);
- controller.resetSimulation();
- }
- /**
- * Set Capacity for all existing Edges.
- *
- * @param cap
- * the Capacity
- */
- public void changeForExisting(float cap) {
- /*
- * for(SubNet sn: controller.getSimManager().getSubNets()){ for(CpsEdge
- * edge: sn.getEdges()){ edge.setCapacity(cap); } } for(CpsEdge edge:
- * controller.getSimManager().getBrokenEdges()){ edge.setCapacity(cap);
- * }
- */
- for (Edge edge : controller.getModel().getEdgesOnCanvas()) {
- edge.setCapacity(cap);
- }
- controller.resetSimulation();
- controller.calculateStateAndVisualForCurrentTimeStep();
- canvas.repaint();
- }
- /**
- * Set the Capacity for all existing and new edges.
- *
- * @param cap
- * the capacity
- */
- public void changeForExAndNew(float cap) {
- changeForNew(cap);
- changeForExisting(cap);
- }
- }
|