From 68415d84101e80888d21c9398208aa81492c3b76 Mon Sep 17 00:00:00 2001
From: BERRADA Louise <louise.berrada1@etu.univ-lorraine.fr>
Date: Tue, 30 May 2023 20:03:50 +0000
Subject: [PATCH] =?UTF-8?q?Revert=20"Suppression=20barre=20=C3=A9l=C3=A8ve?=
 =?UTF-8?q?s"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit b8e0e6b51a5d31ff14556d7b1a1f8e32d22ef7eb
---
 shukan/ShukanStudent.java | 174 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 174 insertions(+)
 create mode 100644 shukan/ShukanStudent.java

diff --git a/shukan/ShukanStudent.java b/shukan/ShukanStudent.java
new file mode 100644
index 0000000..147a4a4
--- /dev/null
+++ b/shukan/ShukanStudent.java
@@ -0,0 +1,174 @@
+package shukan;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**Graphical view for planner of student */
+public class ShukanStudent extends JPanel{
+    /**Height of object */
+    private int height;
+    /** Font metrics features */
+    private FontMetrics fontMetrics;
+    /** Height of the font characters */
+    private int fontHeight = 10;
+    /** Background color */
+    private Color BACK_COLOR = Color.WHITE;
+    /** Standard week column width */
+    private final static int STD_WEEK_WIDTH = 30;
+    /** Standard activity symbol width */
+    private final static int STD_ACTIV_WIDTH = 6;
+    /** Standard number of modules */
+    private final static int STD_MODULES_NUMBER = 14;
+    /** Standard number of weeks */
+    private final static int STD_WEEKS_NUMBER = 20;
+    /** Standard height of a text line */
+    private final int STD_TEXT_HEIGHT = 13;
+    /** Standard application width */
+    private final static int STD_APPLI_WIDTH = STD_WEEK_WIDTH * (STD_WEEKS_NUMBER + 2);
+     /** Standard application height */
+    private final int STD_APPLI_HEIGHT = STD_TEXT_HEIGHT * 3 * (STD_MODULES_NUMBER + 1);
+
+
+    /** Number of modules to display */
+    private int nbModules = STD_MODULES_NUMBER;
+    /** Height of a text line */
+    private int textHeight = STD_TEXT_HEIGHT;
+    /** Application actual width */
+    private int appliWidth = STD_APPLI_WIDTH;
+    /** Application actual height */
+    private int appliHeight = STD_APPLI_HEIGHT;
+    /** Number of weeks to display */
+    private int nbWeeks = STD_WEEKS_NUMBER;
+    /** Standard activity symbol actual width */
+    private int activWidth = STD_ACTIV_WIDTH;
+    /** Week column actual width */
+    private int weekWidth = STD_WEEK_WIDTH;
+
+    /** Grid color */
+    private final Color GRID_COLOR = Color.BLACK;  
+      /** Text color */
+    private Color TEXT_COLOR = Color.BLACK;
+    /** Color background, text, hollydays*/
+    private Color BACK_COLOR2 = Color.LIGHT_GRAY;
+
+
+    /** Displayed data */
+    private ShukanData data = null;
+
+    /** Creates the shukan viewer */
+    public ShukanStudent(ShukanData data, int height){
+        this.data = data;
+        this.height = height;
+
+        setPreferredSize(new Dimension(STD_APPLI_WIDTH, height));
+    }
+
+    /** Draws Shukan view.*/
+    @Override
+    protected void paintComponent(Graphics g) {
+        super.paintComponent(g);
+
+        int w = getWidth();
+        int h = getHeight();
+        adaptSize(w, h);
+
+        Graphics2D g2 = (Graphics2D) g.create();
+        g2.setFont(new Font("Helvetica", Font.PLAIN, 12));
+        fontMetrics = g2.getFontMetrics();
+        fontHeight = fontMetrics.getAscent();
+
+        g2.setColor(BACK_COLOR2);
+        g2.fillRect(appliWidth - w, appliHeight - h, w, h);
+        drawBox (g2, appliWidth - w, appliHeight - h, w, h);
+        displayCalendar(g2);
+    }
+
+    /** Updates the application size.*/
+    private void adaptSize(int width, int height) {
+        if (data != null) 
+        {
+            nbWeeks = data.semesterSize();
+            nbModules = data.numberOfModules();
+
+            textHeight = (int) (height / (3.0f * (nbModules + 1)));
+            appliHeight = textHeight * 3 * (nbModules + 1);
+
+            activWidth = width / (ShukanModule.MAX_ACTIV_PER_WEEK * (nbWeeks + 2));
+            weekWidth = activWidth * ShukanModule.MAX_ACTIV_PER_WEEK;
+            appliWidth = weekWidth * (nbWeeks + 2);
+        }  
+        else 
+        {
+            appliWidth = STD_APPLI_WIDTH;
+            appliHeight = STD_APPLI_HEIGHT;
+        }
+    }
+
+    /** Displays the calendar grid background.*/
+    private void displayCalendar (Graphics2D g2) {
+        g2.setColor(GRID_COLOR);
+        // Lines
+        drawHLine(g2, 0, 40, appliWidth);  
+        
+        // Columns
+        for (int i = 2; i <= nbWeeks + 1; i++)
+            drawVLine(g2, i * weekWidth, 0, appliHeight);
+        
+        drawText(g2, 0, 18, 2 * weekWidth, textHeight, data.studentName());
+
+        for (int i = 0; i < nbWeeks; i++)
+        {
+            int[] weekNumbers = data.weekNumbers ();
+            int[] durations = data.weekDurations ();
+            drawText (g2, (i + 2) * weekWidth, 25,
+                            weekWidth, textHeight, "" + data.studentLoad(i));
+            drawText (g2, (2 + i) * weekWidth, 0,
+                            weekWidth, 20, "/" + durations[i]);
+        }
+    }
+
+    /**Create a new height */
+    public void changeStudentHeight(int newHeight) {
+        setPreferredSize(new Dimension(getWidth(), newHeight));
+        revalidate();
+        repaint();
+    }
+
+
+    /** Draws a vertical line.*/
+    private void drawVLine (Graphics2D g2, int x, int y, int l) {
+        g2.drawLine (x, appliHeight - y, x, appliHeight - y - l);
+    }
+
+    /** Draws a centered text in the given area.*/
+    private void drawText (Graphics2D g2, float posx, float posy,
+                                        float width, float height, String text)
+    {   
+        g2.setColor(TEXT_COLOR);
+        g2.drawString (text, (int) (posx + (width - fontMetrics.stringWidth (text)) / 2),
+                            appliHeight - (int) (posy + (height - fontHeight) / 2));
+    }
+
+    /** Draws a rectangular box.*/
+    private void drawBox (Graphics2D g2, int posx, int posy,int width, int height) {
+        g2.fillRect (posx, appliHeight - posy - height, width, height);
+    }
+
+    /** Draws a horizontal line.*/
+    private void drawHLine (Graphics2D g2, int x, int y, int l)
+    {
+        g2.drawLine (x, appliHeight - y, x + l, appliHeight - y);
+    }
+    
+    /**Change the background color. */
+    public void setBackgroundColor(Color c){
+        BACK_COLOR = c;
+        repaint();
+    }
+
+    /**Change the text color. */
+    public void setForeground(Color c){
+        TEXT_COLOR = c;
+        repaint();
+    }
+}
-- 
GitLab