/*
* CancelPanel.java
* The package panels contains the different class executing the different windows of each function of the FlightSystem Reservation.
*/
package reservation.system.panels;
import reservation.system.FlightSystem;
import reservation.system.Person;
import reservation.system.functions.Functions;
import reservation.system.functions.Cancel;
import reservation.CustomDialog;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Dimension;
import java.util.StringTokenizer;
import java.util.Vector;
/**
* This class hold Cancel structure. This object allows to cancel a reservation for different person or for a whole of person by calling the methods <CODE>cancel</CODE> in {@link reservation.system.FlightSystem}.
* @author Texier Mathieu and Frederic Bidon
* It use a GUI that contains a form with the several field to fill.
*/
public class CancelPanel extends Panels {
/** Creates new form CancelPanel */
public CancelPanel () {
action = new Cancel ();
passengerLabel
= new JLabel ();
passengerList
= new JList ();
bookingLabel.setText ("Enter");
add (bookingLabel);
bookingInput.setText ("booking number");
bookingInput.setText ("");
}
});
add (bookingInput);
identifyButton.setText ("Identify");
identifyAction (evt);
}
});
add (identifyButton);
passengerLabel.setText ("Passenger");
add (passengerLabel);
passengerListScroll.setViewportView (passengerList);
add (passengerListScroll);
}
/**
* Create the button of validation to search the bookingNumber given by the user in the database.
* @throws Exception if the command is not executed.
*/
try {
String bookingString
= bookingInput.
getText ();
if (!bookingString.equals (""))
if (Functions.checkInteger (bookingString,1,fs.getBookingNumberMax ())) {
int bookingNumber
= Integer.
parseInt (bookingString
);
Vector groupePersonVector
= fs.
identify (bookingNumber
);
int groupePersonSize = groupePersonVector.size ();
for (int i=0; i< groupePersonSize; i++) {
listData[i] = ((Person) groupePersonVector.get (i)).getPersonName ();
}
passengerList.setListData (listData);
}
CustomDialog.alert (e);
}
}
/**
* Causes this container to lay out its components.
*/
public void doLayout () {
bookingLabel.setBounds (20, 20, 40, 20);
bookingInput.setBounds (110, 20, 90, 20);
identifyButton.setBounds (210, 20, 70, 20);
passengerLabel.setBounds (20, 60, 80, 20);
passengerList.setBounds (110, 60, 170, 60);
passengerListScroll.setBounds (110, 60, 170, 60);
}
/**
* Set the size of the panel
* @return an instance of Dimension that represents the minimum size of this container.
*/
}
/**
* Set the size of the panel
* @return an instance of Dimension that represents the preferred size of this container.
*/
}
/**
* Initialize the number of the field and fill them with default values.
* Dispaly the label of the Window.
*/
public void init () {
}
/**
* Proceed the execution of the action
* @return the result of the request.
* @param unUsed Not used
* @throws Exception if the command is not executed.
*/
Object selectedPassenger
[] = passengerList.
getSelectedValues ();
argv[0] = bookingInput.getText ();
System.
arraycopy ( selectedPassenger,
0, argv,
1, selectedPassenger.
length );
return action.execute ( argv );
}
private JLabel passengerLabel
;
private JList passengerList
;
}