Class MainWindow

java.lang.Object
javafx.stage.Window
javafx.stage.Stage
real_time_traffic_simulation_with_java.gui.MainWindow
All Implemented Interfaces:
javafx.event.EventTarget

public class MainWindow extends javafx.stage.Stage
Main window class that sets up the primary GUI components and manages the animation timer
  • Property Summary

    Properties inherited from class javafx.stage.Stage

    alwaysOnTop, fullScreenExitHint, fullScreenExitKey, fullScreen, iconified, maxHeight, maximized, maxWidth, minHeight, minWidth, resizable, title

    Properties inherited from class javafx.stage.Window

    eventDispatcher, focused, forceIntegerRenderScale, height, onCloseRequest, onHidden, onHiding, onShowing, onShown, opacity, outputScaleX, outputScaleY, renderScaleX, renderScaleY, scene, showing, width, x, y
  • Constructor Summary

    Constructors
    Constructor
    Description
    MainWindow contructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Start animation timer method to update simulation and refresh map panel at fixed interval definned in Metrics.CONNECT_SPEED_MS.
    void
    Stop animation timer method to stop the animation timer and exporting files service when main window is closed

    Methods inherited from class javafx.stage.Stage

    alwaysOnTopProperty, close, fullScreenExitHintProperty, fullScreenExitKeyProperty, fullScreenProperty, getFullScreenExitHint, getFullScreenExitKeyCombination, getIcons, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getModality, getOwner, getStyle, getTitle, iconifiedProperty, initModality, initOwner, initStyle, isAlwaysOnTop, isFullScreen, isIconified, isMaximized, isResizable, maxHeightProperty, maximizedProperty, maxWidthProperty, minHeightProperty, minWidthProperty, resizableProperty, setAlwaysOnTop, setFullScreen, setFullScreenExitHint, setFullScreenExitKeyCombination, setIconified, setMaxHeight, setMaximized, setMaxWidth, setMinHeight, setMinWidth, setResizable, setScene, setTitle, show, showAndWait, titleProperty, toBack, toFront

    Methods inherited from class javafx.stage.Window

    addEventFilter, addEventHandler, buildEventDispatchChain, centerOnScreen, eventDispatcherProperty, fireEvent, focusedProperty, forceIntegerRenderScaleProperty, getEventDispatcher, getHeight, getOnCloseRequest, getOnHidden, getOnHiding, getOnShowing, getOnShown, getOpacity, getOutputScaleX, getOutputScaleY, getProperties, getRenderScaleX, getRenderScaleY, getScene, getUserData, getWidth, getWindows, getX, getY, hasProperties, heightProperty, hide, isFocused, isForceIntegerRenderScale, isShowing, onCloseRequestProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, opacityProperty, outputScaleXProperty, outputScaleYProperty, removeEventFilter, removeEventHandler, renderScaleXProperty, renderScaleYProperty, requestFocus, sceneProperty, setEventDispatcher, setEventHandler, setForceIntegerRenderScale, setHeight, setOnCloseRequest, setOnHidden, setOnHiding, setOnShowing, setOnShown, setOpacity, setRenderScaleX, setRenderScaleY, setUserData, setWidth, setX, setY, showingProperty, sizeToScene, widthProperty, xProperty, yProperty

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MainWindow

      public MainWindow(SimulationEngine engine)
      MainWindow contructor. Its have simulation engine as parameter to pass to other comfponents
      Parameters:
      engine - The simulation engine instance
  • Method Details

    • startAnimationTimer

      public void startAnimationTimer()
      Start animation timer method to update simulation and refresh map panel at fixed interval definned in Metrics.CONNECT_SPEED_MS.
      This method works by create a stepIntervalNanos variable to store the interval time in nanoseconds.
      then create an AnimationTimer object and override its handle method.

      class AnimationTimer allows us to create a timer, that is called in each frame while it is active.
      An extending class has to override the method handle(long) which will be called in every frame.
      -Oracle AnimationTimer Doc-

      Which is what we want because we need a method to update the simulation (call SimulationEngine and use it stepSimulation method) and call Map panel refresh methos to update the map in each frame. The method will be talk over the MapPanel.java

      the handle parameter "now" is the timestamp of the current frame given in nanoseconds. This value will be the same for all AnimationTimers called during one frame. (Read more at the Oracle documentation! really recommended)

      Inside the handle method, we check if the time between the current frame (now) and the last time step is less than the stepIntervalNanos, if yes we simply return and do nothing. But if not, meaning the time has passesd more than the interval we set, we call the stepSimulation method and refresh the map, then update the lastStepTime to the current time.

      Incase Sumo connection gets closed, we catch the IllegalStateException and stop the animation timer.

    • stopAnimationTimer

      public void stopAnimationTimer()
      Stop animation timer method to stop the animation timer and exporting files service when main window is closed