Class SwingWindow

java.lang.Object
ch.epfl.cs107.play.math.Node
ch.epfl.cs107.play.window.swing.SwingWindow
All Implemented Interfaces:
Attachable, Positionable, Audio, Canvas, Window

public final class SwingWindow extends Node implements Window
Swing implementation of window context.
  • Constructor Details

    • SwingWindow

      public SwingWindow(String title, FileSystem fileSystem, int width, int height)
      Creates a new window.
      Parameters:
      title - (String): window caption
      fileSystem - (FileSystem): source used to load images
      width - (int): width in pixel of the window
      height - (int): height in pixel of the window
  • Method Details

    • getFocus

      public Button getFocus()
      Specified by:
      getFocus in interface Window
      Returns:
      (Button): whether the windows is active
    • getMouse

      public Mouse getMouse()
      Specified by:
      getMouse in interface Window
      Returns:
      (Mouse): associated mouse controller
    • getKeyboard

      public Keyboard getKeyboard()
      Specified by:
      getKeyboard in interface Window
      Returns:
      (Keyboard): associated keyboard controller
    • isCloseRequested

      public boolean isCloseRequested()
      Specified by:
      isCloseRequested in interface Window
      Returns:
      (boolean): whether the user tried to close the window
    • update

      public void update()
      Specified by:
      update in interface Window
    • dispose

      public void dispose()
      Description copied from interface: Window
      Destroys and closes the window
      Specified by:
      dispose in interface Window
    • getImage

      public SwingImage getImage(String name, RegionOfInterest roi, boolean removeBackground)
      Description copied from interface: Canvas
      Gets image from file system.
      Specified by:
      getImage in interface Canvas
      Parameters:
      name - (String): full name of image, not null
      roi - (RegionOfInterest): region of interest
      removeBackground - (boolean): which indicate if we need to remove an uniform background
      Returns:
      an image object, null on error
    • draw

      public void draw(Item item)
      Add specified item to current draw list.
      Parameters:
      item - (Item) any item, not null
    • drawImage

      public void drawImage(Image image, Transform transform, float alpha, float depth)
      Description copied from interface: Canvas
      Draws specified image.
      Specified by:
      drawImage in interface Canvas
      Parameters:
      image - (Image): any image associated to this context, may be null
      transform - (Transform): any affine transform, not null
      alpha - (float): transparency, between 0.0 and 1.0
      depth - (float): any real, larger values are drawn afterward, i.e. above
    • drawShape

      public void drawShape(Shape shape, Transform transform, Color fillColor, Color outlineColor, float thickness, float alpha, float depth)
      Description copied from interface: Canvas
      Draws specified image
      Specified by:
      drawShape in interface Canvas
      Parameters:
      shape - (Shape): any shape, may be null
      transform - (Transform): any affine transform, not null
      fillColor - (Color): color used to fill the shape, may be null
      outlineColor - (Color): color used to draw shape border, may be null
      thickness - (float): border thickness
      alpha - (float): transparency, between 0.0 and 1.0
      depth - (float): any real, larger values are drawn afterward, i.e. above
    • registerFonts

      public void registerFonts(String directoryName)
      Description copied from interface: Canvas
      Register all the font in a directory
      Specified by:
      registerFonts in interface Canvas
      Parameters:
      directoryName - (String): the name of the directory
    • drawText

      public void drawText(String text, float fontSize, Transform transform, Color fillColor, Color outlineColor, float thickness, String fontName, boolean bold, boolean italics, Vector anchor, TextAlign.Horizontal hAlign, TextAlign.Vertical vAlign, float alpha, float depth)
      Description copied from interface: Canvas
      Creates a new text graphics.
      Specified by:
      drawText in interface Canvas
      Parameters:
      text - (String): content, not null
      fontSize - (float): size
      transform - (Transform): affine transform, not null
      fillColor - (Color): fill color, may be null
      outlineColor - (Color): outline color, may be null
      thickness - (float): outline thickness
      fontName - (String): the font name
      bold - (boolean): whether to use bold font
      italics - (boolean): whether to use italics font
      anchor - (Vector): text anchor
      hAlign - (TextAlign.Horizontal): horizontal alignment of the text around the anchor vector
      vAlign - (TextAlign.Vertical): vertical alignment of the text around the anchor vector
      alpha - (float): transparency, between 0 (invisible) and 1 (opaque)
      depth - (float): render priority, lower-values drawn first
    • getSound

      public SwingSound getSound(String name)
      Description copied from interface: Audio
      Gets sound from file system.
      Specified by:
      getSound in interface Audio
      Parameters:
      name - (String): full name of image, not null
      Returns:
      (Sound): a sound object, null on error
    • playSound

      public void playSound(Sound sound, boolean randomFirstStart, float volume, boolean fadeIn, boolean loop, boolean stopOthersOnStart)
      Description copied from interface: Audio
      Play specified sound.
      Specified by:
      playSound in interface Audio
      Parameters:
      sound - (Sound): any sound associated to this context, may be null
      randomFirstStart - (boolean): indicate if the first start is random in the sound
      volume - (float): 0.0f no sound, 1.0f full audio
      fadeIn - (boolean): indicate if the song fade in until reaching its max volume
      loop - (boolean): indicate if the sound must loop on self ending
      stopOthersOnStart - (boolean): indicate if all other sound are stopped on given sound's start
    • isSoundSupported

      public boolean isSoundSupported()
      Specified by:
      isSoundSupported in interface Audio
      Returns:
      (boolean): true if the sound is supported by the Audio
    • convertPositionOnScreen

      public Vector convertPositionOnScreen(Vector coord)
      Description copied from interface: Canvas
      Convert a coordinate in the canvas to a coordinate in the screen
      Specified by:
      convertPositionOnScreen in interface Canvas
      Parameters:
      coord - the coordinate in the canvas
      Returns:
      the coordinate in the screen
    • getWidth

      public int getWidth()
      Description copied from interface: Canvas
      Return the canvas width
      Specified by:
      getWidth in interface Canvas
      Returns:
      width (int): the canvas width
    • getHeight

      public int getHeight()
      Description copied from interface: Canvas
      Return the canvas height
      Specified by:
      getHeight in interface Canvas
      Returns:
      height (int): the canvas height
    • getXScale

      public float getXScale()
      Description copied from interface: Canvas
      Return the canvas scaled width
      Specified by:
      getXScale in interface Canvas
      Returns:
      width (float): the canvas scaled width
    • getYScale

      public float getYScale()
      Description copied from interface: Canvas
      Return the canvas scaled height
      Specified by:
      getYScale in interface Canvas
      Returns:
      height (float): the canvas scaled height
    • getScaledWidth

      public float getScaledWidth()
      Description copied from interface: Canvas
      Return the canvas scaled width after adjusting to ratio
      Specified by:
      getScaledWidth in interface Canvas
      Returns:
      width (float): the canvas scaled width
    • getScaledHeight

      public float getScaledHeight()
      Description copied from interface: Canvas
      Return the canvas scaled height after adjusting to ratio
      Specified by:
      getScaledHeight in interface Canvas
      Returns:
      height (float): the canvas scaled height