/*
* CustomDialog.java
* The package reservation contains the different class allowing to choose the action to realise.
*/
package reservation;
import reservation.system.panels.*;
import reservation.system.FlightSystem;
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
/**
* This class hold CustomDialog structure. This object analyse the instruction written by the user and determine according to the first element the command to execute.
* Then it instancie a new object which depends to the command and which will execute the instruction of the user.
* The new object instantiated create a new window corresponding to the command to execute.
* @author Texier Mathieu and Frederic Bidon
*/
public class CustomDialog
extends JDialog implements Mode
{
/**Integer defining the command RELOAD.*/
static final public int RELOAD = 0;
/**Integer defining the command READ_COMMAND.*/
static final public int READ_COMMAND = 1;
/**Integer defining the command CREATE.*/
static final public int CREATE = 2;
/**Integer defining the command STORE.*/
static final public int STORE = 3;
/**Integer defining the command RESERVE.*/
static final public int RESERVE = 4;
/**Integer defining the command FLIGHTS.*/
static final public int FLIGHTS = 5;
/**Integer defining the command CANCEL.*/
static final public int CANCEL = 6;
/**Integer defining the command SELECT.*/
static final public int SELECT = 7;
/**Create a new instance with the level of verbosity QUIET*/
public CustomDialog () {
this (QUIET);
}
/**
* Create a new instance of CustomDialog
* @param verboseMode Integer defining the level of verbosity to execute the program.
*/
public CustomDialog (int verboseMode) {
super ();
setModal (true);
String title
= "Flight System";
this.VerboseMode = VerboseMode;
try {
System.
err.
println ("Warning: UnsupportedLookAndFeel: " + laf
);
System.
err.
println ("Error loading " + laf
+ ": " + exc
);
}
try {
if (FlightSystem.getInstance ().getFlightList ().length > 0) {
int res
= JOptionPane.
showConfirmDialog (null,
"Would you like to save the dataBase ?",
"save",
JOptionPane.
YES_NO_OPTION);
MainPanel.Store ();
}
}
});
setResizable (false);
setTitle (title);
action = new MainPanel (this);
titleLabel.
setFont (new Font ("MS Sans Serif",
1,
18));
titleLabel.setText (title);
getContentPane
().
add ((Panels
)action,
BorderLayout.
CENTER);
pack ();
}
/**
* This method determine the number of element of the user's instruction and analyse the first element of this one.
* If it corresponds to an available command of the system, it create a new object depending of the command.
* This new object will execute the instruction with the other elements of the command.
* @param owner Dilog or frame from which the CustomDialog is issue
* @param modal Modal mode
* @param title The title of the window
* @param command The identifier of the command (RELOAD, CREATE, CANCEL ...)
*/
public CustomDialog
(CustomDialog owner,
boolean modal,
String title,
int command
) {
super (owner, modal);
this.owner = owner;
try {
System.
err.
println ("Warning: UnsupportedLookAndFeel: " + laf
);
System.
err.
println ("Error loading " + laf
+ ": " + exc
);
}
setResizable (false);
setTitle (title);
titleLabel.
setFont (new java.
awt.
Font ("MS Sans Serif",
1,
18));
titleLabel.setText (title);
switch(command){
case CREATE:
action = new CreatePanel ();
break;
case RESERVE:
action = new ReservePanel ();
break;
case CANCEL:
action = new CancelPanel ();
break;
case SELECT:
action = new SelectPanel ();
break;
case FLIGHTS:
action = new FlightsPanel ();
break;
default:
action = new MainPanel ();
break;
}
((Panels) action).init ();
FootPanel footPanel = new FootPanel ();
getContentPane
().
add ( (Panels
) action,
BorderLayout.
CENTER);
pack ();
}
/**
* This method create a new dialog window according to the selected command.
*/
public void process () {
if (owner != null)
((Panels) owner.action).init ();
show ();
}
/**
* This method allows to access the private string retValue.
* @return the string retValue.
*/
public String getRetValue
() {
return retValue;
}
/**
* Open a new window to specify the produced error by the user.
* @param exception The message that will be displayed in the message box
*/
static public void alert
(Exception exception
) {
if (VerboseMode == DEBUG)
exception.printStackTrace ();
}
/**
* Open a new dialog window to give more informations to the user.
* @param info The message that will be displayed in the message box
*/
static public void alert
(String info
) {
}
/**
* Hide the dialog
*/
protected void quit (){
hide ();
}
private CustomDialog owner;
private Action action
= new MainPanel
();
static private int VerboseMode = NORMAL;
private class FootPanel
extends JPanel {
/** Creates new form footPanel */
public FootPanel () {
validButton.setText ("Valid");
add (validButton);
try {
retValue = action.execute (null);
CustomDialog.alert (e);
}
quit ();
}
});
cancelButton.setText ("Cancel");
quit ();
}
});
add (cancelButton);
}
}
}