123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- package ui.view;
- import java.awt.BorderLayout;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.ButtonGroup;
- import javax.swing.JButton;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JRadioButton;
- import javax.swing.JTextField;
- import javax.swing.border.EmptyBorder;
- import classes.AbstractCpsObject;
- import classes.CpsEdge;
- import classes.CpsUpperNode;
- import ui.controller.Control;
- /**
- * 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
- */
- public static void main(String[] args) {
- try {
- EditEdgesPopUp dialog = new EditEdgesPopUp();
- dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- dialog.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Constructor.
- */
- public EditEdgesPopUp() {
- super((java.awt.Frame) null, true);
- setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
- this.setTitle(Languages.getLanguage()[46]);
- setBounds(100, 100, 600, 220);
- 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) {
- if (capacityField.getText().equals("infinite")) {
- capacity = -1;
- 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]);
- }
- } else {
- 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);
- lblenterinfiniteFor = new JLabel(Languages.getLanguage()[55]);
- lblenterinfiniteFor.setBounds(237, 11, 360, 14);
- contentPanel.add(lblenterinfiniteFor);
- }
- /**
- * 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 (CpsEdge edge : controller.getModel().getEdgesOnCanvas()) {
- edge.setCapacity(cap);
- edge.setState(true);
- }
- for (AbstractCpsObject abs : controller.getModel().getObjectsOnCanvas()) {
- if (abs instanceof CpsUpperNode) {
- changeInUpperNode((CpsUpperNode) abs, cap);
- }
- }
- controller.resetSimulation();
- controller.calculateStateForCurrentTimeStep();
- canvas.repaint();
- }
- public void changeInUpperNode(CpsUpperNode uN, float cap) {
- for (CpsEdge e : uN.getNodeEdges()) {
- e.setCapacity(cap);
- }
- for (CpsEdge e : uN.getOldEdges()) {
- e.setCapacity(cap);
- }
- for (AbstractCpsObject abs : uN.getNodes()) {
- if (abs instanceof CpsUpperNode) {
- changeInUpperNode((CpsUpperNode) abs, cap);
- }
- }
- }
- /**
- * Set the Capacity for all existing and new edges.
- *
- * @param cap
- * the capacity
- */
- public void changeForExAndNew(float cap) {
- changeForNew(cap);
- changeForExisting(cap);
- }
- }
|