Class Router

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, GraphicComponent, JobContainer

public class Router extends JComponent implements JobContainer, GraphicComponent
Class for a router in the animation
Author:
Lorenzo Torri Date: 02-apr-2024 Time: 10.10
See Also:
  • Constructor Details

    • Router

      public Router(JPanel parent, boolean xcentered, boolean ycentered, Point pos, List<JobContainer> nextContainers, List<Station> nextStations, Simulation simulation)
      Constructor
      Parameters:
      parent - , Jpanel that contains this router
      xcentered - , if the router is xcentered with respect to the parent, if yes, pos.x does not matter
      ycentered - , if the router is ycentered with respect to the parent, if yes, pos.y does not matter
      pos - , position of the Router, if it is x-y centered then the respective coordinates are not considered
      nextContainers - the edges linked to this router
      nextStations - , the stations linked to this router
      simulation - , information of the simulation
    • Router

      public Router(JPanel parent, boolean xcentered, boolean ycentered, Point pos, List<JobContainer> nextContainers, List<Station> nextStations, Simulation simulation, double[] percentages)
      Constructor similar with the one before but with the array of percentage
      Parameters:
      percentages - , must be of size = 3 and all doubles between 0 and 1, and they must sum up to 1. This check is not performed here, since it is something that have to check in the TextField before creating the Animation
  • Method Details

    • paint

      public void paint(Graphics g)
      Overrides:
      paint in class JComponent
    • refresh

      public void refresh()
      Specified by:
      refresh in interface JobContainer
    • addJob

      public void addJob(JobContainer prec, Job newJob)
      Description copied from interface: JobContainer
      Add a new Job to this JobContainer
      Specified by:
      addJob in interface JobContainer
      Parameters:
      newJob - Job to add to this Container
    • changeProbabilities

      public void changeProbabilities(double[] probabilities)
      Method to change probabilities of the router
      Parameters:
      probabilities - new array of probabilities
    • paintProbabilities

      public void paintProbabilities()
      paint the probabilities of each edge
    • updateNextContainers

      public void updateNextContainers(List<JobContainer> nextContainers)
    • setXPos

      public void setXPos(int xpos)
      Specified by:
      setXPos in interface GraphicComponent
    • setYPos

      public void setYPos(int ypos)
      Specified by:
      setYPos in interface GraphicComponent
    • getXPos

      public int getXPos()
      Description copied from interface: GraphicComponent
      Return the drawing starting position in the panel of a component
      Specified by:
      getXPos in interface GraphicComponent
    • getYPos

      public int getYPos()
      Specified by:
      getYPos in interface GraphicComponent
    • getTotalLenght

      public int getTotalLenght()
      Description copied from interface: GraphicComponent
      Get the total length of a component when drawn
      Specified by:
      getTotalLenght in interface GraphicComponent