Merge pull request #28 from EngOsamah/master

d
This commit is contained in:
IMXHERO 2020-12-17 02:01:52 +03:00 committed by GitHub
commit 67b313aabf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 182 additions and 27 deletions

View File

@ -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();
} }

View File

@ -9,6 +9,10 @@ import javax.swing.JButton;
import java.awt.Color; import java.awt.Color;
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 {
@ -26,10 +30,11 @@ public class GUI_ViewBuses {
private static JButton Almansoor; private static JButton Almansoor;
private static JLabel lblTime; private static JLabel lblTime;
private static JLabel lblDate; private static 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 , PDate currenttimeManager) {
@ -75,6 +80,13 @@ public class GUI_ViewBuses {
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);
@ -169,6 +181,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);
} }

126
src/GUI_ViewRoute.java Normal file
View File

@ -0,0 +1,126 @@
import java.awt.Color;
import java.awt.Font;
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 PDate currenttimeManager;
private ArrayList<Campaign> listOfCampaigns;
private JTextField txtStreets;
private JLabel lblDate;
private JLabel lblTime;
public GUI_ViewRoute(Route[] stdRoute, ArrayList<Campaign> listOfCampaigns, PDate currenttimeManager) {
this.stdRoute = stdRoute;
this.listOfCampaigns = listOfCampaigns;
this.currenttimeManager = currenttimeManager;
makeFrame();
}
private void makeFrame() {
frame = new JFrame("Routes");
frame.getContentPane().setBackground(new Color(70, 70, 70));
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.getCurrentTime().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);
}
}

View File

@ -21,8 +21,8 @@ public class GUI_ViewStreet {
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 PDate 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;
@ -50,27 +50,27 @@ public class GUI_ViewStreet {
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(); 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));
@ -248,18 +248,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) {

View File

@ -47,6 +47,7 @@ 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;
public static void main(String[] args) { public static void main(String[] args) {
@ -79,8 +80,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();
@ -153,8 +153,9 @@ public class MakkahCity {
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);
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(1307, 76, 166, 29);
@ -163,6 +164,8 @@ public class MakkahCity {
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);
pause_flag = true;
btnPause.setText("Unpause");
}); });
JButton btnViewCampaigns = new JButton("View Campaigns"); JButton btnViewCampaigns = new JButton("View Campaigns");
@ -178,6 +181,8 @@ public class MakkahCity {
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);
pause_flag = true;
btnPause.setText("Unpause");
}); });
JButton btnExit = new JButton("Exit"); JButton btnExit = new JButton("Exit");
@ -187,7 +192,7 @@ public class MakkahCity {
btnExit.setBounds(1307, 623, 166, 29); btnExit.setBounds(1307, 623, 166, 29);
btnExit.addActionListener(actionEvent -> exit_flag = true); btnExit.addActionListener(actionEvent -> 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);
@ -410,6 +415,7 @@ 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());
} }
currenttimeManager = lastDayTimeMan; currenttimeManager = lastDayTimeMan;
@ -470,6 +476,7 @@ 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());
} }
//When done show menu to analyze. Exit from menu too. //When done show menu to analyze. Exit from menu too.
inputListener.pause(); inputListener.pause();