Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import javax.swing.*;
- import javax.swing.border.*;
- import javax.swing.event.*;
- import model.*;
- import service.Service;
- public class TruckDriverArrivalFrame extends JFrame {
- private static final long serialVersionUID = -7764496032756629451L;
- private JPanel contentPane;
- private JSeparator separator, separator_1, separator_2;
- private JLabel lblDriverInfo, lblEnterSuborderID, lblSuborderResultList,
- lblErrorLabel, lblPhonenumber, lblHoursOfRest, lblGrossweight,
- lblCargotype, lblGrossWeightResult, lblCargotypeResult,
- lblEmptyWeight, lblOrderId, lblSuborderinfo, lblLicensePlate,
- lblCustomer, lblCustomerResult;
- private JTextField txtHours, txtMinutes, txtPhoneNumber, txtSuborderID,
- txtEmptyWeight, txtLicensePlate;
- private JButton btnConfirm, btnAddSuborder;
- private JList<Suborder> lstSuborders;
- private Controller controller = new Controller();
- private JScrollPane scpSuborders;
- private ArrayList<Suborder> enteredSuborders = new ArrayList<Suborder>();
- public TruckDriverArrivalFrame() {
- setIconImage(Toolkit.getDefaultToolkit().getImage(
- TruckDriverArrivalFrame.class.getResource("/gui/icon.jpg")));
- setTitle("Arrival Terminal");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 340, 378);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(this.contentPane);
- contentPane.setLayout(null);
- // LABELS
- lblEnterSuborderID = new JLabel("Enter Suborder ID(s):");
- lblEnterSuborderID.setFont(new Font("Verdana", Font.BOLD, 10));
- lblEnterSuborderID.setBounds(10, 11, 134, 14);
- contentPane.add(lblEnterSuborderID);
- lblSuborderResultList = new JLabel("Suborders for order:");
- lblSuborderResultList.setFont(new Font("Verdana", Font.BOLD, 10));
- lblSuborderResultList.setBounds(10, 69, 167, 14);
- contentPane.add(lblSuborderResultList);
- lblDriverInfo = new JLabel("Driver Information:");
- lblDriverInfo.setFont(new Font("Verdana", Font.BOLD, 10));
- lblDriverInfo.setBounds(10, 200, 134, 14);
- contentPane.add(lblDriverInfo);
- lblPhonenumber = new JLabel("Phonenumber:");
- lblPhonenumber.setFont(new Font("Verdana", Font.PLAIN, 10));
- lblPhonenumber.setBounds(10, 218, 98, 14);
- contentPane.add(lblPhonenumber);
- lblHoursOfRest = new JLabel("Hours of Rest:");
- lblHoursOfRest.setFont(new Font("Verdana", Font.PLAIN, 10));
- lblHoursOfRest.setBounds(133, 218, 98, 14);
- contentPane.add(lblHoursOfRest);
- lblGrossweight = new JLabel("Gross Weight:");
- lblGrossweight.setFont(new Font("Verdana", Font.PLAIN, 10));
- lblGrossweight.setBounds(182, 115, 80, 14);
- contentPane.add(lblGrossweight);
- lblCargotype = new JLabel("Cargotype:");
- lblCargotype.setFont(new Font("Verdana", Font.PLAIN, 10));
- lblCargotype.setBounds(182, 130, 80, 14);
- contentPane.add(lblCargotype);
- lblGrossWeightResult = new JLabel("N/A");
- lblGrossWeightResult.setFont(new Font("Verdana", Font.ITALIC, 10));
- lblGrossWeightResult.setBounds(270, 115, 46, 14);
- contentPane.add(lblGrossWeightResult);
- lblCargotypeResult = new JLabel("N/A");
- lblCargotypeResult.setFont(new Font("Verdana", Font.ITALIC, 10));
- lblCargotypeResult.setBounds(270, 130, 46, 14);
- contentPane.add(lblCargotypeResult);
- lblErrorLabel = new JLabel("");
- lblErrorLabel.setFont(new Font("Verdana", Font.ITALIC, 10));
- lblErrorLabel.setForeground(Color.RED);
- lblErrorLabel.setBounds(10, 312, 219, 14);
- contentPane.add(lblErrorLabel);
- lblEmptyWeight = new JLabel("Empty Weight:");
- lblEmptyWeight.setFont(new Font("Verdana", Font.PLAIN, 10));
- lblEmptyWeight.setBounds(232, 218, 89, 16);
- contentPane.add(lblEmptyWeight);
- lblOrderId = new JLabel("");
- lblOrderId.setFont(new Font("Verdana", Font.BOLD | Font.ITALIC, 10));
- lblOrderId.setBounds(276, 69, 62, 16);
- contentPane.add(lblOrderId);
- lblSuborderinfo = new JLabel("Information:");
- lblSuborderinfo.setFont(new Font("Verdana", Font.BOLD, 10));
- lblSuborderinfo.setBounds(182, 87, 98, 16);
- contentPane.add(lblSuborderinfo);
- lblLicensePlate = new JLabel("License Plate:");
- lblLicensePlate.setFont(new Font("Verdana", Font.PLAIN, 10));
- lblLicensePlate.setBounds(10, 258, 98, 14);
- contentPane.add(lblLicensePlate);
- lblCustomer = new JLabel("Customer:");
- lblCustomer.setFont(new Font("Verdana", Font.PLAIN, 10));
- lblCustomer.setBounds(182, 101, 80, 14);
- contentPane.add(lblCustomer);
- lblCustomerResult = new JLabel("N/A");
- lblCustomerResult.setFont(new Font("Verdana", Font.ITALIC, 10));
- lblCustomerResult.setBounds(270, 101, 46, 14);
- contentPane.add(lblCustomerResult);
- // TEXTFIELDS
- txtSuborderID = new JTextField();
- txtSuborderID
- .setToolTipText("Please enter the Suborder IDs here. You can only enter one ID at a time");
- txtSuborderID.setBounds(10, 30, 160, 28);
- contentPane.add(this.txtSuborderID);
- txtSuborderID.setColumns(10);
- txtPhoneNumber = new JTextField();
- txtPhoneNumber.setToolTipText("Please enter phonenumber here");
- txtPhoneNumber.setBounds(10, 234, 111, 20);
- contentPane.add(txtPhoneNumber);
- txtPhoneNumber.setColumns(10);
- txtHours = new JTextField();
- txtHours.setToolTipText("Please enter the amount of hours");
- txtHours.setBounds(133, 234, 27, 20);
- contentPane.add(txtHours);
- txtHours.setColumns(10);
- txtEmptyWeight = new JTextField();
- txtEmptyWeight.setBounds(232, 234, 79, 20);
- contentPane.add(txtEmptyWeight);
- txtEmptyWeight.setColumns(10);
- txtLicensePlate = new JTextField();
- txtLicensePlate.setBounds(10, 274, 114, 20);
- contentPane.add(txtLicensePlate);
- txtLicensePlate.setColumns(10);
- txtMinutes = new JTextField();
- txtMinutes.setToolTipText("Please enter the amount of minutes");
- txtMinutes.setBounds(168, 234, 35, 20);
- contentPane.add(txtMinutes);
- txtMinutes.setColumns(10);
- // SEPERATORS
- separator = new JSeparator();
- separator.setBounds(10, 83, 302, 2);
- contentPane.add(separator);
- separator_1 = new JSeparator();
- separator_1.setBounds(10, 214, 302, 2);
- contentPane.add(separator_1);
- separator_2 = new JSeparator();
- separator_2.setBounds(10, 298, 311, 2);
- contentPane.add(separator_2);
- // BUTTONS
- btnAddSuborder = new JButton("Get Order(s)");
- btnAddSuborder.setFont(new Font("Verdana", Font.BOLD, 10));
- btnAddSuborder.addActionListener(controller);
- btnAddSuborder.setBounds(182, 30, 132, 28);
- contentPane.add(this.btnAddSuborder);
- btnConfirm = new JButton("Confirm");
- btnConfirm.setMnemonic('C');
- btnConfirm.addActionListener(controller);
- btnConfirm.setFont(new Font("Tahoma", Font.BOLD, 11));
- btnConfirm.setBounds(225, 308, 89, 23);
- contentPane.add(btnConfirm);
- // LISTS AND SCROLLPANES
- lstSuborders = new JList<Suborder>();
- lstSuborders.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- lstSuborders.addListSelectionListener(controller);
- scpSuborders = new JScrollPane(lstSuborders);
- scpSuborders.setBounds(10, 90, 160, 100);
- contentPane.add(scpSuborders);
- }
- private class Controller implements ActionListener, ListSelectionListener {
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == btnAddSuborder) {
- lblErrorLabel.setText("");
- String suborderId = txtSuborderID.getText();
- Suborder so = Service.getSuborder(suborderId);
- if (so == null) {
- lblErrorLabel
- .setText("There is no Suborder with the specific ID");
- } else if (so.getLoading() != null) {
- lblErrorLabel
- .setText("The loading has already been created");
- } else if (enteredSuborders.contains(so)) {
- lblErrorLabel.setText("The Suborder is already entered");
- } else {
- enteredSuborders.add(so);
- txtSuborderID.setText("");
- System.out.println(enteredSuborders);
- lstSuborders.setListData(enteredSuborders
- .toArray(new Suborder[0]));
- }
- }
- if (e.getSource() == btnConfirm) {
- if (enteredSuborders.size() == 0) {
- lblErrorLabel.setText("No Suborder(s) have been selected!");
- } else {
- String phoneNumber = txtPhoneNumber.getText();
- Driver driver = Service
- .getDriver(phoneNumber);
- if (driver == null) {
- lblErrorLabel
- .setText("The driver does not exists!");
- } else {
- Calendar cal = Calendar.getInstance();
- cal.setTime(new Date());
- if (txtHours.getText().length() == 0) {
- lblErrorLabel
- .setText("You must inform of your hours of rest");
- } else {
- int earliestTimeOfNoticeHours = Integer
- .parseInt(txtHours.getText());
- if (txtMinutes.getText().length() == 0) {
- lblErrorLabel
- .setText("You must inform of your hours of rest");
- } else {
- int earliestTimeOfNoticeMinutes = Integer
- .parseInt(txtMinutes.getText());
- cal.add(Calendar.HOUR, earliestTimeOfNoticeHours);
- cal.add(Calendar.MINUTE,
- earliestTimeOfNoticeMinutes);
- Date earliestTimeOfNotice = cal.getTime();
- String emptyweight = txtEmptyWeight.getText();
- if (txtEmptyWeight.getText().length() == 0) {
- lblErrorLabel
- .setText("Empty weight is a requirement!");
- } else {
- double inWeight = Double
- .parseDouble(emptyweight);
- String licensePlate = txtLicensePlate.getText();
- if (licensePlate.length() == 0) {
- lblErrorLabel
- .setText("A license plate for the trailer is required");
- } else {
- Trailer trailer = Service
- .getTrailer(licensePlate);
- if (trailer != null) {
- lblErrorLabel
- .setText("This trailer is already assigned to a suborder");
- } else {
- Loading loading = Service
- .createLoading(
- inWeight,
- earliestTimeOfNotice,
- trailer, driver,
- enteredSuborders);
- int ramp = loading.getRamp()
- .getRampNumber();
- if (loading.getRamp()
- .getLoadingQueue().size() > 0) {
- JOptionPane
- .showMessageDialog(
- TruckDriverArrivalFrame.this,
- "Welcome to Danish Crown. Please go to the parking lot");
- } else {
- JOptionPane
- .showMessageDialog(
- TruckDriverArrivalFrame.this,
- "Welcome to Danish Crown. Please go to ramp "
- + ramp);
- }
- System.out.println(loading);
- TruckDriverArrivalFrame.this
- .dispose();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- public void valueChanged(ListSelectionEvent e) {
- if (e.getSource() == lstSuborders) {
- if (!e.getValueIsAdjusting()
- && lstSuborders.getSelectedIndex() != -1) {
- lblCustomerResult.setText(lstSuborders.getSelectedValue()
- .getOrder().getCustomer().getCompanyName());
- lblGrossWeightResult.setText(""
- + lstSuborders.getSelectedValue().getWeight());
- lblOrderId.setText(lstSuborders.getSelectedValue()
- .getOrder().getOrderid());
- lblCargotypeResult.setText(""
- + lstSuborders.getSelectedValue().getCargoType());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement