GUI_History (#29)
This commit is contained in:
parent
61f3fd63bd
commit
b9c0de4470
@ -100,6 +100,7 @@ class State implements Serializable {
|
||||
|
||||
private ArrayList<Campaign> listOfCampaigns;
|
||||
private ArrayList<Vehicle> listOfVehicles;
|
||||
private ArrayList<Campaign>[] campPerDistrict;
|
||||
private Route[] stdRoutes;
|
||||
private Street[] stdStreet;
|
||||
private Date allArrivedToArafatTime;
|
||||
@ -108,6 +109,7 @@ class State implements Serializable {
|
||||
|
||||
public State(ArrayList<Campaign> listOfCampaigns,
|
||||
ArrayList<Vehicle> listOfVehicles,
|
||||
ArrayList<Campaign>[] campPerDistrict,
|
||||
Route[] stdRoutes,
|
||||
Street[] stdStreet,
|
||||
Date allArrivedToArafatTime,
|
||||
@ -116,6 +118,7 @@ class State implements Serializable {
|
||||
//Make clones since values may change if this is running on a thread.
|
||||
this.listOfCampaigns = (ArrayList<Campaign>) listOfCampaigns.clone();
|
||||
this.listOfVehicles = (ArrayList<Vehicle>) listOfVehicles.clone();
|
||||
this.campPerDistrict = (ArrayList<Campaign>[])campPerDistrict.clone();
|
||||
this.stdRoutes = stdRoutes.clone();
|
||||
this.stdStreet = stdStreet.clone();
|
||||
if (allArrivedToArafatTime != null) {
|
||||
@ -135,7 +138,11 @@ class State implements Serializable {
|
||||
return listOfVehicles;
|
||||
}
|
||||
|
||||
public Route[] getStdRoutes() {
|
||||
public ArrayList<Campaign>[] getCampPerDistrict() {
|
||||
return campPerDistrict;
|
||||
}
|
||||
|
||||
public Route[] getStdRoutes() {
|
||||
return stdRoutes;
|
||||
}
|
||||
|
||||
|
@ -1,43 +1,368 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.UIManager;
|
||||
import java.awt.SystemColor;
|
||||
|
||||
public class GUI_History {
|
||||
|
||||
private static JFrame frame;
|
||||
private List<State> states;
|
||||
private ArrayList<Campaign> listOfCampaigns;
|
||||
private ArrayList<Vehicle> listOfVehicles;
|
||||
private ArrayList<Campaign>[] campPerDistrict;
|
||||
private Route[] stdRoutes;
|
||||
private Street[] stdStreet;
|
||||
private Date currenttimeManager;
|
||||
private JFrame frame;
|
||||
private JTable streetTable;
|
||||
private JTable districtTable;
|
||||
private JLabel lblDate;
|
||||
private JLabel lblDestination;
|
||||
private JLabel lblNumOfBuses;
|
||||
private JLabel lblNumOfDonebuses;
|
||||
private JLabel lblMaximumTripValue;
|
||||
private JLabel lblMinimumTripValue;
|
||||
private JLabel lblBusesArrivedInTheLastHourValue;
|
||||
private JLabel lblAverageTripForLastHourValue;
|
||||
private JLabel lblAverageTimeForTheTrip;
|
||||
private Object[][] streetData;
|
||||
private String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses",
|
||||
"Local Vehicles","Avg. Time"};
|
||||
|
||||
public GUI_History(List<State> states) {
|
||||
this.states = states;
|
||||
initialize();
|
||||
makeFrame();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
private void makeFrame() {
|
||||
setData(states.get(0));
|
||||
frame = new JFrame("History");
|
||||
frame.setBounds(200, 150, 1386, 731);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.getContentPane().setBackground(new Color(70, 70, 70));
|
||||
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
||||
frame.getContentPane().setLayout(null);
|
||||
frame.revalidate();
|
||||
frame.setAutoRequestFocus(false);
|
||||
frame.setVisible(true);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBounds(10, 11, 1228, 727);
|
||||
frame.getContentPane().add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JComboBox<Date> comboBox = new JComboBox<Date>();
|
||||
comboBox.setBounds(453, 46, 302, 42);
|
||||
streetData = new Object[stdStreet.length][6];
|
||||
for (int i = 0; i < stdStreet.length; i++) {
|
||||
streetData[i][0] = stdStreet[i].getName().name();
|
||||
streetData[i][1] = stdStreet[i].getPercentRemainingCapacity();
|
||||
streetData[i][2] = stdStreet[i].getVehicles().size();
|
||||
streetData[i][3] = stdStreet[i].getNumberOfBuses();
|
||||
streetData[i][4] = stdStreet[i].getNumberOfLocalCars();
|
||||
streetData[i][5] = MakkahCity.avgTimeOnStreet(stdStreet[i]);
|
||||
}
|
||||
//District data
|
||||
Object[][] districtData = new Object[campPerDistrict.length][7];
|
||||
String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %",
|
||||
"Avg. Time", "Best time to Arafat", "Best time to District"};
|
||||
|
||||
for (int i = 0; i < campPerDistrict.length; i++) {
|
||||
districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name();
|
||||
districtData[i][1] = campPerDistrict[i].size();
|
||||
districtData[i][2] = MakkahCity.busesInDistrict(District.values()[i]);
|
||||
districtData[i][3] = MakkahCity.getPercentArrival(District.values()[i]);
|
||||
districtData[i][4] = MakkahCity.getAvgTimeOfTrip(District.values()[i]);
|
||||
districtData[i][5] = MakkahCity.getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus());
|
||||
districtData[i][6] = MakkahCity.getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus());
|
||||
}
|
||||
|
||||
//tables
|
||||
|
||||
//Street table
|
||||
streetTable = new JTable(streetData,streetColNames);
|
||||
streetTable.setEnabled(false);
|
||||
DefaultTableModel model = new DefaultTableModel();
|
||||
model.setColumnIdentifiers(streetColNames);
|
||||
streetTable.getTableHeader().setBackground(new Color(17,17,17));
|
||||
streetTable.getTableHeader().setForeground(Color.WHITE);
|
||||
streetTable.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||
streetTable.setBackground(new Color(17,17,17));
|
||||
streetTable.setForeground(Color.white);
|
||||
streetTable.setSelectionBackground(Color.RED);
|
||||
streetTable.setGridColor(new Color(102, 102, 102));
|
||||
streetTable.setSelectionForeground(Color.white);
|
||||
streetTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||
streetTable.setRowHeight(25);
|
||||
streetTable.setAutoCreateRowSorter(true);
|
||||
JScrollPane streetScroll = new JScrollPane(streetTable);
|
||||
streetScroll.setBounds(30,75,1140,329);
|
||||
frame.getContentPane().add(streetScroll);
|
||||
|
||||
//District table
|
||||
districtTable = new JTable(districtData,districtColNames);
|
||||
districtTable.setEnabled(false);
|
||||
districtTable.setForeground(new Color(255, 255, 255));
|
||||
districtTable.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||
districtTable.getTableHeader().setBackground(new Color(17,17,17));
|
||||
districtTable.getTableHeader().setForeground(Color.WHITE);
|
||||
districtTable.setBackground(new Color(17,17,17));
|
||||
districtTable.setSelectionBackground(Color.RED);
|
||||
model.setColumnIdentifiers(districtColNames);
|
||||
districtTable.setSelectionForeground(Color.white);
|
||||
districtTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||
districtTable.setGridColor(new Color(102, 102, 102));
|
||||
JScrollPane districtScroll = new JScrollPane(districtTable);
|
||||
districtScroll.setEnabled(false);
|
||||
districtTable.setAutoCreateRowSorter(true);
|
||||
districtTable.setRowHeight(25);
|
||||
districtTable.revalidate();
|
||||
districtScroll.setBounds(30,452,1140,105);
|
||||
frame.getContentPane().add(districtScroll);
|
||||
|
||||
JLabel lblStreets = new JLabel("Streets");
|
||||
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||
lblStreets.setForeground(new Color(255, 255, 255));
|
||||
lblStreets.setBounds(30, 44, 208, 30);
|
||||
frame.getContentPane().add(lblStreets);
|
||||
|
||||
JLabel lblDistrict = new JLabel("District");
|
||||
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||
lblDistrict.setForeground(new Color(255, 255, 255));
|
||||
lblDistrict.setBounds(30, 425, 166, 29);
|
||||
frame.getContentPane().add(lblDistrict);
|
||||
|
||||
JLabel lblTime = new JLabel("Time:");
|
||||
lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblTime.setForeground(new Color(255, 255, 255));
|
||||
lblTime.setBounds(50, 11, 72, 14);
|
||||
frame.getContentPane().add(lblTime);
|
||||
|
||||
JLabel lblStatus = new JLabel("Status:");
|
||||
lblStatus.setForeground(new Color(255, 255, 255));
|
||||
lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblStatus.setBounds(423, 9, 72, 18);
|
||||
frame.getContentPane().add(lblStatus);
|
||||
|
||||
lblDestination = new JLabel();
|
||||
lblDestination.setForeground(new Color(255, 255, 255));
|
||||
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblDestination.setBounds(477, 9, 184, 18);
|
||||
frame.getContentPane().add(lblDestination);
|
||||
|
||||
lblDate = new JLabel(currenttimeManager.toString());
|
||||
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblDate.setForeground(Color.WHITE);
|
||||
lblDate.setBounds(100, 8, 326, 21);
|
||||
frame.getContentPane().add(lblDate);
|
||||
|
||||
JLabel lblBuses = new JLabel("Buses: ");
|
||||
lblBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblBuses.setForeground(new Color(255, 255, 255));
|
||||
lblBuses.setBackground(new Color(192, 192, 192));
|
||||
lblBuses.setBounds(30, 578, 56, 14);
|
||||
frame.getContentPane().add(lblBuses);
|
||||
|
||||
lblNumOfBuses = new JLabel();
|
||||
lblNumOfBuses.setText("0");
|
||||
lblNumOfBuses.setBackground(new Color(0, 0, 0));
|
||||
lblNumOfBuses.setForeground(new Color(255, 255, 255));
|
||||
lblNumOfBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblNumOfBuses.setBounds(79, 579, 90, 12);
|
||||
frame.getContentPane().add(lblNumOfBuses);
|
||||
|
||||
JLabel lblBusesDone = new JLabel("Buses Done:");
|
||||
lblBusesDone.setForeground(new Color(255, 255, 255));
|
||||
lblBusesDone.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblBusesDone.setBounds(169, 579, 101, 12);
|
||||
frame.getContentPane().add(lblBusesDone);
|
||||
|
||||
lblNumOfDonebuses = new JLabel();
|
||||
lblNumOfDonebuses.setText("0");
|
||||
lblNumOfDonebuses.setForeground(new Color(255, 255, 255));
|
||||
lblNumOfDonebuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblNumOfDonebuses.setBounds(259, 577, 80, 16);
|
||||
frame.getContentPane().add(lblNumOfDonebuses);
|
||||
|
||||
JLabel lblMaximumTrip = new JLabel("Maximum Trip:");
|
||||
lblMaximumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblMaximumTrip.setForeground(new Color(255, 255, 255));
|
||||
lblMaximumTrip.setBounds(30, 619, 112, 22);
|
||||
frame.getContentPane().add(lblMaximumTrip);
|
||||
|
||||
lblMaximumTripValue = new JLabel();
|
||||
lblMaximumTripValue.setText("-:--");
|
||||
lblMaximumTripValue.setForeground(new Color(255, 255, 255));
|
||||
lblMaximumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblMaximumTripValue.setBounds(150, 621, 46, 18);
|
||||
frame.getContentPane().add(lblMaximumTripValue);
|
||||
|
||||
JLabel lblMinimumTrip = new JLabel("MinimumTrip:");
|
||||
lblMinimumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblMinimumTrip.setForeground(Color.WHITE);
|
||||
lblMinimumTrip.setBounds(30, 655, 112, 18);
|
||||
frame.getContentPane().add(lblMinimumTrip);
|
||||
|
||||
lblMinimumTripValue = new JLabel("-:--");
|
||||
lblMinimumTripValue.setForeground(Color.WHITE);
|
||||
lblMinimumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblMinimumTripValue.setBounds(139, 657, 46, 14);
|
||||
frame.getContentPane().add(lblMinimumTripValue);
|
||||
|
||||
JLabel lblBusesArrivedInTheLastHour = new JLabel("Buses Arrived In The Last Hour:");
|
||||
lblBusesArrivedInTheLastHour.setForeground(Color.WHITE);
|
||||
lblBusesArrivedInTheLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblBusesArrivedInTheLastHour.setBounds(360, 578, 237, 14);
|
||||
frame.getContentPane().add(lblBusesArrivedInTheLastHour);
|
||||
|
||||
lblBusesArrivedInTheLastHourValue = new JLabel();
|
||||
lblBusesArrivedInTheLastHourValue.setText("0");
|
||||
lblBusesArrivedInTheLastHourValue.setForeground(Color.WHITE);
|
||||
lblBusesArrivedInTheLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblBusesArrivedInTheLastHourValue.setBounds(594, 578, 90, 14);
|
||||
frame.getContentPane().add(lblBusesArrivedInTheLastHourValue);
|
||||
|
||||
JLabel lblAverageTripForLastHour = new JLabel("Average Trip For Last Hour:");
|
||||
lblAverageTripForLastHour.setForeground(Color.WHITE);
|
||||
lblAverageTripForLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblAverageTripForLastHour.setBackground(Color.BLACK);
|
||||
lblAverageTripForLastHour.setBounds(206, 621, 208, 18);
|
||||
frame.getContentPane().add(lblAverageTripForLastHour);
|
||||
|
||||
lblAverageTripForLastHourValue = new JLabel("(No Arrivals) In Last Hour");
|
||||
lblAverageTripForLastHourValue.setForeground(Color.WHITE);
|
||||
lblAverageTripForLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblAverageTripForLastHourValue.setBounds(423, 621, 216, 18);
|
||||
frame.getContentPane().add(lblAverageTripForLastHourValue);
|
||||
|
||||
JLabel lblAvgTime = new JLabel("Average Time For The Trip:");
|
||||
lblAvgTime.setForeground(Color.WHITE);
|
||||
lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblAvgTime.setBounds(206, 650, 208, 29);
|
||||
frame.getContentPane().add(lblAvgTime);
|
||||
|
||||
lblAverageTimeForTheTrip = new JLabel("-:--");
|
||||
lblAverageTimeForTheTrip.setForeground(Color.WHITE);
|
||||
lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblAverageTimeForTheTrip.setBounds(423, 657, 101, 14);
|
||||
frame.getContentPane().add(lblAverageTimeForTheTrip);
|
||||
|
||||
JButton btnViewRoutes = new JButton("View Routes");
|
||||
btnViewRoutes.setBounds(1195, 75, 166, 30);
|
||||
btnViewRoutes.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
btnViewRoutes.setBackground(new Color(9,9,9));
|
||||
btnViewRoutes.setForeground(Color.white);
|
||||
btnViewRoutes.addActionListener(e -> {
|
||||
GUI_ViewRoute r = new GUI_ViewRoute(stdRoutes ,listOfCampaigns, currenttimeManager);
|
||||
});
|
||||
frame.getContentPane().add(btnViewRoutes);
|
||||
|
||||
JButton btnViewBuses = new JButton("View Buses");
|
||||
btnViewBuses.setBounds(1195, 130, 166, 30);
|
||||
btnViewBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
btnViewBuses.setBackground(new Color(9,9,9));
|
||||
btnViewBuses.setForeground(Color.white);
|
||||
btnViewBuses.addActionListener(e -> {
|
||||
GUI_ViewBuses t = new GUI_ViewBuses(listOfCampaigns , currenttimeManager);
|
||||
});
|
||||
frame.getContentPane().add(btnViewBuses);
|
||||
|
||||
JButton btnViewStreet = new JButton("View Street");
|
||||
btnViewStreet.setBounds(1195, 185, 166, 29);
|
||||
btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
btnViewStreet.setBackground(new Color(9,9,9));
|
||||
btnViewStreet.setForeground(Color.white);
|
||||
btnViewStreet.addActionListener(e -> {
|
||||
GUI_ViewStreet t = new GUI_ViewStreet(stdStreet,currenttimeManager);
|
||||
});
|
||||
frame.getContentPane().add(btnViewStreet);
|
||||
|
||||
JComboBox comboBox = new JComboBox<Date>();
|
||||
comboBox.setBackground(new Color(150, 150 , 150));
|
||||
comboBox.setBounds(1143, 11, 217, 33);
|
||||
for (State state : states) {
|
||||
comboBox.addItem(state.getStateTime());
|
||||
}
|
||||
panel.add(comboBox);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.revalidate();
|
||||
frame.setLocation(200,150);
|
||||
frame.setBounds(200, 150, 1400, 720);
|
||||
frame.setAutoRequestFocus(false);
|
||||
frame.setVisible(true);
|
||||
comboBox.addActionListener(e ->{
|
||||
setData(states.get(comboBox.getSelectedIndex()));
|
||||
updateFrame();
|
||||
});
|
||||
frame.getContentPane().add(comboBox);
|
||||
updateFrame();
|
||||
}
|
||||
|
||||
public void setData(State state) {
|
||||
listOfCampaigns = state.getListOfCampaigns();
|
||||
listOfVehicles = state.getListOfVehicles();
|
||||
campPerDistrict = state.getCampPerDistrict();
|
||||
stdRoutes = state.getStdRoutes();
|
||||
stdStreet = state.getStdStreet();
|
||||
currenttimeManager = state.getStateTime();
|
||||
}
|
||||
|
||||
public void updateFrame() {
|
||||
streetData = new Object[stdStreet.length][6];
|
||||
for (int i = 0; i < stdStreet.length; i++) {
|
||||
streetData[i][0] = stdStreet[i].getName().name();
|
||||
streetData[i][1] = stdStreet[i].getPercentRemainingCapacity();
|
||||
streetData[i][2] = stdStreet[i].getVehicles().size();
|
||||
streetData[i][3] = stdStreet[i].getNumberOfBuses();
|
||||
streetData[i][4] = stdStreet[i].getNumberOfLocalCars();
|
||||
streetData[i][5] = MakkahCity.avgTimeOnStreet(stdStreet[i]);
|
||||
}
|
||||
streetTable.setModel(new DefaultTableModel(streetData ,streetColNames));
|
||||
|
||||
Object[][] districtData = new Object[campPerDistrict.length][7];
|
||||
for (int i = 0; i < campPerDistrict.length; i++) {
|
||||
districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name();
|
||||
districtData[i][1] = campPerDistrict[i].size();
|
||||
districtData[i][2] = MakkahCity.busesInDistrict(District.values()[i]);
|
||||
districtData[i][3] = MakkahCity.getPercentArrival(District.values()[i]);
|
||||
districtData[i][4] = MakkahCity.getAvgTimeOfTrip(District.values()[i]);
|
||||
districtData[i][5] = MakkahCity.getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus());
|
||||
districtData[i][6] = MakkahCity.getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus());
|
||||
}
|
||||
for (int i = 0; i < districtData.length; i++) {
|
||||
for (int j = 0; j < districtData[i].length; j++) {
|
||||
districtTable.setValueAt(districtData[i][j], i, j);
|
||||
}
|
||||
}
|
||||
lblDate.setText(currenttimeManager.toString());
|
||||
|
||||
String status = "";
|
||||
if (currenttimeManager.getDay() == 9) {
|
||||
status = "Heading to Arafat";
|
||||
}
|
||||
else{
|
||||
status = "Heading to Hotels";
|
||||
}
|
||||
lblDestination.setText(status);
|
||||
|
||||
int numberOfBusses = 0;
|
||||
for (Campaign campaign : listOfCampaigns) {
|
||||
numberOfBusses += campaign.getNumberOfBusses();
|
||||
}
|
||||
String bus = String.format("%d", numberOfBusses);
|
||||
lblNumOfBuses.setText(bus);
|
||||
|
||||
String numOfdoneBuses = String.format("%d",MakkahCity.getNumberOfArrivedBusses());
|
||||
lblNumOfDonebuses.setText(numOfdoneBuses);
|
||||
|
||||
if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) {
|
||||
lblMaximumTripValue.setText(Vehicle.getMaxArrived().getTripTime().toString());
|
||||
lblMinimumTripValue.setText(Vehicle.getMinArrived().getTripTime().toString());
|
||||
}
|
||||
|
||||
String NumberOfBussPerHour = String.format("%d", MakkahCity.getNumberOfArrivedBussesPerHour());
|
||||
lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour);
|
||||
|
||||
lblAverageTripForLastHourValue.setText(MakkahCity.avgTimeOfTrip());
|
||||
lblAverageTimeForTheTrip.setText(MakkahCity.getAvgTripForAllDis());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,20 +18,20 @@ import javax.swing.JTextPane;
|
||||
|
||||
public class GUI_ViewBuses {
|
||||
|
||||
private static JFrame frame;
|
||||
private static ArrayList<Vehicle> vehicles = new ArrayList<>();
|
||||
private static ArrayList<Vehicle> vehiclesAlazizya = new ArrayList<>();
|
||||
private static ArrayList<Vehicle> vehiclesAlhijra = new ArrayList<>();
|
||||
private static ArrayList<Vehicle> vehiclesAlmansoor = new ArrayList<>();
|
||||
private static PDate currenttimeManager;
|
||||
private static JTable table;
|
||||
private static Object[][] busData;
|
||||
private static String[] busColNames = {"ID", "Street", "location","Progress", "trip time", "Arrive Time"};
|
||||
private static JButton Alazizya;
|
||||
private static JButton Alhijra;
|
||||
private static JButton Almansoor;
|
||||
private static JLabel lblTime;
|
||||
private static JLabel lblDate;
|
||||
private JFrame frame;
|
||||
private ArrayList<Vehicle> vehicles = new ArrayList<>();
|
||||
private ArrayList<Vehicle> vehiclesAlazizya = new ArrayList<>();
|
||||
private ArrayList<Vehicle> vehiclesAlhijra = new ArrayList<>();
|
||||
private ArrayList<Vehicle> vehiclesAlmansoor = new ArrayList<>();
|
||||
private Date currenttimeManager;
|
||||
private JTable table;
|
||||
private Object[][] busData;
|
||||
private String[] busColNames = {"ID", "Street", "location","Progress", "trip time", "Arrive Time"};
|
||||
private JButton Alazizya;
|
||||
private JButton Alhijra;
|
||||
private JButton Almansoor;
|
||||
private JLabel lblTime;
|
||||
private JLabel lblDate;
|
||||
private JLabel lblStatus;
|
||||
private JLabel lblDestination;
|
||||
private JLabel lblDistrict;
|
||||
@ -39,7 +39,7 @@ public class GUI_ViewBuses {
|
||||
private JTextPane textPane;
|
||||
|
||||
|
||||
public GUI_ViewBuses(ArrayList<Campaign> campaign , PDate currenttimeManager) {
|
||||
public GUI_ViewBuses(ArrayList<Campaign> campaign , Date currenttimeManager) {
|
||||
for (Campaign camp : campaign) {
|
||||
switch (camp.getHotelDistrict()) {
|
||||
case ALAZIZIYA:
|
||||
@ -62,20 +62,6 @@ public class GUI_ViewBuses {
|
||||
|
||||
private void makeFrame() {
|
||||
frame = new JFrame("Buses");
|
||||
busData = new Object[vehicles.size()][6];
|
||||
|
||||
for (int i = 0; i < vehicles.size(); i++) {
|
||||
busData[i][0] = vehicles.get(i).getUID();
|
||||
if (vehicles.get(i).isMoving())
|
||||
busData[i][1] = vehicles.get(i).getCurrentStreet().getName();
|
||||
else busData[i][1] = "Not Moving";
|
||||
busData[i][2] = vehicles.get(i).getCurrentLocation();
|
||||
busData[i][3] = vehicles.get(i).getProgress();
|
||||
busData[i][4] = vehicles.get(i).getTripTime();
|
||||
if (vehicles.get(i).isArrivedToDest())
|
||||
busData[i][5] = vehicles.get(i).getTimeOfArrival();//Formula of time
|
||||
else busData[i][5] = "NOT Arrived";
|
||||
}
|
||||
|
||||
table = new JTable(busData,busColNames);
|
||||
table.setColumnSelectionAllowed(true);
|
||||
@ -118,6 +104,7 @@ public class GUI_ViewBuses {
|
||||
Alazizya.setForeground(Color.white);
|
||||
Alazizya.setBounds(20, 366, 116, 23);
|
||||
Alazizya.addActionListener(e -> {
|
||||
if (vehiclesAlazizya.get(0).getRoute() != null)
|
||||
updateVehicles(vehiclesAlazizya);
|
||||
});
|
||||
frame.getContentPane().add(Alazizya);
|
||||
@ -128,6 +115,7 @@ public class GUI_ViewBuses {
|
||||
Alhijra.setForeground(Color.white);
|
||||
Alhijra.setBounds(20, 269, 116, 23);
|
||||
Alhijra.addActionListener(e -> {
|
||||
if (vehiclesAlhijra.get(0).getRoute() != null)
|
||||
updateVehicles(vehiclesAlhijra);
|
||||
});
|
||||
frame.getContentPane().add(Alhijra);
|
||||
@ -138,6 +126,7 @@ public class GUI_ViewBuses {
|
||||
Almansoor.setForeground(Color.white);
|
||||
Almansoor.setBounds(20, 316, 116, 23);
|
||||
Almansoor.addActionListener(e -> {
|
||||
if (vehiclesAlmansoor.get(0).getRoute() != null)
|
||||
updateVehicles(vehiclesAlmansoor);
|
||||
});
|
||||
frame.getContentPane().add(Almansoor);
|
||||
@ -154,7 +143,7 @@ public class GUI_ViewBuses {
|
||||
lblStatus.setBounds(180, 317, 72, 18);
|
||||
frame.getContentPane().add(lblStatus);
|
||||
|
||||
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
|
||||
lblDate = new JLabel(currenttimeManager.toString());
|
||||
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblDate.setForeground(Color.WHITE);
|
||||
lblDate.setBounds(235, 270, 326, 21);
|
||||
@ -165,7 +154,7 @@ public class GUI_ViewBuses {
|
||||
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblDestination.setBounds(235, 317, 184, 18);
|
||||
frame.getContentPane().add(lblDestination);
|
||||
if (currenttimeManager.getCurrentCalendar().get(Calendar.DAY_OF_MONTH) == 9)
|
||||
if (currenttimeManager.getMonth() == 9)
|
||||
lblDestination.setText("Heading to Arafat");
|
||||
else lblDestination.setText("Heading to Hotels");
|
||||
|
||||
@ -221,7 +210,7 @@ public class GUI_ViewBuses {
|
||||
vehicles.clear();
|
||||
vehicles.addAll(vehiclesDistrict);
|
||||
lblDistrictValue.setText(((Bus)vehiclesDistrict.get(0)).getCampaign().getHotelDistrict().name());
|
||||
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
||||
lblDate.setText(currenttimeManager.toString());
|
||||
updateTable();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.util.Date;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
@ -20,13 +21,13 @@ public class GUI_ViewRoute {
|
||||
private Object[][] routeData;
|
||||
private JTable table;
|
||||
private Route[] stdRoute;
|
||||
private PDate currenttimeManager;
|
||||
private Date currenttimeManager;
|
||||
private ArrayList<Campaign> listOfCampaigns;
|
||||
private JTextField txtStreets;
|
||||
private JLabel lblDate;
|
||||
private JLabel lblTime;
|
||||
|
||||
public GUI_ViewRoute(Route[] stdRoute, ArrayList<Campaign> listOfCampaigns, PDate currenttimeManager) {
|
||||
public GUI_ViewRoute(Route[] stdRoute, ArrayList<Campaign> listOfCampaigns, Date currenttimeManager) {
|
||||
this.stdRoute = stdRoute;
|
||||
this.listOfCampaigns = listOfCampaigns;
|
||||
this.currenttimeManager = currenttimeManager;
|
||||
@ -108,7 +109,7 @@ public class GUI_ViewRoute {
|
||||
lblTime.setBounds(10, 11, 72, 20);
|
||||
frame.getContentPane().add(lblTime);
|
||||
|
||||
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
|
||||
lblDate = new JLabel(currenttimeManager.toString());
|
||||
lblDate.setForeground(Color.WHITE);
|
||||
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblDate.setBounds(61, 11, 326, 20);
|
||||
|
@ -1,8 +1,7 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.util.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
@ -20,7 +19,7 @@ public class GUI_ViewStreet {
|
||||
private Street street;
|
||||
private ArrayList<Vehicle> vehicles = new ArrayList<>();
|
||||
private Street[] stdStreet = new Street[StreetNames.values().length];
|
||||
private PDate currenttimeManager;
|
||||
private Date currenttimeManager;
|
||||
private Object[][] vehicleData;
|
||||
private String[] vehicleColNames = {"ID", "District", "location","Progress", "trip time"};
|
||||
private JTable table;
|
||||
@ -33,9 +32,9 @@ public class GUI_ViewStreet {
|
||||
private JTextField[] textFieldArray = new JTextField[20];
|
||||
private JTextField txtHigh;
|
||||
|
||||
public GUI_ViewStreet(Street[] streets, PDate currenttimeManager) {
|
||||
public GUI_ViewStreet(Street[] streets, Date currenttimeManager) {
|
||||
stdStreet = streets.clone();
|
||||
this.currenttimeManager = (PDate) currenttimeManager.clone();
|
||||
this.currenttimeManager = (Date) currenttimeManager.clone();
|
||||
makeFrame();
|
||||
}
|
||||
|
||||
@ -106,7 +105,7 @@ public class GUI_ViewStreet {
|
||||
textFieldArray[i].setBackground(new Color(255,colorFactor,0));
|
||||
}
|
||||
lblCapcityValue.setText(String.format("%%%d", street.getPercentRemainingCapacity()));
|
||||
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
||||
lblDate.setText(currenttimeManager.toString());
|
||||
lblNumVehicles.setText(String.format("%d", street.getVehicles().size()));
|
||||
lblLengthValue.setText(String.format("%.2f", street.getLength()));
|
||||
lblLanesValue.setText(String.format("%d", street.getNumberOfLanes()));
|
||||
@ -142,7 +141,7 @@ public class GUI_ViewStreet {
|
||||
lblTime.setBounds(193, 11, 72, 20);
|
||||
frame.getContentPane().add(lblTime);
|
||||
|
||||
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
|
||||
lblDate = new JLabel(currenttimeManager.toString());
|
||||
lblDate.setForeground(Color.WHITE);
|
||||
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblDate.setBounds(243, 11, 326, 20);
|
||||
@ -158,7 +157,7 @@ public class GUI_ViewStreet {
|
||||
lblDestination.setForeground(Color.WHITE);
|
||||
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||
lblDestination.setBounds(568, 11, 184, 20);
|
||||
if (currenttimeManager.getCurrentCalendar().get(Calendar.DAY_OF_MONTH) == 9)
|
||||
if (currenttimeManager.getMonth() == 9)
|
||||
lblDestination.setText("Heading to Arafat");
|
||||
else lblDestination.setText("Heading to Hotels");
|
||||
frame.getContentPane().add(lblDestination);
|
||||
|
@ -160,7 +160,7 @@ public class MakkahCity {
|
||||
btnViewRoutes.setBackground(new Color(9,9,9));
|
||||
btnViewRoutes.setForeground(Color.white);
|
||||
btnViewRoutes.addActionListener(e -> {
|
||||
GUI_ViewRoute r = new GUI_ViewRoute(stdRoutes ,listOfCampaigns, currenttimeManager);
|
||||
GUI_ViewRoute r = new GUI_ViewRoute(stdRoutes ,listOfCampaigns,currenttimeManager.getCurrentTime());
|
||||
pause_flag = true;
|
||||
btnPause.setText("Unpause");
|
||||
});
|
||||
@ -170,7 +170,7 @@ public class MakkahCity {
|
||||
btnViewBuses.setBackground(new Color(9,9,9));
|
||||
btnViewBuses.setForeground(Color.white);
|
||||
btnViewBuses.addActionListener(e -> {
|
||||
GUI_ViewBuses t = new GUI_ViewBuses(listOfCampaigns , currenttimeManager);
|
||||
GUI_ViewBuses t = new GUI_ViewBuses(listOfCampaigns , currenttimeManager.getCurrentTime());
|
||||
pause_flag = true;
|
||||
btnPause.setText("Unpause");
|
||||
});
|
||||
@ -187,7 +187,7 @@ public class MakkahCity {
|
||||
btnViewStreet.setBackground(new Color(9,9,9));
|
||||
btnViewStreet.setForeground(Color.white);
|
||||
btnViewStreet.addActionListener(e -> {
|
||||
GUI_ViewStreet t = new GUI_ViewStreet(stdStreet,currenttimeManager);
|
||||
GUI_ViewStreet t = new GUI_ViewStreet(stdStreet,currenttimeManager.getCurrentTime());
|
||||
pause_flag = true;
|
||||
btnPause.setText("Unpause");
|
||||
});
|
||||
@ -222,6 +222,8 @@ public class MakkahCity {
|
||||
btnBrowseHistory.setForeground(Color.white);
|
||||
btnBrowseHistory.addActionListener(e -> {
|
||||
GUI_History hist = new GUI_History(dataManeger.getStates());
|
||||
pause_flag = true;
|
||||
btnPause.setText("Unpause");
|
||||
});
|
||||
|
||||
//Label
|
||||
@ -975,7 +977,7 @@ public class MakkahCity {
|
||||
return sortingRoute;
|
||||
}
|
||||
|
||||
private static Route getShortestRoute(Campaign campaign, Mashier mashier) {
|
||||
public static Route getShortestRoute(Campaign campaign, Mashier mashier) {
|
||||
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
|
||||
Route route = null;
|
||||
double min = Double.MAX_VALUE;
|
||||
@ -1066,7 +1068,7 @@ public class MakkahCity {
|
||||
* Calculate average trip time for last 10 minutes
|
||||
* @return "hh:mm"
|
||||
*/
|
||||
private static String avgTimeOfTrip() {
|
||||
public static String avgTimeOfTrip() {
|
||||
//TODO: does output diff value even after all have arrived.
|
||||
Calendar now = currenttimeManager.getCurrentCalendar();
|
||||
Calendar from = (GregorianCalendar)now.clone();
|
||||
@ -1090,7 +1092,7 @@ public class MakkahCity {
|
||||
return String.format("%2d:%02d", hours, minutes);
|
||||
}
|
||||
|
||||
private static int getPercentArrival(District district) {
|
||||
public static int getPercentArrival(District district) {
|
||||
int sum = 0;
|
||||
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
||||
sum += campaign.getPercentArrived();
|
||||
@ -1098,7 +1100,7 @@ public class MakkahCity {
|
||||
return sum/campPerDistrict[district.ordinal()].size();
|
||||
}
|
||||
|
||||
private static String getAvgTimeOfTrip(District district){
|
||||
public static String getAvgTimeOfTrip(District district){
|
||||
int sum = 0;
|
||||
int counter = 1;
|
||||
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
||||
@ -1117,7 +1119,7 @@ public class MakkahCity {
|
||||
return String.format("%2d:%02d", hours,minutes);
|
||||
}
|
||||
|
||||
private static int getNumberOfArrivedBusses() {
|
||||
public static int getNumberOfArrivedBusses() {
|
||||
int num = 0;
|
||||
for (Campaign campaign : listOfCampaigns) {
|
||||
for (Vehicle vehicle : campaign.getVehicles()){
|
||||
@ -1128,7 +1130,7 @@ public class MakkahCity {
|
||||
return num;
|
||||
}
|
||||
|
||||
private static int getNumberOfArrivedBussesPerHour() {
|
||||
public static int getNumberOfArrivedBussesPerHour() {
|
||||
Calendar now = currenttimeManager.getCurrentCalendar();
|
||||
Calendar from = (GregorianCalendar)now.clone();
|
||||
from.roll(Calendar.HOUR, -1);
|
||||
@ -1190,7 +1192,7 @@ public class MakkahCity {
|
||||
return String.format("%02d:%02d", hours, minutes);
|
||||
}
|
||||
|
||||
private static int busesInDistrict(District district){
|
||||
public static int busesInDistrict(District district){
|
||||
int buses = 0;
|
||||
for (Campaign campaign : campPerDistrict[district.ordinal()]){
|
||||
buses += campaign.getNumberOfBusses();
|
||||
@ -1201,6 +1203,7 @@ public class MakkahCity {
|
||||
private static void saveState(){
|
||||
State s = new State(listOfCampaigns,
|
||||
listOfVehicles,
|
||||
campPerDistrict,
|
||||
stdRoutes,
|
||||
stdStreet,
|
||||
allArrivedToArafatTime,
|
||||
|
Loading…
Reference in New Issue
Block a user