/*
* PlaneEditor.java
*
* Created on 29. Februar 2008, 10:10
*/
package gui.windows;
import framework.IATMCModel;
import framework.IRadarPlaneObject;
import messages.PlaneUpdateObject;
/**
*
* @author m0ng
*/
public class PlaneEditor extends javax.swing.JFrame {
private PlaneEditor localEditor;
private FlightList flightList;
private IRadarPlaneObject selectedPlane;
private IATMCModel atmcModel;
/** Creates new form PlaneEditor */
public PlaneEditor(IATMCModel model, FlightList fl) {
initComponents();
localEditor = this;
flightList = fl;
atmcModel = model;
selectedPlane = fl.getSelectedPlane();
cFlightNumber.setText(selectedPlane.getFlightNumber());
nFlightNumber.setText(selectedPlane.getFlightNumber());
cAirline.setText(selectedPlane.getAirline());
nAirline.setText(selectedPlane.getAirline());
cManufacturer.setText(selectedPlane.getManufacturer());
nManufacturer.setText(selectedPlane.getManufacturer());
cType.setText(selectedPlane.getPlaneType());
nType.setText(selectedPlane.getPlaneType());
cSubType.setText(selectedPlane.getPlaneSubType());
nSubType.setText(selectedPlane.getPlaneSubType());
cSquawk.setText(selectedPlane.getSquawk());
nSquawk.setText(selectedPlane.getSquawk());
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
localEditor.setVisible(true);
}
});
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
detailPanel = new javax.swing.JPanel();
flightNumber = new javax.swing.JLabel();
airline = new javax.swing.JLabel();
type = new javax.swing.JLabel();
subType = new javax.swing.JLabel();
squawk = new javax.swing.JLabel();
current = new javax.swing.JLabel();
newDetails = new javax.swing.JLabel();
cFlightNumber = new javax.swing.JLabel();
cAirline = new javax.swing.JLabel();
cType = new javax.swing.JLabel();
cSubType = new javax.swing.JLabel();
cSquawk = new javax.swing.JLabel();
nFlightNumber = new javax.swing.JTextField();
nAirline = new javax.swing.JTextField();
nType = new javax.swing.JTextField();
nSubType = new javax.swing.JTextField();
nSquawk = new javax.swing.JTextField();
manufacturer = new javax.swing.JLabel();
cManufacturer = new javax.swing.JLabel();
nManufacturer = new javax.swing.JTextField();
acceptButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
errorMessage = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
detailPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Details"));
flightNumber.setText("Flightnumber");
airline.setText("Airline");
type.setText("Type");
subType.setText("SubType");
squawk.setText("Squawk");
current.setText("Current");
newDetails.setText("New");
cFlightNumber.setText("???");
cAirline.setText("???");
cType.setText("???");
cSubType.setText("???");
cSquawk.setText("???");
nAirline.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nAirlineActionPerformed(evt);
}
});
nType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nTypeActionPerformed(evt);
}
});
nSquawk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nSquawkActionPerformed(evt);
}
});
manufacturer.setText("Manufacturer");
cManufacturer.setText("???");
acceptButton.setText("Accept");
acceptButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
acceptButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout detailPanelLayout = new javax.swing.GroupLayout(detailPanel);
detailPanel.setLayout(detailPanelLayout);
detailPanelLayout.setHorizontalGroup(
detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, detailPanelLayout.createSequentialGroup()
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, detailPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(errorMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, detailPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(detailPanelLayout.createSequentialGroup()
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(flightNumber)
.addComponent(airline))
.addGap(58, 58, 58))
.addGroup(detailPanelLayout.createSequentialGroup()
.addComponent(manufacturer, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(detailPanelLayout.createSequentialGroup()
.addComponent(type)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(detailPanelLayout.createSequentialGroup()
.addComponent(subType)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGroup(detailPanelLayout.createSequentialGroup()
.addComponent(squawk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addGap(10, 10, 10)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(cSquawk, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
.addComponent(cSubType, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
.addComponent(cType, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
.addComponent(cManufacturer, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
.addComponent(cAirline, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
.addComponent(current, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
.addComponent(cFlightNumber, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
.addGap(10, 10, 10)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(newDetails)
.addComponent(nManufacturer, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addComponent(nType, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addComponent(nSubType, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addComponent(nSquawk, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addComponent(nFlightNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
.addComponent(nAirline, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, detailPanelLayout.createSequentialGroup()
.addGap(113, 113, 113)
.addComponent(acceptButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton)))
.addContainerGap())
);
detailPanelLayout.setVerticalGroup(
detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(detailPanelLayout.createSequentialGroup()
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(newDetails)
.addComponent(current))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(flightNumber)
.addComponent(cFlightNumber)
.addComponent(nFlightNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(9, 9, 9)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(airline)
.addComponent(cAirline)
.addComponent(nAirline, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(7, 7, 7)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nManufacturer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(manufacturer)
.addComponent(cManufacturer))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(type)
.addComponent(cType))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nSubType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(subType)
.addComponent(cSubType))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nSquawk, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(squawk)
.addComponent(cSquawk))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(errorMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(detailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(acceptButton))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(detailPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(detailPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void nAirlineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nAirlineActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_nAirlineActionPerformed
private void nTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nTypeActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_nTypeActionPerformed
private void nSquawkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nSquawkActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_nSquawkActionPerformed
private void acceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptButtonActionPerformed
if (verifyInput()) {
selectedPlane.setFlightNumber(nFlightNumber.getText());
selectedPlane.setAirline(nAirline.getText());
selectedPlane.setManufacturer(nManufacturer.getText());
selectedPlane.setPlaneType(nType.getText());
selectedPlane.setPlaneSubType(nSubType.getText());
selectedPlane.setSquawk(nSquawk.getText());
atmcModel.sendObject(new PlaneUpdateObject(selectedPlane));
flightList.fireChange();
this.dispose();
}
}//GEN-LAST:event_acceptButtonActionPerformed
private boolean verifyInput(){
if(nFlightNumber.getText() == null || nFlightNumber.getText().equals("") || nFlightNumber.getText().length() > 8){
errorMessage.setText("Invalid Flightnumber");
return false;
}
if(nAirline.getText() == null || nAirline.getText().equals("") || nAirline.getText().length() > 12){
errorMessage.setText("Invalid Airline");
return false;
}
if(nManufacturer.getText() == null || nManufacturer.getText().equals("") || nManufacturer.getText().length() > 12){
errorMessage.setText("Invalid Manufacturer");
return false;
}
if(nType.getText() == null || nType.getText().equals("") || nType.getText().length() > 12){
errorMessage.setText("Invalid Planetype");
return false;
}
if(nSubType.getText() == null || nSubType.getText().equals("") || nSubType.getText().length() > 12){
errorMessage.setText("Invalid Subtype");
return false;
}
if(nSquawk.getText() == null || nSquawk.getText().equals("") || nSquawk.getText().length() > 12){
errorMessage.setText("Invalid Squawk");
return false;
}
return true;
}
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
this.dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton acceptButton;
private javax.swing.JLabel airline;
private javax.swing.JLabel cAirline;
private javax.swing.JLabel cFlightNumber;
private javax.swing.JLabel cManufacturer;
private javax.swing.JLabel cSquawk;
private javax.swing.JLabel cSubType;
private javax.swing.JLabel cType;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel current;
private javax.swing.JPanel detailPanel;
private javax.swing.JLabel errorMessage;
private javax.swing.JLabel flightNumber;
private javax.swing.JLabel manufacturer;
private javax.swing.JTextField nAirline;
private javax.swing.JTextField nFlightNumber;
private javax.swing.JTextField nManufacturer;
private javax.swing.JTextField nSquawk;
private javax.swing.JTextField nSubType;
private javax.swing.JTextField nType;
private javax.swing.JLabel newDetails;
private javax.swing.JLabel squawk;
private javax.swing.JLabel subType;
private javax.swing.JLabel type;
// End of variables declaration//GEN-END:variables
}