Package Helper

Class StringTableFile


  • public class StringTableFile
    extends java.lang.Object
    The StringTableFile class represents a utility class for managing string table data related to the background colors of UI buttons. It provides methods to save and load background colors to and from a file.
    Since:
    2023-12-01
    Version:
    1.0
    Author:
    Laamiri Ouail & Hajar Sadik
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private StringTableFile()
      Private constructor to create a new instance of StringTableFile.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void checkAndCreateDirectory​(java.lang.String directoryPath)
      Checks if the directory at the specified path exists.
      private void checkAndCreateFile​(java.lang.String filePath)
      Checks if the file at the specified path exists.
      static StringTableFile getInstance()
      Retrieves a singleton instance of the StringTableFile class.
      void loadBackgroundColorFromFile()
      Loads background colors from the specified file and updates the UI buttons accordingly.
      java.lang.String[] loadConfigurations()
      Loads configurations (row, column, colors) from the specified file.
      void saveBackgroundColorToFile()
      Saves the background colors to the specified file.
      void saveConfigurations​(short row, short column, java.lang.String defaultBoardColor, java.lang.String player1Color, java.lang.String player2Color, java.lang.String secondPossibleMoveColor, java.lang.String backgroundAppColor)
      Saves the configurations (row, column, colors) to the specified file.
      void saveSauvgardeToFile​(java.lang.String title, int row, int column, int machine)
      Saves a saved state to the specified file, including background colors, title, date and time, and machine identifier.
      void saveVoidColors()
      Saves a default set of background colors to the specified file.
      void setBackgroundColors()
      Sets the background colors based on the provided UI buttons.
      java.util.ArrayList<Sauvgard> uploadSauvgardeFromFile()
      Uploads saved states from the specified file and returns a list of Sauvgard objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • backgroundColors

        private java.lang.String[][] backgroundColors
    • Constructor Detail

      • StringTableFile

        private StringTableFile()
        Private constructor to create a new instance of StringTableFile. Initializes the background colors based on the provided buttons.
    • Method Detail

      • checkAndCreateFile

        private void checkAndCreateFile​(java.lang.String filePath)
        Checks if the file at the specified path exists. If not, creates an empty file.
        Parameters:
        filePath - The path of the file to check and create.
      • checkAndCreateDirectory

        private void checkAndCreateDirectory​(java.lang.String directoryPath)
        Checks if the directory at the specified path exists. If not, creates the directory and any necessary parent directories.
        Parameters:
        directoryPath - The path of the directory to check and create.
      • getInstance

        public static StringTableFile getInstance()
        Retrieves a singleton instance of the StringTableFile class. If an instance does not exist, a new one is created based on the provided buttons.
        Returns:
        The singleton instance of StringTableFile.
      • setBackgroundColors

        public void setBackgroundColors()
        Sets the background colors based on the provided UI buttons.
      • saveVoidColors

        public void saveVoidColors()
        Saves a default set of background colors to the specified file.
      • saveBackgroundColorToFile

        public void saveBackgroundColorToFile()
        Saves the background colors to the specified file.
      • loadBackgroundColorFromFile

        public void loadBackgroundColorFromFile()
        Loads background colors from the specified file and updates the UI buttons accordingly.
      • saveConfigurations

        public void saveConfigurations​(short row,
                                       short column,
                                       java.lang.String defaultBoardColor,
                                       java.lang.String player1Color,
                                       java.lang.String player2Color,
                                       java.lang.String secondPossibleMoveColor,
                                       java.lang.String backgroundAppColor)
        Saves the configurations (row, column, colors) to the specified file.
        Parameters:
        row - The number of rows.
        column - The number of columns.
        defaultBoardColor - The default board color.
        player1Color - The color for player 1.
        player2Color - The color for player 2.
        secondPossibleMoveColor - The color for the second possible move.
        backgroundAppColor - The background color of the application.
      • loadConfigurations

        public java.lang.String[] loadConfigurations()
        Loads configurations (row, column, colors) from the specified file.
        Returns:
        An array containing loaded configuration values.
      • saveSauvgardeToFile

        public void saveSauvgardeToFile​(java.lang.String title,
                                        int row,
                                        int column,
                                        int machine)
        Saves a saved state to the specified file, including background colors, title, date and time, and machine identifier.
        Parameters:
        title - The title of the saved state.
        row - The number of rows in the saved state.
        column - The number of columns in the saved state.
        machine - The machine identifier associated with the saved state.
      • uploadSauvgardeFromFile

        public java.util.ArrayList<Sauvgard> uploadSauvgardeFromFile()
        Uploads saved states from the specified file and returns a list of Sauvgard objects.
        Returns:
        An ArrayList of Sauvgard objects representing saved states.