Compare commits
24 Commits
browse-his
...
master
Author | SHA1 | Date | |
---|---|---|---|
e3e7bf5ccd | |||
b386665e66 | |||
5e1ff6451c | |||
5be16de49f | |||
f4bc812f23 | |||
f137b07c1e | |||
c07dc8a87c | |||
|
f30a64a5b5 | ||
|
dc12b51801 | ||
|
1745db8700 | ||
|
8085b5b951 | ||
|
b9c0de4470 | ||
|
61f3fd63bd | ||
d915e04832 | |||
|
67b313aabf | ||
|
7e50caf26a | ||
|
1db0ce7ca7 | ||
|
67c81d22d6 | ||
|
b3847bad78 | ||
|
9cbb063af0 | ||
a795117895 | |||
9cf847ad46 | |||
ab3acdec9b | |||
9a610b65e6 |
6
.classpath
Normal file
6
.classpath
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
@ -2,9 +2,6 @@
|
|||||||
<artifact type="jar" build-on-make="true" name="Hajj-simulation:jar">
|
<artifact type="jar" build-on-make="true" name="Hajj-simulation:jar">
|
||||||
<output-path>$PROJECT_DIR$/out/artifacts/Hajj_simulation_jar</output-path>
|
<output-path>$PROJECT_DIR$/out/artifacts/Hajj_simulation_jar</output-path>
|
||||||
<root id="archive" name="Hajj-simulation.jar">
|
<root id="archive" name="Hajj-simulation.jar">
|
||||||
<element id="directory" name="META-INF">
|
|
||||||
<element id="file-copy" path="$PROJECT_DIR$/out/META-INF/MANIFEST.MF" />
|
|
||||||
</element>
|
|
||||||
<element id="module-output" name="Hajj-simulation" />
|
<element id="module-output" name="Hajj-simulation" />
|
||||||
</root>
|
</root>
|
||||||
</artifact>
|
</artifact>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Hajj-simulation</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
14
package.sh
Executable file
14
package.sh
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
GIT=$(command -v git)
|
||||||
|
HEAD=$(command -v head)
|
||||||
|
CUT=$(command -v cut)
|
||||||
|
|
||||||
|
JAR_ARTIFACT="out/artifacts/Hajj_simulation_jar/Hajj-simulation.jar"
|
||||||
|
|
||||||
|
if [ -z $"GIT" ] || [ -z $"HEAD" ] || [ -z $"CUT" ]; then
|
||||||
|
echo "Tools missing"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
tar -cvf Hajj-Simulation-$(git log | head -n1 | cut -d' ' -f2).tar.gz $JAR_ARTIFACT run.sh
|
||||||
|
fi
|
9
run.sh
Executable file
9
run.sh
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
jav=$(command -v java)
|
||||||
|
|
||||||
|
if [ -z "$jav" ]; then
|
||||||
|
>&2 echo "Can't find java installation"
|
||||||
|
else
|
||||||
|
java -jar out/artifacts/Hajj_simulation_jar/Hajj-simulation.jar
|
||||||
|
fi
|
@ -33,7 +33,7 @@ public class Bus extends CivilVehicle {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
s.append(String.format("\nID: %s, Campaign ID: %s\n",this.getUID() , getCampaign().getUID()));
|
s.append(String.format("ID: %s, Campaign ID: %s\n",this.getUID() , getCampaign().getUID()));
|
||||||
s.append(super.toString());
|
s.append(super.toString());
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DataManeger {
|
public class DataManeger {
|
||||||
|
|
||||||
private File workingDir;
|
private File workingDir;
|
||||||
|
|
||||||
public DataManeger(){
|
public DataManeger(){
|
||||||
workingDir = new File(".");
|
workingDir = new File("./data/");
|
||||||
|
workingDir.mkdir();
|
||||||
|
clearData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean stateAvailable(Date time) {
|
public boolean stateAvailable(Date time) {
|
||||||
File f = new File(String.format("0x%016X.bin", time.getTime()));
|
File f = new File(String.format("./data/%s.bin", time.getTime()));
|
||||||
return f.exists();
|
return f.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ public class DataManeger {
|
|||||||
if (stateAvailable(time)){
|
if (stateAvailable(time)){
|
||||||
try {
|
try {
|
||||||
ObjectInputStream objectInputStream = new ObjectInputStream(
|
ObjectInputStream objectInputStream = new ObjectInputStream(
|
||||||
new FileInputStream(String.format("%016X.bin", time.getTime())));
|
new FileInputStream(String.format("./data/%s.bin", time.getTime())));
|
||||||
state = (State)objectInputStream.readObject();
|
state = (State)objectInputStream.readObject();
|
||||||
objectInputStream.close();
|
objectInputStream.close();
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
@ -34,7 +35,7 @@ public class DataManeger {
|
|||||||
|
|
||||||
public boolean saveState(State state, Date time){
|
public boolean saveState(State state, Date time){
|
||||||
try {
|
try {
|
||||||
FileOutputStream fs = new FileOutputStream(String.format("%016X.bin", time.getTime()));
|
FileOutputStream fs = new FileOutputStream(String.format("./data/%s.bin", time.getTime()));
|
||||||
BufferedOutputStream bfs = new BufferedOutputStream(fs);
|
BufferedOutputStream bfs = new BufferedOutputStream(fs);
|
||||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(bfs);
|
ObjectOutputStream objectOutputStream = new ObjectOutputStream(bfs);
|
||||||
objectOutputStream.writeObject(state);
|
objectOutputStream.writeObject(state);
|
||||||
@ -57,7 +58,7 @@ public class DataManeger {
|
|||||||
if (file.getName().contains(".bin")){
|
if (file.getName().contains(".bin")){
|
||||||
String timeInName = file.getName().replaceAll(".bin", "").trim();
|
String timeInName = file.getName().replaceAll(".bin", "").trim();
|
||||||
if ("".equals(timeInName)) continue;
|
if ("".equals(timeInName)) continue;
|
||||||
long time = Long.parseLong(timeInName, 16);
|
long time = Long.parseLong(timeInName);
|
||||||
timesList.add(new HijriDate(time));
|
timesList.add(new HijriDate(time));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,6 +66,32 @@ public class DataManeger {
|
|||||||
times = timesList.toArray(times);
|
times = timesList.toArray(times);
|
||||||
return times;
|
return times;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<State> getStates(){
|
||||||
|
List<State> list = new ArrayList<>();
|
||||||
|
for (File file : workingDir.listFiles()) {
|
||||||
|
if (file.getName().contains(".bin")){
|
||||||
|
try {
|
||||||
|
FileInputStream fileInputStream = new FileInputStream(file);
|
||||||
|
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
|
||||||
|
ObjectInputStream objectInputStream = new ObjectInputStream(bufferedInputStream);
|
||||||
|
State state = (State) objectInputStream.readObject();
|
||||||
|
list.add(state);
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearData() {
|
||||||
|
for (File file : savedStateFiles()) {
|
||||||
|
if (file.getName().contains(".bin")){
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class State implements Serializable {
|
class State implements Serializable {
|
||||||
@ -73,15 +100,27 @@ class State implements Serializable {
|
|||||||
|
|
||||||
private ArrayList<Campaign> listOfCampaigns;
|
private ArrayList<Campaign> listOfCampaigns;
|
||||||
private ArrayList<Vehicle> listOfVehicles;
|
private ArrayList<Vehicle> listOfVehicles;
|
||||||
|
private ArrayList<Campaign>[] campPerDistrict;
|
||||||
private Route[] stdRoutes;
|
private Route[] stdRoutes;
|
||||||
private Street[] stdStreet;
|
private Street[] stdStreet;
|
||||||
private Date allArrivedToArafatTime;
|
private Date allArrivedToArafatTime;
|
||||||
private Date allArrivedToHotelsTime;
|
private Date allArrivedToHotelsTime;
|
||||||
|
private Date stateTime;
|
||||||
|
private String maxTrip;
|
||||||
|
private String minTrip;
|
||||||
|
|
||||||
public State(ArrayList<Campaign> listOfCampaigns, ArrayList<Vehicle> listOfVehicles, Route[] stdRoutes, Street[] stdStreet, Date allArrivedToArafatTime, Date allArrivedToHotelsTime) {
|
public State(ArrayList<Campaign> listOfCampaigns,
|
||||||
|
ArrayList<Vehicle> listOfVehicles,
|
||||||
|
ArrayList<Campaign>[] campPerDistrict,
|
||||||
|
Route[] stdRoutes,
|
||||||
|
Street[] stdStreet,
|
||||||
|
Date allArrivedToArafatTime,
|
||||||
|
Date allArrivedToHotelsTime,
|
||||||
|
Date stateTime) {
|
||||||
//Make clones since values may change if this is running on a thread.
|
//Make clones since values may change if this is running on a thread.
|
||||||
this.listOfCampaigns = (ArrayList<Campaign>) listOfCampaigns.clone();
|
this.listOfCampaigns = (ArrayList<Campaign>) listOfCampaigns.clone();
|
||||||
this.listOfVehicles = (ArrayList<Vehicle>) listOfVehicles.clone();
|
this.listOfVehicles = (ArrayList<Vehicle>) listOfVehicles.clone();
|
||||||
|
this.campPerDistrict = (ArrayList<Campaign>[])campPerDistrict.clone();
|
||||||
this.stdRoutes = stdRoutes.clone();
|
this.stdRoutes = stdRoutes.clone();
|
||||||
this.stdStreet = stdStreet.clone();
|
this.stdStreet = stdStreet.clone();
|
||||||
if (allArrivedToArafatTime != null) {
|
if (allArrivedToArafatTime != null) {
|
||||||
@ -90,6 +129,15 @@ class State implements Serializable {
|
|||||||
if (allArrivedToHotelsTime != null) {
|
if (allArrivedToHotelsTime != null) {
|
||||||
this.allArrivedToHotelsTime = (Date) allArrivedToHotelsTime.clone();
|
this.allArrivedToHotelsTime = (Date) allArrivedToHotelsTime.clone();
|
||||||
}
|
}
|
||||||
|
this.stateTime = stateTime;
|
||||||
|
if (Vehicle.getMinArrived() != null && Vehicle.getMaxArrived() != null){
|
||||||
|
this.maxTrip = Vehicle.getMaxArrived().getTripTime();
|
||||||
|
this.minTrip = Vehicle.getMinArrived().getTripTime();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.maxTrip = "N/A";
|
||||||
|
this.minTrip = "N/A";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Campaign> getListOfCampaigns() {
|
public ArrayList<Campaign> getListOfCampaigns() {
|
||||||
@ -100,6 +148,10 @@ class State implements Serializable {
|
|||||||
return listOfVehicles;
|
return listOfVehicles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<Campaign>[] getCampPerDistrict() {
|
||||||
|
return campPerDistrict;
|
||||||
|
}
|
||||||
|
|
||||||
public Route[] getStdRoutes() {
|
public Route[] getStdRoutes() {
|
||||||
return stdRoutes;
|
return stdRoutes;
|
||||||
}
|
}
|
||||||
@ -115,4 +167,16 @@ class State implements Serializable {
|
|||||||
public Date getAllArrivedToHotelsTime() {
|
public Date getAllArrivedToHotelsTime() {
|
||||||
return allArrivedToHotelsTime;
|
return allArrivedToHotelsTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getStateTime() {
|
||||||
|
return stateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaxTrip() {
|
||||||
|
return maxTrip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMinTrip() {
|
||||||
|
return minTrip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,512 @@
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.EventQueue;
|
import java.awt.Font;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
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 {
|
public class GUI_History {
|
||||||
|
|
||||||
private static JFrame frame;
|
private List<State> states;
|
||||||
private static JLabel Time;
|
private State selectedState;
|
||||||
|
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"};
|
||||||
|
private String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %",
|
||||||
|
"Avg. Time", "Best time to Arafat", "Best time to District"};
|
||||||
|
|
||||||
/**
|
public GUI_History(List<State> states) {
|
||||||
* Launch the application.
|
this.states = states;
|
||||||
*/
|
makeFrame();
|
||||||
public static void main(String[] args) {
|
|
||||||
EventQueue.invokeLater(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
GUI_History window = new GUI_History();
|
|
||||||
window.frame.setVisible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void makeFrame() {
|
||||||
* Create the application.
|
setData(states.get(0));
|
||||||
*/
|
|
||||||
public GUI_History() {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the contents of the frame.
|
|
||||||
*/
|
|
||||||
private void initialize() {
|
|
||||||
frame = new JFrame("History");
|
frame = new JFrame("History");
|
||||||
frame.getContentPane().setBackground(new Color(70, 70, 70));
|
frame.setBounds(200, 150, 1386, 731);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
frame.getContentPane().setBackground(new Color(50,50,50));
|
||||||
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
||||||
frame.getContentPane().setLayout(null);
|
frame.getContentPane().setLayout(null);
|
||||||
frame.setLocationRelativeTo(null);
|
|
||||||
frame.revalidate();
|
frame.revalidate();
|
||||||
frame.setLocation(200,150);
|
|
||||||
frame.setAutoRequestFocus(false);
|
frame.setAutoRequestFocus(false);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setVisible(true);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
selectedState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
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] = 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] = busesInDistrict(District.values()[i]);
|
||||||
|
districtData[i][3] = getPercentArrival(District.values()[i]);
|
||||||
|
districtData[i][4] = getAvgTimeOfTrip(District.values()[i]);
|
||||||
|
districtData[i][5] = getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus());
|
||||||
|
districtData[i][6] = getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus());
|
||||||
|
}
|
||||||
|
districtTable.setModel(new DefaultTableModel(districtData, districtColNames));
|
||||||
|
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", getNumberOfArrivedBusses());
|
||||||
|
lblNumOfDonebuses.setText(numOfdoneBuses);
|
||||||
|
|
||||||
|
String NumberOfBussPerHour = String.format("%d", getNumberOfArrivedBussesPerHour());
|
||||||
|
lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour);
|
||||||
|
|
||||||
|
lblAverageTripForLastHourValue.setText(avgTimeOfTrip());
|
||||||
|
lblAverageTimeForTheTrip.setText(getAvgTripForAllDis());
|
||||||
|
lblMaximumTripValue.setText(selectedState.getMaxTrip());
|
||||||
|
lblMinimumTripValue.setText(selectedState.getMinTrip());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Methods
|
||||||
|
public String avgTimeOnStreet(Street street) {
|
||||||
|
int sum = 0;
|
||||||
|
int counter = 1;
|
||||||
|
for (Campaign campaign : listOfCampaigns)
|
||||||
|
for (Vehicle vehicle : campaign.getArrivedVehicles())
|
||||||
|
if (vehicle.hasCrossedStreet(street)){
|
||||||
|
sum += vehicle.getTimeOnStreet(street);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
sum /= counter;
|
||||||
|
int hours = sum / 60;
|
||||||
|
int minutes = sum % 60;
|
||||||
|
if (hours == 0 && minutes == 0) return street.getFastestTimeOfTravel(new Bus());
|
||||||
|
return String.format("%02d:%02d", hours, minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int busesInDistrict(District district){
|
||||||
|
int buses = 0;
|
||||||
|
for (Campaign campaign : campPerDistrict[district.ordinal()]){
|
||||||
|
buses += campaign.getNumberOfBusses();
|
||||||
|
}
|
||||||
|
return buses;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getPercentArrival(District district) {
|
||||||
|
int sum = 0;
|
||||||
|
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
||||||
|
sum += campaign.getPercentArrived();
|
||||||
|
}
|
||||||
|
return sum/campPerDistrict[district.ordinal()].size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAvgTimeOfTrip(District district){
|
||||||
|
int sum = 0;
|
||||||
|
int counter = 1;
|
||||||
|
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
||||||
|
for (Vehicle vehicle : campaign.getVehicles()) {
|
||||||
|
if (vehicle.isArrivedToDest()) {
|
||||||
|
long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
|
||||||
|
sum+= minutes;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum = sum /counter;
|
||||||
|
int hours = sum / 60;
|
||||||
|
int minutes = sum % 60;
|
||||||
|
if (hours == 0 && minutes == 0) return " n/a";
|
||||||
|
return String.format("%2d:%02d", hours,minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Route getShortestRoute(Campaign campaign, Mashier mashier) {
|
||||||
|
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
|
||||||
|
Route route = null;
|
||||||
|
double min = Double.MAX_VALUE;
|
||||||
|
for (Route r : routes) {
|
||||||
|
if (r.getMashier() == mashier){
|
||||||
|
if (r.getTotalLength() < min) {
|
||||||
|
min = r.getTotalLength();
|
||||||
|
route = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return route;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Route[] getRoutesToDistrict(District district) {
|
||||||
|
ArrayList<Route> routes = new ArrayList<>();
|
||||||
|
for (Route route : stdRoutes) {
|
||||||
|
if (route.getHotelArea() == district) {
|
||||||
|
routes.add(route);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Route[] routesArray = new Route[routes.size()];
|
||||||
|
return routes.toArray(routesArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfArrivedBusses() {
|
||||||
|
int num = 0;
|
||||||
|
for (Campaign campaign : listOfCampaigns) {
|
||||||
|
for (Vehicle vehicle : campaign.getVehicles()){
|
||||||
|
if (vehicle instanceof Bus &&
|
||||||
|
vehicle.isArrivedToDest()) num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfArrivedBussesPerHour() {
|
||||||
|
Calendar now = new GregorianCalendar();
|
||||||
|
now.setTime(currenttimeManager);
|
||||||
|
Calendar from = (GregorianCalendar)now.clone();
|
||||||
|
from.roll(Calendar.HOUR, -1);
|
||||||
|
int num = 0;
|
||||||
|
for (Campaign campaign : listOfCampaigns){
|
||||||
|
for (Vehicle bus : campaign.getVehicles()){
|
||||||
|
if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime())
|
||||||
|
&& bus.getTimeOfArrival().after(from.getTime())) {
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String avgTimeOfTrip() {
|
||||||
|
//TODO: does output diff value even after all have arrived.
|
||||||
|
Calendar now = new GregorianCalendar();
|
||||||
|
now.setTime(currenttimeManager);
|
||||||
|
Calendar from = (GregorianCalendar)now.clone();
|
||||||
|
from.roll(Calendar.HOUR, -1);
|
||||||
|
int counter = 1;
|
||||||
|
int sum = 0;
|
||||||
|
for (Campaign campaign : listOfCampaigns){
|
||||||
|
for (Vehicle bus : campaign.getVehicles()){
|
||||||
|
if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime())
|
||||||
|
&& bus.getTimeOfArrival().after(from.getTime())) {
|
||||||
|
long minutes = (bus.getTimeOfArrival().getTime() - bus.getTimeStartedMoving().getTime())/60000;
|
||||||
|
sum+= minutes;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum = sum /counter;
|
||||||
|
int hours = sum / 60;
|
||||||
|
int minutes = sum % 60;
|
||||||
|
if (hours == 0 && minutes == 0) return "(No Arrivals) In Last Hour";
|
||||||
|
return String.format("%2d:%02d", hours, minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAvgTripForAllDis() {
|
||||||
|
int sum = 0;
|
||||||
|
int counter = 1;
|
||||||
|
for (Campaign campaign : listOfCampaigns) {
|
||||||
|
for (Vehicle vehicle : campaign.getVehicles()) {
|
||||||
|
if (vehicle.isArrivedToDest()) {
|
||||||
|
long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
|
||||||
|
sum+= minutes;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}//Make the following a method since it is the same other method
|
||||||
|
sum = sum /counter;
|
||||||
|
int hours = sum / 60;
|
||||||
|
int minutes = sum % 60;
|
||||||
|
if (hours == 0 && minutes == 0) return "-:--";
|
||||||
|
return String.format("%2d:%02d", hours,minutes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
237
src/GUI_Report.java
Normal file
237
src/GUI_Report.java
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
|
||||||
|
public class GUI_Report {
|
||||||
|
JFrame frame;
|
||||||
|
private static ArrayList<Campaign> listOfCampaigns;
|
||||||
|
private static Route[] stdRoutes;
|
||||||
|
private JTable streetTable;
|
||||||
|
private JTable districtTable;
|
||||||
|
private Street[] stdStreet;
|
||||||
|
private Date currenttimeManager;
|
||||||
|
private static ArrayList<Campaign>[] campPerDistrict;
|
||||||
|
private String[] streetColNames = {"Street Name", "Street Load %", "Total","Buses","Local Vehicles","Avg. Time"};
|
||||||
|
private String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %","Avg. Time", "Best time to Arafat", "Best time to District"};
|
||||||
|
private Object[][] streetData;
|
||||||
|
private Object[][] districtData;
|
||||||
|
private JLabel lblDate;
|
||||||
|
|
||||||
|
public GUI_Report(ArrayList<Campaign> listOfCampaigns, Route[] stdRoutes, Street[] stdStreet, ArrayList<Campaign>[] campPerDistrict, Date currenttimeManager) {
|
||||||
|
this.listOfCampaigns = listOfCampaigns;
|
||||||
|
this.stdRoutes = stdRoutes;
|
||||||
|
this.stdStreet = stdStreet;
|
||||||
|
this.campPerDistrict = campPerDistrict;
|
||||||
|
this.currenttimeManager = currenttimeManager;
|
||||||
|
makeFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void makeFrame() {
|
||||||
|
frame = new JFrame("Report");
|
||||||
|
|
||||||
|
//Street data
|
||||||
|
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] = avgTimeOnStreet(stdStreet[i]);
|
||||||
|
}
|
||||||
|
DefaultTableModel model = new DefaultTableModel();
|
||||||
|
model.setColumnIdentifiers(streetColNames);
|
||||||
|
//district
|
||||||
|
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] = busesInDistrict(District.values()[i]);
|
||||||
|
districtData[i][3] = getPercentArrival(District.values()[i]);
|
||||||
|
districtData[i][4] = getAvgTimeOfTrip(District.values()[i]);
|
||||||
|
districtData[i][5] = getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus());
|
||||||
|
districtData[i][6] = getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus());
|
||||||
|
}
|
||||||
|
//tables
|
||||||
|
|
||||||
|
//Street table
|
||||||
|
streetTable = new JTable(streetData,streetColNames);
|
||||||
|
streetTable.setEnabled(false);
|
||||||
|
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.setGridColor(new Color(102, 102, 102));
|
||||||
|
streetTable.setSelectionForeground(Color.white);
|
||||||
|
streetTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
|
streetTable.setRowHeight(20);
|
||||||
|
streetTable.setAutoCreateRowSorter(true);
|
||||||
|
JScrollPane streetScroll = new JScrollPane(streetTable);
|
||||||
|
streetTable.getColumnModel().getColumn(0).setPreferredWidth(111);
|
||||||
|
streetTable.getColumnModel().getColumn(1).setPreferredWidth(46);
|
||||||
|
streetTable.getColumnModel().getColumn(2).setPreferredWidth(1);
|
||||||
|
streetTable.getColumnModel().getColumn(3).setPreferredWidth(0);
|
||||||
|
streetTable.getColumnModel().getColumn(4).setPreferredWidth(60);
|
||||||
|
streetTable.getColumnModel().getColumn(5).setPreferredWidth(0);
|
||||||
|
streetScroll.setBounds(10,75,809,269);
|
||||||
|
|
||||||
|
//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.getColumnModel().getColumn(0).setPreferredWidth(43);
|
||||||
|
districtTable.getColumnModel().getColumn(1).setPreferredWidth(30);
|
||||||
|
districtTable.getColumnModel().getColumn(2).setPreferredWidth(0);
|
||||||
|
districtTable.getColumnModel().getColumn(3).setPreferredWidth(0);
|
||||||
|
districtTable.getColumnModel().getColumn(4).setPreferredWidth(0);
|
||||||
|
districtTable.getColumnModel().getColumn(5).setPreferredWidth(85);
|
||||||
|
districtTable.getColumnModel().getColumn(6).setPreferredWidth(93);
|
||||||
|
districtTable.setRowHeight(20);
|
||||||
|
districtTable.revalidate();
|
||||||
|
districtScroll.setBounds(10,395,809,89);
|
||||||
|
|
||||||
|
//lbl
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
//Add Elements
|
||||||
|
frame.getContentPane().add(streetScroll);
|
||||||
|
frame.getContentPane().add(districtScroll);
|
||||||
|
frame.getContentPane().setBackground(new Color(50,50,50));
|
||||||
|
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
||||||
|
frame.setBounds(100,100,856,540);
|
||||||
|
frame.getContentPane().setLayout(null);
|
||||||
|
|
||||||
|
JLabel lblStreets = new JLabel("Streets");
|
||||||
|
lblStreets.setForeground(Color.WHITE);
|
||||||
|
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||||
|
lblStreets.setBounds(10, 34, 208, 30);
|
||||||
|
frame.getContentPane().add(lblStreets);
|
||||||
|
|
||||||
|
JLabel lblDistrict = new JLabel("District");
|
||||||
|
lblDistrict.setForeground(Color.WHITE);
|
||||||
|
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||||
|
lblDistrict.setBounds(10, 355, 166, 29);
|
||||||
|
frame.getContentPane().add(lblDistrict);
|
||||||
|
|
||||||
|
JLabel lblTime_1 = new JLabel("Time:");
|
||||||
|
lblTime_1.setForeground(Color.WHITE);
|
||||||
|
lblTime_1.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblTime_1.setBounds(190, 21, 72, 14);
|
||||||
|
frame.getContentPane().add(lblTime_1);
|
||||||
|
|
||||||
|
lblDate = new JLabel(currenttimeManager.toString());
|
||||||
|
lblDate.setForeground(Color.WHITE);
|
||||||
|
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblDate.setBounds(238, 18, 326, 21);
|
||||||
|
frame.getContentPane().add(lblDate);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
frame.revalidate();
|
||||||
|
frame.setLocation(100,150);
|
||||||
|
frame.setAutoRequestFocus(false);
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Methods
|
||||||
|
public static String avgTimeOnStreet(Street street) {
|
||||||
|
int sum = 0;
|
||||||
|
int counter = 1;
|
||||||
|
for (Campaign campaign : listOfCampaigns)
|
||||||
|
for (Vehicle vehicle : campaign.getArrivedVehicles())
|
||||||
|
if (vehicle.hasCrossedStreet(street)){
|
||||||
|
sum += vehicle.getTimeOnStreet(street);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
sum /= counter;
|
||||||
|
int hours = sum / 60;
|
||||||
|
int minutes = sum % 60;
|
||||||
|
if (hours == 0 && minutes == 0) return street.getFastestTimeOfTravel(new Bus());
|
||||||
|
return String.format("%02d:%02d", hours, minutes);
|
||||||
|
}
|
||||||
|
private static int busesInDistrict(District district){
|
||||||
|
int buses = 0;
|
||||||
|
for (Campaign campaign : campPerDistrict[district.ordinal()]){
|
||||||
|
buses += campaign.getNumberOfBusses();
|
||||||
|
}
|
||||||
|
return buses;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getPercentArrival(District district) {
|
||||||
|
int sum = 0;
|
||||||
|
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
||||||
|
sum += campaign.getPercentArrived();
|
||||||
|
}
|
||||||
|
return sum/campPerDistrict[district.ordinal()].size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getAvgTimeOfTrip(District district){
|
||||||
|
int sum = 0;
|
||||||
|
int counter = 1;
|
||||||
|
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
||||||
|
for (Vehicle vehicle : campaign.getVehicles()) {
|
||||||
|
if (vehicle.isArrivedToDest()) {
|
||||||
|
long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
|
||||||
|
sum+= minutes;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum = sum /counter;
|
||||||
|
int hours = sum / 60;
|
||||||
|
int minutes = sum % 60;
|
||||||
|
if (hours == 0 && minutes == 0) return " n/a";
|
||||||
|
return String.format("%2d:%02d", hours,minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Route getShortestRoute(Campaign campaign, Mashier mashier) {
|
||||||
|
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
|
||||||
|
Route route = null;
|
||||||
|
double min = Double.MAX_VALUE;
|
||||||
|
for (Route r : routes) {
|
||||||
|
if (r.getMashier() == mashier){
|
||||||
|
if (r.getTotalLength() < min) {
|
||||||
|
min = r.getTotalLength();
|
||||||
|
route = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return route;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Route[] getRoutesToDistrict(District district) {
|
||||||
|
ArrayList<Route> routes = new ArrayList<>();
|
||||||
|
for (Route route : stdRoutes) {
|
||||||
|
if (route.getHotelArea() == district) {
|
||||||
|
routes.add(route);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Route[] routesArray = new Route[routes.size()];
|
||||||
|
return routes.toArray(routesArray);
|
||||||
|
}
|
||||||
|
}
|
@ -7,32 +7,39 @@ import java.util.Calendar;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.DropMode;
|
||||||
|
import javax.swing.JTextPane;
|
||||||
|
|
||||||
public class GUI_ViewBuses {
|
public class GUI_ViewBuses {
|
||||||
|
|
||||||
private static JFrame frame;
|
private JFrame frame;
|
||||||
private static ArrayList<Vehicle> vehicles = new ArrayList<>();
|
private ArrayList<Vehicle> vehicles = new ArrayList<>();
|
||||||
private static ArrayList<Vehicle> vehiclesAlazizya = new ArrayList<>();
|
private ArrayList<Vehicle> vehiclesAlazizya = new ArrayList<>();
|
||||||
private static ArrayList<Vehicle> vehiclesAlhijra = new ArrayList<>();
|
private ArrayList<Vehicle> vehiclesAlhijra = new ArrayList<>();
|
||||||
private static ArrayList<Vehicle> vehiclesAlmansoor = new ArrayList<>();
|
private ArrayList<Vehicle> vehiclesAlmansoor = new ArrayList<>();
|
||||||
private static PDate currenttimeManager;
|
private Date currenttimeManager;
|
||||||
private static JTable table;
|
private JTable table;
|
||||||
private static Object[][] busData;
|
private Object[][] busData;
|
||||||
private static String[] busColNames = {"ID", "Street", "location","Progress", "trip time", "Arrive Time"};
|
private String[] busColNames = {"ID", "Street", "location","Progress", "trip time", "Arrive Time"};
|
||||||
private static JButton Alazizya;
|
private JButton Alazizya;
|
||||||
private static JButton Alhijra;
|
private JButton Alhijra;
|
||||||
private static JButton Almansoor;
|
private JButton Almansoor;
|
||||||
private static JLabel lblTime;
|
private JLabel lblTime;
|
||||||
private static JLabel lblDate;
|
private JLabel lblDate;
|
||||||
JLabel lblStatus;
|
private JLabel lblStatus;
|
||||||
private JLabel lblDestination;
|
private JLabel lblDestination;
|
||||||
private JLabel lblDistrict;
|
private JLabel lblDistrict;
|
||||||
private JLabel lblDistrictValue;
|
private JLabel lblDistrictValue;
|
||||||
|
private JTextPane textPane;
|
||||||
|
|
||||||
|
|
||||||
public GUI_ViewBuses(ArrayList<Campaign> campaign , PDate currenttimeManager) {
|
public GUI_ViewBuses(ArrayList<Campaign> campaign , Date currenttimeManager) {
|
||||||
for (Campaign camp : campaign) {
|
for (Campaign camp : campaign) {
|
||||||
switch (camp.getHotelDistrict()) {
|
switch (camp.getHotelDistrict()) {
|
||||||
case ALAZIZIYA:
|
case ALAZIZIYA:
|
||||||
@ -55,26 +62,19 @@ public class GUI_ViewBuses {
|
|||||||
|
|
||||||
private void makeFrame() {
|
private void makeFrame() {
|
||||||
frame = new JFrame("Buses");
|
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 = new JTable(busData,busColNames);
|
||||||
table.setColumnSelectionAllowed(true);
|
table.setColumnSelectionAllowed(true);
|
||||||
table.setCellSelectionEnabled(true);
|
table.setCellSelectionEnabled(true);
|
||||||
DefaultTableModel model = new DefaultTableModel();
|
DefaultTableModel model = new DefaultTableModel();
|
||||||
model.setColumnIdentifiers(busColNames);
|
model.setColumnIdentifiers(busColNames);
|
||||||
|
ListSelectionModel model2 = table.getSelectionModel();
|
||||||
|
model2.addListSelectionListener(e -> {
|
||||||
|
if (!model2.isSelectionEmpty()) {
|
||||||
|
int row = model2.getMinSelectionIndex();
|
||||||
|
textPane.setText(((Bus)vehicles.get(row)).toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
table.getTableHeader().setBackground(new Color(17,17,17));
|
table.getTableHeader().setBackground(new Color(17,17,17));
|
||||||
table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
table.getTableHeader().setForeground(Color.WHITE);
|
table.getTableHeader().setForeground(Color.WHITE);
|
||||||
@ -91,7 +91,7 @@ public class GUI_ViewBuses {
|
|||||||
scrollPane.getVerticalScrollBar().setBackground(new Color(17,17,17));
|
scrollPane.getVerticalScrollBar().setBackground(new Color(17,17,17));
|
||||||
scrollPane.setBounds(20, 24, 887, 236);
|
scrollPane.setBounds(20, 24, 887, 236);
|
||||||
|
|
||||||
frame.getContentPane().setBackground(new Color(70, 70, 70));
|
frame.getContentPane().setBackground(new Color(50,50,50));
|
||||||
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
||||||
frame.setBounds(100,100,972,454);
|
frame.setBounds(100,100,972,454);
|
||||||
frame.getContentPane().setLayout(null);
|
frame.getContentPane().setLayout(null);
|
||||||
@ -104,6 +104,7 @@ public class GUI_ViewBuses {
|
|||||||
Alazizya.setForeground(Color.white);
|
Alazizya.setForeground(Color.white);
|
||||||
Alazizya.setBounds(20, 366, 116, 23);
|
Alazizya.setBounds(20, 366, 116, 23);
|
||||||
Alazizya.addActionListener(e -> {
|
Alazizya.addActionListener(e -> {
|
||||||
|
if (vehiclesAlazizya.get(0).getRoute() != null)
|
||||||
updateVehicles(vehiclesAlazizya);
|
updateVehicles(vehiclesAlazizya);
|
||||||
});
|
});
|
||||||
frame.getContentPane().add(Alazizya);
|
frame.getContentPane().add(Alazizya);
|
||||||
@ -114,6 +115,7 @@ public class GUI_ViewBuses {
|
|||||||
Alhijra.setForeground(Color.white);
|
Alhijra.setForeground(Color.white);
|
||||||
Alhijra.setBounds(20, 269, 116, 23);
|
Alhijra.setBounds(20, 269, 116, 23);
|
||||||
Alhijra.addActionListener(e -> {
|
Alhijra.addActionListener(e -> {
|
||||||
|
if (vehiclesAlhijra.get(0).getRoute() != null)
|
||||||
updateVehicles(vehiclesAlhijra);
|
updateVehicles(vehiclesAlhijra);
|
||||||
});
|
});
|
||||||
frame.getContentPane().add(Alhijra);
|
frame.getContentPane().add(Alhijra);
|
||||||
@ -124,6 +126,7 @@ public class GUI_ViewBuses {
|
|||||||
Almansoor.setForeground(Color.white);
|
Almansoor.setForeground(Color.white);
|
||||||
Almansoor.setBounds(20, 316, 116, 23);
|
Almansoor.setBounds(20, 316, 116, 23);
|
||||||
Almansoor.addActionListener(e -> {
|
Almansoor.addActionListener(e -> {
|
||||||
|
if (vehiclesAlmansoor.get(0).getRoute() != null)
|
||||||
updateVehicles(vehiclesAlmansoor);
|
updateVehicles(vehiclesAlmansoor);
|
||||||
});
|
});
|
||||||
frame.getContentPane().add(Almansoor);
|
frame.getContentPane().add(Almansoor);
|
||||||
@ -140,7 +143,7 @@ public class GUI_ViewBuses {
|
|||||||
lblStatus.setBounds(180, 317, 72, 18);
|
lblStatus.setBounds(180, 317, 72, 18);
|
||||||
frame.getContentPane().add(lblStatus);
|
frame.getContentPane().add(lblStatus);
|
||||||
|
|
||||||
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
|
lblDate = new JLabel(currenttimeManager.toString());
|
||||||
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblDate.setForeground(Color.WHITE);
|
lblDate.setForeground(Color.WHITE);
|
||||||
lblDate.setBounds(235, 270, 326, 21);
|
lblDate.setBounds(235, 270, 326, 21);
|
||||||
@ -151,7 +154,9 @@ public class GUI_ViewBuses {
|
|||||||
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblDestination.setBounds(235, 317, 184, 18);
|
lblDestination.setBounds(235, 317, 184, 18);
|
||||||
frame.getContentPane().add(lblDestination);
|
frame.getContentPane().add(lblDestination);
|
||||||
if (currenttimeManager.getCurrentCalendar().get(Calendar.DAY_OF_MONTH) == 9)
|
Calendar cal = new GregorianCalendar();
|
||||||
|
cal.setTime(currenttimeManager);
|
||||||
|
if (cal.get(Calendar.DAY_OF_MONTH) == 9)
|
||||||
lblDestination.setText("Heading to Arafat");
|
lblDestination.setText("Heading to Arafat");
|
||||||
else lblDestination.setText("Heading to Hotels");
|
else lblDestination.setText("Heading to Hotels");
|
||||||
|
|
||||||
@ -169,6 +174,16 @@ public class GUI_ViewBuses {
|
|||||||
lblDistrictValue.setBounds(247, 371, 129, 12);
|
lblDistrictValue.setBounds(247, 371, 129, 12);
|
||||||
frame.getContentPane().add(lblDistrictValue);
|
frame.getContentPane().add(lblDistrictValue);
|
||||||
|
|
||||||
|
textPane = new JTextPane();
|
||||||
|
textPane.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
textPane.setForeground(Color.WHITE);
|
||||||
|
textPane.setBackground(Color.BLACK);
|
||||||
|
|
||||||
|
JScrollPane scrolltext = new JScrollPane(textPane);
|
||||||
|
scrolltext.setBounds(523, 271, 384, 133);
|
||||||
|
frame.getContentPane().add(scrolltext);
|
||||||
|
|
||||||
|
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +201,7 @@ public class GUI_ViewBuses {
|
|||||||
else busData[i][3] = "%0";
|
else busData[i][3] = "%0";
|
||||||
busData[i][4] = vehicles.get(i).getTripTime();
|
busData[i][4] = vehicles.get(i).getTripTime();
|
||||||
if (vehicles.get(i).isArrivedToDest())
|
if (vehicles.get(i).isArrivedToDest())
|
||||||
busData[i][5] = vehicles.get(i).getTimeOfArrival().toString();//Formula of time
|
busData[i][5] = getShortTime(vehicles.get(i).getTimeOfArrival());
|
||||||
else busData[i][5] = "NOT Arrived";
|
else busData[i][5] = "NOT Arrived";
|
||||||
}
|
}
|
||||||
table.setModel(new DefaultTableModel(busData ,busColNames));
|
table.setModel(new DefaultTableModel(busData ,busColNames));
|
||||||
@ -197,7 +212,13 @@ public class GUI_ViewBuses {
|
|||||||
vehicles.clear();
|
vehicles.clear();
|
||||||
vehicles.addAll(vehiclesDistrict);
|
vehicles.addAll(vehiclesDistrict);
|
||||||
lblDistrictValue.setText(((Bus)vehiclesDistrict.get(0)).getCampaign().getHotelDistrict().name());
|
lblDistrictValue.setText(((Bus)vehiclesDistrict.get(0)).getCampaign().getHotelDistrict().name());
|
||||||
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
lblDate.setText(currenttimeManager.toString());
|
||||||
updateTable();
|
updateTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getShortTime(Date time) {
|
||||||
|
Calendar cal = new GregorianCalendar();
|
||||||
|
cal.setTime(time);
|
||||||
|
return String.format("%02d:%02d", cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
127
src/GUI_ViewRoute.java
Normal file
127
src/GUI_ViewRoute.java
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.DefaultComboBoxModel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JScrollBar;
|
||||||
|
|
||||||
|
public class GUI_ViewRoute {
|
||||||
|
JFrame frame;
|
||||||
|
private String[] routeColNames = {"Num", "Status", "Length","Capacity", "Best Time", "Used By"};
|
||||||
|
private Object[][] routeData;
|
||||||
|
private JTable table;
|
||||||
|
private Route[] stdRoute;
|
||||||
|
private Date currenttimeManager;
|
||||||
|
private ArrayList<Campaign> listOfCampaigns;
|
||||||
|
private JTextField txtStreets;
|
||||||
|
private JLabel lblDate;
|
||||||
|
private JLabel lblTime;
|
||||||
|
|
||||||
|
public GUI_ViewRoute(Route[] stdRoute, ArrayList<Campaign> listOfCampaigns, Date currenttimeManager) {
|
||||||
|
this.stdRoute = stdRoute;
|
||||||
|
this.listOfCampaigns = listOfCampaigns;
|
||||||
|
this.currenttimeManager = currenttimeManager;
|
||||||
|
makeFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeFrame() {
|
||||||
|
frame = new JFrame("Routes");
|
||||||
|
frame.getContentPane().setBackground(new Color(50,50,50));
|
||||||
|
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
||||||
|
frame.setBounds(100,100,815,480);
|
||||||
|
frame.getContentPane().setLayout(null);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
routeData = new Object[stdRoute.length][6];
|
||||||
|
for (int i = 0; i < stdRoute.length; i++) {
|
||||||
|
routeData[i][0] = i;
|
||||||
|
routeData[i][1] = String.format("%s : %s",stdRoute[i].getHotelArea(),stdRoute[i].getMashier());
|
||||||
|
routeData[i][2] = stdRoute[i].getTotalLength();
|
||||||
|
routeData[i][3] = String.format("%.2f",stdRoute[i].capcity());
|
||||||
|
routeData[i][4] = stdRoute[i].getFastestTimeOfTravel(new Bus());
|
||||||
|
int count = 0;
|
||||||
|
for (Campaign campaign : listOfCampaigns)
|
||||||
|
if (campaign.getRoute() == stdRoute[i])
|
||||||
|
count += campaign.getVehicles().size();
|
||||||
|
|
||||||
|
routeData[i][5] = String.format("%d buses", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
table = new JTable(routeData,routeColNames);
|
||||||
|
table.setModel(new DefaultTableModel(routeData,routeColNames));
|
||||||
|
table.getColumnModel().getColumn(0).setPreferredWidth(30);
|
||||||
|
table.getColumnModel().getColumn(1).setPreferredWidth(190);
|
||||||
|
table.getColumnModel().getColumn(2).setPreferredWidth(55);
|
||||||
|
table.getColumnModel().getColumn(3).setPreferredWidth(57);
|
||||||
|
table.getColumnModel().getColumn(5).setPreferredWidth(75);
|
||||||
|
table.setColumnSelectionAllowed(true);
|
||||||
|
table.setCellSelectionEnabled(true);
|
||||||
|
DefaultTableModel model = new DefaultTableModel();
|
||||||
|
model.setColumnIdentifiers(routeColNames);
|
||||||
|
ListSelectionModel model2 = table.getSelectionModel();
|
||||||
|
model2.addListSelectionListener(e -> {
|
||||||
|
int row = model2.getMinSelectionIndex();
|
||||||
|
String streets = "";
|
||||||
|
for (Street street : stdRoute[row].getStreets())
|
||||||
|
streets += street.getName().name() +" >> ";
|
||||||
|
if (stdRoute[row].getMashier() == Mashier.ARAFAT)
|
||||||
|
txtStreets.setText(stdRoute[row].getHotelArea().name()+" >> "+streets+stdRoute[row].getMashier().name());
|
||||||
|
else txtStreets.setText(stdRoute[row].getMashier().name()+" >> "+streets+stdRoute[row].getHotelArea().name());
|
||||||
|
});
|
||||||
|
table.getTableHeader().setBackground(new Color(17,17,17));
|
||||||
|
table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
|
table.getTableHeader().setForeground(Color.WHITE);
|
||||||
|
table.setBackground(new Color(17,17,17));
|
||||||
|
table.setForeground(Color.WHITE);
|
||||||
|
table.setGridColor(new Color(102, 102, 102));
|
||||||
|
table.setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
|
table.setRowHeight(25);
|
||||||
|
table.setAutoCreateRowSorter(true);
|
||||||
|
table.revalidate();
|
||||||
|
|
||||||
|
|
||||||
|
JScrollPane scrollPane = new JScrollPane(table);
|
||||||
|
scrollPane.setBounds(10, 44, 755, 300);
|
||||||
|
frame.getContentPane().add(scrollPane);
|
||||||
|
|
||||||
|
txtStreets = new JTextField("Select Route");
|
||||||
|
txtStreets.setBackground(Color.BLACK);
|
||||||
|
txtStreets.setForeground(Color.WHITE);
|
||||||
|
txtStreets.setFont(new Font("Rockwell", Font.PLAIN, 17));
|
||||||
|
txtStreets.setBounds(10, 382, 755, 48);
|
||||||
|
frame.getContentPane().add(txtStreets);
|
||||||
|
txtStreets.setColumns(10);
|
||||||
|
|
||||||
|
lblTime = new JLabel("Time:");
|
||||||
|
lblTime.setForeground(Color.WHITE);
|
||||||
|
lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblTime.setBounds(10, 11, 72, 20);
|
||||||
|
frame.getContentPane().add(lblTime);
|
||||||
|
|
||||||
|
lblDate = new JLabel(currenttimeManager.toString());
|
||||||
|
lblDate.setForeground(Color.WHITE);
|
||||||
|
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblDate.setBounds(61, 11, 326, 20);
|
||||||
|
frame.getContentPane().add(lblDate);
|
||||||
|
|
||||||
|
JLabel lblStreets = new JLabel("Streets :");
|
||||||
|
lblStreets.setForeground(Color.WHITE);
|
||||||
|
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblStreets.setBounds(10, 355, 72, 20);
|
||||||
|
frame.getContentPane().add(lblStreets);
|
||||||
|
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,9 @@
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
@ -10,13 +11,9 @@ import javax.swing.event.ListSelectionEvent;
|
|||||||
import javax.swing.event.ListSelectionListener;
|
import javax.swing.event.ListSelectionListener;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
|
||||||
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.Default;
|
|
||||||
|
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.AbstractListModel;
|
import javax.swing.AbstractListModel;
|
||||||
import javax.swing.DefaultListModel;
|
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.JProgressBar;
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
public class GUI_ViewStreet {
|
public class GUI_ViewStreet {
|
||||||
@ -24,9 +21,9 @@ public class GUI_ViewStreet {
|
|||||||
private Street street;
|
private Street street;
|
||||||
private ArrayList<Vehicle> vehicles = new ArrayList<>();
|
private ArrayList<Vehicle> vehicles = new ArrayList<>();
|
||||||
private Street[] stdStreet = new Street[StreetNames.values().length];
|
private Street[] stdStreet = new Street[StreetNames.values().length];
|
||||||
private PDate currenttimeManager;
|
private Date currenttimeManager;
|
||||||
private Object[][] busData;
|
private Object[][] vehicleData;
|
||||||
private String[] busColNames = {"ID", "District", "location","Progress", "trip time"};
|
private String[] vehicleColNames = {"ID", "District", "location","Progress", "trip time"};
|
||||||
private JTable table;
|
private JTable table;
|
||||||
private JLabel lblCapcityValue;
|
private JLabel lblCapcityValue;
|
||||||
private JLabel lblDate;
|
private JLabel lblDate;
|
||||||
@ -37,44 +34,42 @@ public class GUI_ViewStreet {
|
|||||||
private JTextField[] textFieldArray = new JTextField[20];
|
private JTextField[] textFieldArray = new JTextField[20];
|
||||||
private JTextField txtHigh;
|
private JTextField txtHigh;
|
||||||
|
|
||||||
public GUI_ViewStreet(Street[] streets, PDate currenttimeManager) {
|
public GUI_ViewStreet(Street[] streets, Date currenttimeManager) {
|
||||||
stdStreet = streets.clone();
|
stdStreet = streets.clone();
|
||||||
this.currenttimeManager = (PDate) currenttimeManager.clone();
|
this.currenttimeManager = (Date) currenttimeManager.clone();
|
||||||
makeFrame();
|
makeFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeFrame() {
|
private void makeFrame() {
|
||||||
//street = stdStreet[0];
|
//street = stdStreet[0];
|
||||||
frame = new JFrame("Streets");
|
frame = new JFrame("Streets");
|
||||||
frame.getContentPane().setBackground(new Color(70, 70, 70));
|
frame.getContentPane().setBackground(new Color(50,50,50));
|
||||||
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
frame.getContentPane().setForeground(new Color(0, 0, 0));
|
||||||
frame.setBounds(100,100,815,480);
|
frame.setBounds(100,100,815,480);
|
||||||
frame.getContentPane().setLayout(null);
|
frame.getContentPane().setLayout(null);
|
||||||
frame.setLocationRelativeTo(null);
|
frame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
vehicleData = new Object[vehicles.size()][6];
|
||||||
|
|
||||||
busData = new Object[vehicles.size()][6];
|
|
||||||
for (int i = 0; i < vehicles.size(); i++) {
|
for (int i = 0; i < vehicles.size(); i++) {
|
||||||
busData[i][0] = vehicles.get(i).getUID();
|
vehicleData[i][0] = vehicles.get(i).getUID();
|
||||||
if (vehicles.get(i) instanceof Bus)
|
if (vehicles.get(i) instanceof Bus)
|
||||||
busData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
|
vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
|
||||||
else busData[i][1] = "Local Vehicle";
|
else vehicleData[i][1] = "Local Vehicle";
|
||||||
busData[i][2] = vehicles.get(i).getCurrentLocation();
|
vehicleData[i][2] = vehicles.get(i).getCurrentLocation();
|
||||||
busData[i][3] = vehicles.get(i).getProgress();
|
vehicleData[i][3] = vehicles.get(i).getProgress();
|
||||||
busData[i][4] = vehicles.get(i).getTripTime();
|
vehicleData[i][4] = vehicles.get(i).getTripTime();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table = new JTable(busData,busColNames);
|
table = new JTable(vehicleData,vehicleColNames);
|
||||||
table.setColumnSelectionAllowed(true);
|
table.setColumnSelectionAllowed(true);
|
||||||
table.setCellSelectionEnabled(true);
|
table.setCellSelectionEnabled(true);
|
||||||
DefaultTableModel model = new DefaultTableModel();
|
DefaultTableModel model = new DefaultTableModel();
|
||||||
model.setColumnIdentifiers(busColNames);
|
model.setColumnIdentifiers(vehicleColNames);
|
||||||
table.getTableHeader().setBackground(new Color(17,17,17));
|
table.getTableHeader().setBackground(new Color(17,17,17));
|
||||||
table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
table.getTableHeader().setForeground(Color.WHITE);
|
table.getTableHeader().setForeground(Color.WHITE);
|
||||||
table.setModel(new DefaultTableModel(busData ,busColNames));
|
table.setModel(new DefaultTableModel(vehicleData ,vehicleColNames));
|
||||||
table.setBackground(new Color(17,17,17));
|
table.setBackground(new Color(17,17,17));
|
||||||
table.setForeground(Color.WHITE);
|
table.setForeground(Color.WHITE);
|
||||||
table.setGridColor(new Color(102, 102, 102));
|
table.setGridColor(new Color(102, 102, 102));
|
||||||
@ -110,7 +105,7 @@ public class GUI_ViewStreet {
|
|||||||
textFieldArray[i].setBackground(new Color(255,colorFactor,0));
|
textFieldArray[i].setBackground(new Color(255,colorFactor,0));
|
||||||
}
|
}
|
||||||
lblCapcityValue.setText(String.format("%%%d", street.getPercentRemainingCapacity()));
|
lblCapcityValue.setText(String.format("%%%d", street.getPercentRemainingCapacity()));
|
||||||
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
lblDate.setText(currenttimeManager.toString());
|
||||||
lblNumVehicles.setText(String.format("%d", street.getVehicles().size()));
|
lblNumVehicles.setText(String.format("%d", street.getVehicles().size()));
|
||||||
lblLengthValue.setText(String.format("%.2f", street.getLength()));
|
lblLengthValue.setText(String.format("%.2f", street.getLength()));
|
||||||
lblLanesValue.setText(String.format("%d", street.getNumberOfLanes()));
|
lblLanesValue.setText(String.format("%d", street.getNumberOfLanes()));
|
||||||
@ -146,7 +141,7 @@ public class GUI_ViewStreet {
|
|||||||
lblTime.setBounds(193, 11, 72, 20);
|
lblTime.setBounds(193, 11, 72, 20);
|
||||||
frame.getContentPane().add(lblTime);
|
frame.getContentPane().add(lblTime);
|
||||||
|
|
||||||
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
|
lblDate = new JLabel(currenttimeManager.toString());
|
||||||
lblDate.setForeground(Color.WHITE);
|
lblDate.setForeground(Color.WHITE);
|
||||||
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblDate.setBounds(243, 11, 326, 20);
|
lblDate.setBounds(243, 11, 326, 20);
|
||||||
@ -162,7 +157,9 @@ public class GUI_ViewStreet {
|
|||||||
lblDestination.setForeground(Color.WHITE);
|
lblDestination.setForeground(Color.WHITE);
|
||||||
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblDestination.setBounds(568, 11, 184, 20);
|
lblDestination.setBounds(568, 11, 184, 20);
|
||||||
if (currenttimeManager.getCurrentCalendar().get(Calendar.DAY_OF_MONTH) == 9)
|
Calendar cal = new GregorianCalendar();
|
||||||
|
cal.setTime(currenttimeManager);
|
||||||
|
if (cal.get(Calendar.DAY_OF_MONTH) == 9)
|
||||||
lblDestination.setText("Heading to Arafat");
|
lblDestination.setText("Heading to Arafat");
|
||||||
else lblDestination.setText("Heading to Hotels");
|
else lblDestination.setText("Heading to Hotels");
|
||||||
frame.getContentPane().add(lblDestination);
|
frame.getContentPane().add(lblDestination);
|
||||||
@ -252,18 +249,18 @@ public class GUI_ViewStreet {
|
|||||||
|
|
||||||
public void updateTable() {
|
public void updateTable() {
|
||||||
if (vehicles.isEmpty()) return;
|
if (vehicles.isEmpty()) return;
|
||||||
busData = new Object[vehicles.size()][6];
|
vehicleData = new Object[vehicles.size()][6];
|
||||||
for (int i = 0; i < vehicles.size(); i++) {
|
for (int i = 0; i < vehicles.size(); i++) {
|
||||||
busData[i][0] = vehicles.get(i).getUID();// TODO: There is an Exception error here;
|
vehicleData[i][0] = vehicles.get(i).getUID();// TODO: There is an Exception error here;
|
||||||
if (vehicles.get(i) instanceof Bus)
|
if (vehicles.get(i) instanceof Bus)
|
||||||
busData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
|
vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
|
||||||
else busData[i][1] = "Local Vehicle";
|
else vehicleData[i][1] = "Local Vehicle";
|
||||||
busData[i][2] = vehicles.get(i).getCurrentLocation();
|
vehicleData[i][2] = vehicles.get(i).getCurrentLocation();
|
||||||
busData[i][3] = vehicles.get(i).getProgress();
|
vehicleData[i][3] = vehicles.get(i).getProgress();
|
||||||
busData[i][4] = vehicles.get(i).getTripTime();
|
vehicleData[i][4] = vehicles.get(i).getTripTime();
|
||||||
|
|
||||||
}
|
}
|
||||||
table.setModel(new DefaultTableModel(busData ,busColNames));
|
table.setModel(new DefaultTableModel(vehicleData ,vehicleColNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
public double capcityPoint(int x) {
|
public double capcityPoint(int x) {
|
||||||
|
@ -31,6 +31,8 @@ public class MakkahCity {
|
|||||||
private static final InputListener inputListener = new InputListener();
|
private static final InputListener inputListener = new InputListener();
|
||||||
private static final Thread t = new Thread(inputListener,"InputThread-Makkah");
|
private static final Thread t = new Thread(inputListener,"InputThread-Makkah");
|
||||||
private static boolean isAllRoutSet;
|
private static boolean isAllRoutSet;
|
||||||
|
private static final DataManeger dataManeger = new DataManeger();
|
||||||
|
private static volatile boolean done_flag;
|
||||||
//GUI
|
//GUI
|
||||||
private static boolean exit_flag;
|
private static boolean exit_flag;
|
||||||
private static boolean pause_flag;
|
private static boolean pause_flag;
|
||||||
@ -46,10 +48,15 @@ public class MakkahCity {
|
|||||||
private static JLabel lblMinimumTripValue;
|
private static JLabel lblMinimumTripValue;
|
||||||
private static JLabel lblBusesArrivedInTheLastHourValue;
|
private static JLabel lblBusesArrivedInTheLastHourValue;
|
||||||
private static JLabel lblAverageTripForLastHourValue;
|
private static JLabel lblAverageTripForLastHourValue;
|
||||||
|
private static JButton btnPause;
|
||||||
|
private static JLabel lblAverageTimeForTheTrip;
|
||||||
|
private static JLabel lblArrivedToArafatTime;
|
||||||
|
private static JLabel lblArrivedToHotelsTime;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
//TODO: fix state errors
|
||||||
t.start();
|
t.start();
|
||||||
//Gen Camp
|
//Gen Camp
|
||||||
campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>();
|
campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>();
|
||||||
@ -78,8 +85,7 @@ public class MakkahCity {
|
|||||||
//Street data
|
//Street data
|
||||||
Object[][] streetData = new Object[stdStreet.length][6];
|
Object[][] streetData = new Object[stdStreet.length][6];
|
||||||
String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses",
|
String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses",
|
||||||
"Local Vehicles",
|
"Local Vehicles","Avg. Time"};
|
||||||
"Avg. Time"};
|
|
||||||
|
|
||||||
for (int i = 0; i < stdStreet.length; i++) {
|
for (int i = 0; i < stdStreet.length; i++) {
|
||||||
streetData[i][0] = stdStreet[i].getName().name();
|
streetData[i][0] = stdStreet[i].getName().name();
|
||||||
@ -120,10 +126,16 @@ public class MakkahCity {
|
|||||||
streetTable.setGridColor(new Color(102, 102, 102));
|
streetTable.setGridColor(new Color(102, 102, 102));
|
||||||
streetTable.setSelectionForeground(Color.white);
|
streetTable.setSelectionForeground(Color.white);
|
||||||
streetTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
|
streetTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
streetTable.setRowHeight(25);
|
streetTable.setRowHeight(20);
|
||||||
streetTable.setAutoCreateRowSorter(true);
|
streetTable.setAutoCreateRowSorter(true);
|
||||||
|
streetTable.getColumnModel().getColumn(0).setPreferredWidth(111);
|
||||||
|
streetTable.getColumnModel().getColumn(1).setPreferredWidth(46);
|
||||||
|
streetTable.getColumnModel().getColumn(2).setPreferredWidth(1);
|
||||||
|
streetTable.getColumnModel().getColumn(3).setPreferredWidth(0);
|
||||||
|
streetTable.getColumnModel().getColumn(4).setPreferredWidth(60);
|
||||||
|
streetTable.getColumnModel().getColumn(5).setPreferredWidth(0);
|
||||||
JScrollPane streetScroll = new JScrollPane(streetTable);
|
JScrollPane streetScroll = new JScrollPane(streetTable);
|
||||||
streetScroll.setBounds(50,100,1216,329);
|
streetScroll.setBounds(22,100,809,269);
|
||||||
|
|
||||||
//District table
|
//District table
|
||||||
districtTable = new JTable(districtData,districtColNames);
|
districtTable = new JTable(districtData,districtColNames);
|
||||||
@ -141,56 +153,76 @@ public class MakkahCity {
|
|||||||
JScrollPane districtScroll = new JScrollPane(districtTable);
|
JScrollPane districtScroll = new JScrollPane(districtTable);
|
||||||
districtScroll.setEnabled(false);
|
districtScroll.setEnabled(false);
|
||||||
districtTable.setAutoCreateRowSorter(true);
|
districtTable.setAutoCreateRowSorter(true);
|
||||||
districtTable.setRowHeight(25);
|
districtTable.setRowHeight(20);
|
||||||
|
districtTable.getColumnModel().getColumn(0).setPreferredWidth(43);
|
||||||
|
districtTable.getColumnModel().getColumn(1).setPreferredWidth(30);
|
||||||
|
districtTable.getColumnModel().getColumn(2).setPreferredWidth(0);
|
||||||
|
districtTable.getColumnModel().getColumn(3).setPreferredWidth(0);
|
||||||
|
districtTable.getColumnModel().getColumn(4).setPreferredWidth(0);
|
||||||
|
districtTable.getColumnModel().getColumn(5).setPreferredWidth(85);
|
||||||
|
districtTable.getColumnModel().getColumn(6).setPreferredWidth(93);
|
||||||
districtTable.revalidate();
|
districtTable.revalidate();
|
||||||
districtScroll.setBounds(50,478,1216,105);
|
districtScroll.setBounds(22,420,809,89);
|
||||||
|
|
||||||
//Buttons
|
//Buttons
|
||||||
JButton btnViewRoutes = new JButton("View Routes");
|
JButton btnViewRoutes = new JButton("View Routes");
|
||||||
btnViewRoutes.setBounds(1307, 33, 166, 29);
|
btnViewRoutes.setBounds(888, 33, 166, 29);
|
||||||
btnViewRoutes.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
btnViewRoutes.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
btnViewRoutes.setBackground(new Color(9,9,9));
|
btnViewRoutes.setBackground(new Color(9,9,9));
|
||||||
btnViewRoutes.setForeground(Color.white);
|
btnViewRoutes.setForeground(Color.white);
|
||||||
btnViewRoutes.addActionListener(e -> {
|
btnViewRoutes.addActionListener(e -> {
|
||||||
EventControll t = new EventControll();
|
GUI_ViewRoute r = new GUI_ViewRoute(stdRoutes ,listOfCampaigns,currenttimeManager.getCurrentTime());
|
||||||
t.setData(stdRoutes[0]);
|
pause_flag = true;
|
||||||
|
btnPause.setText("Unpause");
|
||||||
});
|
});
|
||||||
JButton btnViewBuses = new JButton("View Buses");
|
JButton btnViewBuses = new JButton("View Buses");
|
||||||
btnViewBuses.setBounds(1307, 76, 166, 29);
|
btnViewBuses.setBounds(888, 73, 166, 29);
|
||||||
btnViewBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
btnViewBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
btnViewBuses.setBackground(new Color(9,9,9));
|
btnViewBuses.setBackground(new Color(9,9,9));
|
||||||
btnViewBuses.setForeground(Color.white);
|
btnViewBuses.setForeground(Color.white);
|
||||||
btnViewBuses.addActionListener(e -> {
|
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");
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton btnViewCampaigns = new JButton("View Campaigns");
|
JButton btnViewReport = new JButton("View Report");
|
||||||
btnViewCampaigns.setBounds(1307, 119, 166, 29);
|
btnViewReport.setBounds(888, 153, 166, 29);
|
||||||
btnViewCampaigns.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
btnViewReport.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
btnViewCampaigns.setBackground(new Color(9,9,9));
|
btnViewReport.setBackground(new Color(9,9,9));
|
||||||
btnViewCampaigns.setForeground(Color.white);
|
btnViewReport.setForeground(Color.white);
|
||||||
|
btnViewReport.addActionListener(e -> {
|
||||||
|
GUI_Report r = new GUI_Report(listOfCampaigns, stdRoutes, stdStreet, campPerDistrict, currenttimeManager.getCurrentTime());
|
||||||
|
pause_flag = true;
|
||||||
|
btnPause.setText("Unpause");
|
||||||
|
});
|
||||||
|
|
||||||
JButton btnViewStreet = new JButton("View Street");
|
JButton btnViewStreet = new JButton("View Street");
|
||||||
btnViewStreet.setBounds(1307, 159, 166, 29);
|
btnViewStreet.setBounds(888, 113, 166, 29);
|
||||||
btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
btnViewStreet.setBackground(new Color(9,9,9));
|
btnViewStreet.setBackground(new Color(9,9,9));
|
||||||
btnViewStreet.setForeground(Color.white);
|
btnViewStreet.setForeground(Color.white);
|
||||||
btnViewStreet.addActionListener(e -> {
|
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");
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton btnExit = new JButton("Exit");
|
JButton btnExit = new JButton("Exit");
|
||||||
btnExit.setBackground(new Color(9,9,9));
|
btnExit.setBackground(new Color(9,9,9));
|
||||||
btnExit.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
btnExit.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
btnExit.setForeground(Color.white);
|
btnExit.setForeground(Color.white);
|
||||||
btnExit.setBounds(1307, 623, 166, 29);
|
btnExit.setBounds(888, 623, 166, 29);
|
||||||
btnExit.addActionListener(actionEvent -> exit_flag = true);
|
btnExit.addActionListener(actionEvent -> {
|
||||||
|
if (pause_flag || done_flag) System.exit(0);
|
||||||
|
else exit_flag = true;
|
||||||
|
});
|
||||||
|
|
||||||
JButton btnPause = new JButton("Pause");
|
btnPause = new JButton("Pause");
|
||||||
btnPause.setBackground(new Color(9,9,9));
|
btnPause.setBackground(new Color(9,9,9));
|
||||||
btnPause.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
btnPause.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
btnPause.setForeground(Color.white);
|
btnPause.setForeground(Color.white);
|
||||||
btnPause.setBounds(1307, 240, 166, 29);
|
btnPause.setBounds(888, 233, 166, 29);
|
||||||
btnPause.addActionListener(actionEvent -> {
|
btnPause.addActionListener(actionEvent -> {
|
||||||
if (!pause_flag) {
|
if (!pause_flag) {
|
||||||
pause_flag = true;
|
pause_flag = true;
|
||||||
@ -203,118 +235,146 @@ public class MakkahCity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
JButton btnBrowseHistory = new JButton("Browse History");
|
JButton btnBrowseHistory = new JButton("Browse History");
|
||||||
btnBrowseHistory.setBounds(1307, 199, 166, 29);
|
btnBrowseHistory.setBounds(888, 193, 166, 29);
|
||||||
btnBrowseHistory.setBackground(new Color(9,9,9));
|
btnBrowseHistory.setBackground(new Color(9,9,9));
|
||||||
btnBrowseHistory.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
btnBrowseHistory.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
btnBrowseHistory.setForeground(Color.white);
|
btnBrowseHistory.setForeground(Color.white);
|
||||||
|
btnBrowseHistory.addActionListener(e -> {
|
||||||
|
GUI_History hist = new GUI_History(dataManeger.getStates());
|
||||||
|
pause_flag = true;
|
||||||
|
btnPause.setText("Unpause");
|
||||||
|
});
|
||||||
|
|
||||||
//Label
|
//Label
|
||||||
JLabel lblStreets = new JLabel("Streets");
|
JLabel lblStreets = new JLabel("Streets");
|
||||||
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||||
lblStreets.setForeground(new Color(255, 255, 255));
|
lblStreets.setForeground(new Color(255, 255, 255));
|
||||||
lblStreets.setBounds(49, 59, 208, 30);
|
lblStreets.setBounds(22, 59, 208, 30);
|
||||||
|
|
||||||
JLabel lblDistrict = new JLabel("District");
|
JLabel lblDistrict = new JLabel("District");
|
||||||
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||||
lblDistrict.setForeground(new Color(255, 255, 255));
|
lblDistrict.setForeground(new Color(255, 255, 255));
|
||||||
lblDistrict.setBounds(49, 438, 166, 29);
|
lblDistrict.setBounds(22, 380, 166, 29);
|
||||||
|
|
||||||
JLabel lblTime = new JLabel("Time:");
|
JLabel lblTime = new JLabel("Time:");
|
||||||
lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblTime.setForeground(new Color(255, 255, 255));
|
lblTime.setForeground(new Color(255, 255, 255));
|
||||||
lblTime.setBounds(50, 11, 72, 14);
|
lblTime.setBounds(22, 11, 72, 14);
|
||||||
|
|
||||||
JLabel lblStatus = new JLabel("Status:");
|
JLabel lblStatus = new JLabel("Status:");
|
||||||
lblStatus.setForeground(new Color(255, 255, 255));
|
lblStatus.setForeground(new Color(255, 255, 255));
|
||||||
lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblStatus.setBounds(423, 9, 72, 18);
|
lblStatus.setBounds(343, 9, 72, 18);
|
||||||
|
|
||||||
lblDestination = new JLabel();
|
lblDestination = new JLabel();
|
||||||
lblDestination.setForeground(new Color(255, 255, 255));
|
lblDestination.setForeground(new Color(255, 255, 255));
|
||||||
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblDestination.setBounds(477, 9, 184, 18);
|
lblDestination.setBounds(408, 9, 184, 18);
|
||||||
|
|
||||||
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
|
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
|
||||||
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblDate.setForeground(Color.WHITE);
|
lblDate.setForeground(Color.WHITE);
|
||||||
lblDate.setBounds(100, 8, 326, 21);
|
lblDate.setBounds(69, 8, 326, 21);
|
||||||
|
|
||||||
JLabel lblBuses = new JLabel("Buses: ");
|
JLabel lblBuses = new JLabel("Buses: ");
|
||||||
lblBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblBuses.setForeground(new Color(255, 255, 255));
|
lblBuses.setForeground(new Color(255, 255, 255));
|
||||||
lblBuses.setBackground(new Color(192, 192, 192));
|
lblBuses.setBackground(new Color(192, 192, 192));
|
||||||
lblBuses.setBounds(49, 605, 56, 14);
|
lblBuses.setBounds(22, 532, 56, 14);
|
||||||
|
|
||||||
lblNumOfBuses = new JLabel();
|
lblNumOfBuses = new JLabel();
|
||||||
lblNumOfBuses.setText("0");
|
lblNumOfBuses.setText("0");
|
||||||
lblNumOfBuses.setBackground(new Color(0, 0, 0));
|
lblNumOfBuses.setBackground(new Color(0, 0, 0));
|
||||||
lblNumOfBuses.setForeground(new Color(255, 255, 255));
|
lblNumOfBuses.setForeground(new Color(255, 255, 255));
|
||||||
lblNumOfBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblNumOfBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblNumOfBuses.setBounds(100, 606, 90, 12);
|
lblNumOfBuses.setBounds(69, 533, 90, 12);
|
||||||
|
|
||||||
JLabel lblBusesDone = new JLabel("Buses Done:");
|
JLabel lblBusesDone = new JLabel("Buses Done:");
|
||||||
lblBusesDone.setForeground(new Color(255, 255, 255));
|
lblBusesDone.setForeground(new Color(255, 255, 255));
|
||||||
lblBusesDone.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblBusesDone.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblBusesDone.setBounds(199, 606, 101, 12);
|
lblBusesDone.setBounds(143, 533, 101, 12);
|
||||||
|
|
||||||
lblNumOfDonebuses = new JLabel();
|
lblNumOfDonebuses = new JLabel();
|
||||||
lblNumOfDonebuses.setText("0");
|
lblNumOfDonebuses.setText("0");
|
||||||
lblNumOfDonebuses.setForeground(new Color(255, 255, 255));
|
lblNumOfDonebuses.setForeground(new Color(255, 255, 255));
|
||||||
lblNumOfDonebuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblNumOfDonebuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblNumOfDonebuses.setBounds(293, 604, 80, 16);
|
lblNumOfDonebuses.setBounds(234, 531, 80, 16);
|
||||||
|
|
||||||
JLabel lblMaximumTrip = new JLabel("Maximum Trip:");
|
JLabel lblMaximumTrip = new JLabel("Maximum Trip:");
|
||||||
lblMaximumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblMaximumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblMaximumTrip.setForeground(new Color(255, 255, 255));
|
lblMaximumTrip.setForeground(new Color(255, 255, 255));
|
||||||
lblMaximumTrip.setBounds(49, 666, 112, 22);
|
lblMaximumTrip.setBounds(22, 557, 112, 22);
|
||||||
|
|
||||||
lblMaximumTripValue = new JLabel();
|
lblMaximumTripValue = new JLabel();
|
||||||
lblMaximumTripValue.setText("-:--");
|
lblMaximumTripValue.setText("-:--");
|
||||||
lblMaximumTripValue.setForeground(new Color(255, 255, 255));
|
lblMaximumTripValue.setForeground(new Color(255, 255, 255));
|
||||||
lblMaximumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblMaximumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblMaximumTripValue.setBounds(169, 668, 46, 18);
|
lblMaximumTripValue.setBounds(142, 559, 46, 18);
|
||||||
|
|
||||||
JLabel lblMinimumTrip = new JLabel("MinimumTrip:");
|
JLabel lblMinimumTrip = new JLabel("Minimum Trip:");
|
||||||
lblMinimumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblMinimumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblMinimumTrip.setForeground(Color.WHITE);
|
lblMinimumTrip.setForeground(Color.WHITE);
|
||||||
lblMinimumTrip.setBounds(49, 699, 112, 18);
|
lblMinimumTrip.setBounds(22, 587, 112, 18);
|
||||||
|
|
||||||
lblMinimumTripValue = new JLabel("-:--");
|
lblMinimumTripValue = new JLabel("-:--");
|
||||||
lblMinimumTripValue.setForeground(Color.WHITE);
|
lblMinimumTripValue.setForeground(Color.WHITE);
|
||||||
lblMinimumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblMinimumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblMinimumTripValue.setBounds(167, 701, 90, 14);
|
lblMinimumTripValue.setBounds(143, 589, 90, 14);
|
||||||
|
|
||||||
JLabel lblBusesArrivedInTheLastHour = new JLabel("Buses Arrived In The Last Hour:");
|
JLabel lblBusesArrivedInTheLastHour = new JLabel("Buses Arrived In The Last Hour:");
|
||||||
lblBusesArrivedInTheLastHour.setForeground(Color.WHITE);
|
lblBusesArrivedInTheLastHour.setForeground(Color.WHITE);
|
||||||
lblBusesArrivedInTheLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblBusesArrivedInTheLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblBusesArrivedInTheLastHour.setBounds(395, 605, 237, 14);
|
lblBusesArrivedInTheLastHour.setBounds(333, 532, 237, 14);
|
||||||
|
|
||||||
lblBusesArrivedInTheLastHourValue = new JLabel();
|
lblBusesArrivedInTheLastHourValue = new JLabel();
|
||||||
lblBusesArrivedInTheLastHourValue.setText("0");
|
lblBusesArrivedInTheLastHourValue.setText("0");
|
||||||
lblBusesArrivedInTheLastHourValue.setForeground(Color.WHITE);
|
lblBusesArrivedInTheLastHourValue.setForeground(Color.WHITE);
|
||||||
lblBusesArrivedInTheLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblBusesArrivedInTheLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblBusesArrivedInTheLastHourValue.setBounds(628, 605, 90, 14);
|
lblBusesArrivedInTheLastHourValue.setBounds(566, 532, 90, 14);
|
||||||
|
|
||||||
JLabel lblAverageTripForLastHour = new JLabel("Average Trip For Last Hour:");
|
JLabel lblAverageTripForLastHour = new JLabel("Average Trip For Last Hour:");
|
||||||
lblAverageTripForLastHour.setForeground(Color.WHITE);
|
lblAverageTripForLastHour.setForeground(Color.WHITE);
|
||||||
lblAverageTripForLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblAverageTripForLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblAverageTripForLastHour.setBackground(Color.BLACK);
|
lblAverageTripForLastHour.setBackground(Color.BLACK);
|
||||||
lblAverageTripForLastHour.setBounds(287, 668, 208, 18);
|
lblAverageTripForLastHour.setBounds(198, 559, 208, 18);
|
||||||
|
|
||||||
lblAverageTripForLastHourValue = new JLabel("(No Arrivals) In Last Hour");
|
lblAverageTripForLastHourValue = new JLabel("(No Arrivals) In Last Hour");
|
||||||
lblAverageTripForLastHourValue.setForeground(Color.WHITE);
|
lblAverageTripForLastHourValue.setForeground(Color.WHITE);
|
||||||
lblAverageTripForLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblAverageTripForLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblAverageTripForLastHourValue.setBounds(502, 668, 216, 18);
|
lblAverageTripForLastHourValue.setBounds(408, 557, 216, 18);
|
||||||
|
|
||||||
JLabel lblAvgTime = new JLabel("Average Time For The Trip:");
|
JLabel lblAvgTime = new JLabel("Average Time For The Trip:");
|
||||||
lblAvgTime.setForeground(Color.WHITE);
|
lblAvgTime.setForeground(Color.WHITE);
|
||||||
lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblAvgTime.setBounds(287, 694, 208, 29);
|
lblAvgTime.setBounds(198, 582, 208, 29);
|
||||||
|
|
||||||
JLabel lblAverageTimeForTheTrip = new JLabel("-:--");
|
lblAverageTimeForTheTrip = new JLabel("-:--");
|
||||||
lblAverageTimeForTheTrip.setForeground(Color.WHITE);
|
lblAverageTimeForTheTrip.setForeground(Color.WHITE);
|
||||||
lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
lblAverageTimeForTheTrip.setBounds(512, 701, 101, 14);
|
lblAverageTimeForTheTrip.setBounds(408, 589, 101, 14);
|
||||||
|
|
||||||
|
JLabel lblArrivedToArafat = new JLabel("All Arrived To Arafat At:");
|
||||||
|
lblArrivedToArafat.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblArrivedToArafat.setForeground(Color.WHITE);
|
||||||
|
lblArrivedToArafat.setBounds(18, 613, 216, 14);
|
||||||
|
makkahFrame.getContentPane().add(lblArrivedToArafat);
|
||||||
|
|
||||||
|
JLabel lblArrivedToHotels = new JLabel("All Arrived To Hotels At:");
|
||||||
|
lblArrivedToHotels.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblArrivedToHotels.setForeground(Color.WHITE);
|
||||||
|
lblArrivedToHotels.setBounds(18, 638, 184, 14);
|
||||||
|
makkahFrame.getContentPane().add(lblArrivedToHotels);
|
||||||
|
|
||||||
|
lblArrivedToArafatTime = new JLabel("N/A");
|
||||||
|
lblArrivedToArafatTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblArrivedToArafatTime.setForeground(Color.WHITE);
|
||||||
|
lblArrivedToArafatTime.setBounds(208, 613, 358, 14);
|
||||||
|
makkahFrame.getContentPane().add(lblArrivedToArafatTime);
|
||||||
|
|
||||||
|
lblArrivedToHotelsTime = new JLabel("N/A");
|
||||||
|
lblArrivedToHotelsTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblArrivedToHotelsTime.setForeground(Color.WHITE);
|
||||||
|
lblArrivedToHotelsTime.setBounds(208, 638, 358, 14);
|
||||||
|
|
||||||
//Add Elements
|
//Add Elements
|
||||||
makkahFrame.getContentPane().add(streetScroll);
|
makkahFrame.getContentPane().add(streetScroll);
|
||||||
@ -329,7 +389,7 @@ public class MakkahCity {
|
|||||||
makkahFrame.getContentPane().add(lblNumOfDonebuses);
|
makkahFrame.getContentPane().add(lblNumOfDonebuses);
|
||||||
makkahFrame.getContentPane().add(btnExit);
|
makkahFrame.getContentPane().add(btnExit);
|
||||||
makkahFrame.getContentPane().add(btnViewStreet);
|
makkahFrame.getContentPane().add(btnViewStreet);
|
||||||
makkahFrame.getContentPane().add(btnViewCampaigns);
|
makkahFrame.getContentPane().add(btnViewReport);
|
||||||
makkahFrame.getContentPane().add(btnViewBuses);
|
makkahFrame.getContentPane().add(btnViewBuses);
|
||||||
makkahFrame.getContentPane().add(btnViewRoutes);
|
makkahFrame.getContentPane().add(btnViewRoutes);
|
||||||
makkahFrame.getContentPane().add(lblAverageTripForLastHour);
|
makkahFrame.getContentPane().add(lblAverageTripForLastHour);
|
||||||
@ -348,21 +408,26 @@ public class MakkahCity {
|
|||||||
makkahFrame.getContentPane().add(btnPause);
|
makkahFrame.getContentPane().add(btnPause);
|
||||||
|
|
||||||
//Frame Settings
|
//Frame Settings
|
||||||
makkahFrame.getContentPane().setBackground(new Color(70, 70, 70));
|
makkahFrame.getContentPane().setBackground(new Color(50,50,50));
|
||||||
makkahFrame.getContentPane().setForeground(new Color(0, 0, 0));
|
makkahFrame.getContentPane().setForeground(new Color(0, 0, 0));
|
||||||
makkahFrame.setBounds(100,100,1519,777);
|
makkahFrame.setBounds(100,100,1089,714);
|
||||||
makkahFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
makkahFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
makkahFrame.getContentPane().setLayout(null);
|
makkahFrame.getContentPane().setLayout(null);
|
||||||
|
makkahFrame.getContentPane().add(lblArrivedToHotelsTime);
|
||||||
makkahFrame.setLocationRelativeTo(null);
|
makkahFrame.setLocationRelativeTo(null);
|
||||||
makkahFrame.revalidate();
|
makkahFrame.revalidate();
|
||||||
makkahFrame.setLocation(200,150);
|
makkahFrame.setLocation(200,150);
|
||||||
makkahFrame.setAutoRequestFocus(false);
|
makkahFrame.setAutoRequestFocus(false);
|
||||||
makkahFrame.setVisible(true);
|
makkahFrame.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
//Set Routes for Campaigns
|
//Set Routes for Campaigns
|
||||||
while(!firstDayTimeMan.isEnded()) {
|
while(!firstDayTimeMan.isEnded()) {
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
|
if (!isAllRoutSet) {
|
||||||
|
isAllRoutSet = true;
|
||||||
|
setRoutesForCampaigns(Mashier.ARAFAT);
|
||||||
|
}
|
||||||
//Start of Every hour
|
//Start of Every hour
|
||||||
if (firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) == 0){
|
if (firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) == 0){
|
||||||
System.out.println("\n\n" + getStreetsReport());
|
System.out.println("\n\n" + getStreetsReport());
|
||||||
@ -371,10 +436,6 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
else System.out.print(".");
|
else System.out.print(".");
|
||||||
|
|
||||||
if (!isAllRoutSet) {
|
|
||||||
isAllRoutSet = true;
|
|
||||||
setRoutesForCampaigns(Mashier.ARAFAT);
|
|
||||||
}
|
|
||||||
clearDoneCivilVehicles();
|
clearDoneCivilVehicles();
|
||||||
addCivilVehicleNoise();
|
addCivilVehicleNoise();
|
||||||
for (Vehicle vehicle : listOfVehicles) {
|
for (Vehicle vehicle : listOfVehicles) {
|
||||||
@ -406,6 +467,8 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
if (isAllArrived() && allArrivedToArafatTime == null) allArrivedToArafatTime = (Date)currenttimeManager.getCurrentTime().clone();
|
if (isAllArrived() && allArrivedToArafatTime == null) allArrivedToArafatTime = (Date)currenttimeManager.getCurrentTime().clone();
|
||||||
firstDayTimeMan.step(Calendar.MINUTE, 1);
|
firstDayTimeMan.step(Calendar.MINUTE, 1);
|
||||||
|
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
||||||
|
//lblArrivedToArafatTime.setText(getDistTimeForLbl());
|
||||||
}
|
}
|
||||||
|
|
||||||
currenttimeManager = lastDayTimeMan;
|
currenttimeManager = lastDayTimeMan;
|
||||||
@ -423,6 +486,12 @@ public class MakkahCity {
|
|||||||
setRoutesForCampaigns(Mashier.MINA);
|
setRoutesForCampaigns(Mashier.MINA);
|
||||||
while(!lastDayTimeMan.isEnded()) {
|
while(!lastDayTimeMan.isEnded()) {
|
||||||
checkInput();
|
checkInput();
|
||||||
|
|
||||||
|
if (!isAllRoutSet) {
|
||||||
|
isAllRoutSet = true;
|
||||||
|
setRoutesForCampaigns(Mashier.MINA);
|
||||||
|
}
|
||||||
|
|
||||||
//Start of Every hour
|
//Start of Every hour
|
||||||
if (lastDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) == 0){
|
if (lastDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) == 0){
|
||||||
System.out.println("\n\n" + getStreetsReport());
|
System.out.println("\n\n" + getStreetsReport());
|
||||||
@ -431,11 +500,6 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
else System.out.print(".");
|
else System.out.print(".");
|
||||||
|
|
||||||
|
|
||||||
if (!isAllRoutSet) {
|
|
||||||
isAllRoutSet = true;
|
|
||||||
setRoutesForCampaigns(Mashier.MINA);
|
|
||||||
}
|
|
||||||
clearDoneCivilVehicles();
|
clearDoneCivilVehicles();
|
||||||
addCivilVehicleNoise();
|
addCivilVehicleNoise();
|
||||||
for (Vehicle vehicle : listOfVehicles) {
|
for (Vehicle vehicle : listOfVehicles) {
|
||||||
@ -466,8 +530,11 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
if (isAllArrived() && allArrivedToHotelsTime == null) allArrivedToHotelsTime = (Date)currenttimeManager.getCurrentTime().clone();
|
if (isAllArrived() && allArrivedToHotelsTime == null) allArrivedToHotelsTime = (Date)currenttimeManager.getCurrentTime().clone();
|
||||||
lastDayTimeMan.step(Calendar.MINUTE, 1);
|
lastDayTimeMan.step(Calendar.MINUTE, 1);
|
||||||
|
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
||||||
|
//lblArrivedToHotelsTime.setText(getDistTimeForLbl());
|
||||||
}
|
}
|
||||||
//When done show menu to analyze. Exit from menu too.
|
//When done show menu to analyze. Exit from menu too.
|
||||||
|
done_flag = true;
|
||||||
inputListener.pause();
|
inputListener.pause();
|
||||||
startMenu();
|
startMenu();
|
||||||
}
|
}
|
||||||
@ -932,7 +999,7 @@ public class MakkahCity {
|
|||||||
return sortingRoute;
|
return sortingRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Route getShortestRoute(Campaign campaign, Mashier mashier) {
|
public static Route getShortestRoute(Campaign campaign, Mashier mashier) {
|
||||||
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
|
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
|
||||||
Route route = null;
|
Route route = null;
|
||||||
double min = Double.MAX_VALUE;
|
double min = Double.MAX_VALUE;
|
||||||
@ -1023,7 +1090,7 @@ public class MakkahCity {
|
|||||||
* Calculate average trip time for last 10 minutes
|
* Calculate average trip time for last 10 minutes
|
||||||
* @return "hh:mm"
|
* @return "hh:mm"
|
||||||
*/
|
*/
|
||||||
private static String avgTimeOfTrip() {
|
public static String avgTimeOfTrip() {
|
||||||
//TODO: does output diff value even after all have arrived.
|
//TODO: does output diff value even after all have arrived.
|
||||||
Calendar now = currenttimeManager.getCurrentCalendar();
|
Calendar now = currenttimeManager.getCurrentCalendar();
|
||||||
Calendar from = (GregorianCalendar)now.clone();
|
Calendar from = (GregorianCalendar)now.clone();
|
||||||
@ -1047,7 +1114,7 @@ public class MakkahCity {
|
|||||||
return String.format("%2d:%02d", hours, minutes);
|
return String.format("%2d:%02d", hours, minutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getPercentArrival(District district) {
|
public static int getPercentArrival(District district) {
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
||||||
sum += campaign.getPercentArrived();
|
sum += campaign.getPercentArrived();
|
||||||
@ -1055,7 +1122,7 @@ public class MakkahCity {
|
|||||||
return sum/campPerDistrict[district.ordinal()].size();
|
return sum/campPerDistrict[district.ordinal()].size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getAvgTimeOfTrip(District district){
|
public static String getAvgTimeOfTrip(District district){
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
for (Campaign campaign : campPerDistrict[district.ordinal()]) {
|
||||||
@ -1074,7 +1141,7 @@ public class MakkahCity {
|
|||||||
return String.format("%2d:%02d", hours,minutes);
|
return String.format("%2d:%02d", hours,minutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getNumberOfArrivedBusses() {
|
public static int getNumberOfArrivedBusses() {
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (Campaign campaign : listOfCampaigns) {
|
for (Campaign campaign : listOfCampaigns) {
|
||||||
for (Vehicle vehicle : campaign.getVehicles()){
|
for (Vehicle vehicle : campaign.getVehicles()){
|
||||||
@ -1085,7 +1152,7 @@ public class MakkahCity {
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getNumberOfArrivedBussesPerHour() {
|
public static int getNumberOfArrivedBussesPerHour() {
|
||||||
Calendar now = currenttimeManager.getCurrentCalendar();
|
Calendar now = currenttimeManager.getCurrentCalendar();
|
||||||
Calendar from = (GregorianCalendar)now.clone();
|
Calendar from = (GregorianCalendar)now.clone();
|
||||||
from.roll(Calendar.HOUR, -1);
|
from.roll(Calendar.HOUR, -1);
|
||||||
@ -1147,7 +1214,7 @@ public class MakkahCity {
|
|||||||
return String.format("%02d:%02d", hours, minutes);
|
return String.format("%02d:%02d", hours, minutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int busesInDistrict(District district){
|
public static int busesInDistrict(District district){
|
||||||
int buses = 0;
|
int buses = 0;
|
||||||
for (Campaign campaign : campPerDistrict[district.ordinal()]){
|
for (Campaign campaign : campPerDistrict[district.ordinal()]){
|
||||||
buses += campaign.getNumberOfBusses();
|
buses += campaign.getNumberOfBusses();
|
||||||
@ -1158,23 +1225,18 @@ public class MakkahCity {
|
|||||||
private static void saveState(){
|
private static void saveState(){
|
||||||
State s = new State(listOfCampaigns,
|
State s = new State(listOfCampaigns,
|
||||||
listOfVehicles,
|
listOfVehicles,
|
||||||
|
campPerDistrict,
|
||||||
stdRoutes,
|
stdRoutes,
|
||||||
stdStreet,
|
stdStreet,
|
||||||
allArrivedToArafatTime,
|
allArrivedToArafatTime,
|
||||||
allArrivedToHotelsTime);
|
allArrivedToHotelsTime,
|
||||||
DataManeger dataManeger = new DataManeger();
|
currenttimeManager.getCurrentTime());
|
||||||
dataManeger.saveState(s, currenttimeManager.getCurrentTime());
|
dataManeger.saveState(s, currenttimeManager.getCurrentTime());
|
||||||
System.out.println(Arrays.toString(dataManeger.savedStatesTimes())); //TODO FOR DEBUG REMOVE
|
|
||||||
|
|
||||||
boolean result = dataManeger.saveState(s, currenttimeManager.getCurrentTime());
|
boolean result = dataManeger.saveState(s, currenttimeManager.getCurrentTime());
|
||||||
if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());
|
if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static State loadState(Date time){
|
|
||||||
DataManeger dataManeger = new DataManeger();
|
|
||||||
return dataManeger.loadState(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void updateStreetFrame() {
|
private static void updateStreetFrame() {
|
||||||
Object[][] streetData = new Object[stdStreet.length][6];
|
Object[][] streetData = new Object[stdStreet.length][6];
|
||||||
for (int i = 0; i < stdStreet.length; i++) {
|
for (int i = 0; i < stdStreet.length; i++) {
|
||||||
@ -1206,6 +1268,15 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
||||||
|
if (lblArrivedToArafatTime.getText().equalsIgnoreCase("N/A"))
|
||||||
|
if (allArrivedToArafatTime != null) {
|
||||||
|
lblArrivedToArafatTime.setText(allArrivedToArafatTime.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lblArrivedToHotelsTime.getText().equalsIgnoreCase("N/A"))
|
||||||
|
if (allArrivedToHotelsTime != null) {
|
||||||
|
lblArrivedToHotelsTime.setText(allArrivedToHotelsTime.toString());
|
||||||
|
}
|
||||||
|
|
||||||
String status = "";
|
String status = "";
|
||||||
if (currenttimeManager == firstDayTimeMan) {
|
if (currenttimeManager == firstDayTimeMan) {
|
||||||
@ -1235,16 +1306,47 @@ public class MakkahCity {
|
|||||||
lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour);
|
lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour);
|
||||||
|
|
||||||
lblAverageTripForLastHourValue.setText(avgTimeOfTrip());
|
lblAverageTripForLastHourValue.setText(avgTimeOfTrip());
|
||||||
|
lblAverageTimeForTheTrip.setText(getAvgTripForAllDis());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Avg for All the Dist
|
public static String getAvgTripForAllDis() {
|
||||||
public static void getAvgTripForAllDis() {
|
int sum = 0;
|
||||||
for (int i = 0; i < campPerDistrict.length; i++) {
|
int counter = 1;
|
||||||
getAvgTimeOfTrip(District.values()[i]);
|
for (Campaign campaign : listOfCampaigns) {
|
||||||
|
for (Vehicle vehicle : campaign.getVehicles()) {
|
||||||
|
if (vehicle.isArrivedToDest()) {
|
||||||
|
long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
|
||||||
|
sum+= minutes;
|
||||||
|
counter++;
|
||||||
}
|
}
|
||||||
//lblAverageTripForLastHourValue.setText();
|
|
||||||
}
|
}
|
||||||
|
}//Make the following a method since it is the same other method
|
||||||
|
sum = sum /counter;
|
||||||
|
int hours = sum / 60;
|
||||||
|
int minutes = sum % 60;
|
||||||
|
if (hours == 0 && minutes == 0) return "-:--";
|
||||||
|
return String.format("%2d:%02d", hours,minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getDistTimeForLbl() {
|
||||||
|
int numberOfBusses = 0;
|
||||||
|
int numberOfArrivedBuses = getNumberOfArrivedBusses();
|
||||||
|
|
||||||
|
for (Campaign campaign : listOfCampaigns) {
|
||||||
|
numberOfBusses += campaign.getNumberOfBusses();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean Done = isAllArrived();
|
||||||
|
if (Done && allArrivedToArafatTime != null) {
|
||||||
|
return String.format("%s", allArrivedToArafatTime);
|
||||||
|
}
|
||||||
|
if (Done && allArrivedToHotelsTime != null) {
|
||||||
|
return String.format("%s",allArrivedToHotelsTime);
|
||||||
|
}
|
||||||
|
return "N/A";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user