Package View

Class App

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class App extends JFrame
The main class representing the Utility App.

This class represents the main application window for the Utility App. It extends the JFrame class and contains fields for various views and controllers used in the application. It also includes a reference to the logged-in customer. The class provides a central point for managing the application's views and controllers.

Note: The actual implementation of the views and controllers is not shown in this class. Please refer to the specific view and controller classes for more details.

See Also:
  • Field Details

    • loginSelectionView

      private LoginSelectionView loginSelectionView
      The view for selecting the login type.
    • adminLoginView

      private AdminLoginView adminLoginView
      The view for admin login.
    • customerLoginView

      private CustomerLoginView customerLoginView
      The view for customer login.
    • customerRegistrationView

      private CustomerRegistrationView customerRegistrationView
      The view for customer registration.
    • customerDashboardView

      private CustomerDashboardView customerDashboardView
      The view for the customer dashboard.
    • adminDashboardView

      private AdminDashboardView adminDashboardView
      The view for the admin dashboard.
    • newBillView

      private NewBillView newBillView
      The view for creating a new bill.
    • editBillView

      private EditBillView editBillView
      The view for editing a bill.
    • editServiceView

      private EditServiceView editServiceView
      The view for editing a service.
    • customerController

      private CustomerController customerController
      The controller for managing customer-related operations.
    • loggedInCustomer

      private Customer loggedInCustomer
      The currently logged-in customer.
  • Constructor Details

    • App

      public App()
      Constructs a new instance of the Utility App.

      This constructor initializes the main application window. It sets the title of the window to "Utility App", sets the default close operation to exit on close, sets the size of the window to 650x750 pixels, centers the window on the screen, makes the window non-resizable, and initializes the customer controller and the logged-in customer to null. Finally, it makes the window visible and displays the selection pane.

      See Also:
  • Method Details

    • paneChange

      protected void paneChange(JPanel panel)
      Changes the displayed panel in the container.

      This method replaces the currently displayed panel in the container with the specified panel. It first removes all components from the content pane using the removeAll method, then adds the panel to the content pane using the add method. Finally, it calls the revalidate and repaint methods to update the container and repaint it.

      Parameters:
      panel - the panel to be displayed in the container
      See Also:
    • selectionPane

      protected void selectionPane()
      Displays the selection pane for login.

      This method creates a new instance of the LoginSelectionView class and assigns it to the loginSelectionView field of the current instance. It then invokes the paneChange method, passing the loginSelectionView as a parameter, to display the selection pane for login.

      See Also:
    • customerLogin

      protected void customerLogin()
      Displays the customer login view.

      This method creates a new instance of the CustomerLoginView class and assigns it to the customerLoginView field of the current instance. It then invokes the paneChange method, passing the customerLoginView as a parameter, to display the customer login view.

      See Also:
    • validateCustomerLogin

      protected boolean validateCustomerLogin(String username, String password)
      Validates the login credentials of a customer.

      This method validates the login credentials of a customer by invoking the CustomerController.validateLogin(String, String) method and passing the provided username and password as parameters.

      Parameters:
      username - The username of the customer.
      password - The password of the customer.
      Returns:
      true if the login credentials are valid, false otherwise.
      See Also:
    • loadCustomer

      protected Customer loadCustomer(String username, String password)
      Loads a customer based on the provided username and password.

      This method loads a customer by invoking the CustomerController.loadCustomer(String, String) method and passing the provided username and password as parameters. The loaded customer is then assigned to the loggedInCustomer field of the current instance.

      Parameters:
      username - The username of the customer to be loaded.
      password - The password of the customer to be loaded.
      Returns:
      The customer that has been loaded based on the provided credentials.
      See Also:
    • customerDashboard

      protected void customerDashboard()
      Opens the customer dashboard view.

      This method opens the customer dashboard view by creating a new instance of the CustomerDashboardView class and passing the current instance and the logged-in customer as parameters. It then calls the #paneChange(View) method to change the active pane to the customer dashboard view.

      Parameters:
      loggedInCustomer - The logged-in customer object.
      See Also:
    • newBillView

      protected void newBillView()
      Opens the new bill view for creating a new bill.

      This method opens the new bill view by creating a new instance of the NewBillView class and passing the current instance as a parameter. It then calls the #paneChange(View) method to change the active pane to the new bill view.

      See Also:
    • addNewBill

      protected void addNewBill(String utilityType, double meterMeasurement, String date)
      Adds a new bill for the logged-in customer.

      This method allows the logged-in customer to add a new bill by specifying the utility type, meter measurement, and date. It calls the Customer.addBill(String, double, String) method on the loggedInCustomer object, passing the utilityType, meterMeasurement, and date as parameters.

      Parameters:
      utilityType - The type of utility for the bill (e.g., electricity, water, gas).
      meterMeasurement - The meter measurement for the bill.
      date - The date of the bill in the format "yyyy-MM-dd".
      Throws:
      IllegalArgumentException - if the utilityType or date is invalid.
      See Also:
    • editBillPage

      protected void editBillPage(UtilityBill utilityBill)
      Opens the edit bill page for a specific utility bill.

      This method opens the edit bill page for a specific utility bill by creating a new instance of the EditBillView class and passing the current instance and the utility bill as parameters. It then calls the #paneChange(View) method to change the active pane to the edit bill view.

      Parameters:
      utilityBill - The utility bill to be edited.
      See Also:
    • editBill

      protected void editBill(int id, double meterMeasurement)
      Edits a bill for the logged-in customer.

      This method allows the logged-in customer to edit a bill by specifying the ID of the bill and the new meter measurement. It calls the Customer.editBill(int, double) method on the loggedInCustomer object, passing the ID and meterMeasurement as parameters.

      Parameters:
      id - The ID of the bill to be edited.
      meterMeasurement - The new meter measurement for the bill.
      Throws:
      IllegalArgumentException - if the ID is invalid or does not correspond to a bill for the logged-in customer.
      See Also:
    • deleteBill

      protected void deleteBill(int id)
      Deletes a bill for the logged-in customer.

      This method deletes the bill with the specified ID for the currently logged-in customer. It calls the Customer.deleteBill(int) method on the loggedInCustomer object, passing the ID as the parameter.

      Parameters:
      id - The ID of the bill to be deleted.
      Throws:
      IllegalArgumentException - if the ID is invalid or does not correspond to a bill for the logged-in customer.
      See Also:
    • openRegistrationView

      protected void openRegistrationView()
      Opens the registration view for new customers.

      This method creates a new instance of the CustomerRegistrationView class and sets it as the active pane by calling the paneChange(javax.swing.JPanel) method. The registration view provides a user interface for new customers to register and create an account in the system.

      See Also:
    • registerNewUser

      protected boolean registerNewUser(String username, String email, String password)
      Registers a new user in the system.

      This method registers a new user with the specified username, email, and password. It delegates the registration process to the CustomerController class by calling its CustomerController.registerNewUser(java.lang.String, java.lang.String, java.lang.String) method. The method returns a boolean value indicating the success or failure of the registration process.

      Parameters:
      username - The username of the new user.
      email - The email address of the new user.
      password - The password of the new user.
      Returns:
      true if the user registration is successful, false otherwise.
      Throws:
      NullPointerException - if any of the parameters (username, email, password) is null.
      See Also:
    • adminLogin

      protected void adminLogin()
      Displays the admin login view.

      This method creates a new instance of the AdminLoginView class, passing the current instance of the class as a parameter. It then calls the paneChange(javax.swing.JPanel) method to change the active pane to the newly created admin login view.

      The admin login view provides a user interface for administrators to authenticate themselves and gain access to the administrative functionalities of the system.

      See Also:
    • adminDashboard

      protected void adminDashboard()
      Displays the admin dashboard view.

      This method creates a new instance of the AdminDashboardView class, passing the current instance of the class as a parameter. It then calls the paneChange(javax.swing.JPanel) method to change the active pane to the newly created admin dashboard view.

      See Also:
    • editServicePage

      protected void editServicePage(ServiceType serviceType)
      Opens the edit service page for a specific service type.

      This method creates a new instance of the EditServiceView class, passing the current instance of the class and the specified service type as parameters. It then calls the paneChange(javax.swing.JPanel) method to change the active pane to the newly created edit service view.

      Parameters:
      serviceType - The service type for which the edit service page should be opened.
      Throws:
      NullPointerException - If the serviceType parameter is null.
      See Also:
    • editService

      protected void editService(ServiceType serviceType, double serviceCharges, double unitCharges)
      Updates the service charges and unit charges for a specific service type.

      This method updates the service charges and unit charges for a given service type. It calls the necessary methods from the ServiceController class to perform the updates.

      Parameters:
      serviceType - The service type to be edited.
      serviceCharges - The new service charges to be set for the service type.
      unitCharges - The new unit charges to be set for the service type.
      Throws:
      NullPointerException - If the serviceType parameter is null.
      IllegalArgumentException - If the serviceCharges or unitCharges parameters are negative.
      See Also: