From f517b8ea007732d54762b6636810f053f24c143f Mon Sep 17 00:00:00 2001 From: EngOsamah <74116947+EngOsamah@users.noreply.github.com> Date: Fri, 11 Dec 2020 05:35:18 +0300 Subject: [PATCH] GUI_ViewBuses --- src/GUI_ViewBuses.java | 178 +++++++++++++++++++++++++++++++++-------- src/MakkahCity.java | 8 +- 2 files changed, 148 insertions(+), 38 deletions(-) diff --git a/src/GUI_ViewBuses.java b/src/GUI_ViewBuses.java index e52198e..ecfd38f 100644 --- a/src/GUI_ViewBuses.java +++ b/src/GUI_ViewBuses.java @@ -1,35 +1,35 @@ import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JLabel; -import java.awt.BorderLayout; -import javax.swing.JPanel; import java.awt.Font; -import java.awt.Frame; -import java.awt.Panel; import java.util.ArrayList; +import java.util.Calendar; import javax.swing.JScrollPane; -import java.awt.FlowLayout; import javax.swing.JButton; import java.awt.Color; -import javax.swing.SwingConstants; import javax.swing.table.DefaultTableModel; -import javax.swing.BoxLayout; -import java.awt.Component; -import javax.swing.Box; -import java.awt.GridLayout; -import java.awt.GridBagLayout; -import java.awt.GridBagConstraints; -import java.awt.Insets; -import javax.swing.JTextField; -import javax.swing.JScrollBar; import javax.swing.JTable; public class GUI_ViewBuses { private static JFrame frame; private static ArrayList vehicles = new ArrayList<>(); + private static ArrayList vehiclesAlazizya = new ArrayList<>(); + private static ArrayList vehiclesAlhijra = new ArrayList<>(); + private static ArrayList vehiclesAlmansoor = new ArrayList<>(); + private static PDate currenttimeManager; private static JTable table; -// private JLabel lblNewLabel; + private static Object[][] busData; + private static String[] busColNames = {"ID", "Street", "location","Progress", "trip time", "Arrive Time"}; + private static JButton Alazizya; + private static JButton Alhijra; + private static JButton Almansoor; + private static JLabel lblTime; + private static JLabel lblDate; + JLabel lblStatus; + private JLabel lblDestination; + private JLabel lblDistrict; + private JLabel lblDistrictValue; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @@ -41,25 +41,41 @@ public class GUI_ViewBuses { e.printStackTrace(); } } + }); + } public GUI_ViewBuses() { - makeFrame(); + //makeFrame(); } private void makeFrame() { frame = new JFrame("Buses"); - Object[][] busData = new Object[vehicles.size()][5]; - String[] busColNames = {"ID", "trip time", "location", "Street", "district" - }; + busData = new Object[vehicles.size()][6]; + + + for (int i = 0; i < vehicles.size(); i++) { + busData[i][0] = vehicles.get(i).getUID(); + if (vehicles.get(i).isMoving()) + busData[i][1] = vehicles.get(i).getCurrentStreet().getName(); + else busData[i][1] = "Not Moving"; + busData[i][2] = vehicles.get(i).getCurrentLocation(); + busData[i][3] = vehicles.get(i).getProgress(); + busData[i][4] = vehicles.get(i).getTripTime(); + if (vehicles.get(i).isArrivedToDest()) + busData[i][5] = vehicles.get(i).getTimeOfArrival();//Formula of time + else busData[i][5] = "NOT Arrived"; + } table = new JTable(busData,busColNames); + table.setColumnSelectionAllowed(true); + table.setCellSelectionEnabled(true); DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(busColNames); table.getTableHeader().setBackground(new Color(17,17,17)); table.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18)); table.getTableHeader().setForeground(Color.WHITE); - table.setModel(model); + table.setModel(new DefaultTableModel(busData ,busColNames)); table.setBackground(new Color(17,17,17)); table.setForeground(Color.WHITE); table.setGridColor(new Color(102, 102, 102)); @@ -69,10 +85,8 @@ public class GUI_ViewBuses { table.revalidate(); JScrollPane scrollPane = new JScrollPane(table); - scrollPane.setEnabled(false); - scrollPane.setBounds(20, 24, 668, 236); + scrollPane.setBounds(20, 24, 754, 236); - frame.getContentPane().add(scrollPane); frame.getContentPane().setBackground(new Color(70, 70, 70)); frame.getContentPane().setForeground(new Color(0, 0, 0)); frame.setBounds(100,100,814,454); @@ -81,19 +95,115 @@ public class GUI_ViewBuses { frame.setLocationRelativeTo(null); frame.getContentPane().add(scrollPane); - JButton btnNewButton = new JButton("New button"); - btnNewButton.setBounds(89, 306, 89, 23); - frame.getContentPane().add(btnNewButton); + Alazizya = new JButton("Alazizya"); + Alazizya.setBounds(30, 271, 99, 23); + Alazizya.addActionListener(e -> { + updateVehicles(vehiclesAlazizya); + }); + frame.getContentPane().add(Alazizya); - JButton btnNewButton_1 = new JButton("New button"); - btnNewButton_1.setBounds(222, 306, 89, 23); - frame.getContentPane().add(btnNewButton_1); + Alhijra = new JButton("Alhijra"); + Alhijra.setBounds(30, 317, 99, 23); + Alhijra.addActionListener(e -> { + updateVehicles(vehiclesAlhijra); + }); + frame.getContentPane().add(Alhijra); - JButton btnNewButton_2 = new JButton("New button"); - btnNewButton_2.setBounds(341, 306, 89, 23); - frame.getContentPane().add(btnNewButton_2); - frame.setVisible(true); + Almansoor = new JButton("Almansoor"); + Almansoor.setBounds(30, 366, 99, 23); + Almansoor.addActionListener(e -> { + updateVehicles(vehiclesAlmansoor); + }); + frame.getContentPane().add(Almansoor); + lblTime = new JLabel("Time:"); + lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); + lblTime.setForeground(new Color(255, 255, 255)); + lblTime.setBounds(180, 273, 72, 14); + frame.getContentPane().add(lblTime); + + lblStatus = new JLabel("Status:"); + lblStatus.setForeground(new Color(255, 255, 255)); + lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16)); + lblStatus.setBounds(180, 317, 72, 18); + frame.getContentPane().add(lblStatus); + lblDate = new JLabel(currenttimeManager.getCurrentTime().toString()); + lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16)); + lblDate.setForeground(Color.WHITE); + lblDate.setBounds(235, 270, 326, 21); + frame.getContentPane().add(lblDate); + + lblDestination = new JLabel(); + lblDestination.setForeground(Color.WHITE); + lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16)); + lblDestination.setBounds(235, 317, 184, 18); + frame.getContentPane().add(lblDestination); + if (currenttimeManager.getCurrentCalendar().get(Calendar.DAY_OF_MONTH) == 9) + lblDestination.setText("Heading to Arafat"); + else lblDestination.setText("Heading to Hotels"); + + lblDistrict = new JLabel("District: "); + lblDistrict.setForeground(Color.WHITE); + lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 16)); + lblDistrict.setBackground(Color.LIGHT_GRAY); + lblDistrict.setBounds(180, 370, 72, 14); + frame.getContentPane().add(lblDistrict); + + lblDistrictValue = new JLabel(); + lblDistrictValue.setText("0"); + lblDistrictValue.setForeground(Color.WHITE); + lblDistrictValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); + lblDistrictValue.setBackground(Color.BLACK); + lblDistrictValue.setBounds(247, 371, 90, 12); + frame.getContentPane().add(lblDistrictValue); + + + + frame.setVisible(true); + } + + public void setData(ArrayList campaign , PDate currenttimeManager) { + for (Campaign camp : campaign) { + switch (camp.getHotelDistrict()) { + case ALAZIZIYA: + vehiclesAlazizya.add(camp.getVehicles().get(0)); + break; + case ALHIJRA: + vehiclesAlhijra.add(camp.getVehicles().get(0)); + break; + case ALMANSOOR: + vehiclesAlmansoor.add(camp.getVehicles().get(0)); + break; + default: + break; } + } + this.currenttimeManager = currenttimeManager; + makeFrame(); + } + + public void updateTable() { + 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().toString();//Formula of time + else busData[i][5] = "NOT Arrived"; + } + table.setModel(new DefaultTableModel(busData ,busColNames)); + } + + public void updateVehicles(ArrayList vehiclesDistrict) { + vehicles.clear(); + vehicles.addAll(vehiclesDistrict); + lblDistrictValue.setText(((Bus)vehiclesDistrict.get(0)).getCampaign().getHotelDistrict().name()); + updateTable(); + } } diff --git a/src/MakkahCity.java b/src/MakkahCity.java index f8891f1..8ed1235 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -164,10 +164,10 @@ public class MakkahCity { 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(); -// t.setData(listOfCampaigns); -// }); + btnViewBuses.addActionListener(e -> { + GUI_ViewBuses t = new GUI_ViewBuses(); + t.setData(listOfCampaigns , currenttimeManager); + }); JButton btnViewCampaigns = new JButton("View Campaigns"); btnViewCampaigns.setBounds(1307, 119, 166, 29);