package de.jan.flugplaner.frame;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import de.jan.flugplaner.Planner;
import de.jan.flugplaner.utils.DocumentLengthFilter;
import de.jan.flugplaner.utils.MessageBox;
@SuppressWarnings("serial")
public class FP_Frame extends JFrame implements ActionListener{
private JMenuBar mainBar;
private JMenu hilfeMenu;
private MessageBox box = new MessageBox();
private Dimension dim01 = new Dimension(800, 500);
private String title = "Flugplanner Version 1.0 For FSX & FS04";
private static boolean firstRun = false;
private JComboBox<String> selectAddon;
private JCheckBox useIVAODatenbank;
private JTextField departure;
private JTextField destination;
private JButton createPlan;
private JLabel selectAddonLabel;
private JLabel useIVAOLabel;
private JLabel departureLabel;
private JLabel destinationLabel;
private JLabel fuelReserve;
private JLabel fuelReserveDesc;
private JLabel fuelOnly;
private JLabel fuelOnlyDesc;
private JLabel fuelOnBoard;
private JLabel fuelOnBoardDesc;
private JTextArea route;
private JLabel routeDesc;
private JLabel miles;
private JLabel milesDesc;
private Border mainborder;
private JLabel altiudeLabel;
private JLabel altiude;
private JLabel SIDLabel;
private JLabel STARLabel;
private JLabel SID;
private JLabel STAR;
private JButton beenden;
private JMenuItem flughäfen;
private JMenuItem support;
private void loadSystem() {
//Only Labels
fuelOnBoardDesc = new JLabel("Ihr gesamter Treibstoff:");
fuelOnBoardDesc.setBounds(400, 0, 250, 50);
add(fuelOnBoardDesc);
fuelOnlyDesc = new JLabel("Ihr benötigter Treibstoff:");
fuelOnlyDesc.setBounds(400, 35, 250, 50);
add(fuelOnlyDesc);
fuelReserveDesc = new JLabel("Ihr Reserve Treibstoff:");
fuelReserveDesc.setBounds(400, 70, 250, 50);
add(fuelReserveDesc);
routeDesc = new JLabel("Ihre Route:");
routeDesc.setBounds(400, 235, 250, 50);
add(routeDesc);
milesDesc = new JLabel("Meilen(ungefair):");
milesDesc.setBounds(400, 103, 250, 50);
add(milesDesc);
altiudeLabel = new JLabel("Bevorzugte Altiude:");
altiudeLabel.setBounds(400, 135, 250, 50);
add(altiudeLabel);
SIDLabel = new JLabel("Bevorzugte SID:");
SIDLabel.setBounds(400, 170, 250, 50);
add(SIDLabel);
STARLabel = new JLabel("Bevorzugte STAR:");
STARLabel.setBounds(400, 205, 250, 50);
add(STARLabel);
//Systems
fuelOnBoard = new JLabel(" lbs");
fuelOnBoard.setBounds(650, 0, 250, 50);
add(fuelOnBoard);
fuelOnly = new JLabel(" lbs");
fuelOnly.setBounds(650, 35, 250, 50);
add(fuelOnly);
fuelReserve = new JLabel(" lbs");
fuelReserve.setBounds(650, 70, 250, 50);
add(fuelReserve);
route = new JTextArea();
route.setLineWrap(true);
route.setEditable(false);
route.setVisible(true);
route.setBounds(400, 275, 380, 100);
mainborder = BorderFactory.createLineBorder(Color.BLACK);
route.setBorder(BorderFactory.createCompoundBorder(mainborder, BorderFactory.createEmptyBorder(10, 10, 10, 10)));
JScrollPane sbr = new JScrollPane(route);
sbr.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
sbr.setBounds(400, 275, 380, 100);
add(sbr);
miles = new JLabel(" nm");
miles.setBounds(650, 103, 250, 50);
add(miles);
altiude = new JLabel(" feet (FL )");
altiude.setBounds(619, 135, 250, 50);
add(altiude);
SID = new JLabel();
SID.setBounds(650, 170, 250, 50);
add(SID);
STAR = new JLabel();
STAR.setBounds(650, 205, 250, 50);
add(STAR);
}
public FP_Frame() {
setSize(dim01);
setLocationRelativeTo(null);
setResizable(false);
setAlwaysOnTop(false);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle(title);
new Planner();
regMenus();
loadCommpomenten();
loadSystem();
loadLabels();
setVisible(true);
System.out.println(new Planner().liste.toString());
}
private void loadCommpomenten() {
beenden = new JButton("Beenden");
beenden.setBounds(500, 400, 250, 45);
beenden.addActionListener(this);
add(beenden);
createPlan = new JButton("Flugplan Erstellen");
createPlan.setBounds(10, 400, 250, 45);
createPlan.addActionListener(this);
add(createPlan);
departure = new JTextField(4);
departure.setBounds(10, 185, 72, 30);
departure.setFont(new Font("Fad", Font.PLAIN, 24));
departure.setDocument(new DocumentLengthFilter(4));
add(departure);
destination = new JTextField(4);
destination.setBounds(10, 250, 72, 30);
destination.setFont(new Font("Fad", Font.PLAIN, 24));
destination.setDocument(new DocumentLengthFilter(4));
add(destination);
useIVAODatenbank = new JCheckBox("Ja!");
useIVAODatenbank.setBounds(10, 120, 200, 30);
add(useIVAODatenbank);
selectAddon = new JComboBox<String>();
selectAddon.setBackground(Color.white);
selectAddon.setBounds(10, 50, 265, 30);
loadSupportAddons();
add(selectAddon);
}
private void regMenus() {
mainBar = new JMenuBar();
hilfeMenu = new JMenu("Allgemeine Hilfe");
flughäfen = new JMenuItem("Registrierte Flughäfen");
support = new JMenuItem("Support (Konkat)");
hilfeMenu.add(flughäfen);
hilfeMenu.add(support);
mainBar.add(hilfeMenu);
flughäfen.addActionListener(this);
support.addActionListener(this);
setJMenuBar(mainBar);
}
private void loadSupportAddons() {
selectAddon.addItem("PMDG 737 NGX(800WL)");
}
private void loadLabels() {
departureLabel = new JLabel();
departureLabel.setBounds(10, 160, 300, 30);
departureLabel.setText("Geben sie ihr ihren Start ein: (ICAO Only!)");
add(departureLabel);
destinationLabel = new JLabel();
destinationLabel.setBounds(10, 225, 300, 30);
destinationLabel.setText("Geben sie ihr Ziel ein: (ICAO Only!)");
add(destinationLabel);
selectAddonLabel = new JLabel();
selectAddonLabel.setBounds(10, 20, 300, 30);
selectAddonLabel.setText("Bitte welchen sie ein Addon Flugzeug aus:");
add(selectAddonLabel);
useIVAOLabel = new JLabel();
useIVAOLabel.setBounds(10, 100, 300, 30);
useIVAOLabel.setText("IVAO Datenbank benutzen?");
add(useIVAOLabel);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == createPlan) {
if(departure.getText().isEmpty() && destination.getText().isEmpty() || departure.getText().isEmpty() ||
destination.getText().isEmpty()) {
box.sendWarningMessageBoxWithTitle("Du hast nicht alles ausgefüllt!", "Nicht ausgefüllte Felder!");
}else{
Planner plr = new Planner(departure.getText(), destination.getText(), useIVAODatenbank.isSelected(),
selectAddon.getSelectedItem().toString(), route, SID, STAR, altiude, fuelOnly, fuelReserve, fuelOnBoard,
miles);
plr.create();
}
}
if(source == beenden) {
System.exit(0);
}
if(source == flughäfen) {
box.sendMessageBox("Registere Flughäfen:\n" +
"EDDG, EDDS");
}
if(source == support) {
box.sendMessageBox("Benötigtes du Hilfe? \n" +
"Konkat über Skype: flug.zeug21 \n" +
"E-Mail: [email]janboy2000@hotmail.de[/email]");
}
}
public static boolean isAlreadyLoaded() {
if(!firstRun) {
firstRun = true;
return false;
}else{
return true;
}
}
public static void unload() {
if(firstRun) {
firstRun = false;
}
}
}