Class SecondPanel


  • class SecondPanel
    extends java.lang.Object
    This class allows the management of the secondary panel located on the right of the graphical interface. It is in this panel that we set up a form to provide all the values of the tasks (Title, type of task, description, priority and deadline). There are also three buttons to manipulate the software data, such as saving or modifying tasks, but also a button to cancel the entry.
    Author:
    CADOUL Michael AND VERY-GRIETTE Milan
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.swing.JButton abortBtn
      Delete a task button
      private int actualTask
      Displayed when nothing is selected
      private javax.swing.JButton addType
      Input for the date
      private javax.swing.JComboBox boxType
      Type JLabel
      private javax.swing.JPanel buttonsPanel
      JPanel component for the SecondPanel
      private static java.lang.String DATE_FORMAT
      Close a task button
      private javax.swing.JButton deleteBtn
      Save a task button
      private javax.swing.JLabel labelDate
      Input with slider for the priority
      private javax.swing.JLabel labelDesc
      Input for the type of task
      private javax.swing.JLabel labelPriority
      Input for the description
      private javax.swing.JLabel labelTitre
      JPanel in order to organize easily in a layout
      private javax.swing.JLabel labelType
      JTextField, input for the title
      private javax.swing.JLabel mWelcome
      Pattern to check the date
      private javax.swing.JButton rmType
      Add a type button
      private javax.swing.JButton saveBtn
      Remove a type button
      private javax.swing.JPanel secondPanel  
      private javax.swing.JSlider sliderPriority
      Priority JLabel
      private javax.swing.JTextField textDate
      Date JLabel
      private javax.swing.JTextArea textDesc
      Description JLabel
      private javax.swing.JTextField textTitre
      Title JLabel
    • Constructor Summary

      Constructors 
      Constructor Description
      SecondPanel​(MainPanel mainPanel)
      Class constructor
    • Method Summary

      Modifier and Type Method Description
      private boolean checkTaskExist​(MainPanel mainPanel)
      Used to check if a task already exists in order to prevent data duplication (based on the title of the tasks)
      private boolean checkTypeExist​(MainPanel context, int i)
      Used to check if the type already exists, in order to prevent deleting a used type of task.
      private boolean checkTypeExist​(MainPanel mainPanel, java.lang.String input)
      Used to check if a type already exists, in order to prevent data duplication
      (package private) void emptyPanel()
      Function that empty the content of all the components in this SecondPanel.
      (package private) int getActualTask()
      Getter
      (package private) javax.swing.JPanel getSecondPanel()
      Getter
      (package private) void hideComponents()
      Used to hide all the components of the SecondPanel.
      private static boolean isDateValid​(java.lang.String date)
      Used to check if the date exists and in a valid format.
      (package private) void loadTask​(int index, MainPanel context)
      Used to load a task in the second panel, when selected in the JList for example, with a specific index in the array of TaskStorage, with the current "context".
      private void proceedSave​(MainPanel mainPanel)
      Used to save a task.
      (package private) void refreshBoxType​(MainPanel mainPanel)
      Used to refresh the JComboBox, in order to display all the types of task if something was added or deleted.
      (package private) void setActualTask​(int actualTask)
      Setter
      private void setConstraints​(javax.swing.SpringLayout layout)
      Used to set all the constraints for a "responsive" layout (SpringLayout).
      (package private) void showComponent​(boolean boolContext)
      Used to show some components, according to a specific context (eg.
      private int showDialog​(MainPanel mainPanel, java.lang.String message)
      Used to display a dynamic confirmation message JOptionPane.
      • Methods inherited from class java.lang.Object

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

      • secondPanel

        private javax.swing.JPanel secondPanel
      • buttonsPanel

        private javax.swing.JPanel buttonsPanel
        JPanel component for the SecondPanel
      • labelTitre

        private javax.swing.JLabel labelTitre
        JPanel in order to organize easily in a layout
      • textTitre

        private javax.swing.JTextField textTitre
        Title JLabel
      • labelType

        private javax.swing.JLabel labelType
        JTextField, input for the title
      • boxType

        private javax.swing.JComboBox boxType
        Type JLabel
      • labelDesc

        private javax.swing.JLabel labelDesc
        Input for the type of task
      • textDesc

        private javax.swing.JTextArea textDesc
        Description JLabel
      • labelPriority

        private javax.swing.JLabel labelPriority
        Input for the description
      • sliderPriority

        private javax.swing.JSlider sliderPriority
        Priority JLabel
      • labelDate

        private javax.swing.JLabel labelDate
        Input with slider for the priority
      • textDate

        private javax.swing.JTextField textDate
        Date JLabel
      • addType

        private javax.swing.JButton addType
        Input for the date
      • rmType

        private javax.swing.JButton rmType
        Add a type button
      • saveBtn

        private javax.swing.JButton saveBtn
        Remove a type button
      • deleteBtn

        private javax.swing.JButton deleteBtn
        Save a task button
      • abortBtn

        private javax.swing.JButton abortBtn
        Delete a task button
      • DATE_FORMAT

        private static final java.lang.String DATE_FORMAT
        Close a task button
        See Also:
        Constant Field Values
      • mWelcome

        private javax.swing.JLabel mWelcome
        Pattern to check the date
      • actualTask

        private int actualTask
        Displayed when nothing is selected
    • Constructor Detail

      • SecondPanel

        SecondPanel​(MainPanel mainPanel)
        Class constructor
        Parameters:
        mainPanel - Reference to the MainPanel. This is useful if we want to access and modify all the UI. Sometimes, we call this reference, a "context".
    • Method Detail

      • getActualTask

        int getActualTask()
        Getter
        Returns:
        The value of the ActualTask (index of the array located in TaskStorage). If the value is -1, then the task is new.
      • setActualTask

        void setActualTask​(int actualTask)
        Setter
        Parameters:
        actualTask - A new value
      • refreshBoxType

        void refreshBoxType​(MainPanel mainPanel)
        Used to refresh the JComboBox, in order to display all the types of task if something was added or deleted.
        Parameters:
        mainPanel - Using the reference to the MainPanel.
      • checkTypeExist

        private boolean checkTypeExist​(MainPanel context,
                                       int i)
        Used to check if the type already exists, in order to prevent deleting a used type of task.
        Parameters:
        context - Using the reference to the MainPanel.
        i - Index of the type, stored in the TaskStorage (or the index of the JComboBox, that's the same)
        Returns:
        Boolean value, TRUE if it exists, FALSE if not.
      • proceedSave

        private void proceedSave​(MainPanel mainPanel)
        Used to save a task. But Firstly, checks if there's some important (and valid) data to set in the fields of the SecondPanel.
        Parameters:
        mainPanel - Using the reference to the MainPanel.
        Throws:
        java.lang.IllegalArgumentException - Threw if some entries are not valid or empty.
      • emptyPanel

        void emptyPanel()
        Function that empty the content of all the components in this SecondPanel.
      • checkTaskExist

        private boolean checkTaskExist​(MainPanel mainPanel)
        Used to check if a task already exists in order to prevent data duplication (based on the title of the tasks)
        Parameters:
        mainPanel - Using the reference to the MainPanel.
        Returns:
        Boolean value, TRUE if it exists, FALSE if not.
      • checkTypeExist

        private boolean checkTypeExist​(MainPanel mainPanel,
                                       java.lang.String input)
        Used to check if a type already exists, in order to prevent data duplication
        Parameters:
        mainPanel - Using the reference to the MainPanel.
        input - The user input that we want to check.
        Returns:
        Boolean value, TRUE if it exists, FALSE if not.
      • showDialog

        private int showDialog​(MainPanel mainPanel,
                               java.lang.String message)
        Used to display a dynamic confirmation message JOptionPane.
        Parameters:
        mainPanel - Using the reference to the MainPanel.
        message - The message that we want to display
        Returns:
        Integer value (the user answer, YES or NO)
      • showComponent

        void showComponent​(boolean boolContext)
        Used to show some components, according to a specific context (eg. Delete button for a task that doesn't exist doesn't make any sense.)
        Parameters:
        boolContext - IF false THEN createTaskContext, IF true THEN modifyTaskContext.
      • hideComponents

        void hideComponents()
        Used to hide all the components of the SecondPanel.
      • isDateValid

        private static boolean isDateValid​(java.lang.String date)
        Used to check if the date exists and in a valid format.
        Parameters:
        date - The date that we want to check.
        Returns:
        Boolean value, TRUE if the date is valid, FALSE if not.
      • setConstraints

        private void setConstraints​(javax.swing.SpringLayout layout)
        Used to set all the constraints for a "responsive" layout (SpringLayout). All the objects in a SpringLayout is organised with several constraints. All we have to do is to define which components have a constraint in which side of the object A constraint must have a component, the side of a component, with another component with a specific side and the "distance" between the two objects
        Parameters:
        layout - The layout that we want to organize.
      • getSecondPanel

        javax.swing.JPanel getSecondPanel()
        Getter
        Returns:
        The JPanel element.
      • loadTask

        void loadTask​(int index,
                      MainPanel context)
        Used to load a task in the second panel, when selected in the JList for example, with a specific index in the array of TaskStorage, with the current "context".
        Parameters:
        index - The index of the task in TaskStorage
        context - Using the reference to the MainPanel.