package pipe.gui;

import java.awt.Container;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import pipe.dataLayer.Arc;
//import pipe.dataLayer.ArrowLabel;

public class EditWeightAction extends AbstractAction{

  private String label;
  private Container contentPane;
  private Arc myArc;

  public EditWeightAction(Container contentPane, Arc a){
    this.contentPane = contentPane;
    myArc = a;
  }


  public void actionPerformed(ActionEvent e){

    int currentWeighting = myArc.getWeight();

    String input = JOptionPane.showInputDialog("Weighting:", String.valueOf(currentWeighting));
    try {
      int newWeighting = Integer.parseInt(input);
      if(newWeighting < 1)
        JOptionPane.showMessageDialog(contentPane, "Weighting cannot be less than 1.  Please re-enter");
      else
        myArc.setWeight(newWeighting);

    } catch(Exception exc){
      if(input!=null)
        JOptionPane.showMessageDialog(contentPane, "Please enter a number.", "Invalid entry", JOptionPane.ERROR_MESSAGE);
      System.err.println(exc.toString());
    }
  }
}


