a few changes

This commit is contained in:
EngOsamah 2020-12-17 01:13:14 +03:00
parent 1db0ce7ca7
commit 7e50caf26a
3 changed files with 44 additions and 37 deletions

View File

@ -16,8 +16,8 @@ import javax.swing.JScrollBar;
public class GUI_ViewRoute {
JFrame frame;
private String[] vehicleColNames = {"Num", "Status", "Length","Capacity", "Best Time", "Used By"};
private Object[][] vehicleData;
private String[] routeColNames = {"Num", "Status", "Length","Capacity", "Best Time", "Used By"};
private Object[][] routeData;
private JTable table;
private Route[] stdRoute;
private PDate currenttimeManager;
@ -41,24 +41,24 @@ public class GUI_ViewRoute {
frame.getContentPane().setLayout(null);
frame.setLocationRelativeTo(null);
vehicleData = new Object[stdRoute.length][6];
routeData = new Object[stdRoute.length][6];
for (int i = 0; i < stdRoute.length; i++) {
vehicleData[i][0] = i;
vehicleData[i][1] = String.format("%s : %s",stdRoute[i].getHotelArea(),stdRoute[i].getMashier());
vehicleData[i][2] = stdRoute[i].getTotalLength();
vehicleData[i][3] = String.format("%.2f",stdRoute[i].capcity());
vehicleData[i][4] = stdRoute[i].getFastestTimeOfTravel(new Bus());
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();
vehicleData[i][5] = String.format("%d buses", count);
routeData[i][5] = String.format("%d buses", count);
}
table = new JTable(vehicleData,vehicleColNames);
table.setModel(new DefaultTableModel(vehicleData,vehicleColNames));
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);
@ -67,7 +67,7 @@ public class GUI_ViewRoute {
table.setColumnSelectionAllowed(true);
table.setCellSelectionEnabled(true);
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(vehicleColNames);
model.setColumnIdentifiers(routeColNames);
ListSelectionModel model2 = table.getSelectionModel();
model2.addListSelectionListener(e -> {
int row = model2.getMinSelectionIndex();

View File

@ -21,8 +21,8 @@ public class GUI_ViewStreet {
private ArrayList<Vehicle> vehicles = new ArrayList<>();
private Street[] stdStreet = new Street[StreetNames.values().length];
private PDate currenttimeManager;
private Object[][] busData;
private String[] busColNames = {"ID", "District", "location","Progress", "trip time"};
private Object[][] vehicleData;
private String[] vehicleColNames = {"ID", "District", "location","Progress", "trip time"};
private JTable table;
private JLabel lblCapcityValue;
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++) {
busData[i][0] = vehicles.get(i).getUID();
vehicleData[i][0] = vehicles.get(i).getUID();
if (vehicles.get(i) instanceof Bus)
busData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
else busData[i][1] = "Local Vehicle";
busData[i][2] = vehicles.get(i).getCurrentLocation();
busData[i][3] = vehicles.get(i).getProgress();
busData[i][4] = vehicles.get(i).getTripTime();
vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
else vehicleData[i][1] = "Local Vehicle";
vehicleData[i][2] = vehicles.get(i).getCurrentLocation();
vehicleData[i][3] = vehicles.get(i).getProgress();
vehicleData[i][4] = vehicles.get(i).getTripTime();
}
table = new JTable(busData,busColNames);
table = new JTable(vehicleData,vehicleColNames);
table.setColumnSelectionAllowed(true);
table.setCellSelectionEnabled(true);
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(busColNames);
model.setColumnIdentifiers(vehicleColNames);
table.getTableHeader().setBackground(new Color(17,17,17));
table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
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.setForeground(Color.WHITE);
table.setGridColor(new Color(102, 102, 102));
@ -248,18 +248,18 @@ public class GUI_ViewStreet {
public void updateTable() {
if (vehicles.isEmpty()) return;
busData = new Object[vehicles.size()][6];
vehicleData = new Object[vehicles.size()][6];
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)
busData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
else busData[i][1] = "Local Vehicle";
busData[i][2] = vehicles.get(i).getCurrentLocation();
busData[i][3] = vehicles.get(i).getProgress();
busData[i][4] = vehicles.get(i).getTripTime();
vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
else vehicleData[i][1] = "Local Vehicle";
vehicleData[i][2] = vehicles.get(i).getCurrentLocation();
vehicleData[i][3] = vehicles.get(i).getProgress();
vehicleData[i][4] = vehicles.get(i).getTripTime();
}
table.setModel(new DefaultTableModel(busData ,busColNames));
table.setModel(new DefaultTableModel(vehicleData ,vehicleColNames));
}
public double capcityPoint(int x) {

View File

@ -47,6 +47,7 @@ public class MakkahCity {
private static JLabel lblMinimumTripValue;
private static JLabel lblBusesArrivedInTheLastHourValue;
private static JLabel lblAverageTripForLastHourValue;
private static JButton btnPause;
public static void main(String[] args) {
@ -79,8 +80,7 @@ public class MakkahCity {
//Street data
Object[][] streetData = new Object[stdStreet.length][6];
String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses",
"Local Vehicles",
"Avg. Time"};
"Local Vehicles","Avg. Time"};
for (int i = 0; i < stdStreet.length; i++) {
streetData[i][0] = stdStreet[i].getName().name();
@ -153,8 +153,9 @@ public class MakkahCity {
btnViewRoutes.setBackground(new Color(9,9,9));
btnViewRoutes.setForeground(Color.white);
btnViewRoutes.addActionListener(e -> {
EventControll t = new EventControll();
t.setData(stdRoutes[0]);
GUI_ViewRoute r = new GUI_ViewRoute(stdRoutes ,listOfCampaigns, currenttimeManager);
pause_flag = true;
btnPause.setText("Unpause");
});
JButton btnViewBuses = new JButton("View Buses");
btnViewBuses.setBounds(1307, 76, 166, 29);
@ -163,6 +164,8 @@ public class MakkahCity {
btnViewBuses.setForeground(Color.white);
btnViewBuses.addActionListener(e -> {
GUI_ViewBuses t = new GUI_ViewBuses(listOfCampaigns , currenttimeManager);
pause_flag = true;
btnPause.setText("Unpause");
});
JButton btnViewCampaigns = new JButton("View Campaigns");
@ -178,6 +181,8 @@ public class MakkahCity {
btnViewStreet.setForeground(Color.white);
btnViewStreet.addActionListener(e -> {
GUI_ViewStreet t = new GUI_ViewStreet(stdStreet,currenttimeManager);
pause_flag = true;
btnPause.setText("Unpause");
});
JButton btnExit = new JButton("Exit");
@ -187,7 +192,7 @@ public class MakkahCity {
btnExit.setBounds(1307, 623, 166, 29);
btnExit.addActionListener(actionEvent -> exit_flag = true);
JButton btnPause = new JButton("Pause");
btnPause = new JButton("Pause");
btnPause.setBackground(new Color(9,9,9));
btnPause.setFont(new Font("Rockwell", Font.PLAIN, 16));
btnPause.setForeground(Color.white);
@ -410,6 +415,7 @@ public class MakkahCity {
}
if (isAllArrived() && allArrivedToArafatTime == null) allArrivedToArafatTime = (Date)currenttimeManager.getCurrentTime().clone();
firstDayTimeMan.step(Calendar.MINUTE, 1);
lblDate.setText(currenttimeManager.getCurrentTime().toString());
}
currenttimeManager = lastDayTimeMan;
@ -470,6 +476,7 @@ public class MakkahCity {
}
if (isAllArrived() && allArrivedToHotelsTime == null) allArrivedToHotelsTime = (Date)currenttimeManager.getCurrentTime().clone();
lastDayTimeMan.step(Calendar.MINUTE, 1);
lblDate.setText(currenttimeManager.getCurrentTime().toString());
}
//When done show menu to analyze. Exit from menu too.
inputListener.pause();