From ac400a9de447341d6e56ba51ac571de88ecd0357 Mon Sep 17 00:00:00 2001
From: CHEVALIER Noemy <noemy.chevalier7@etu.univ-lorraine.fr>
Date: Sun, 28 May 2023 21:17:03 +0000
Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20du=20fichier=20ShukanStudent?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 shukan/ShukanStudent.java | 198 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 198 insertions(+)
 create mode 100644 shukan/ShukanStudent.java

diff --git a/shukan/ShukanStudent.java b/shukan/ShukanStudent.java
new file mode 100644
index 0000000..e5bc636
--- /dev/null
+++ b/shukan/ShukanStudent.java
@@ -0,0 +1,198 @@
+package shukan;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class ShukanStudent extends JPanel{
+
+    public static final long serialVersionUID = 2L;
+    private int height;
+
+    private FontMetrics fontMetrics;
+    private int fontHeight = 10;
+    private Color BACK_COLOR = Color.WHITE;
+
+    private final static int STD_WEEK_WIDTH = 30;
+    private final static int STD_ACTIV_WIDTH = 6;
+    private final static int STD_MODULES_NUMBER = 14;
+    private final static int STD_WEEKS_NUMBER = 20;
+    private final int STD_TEXT_HEIGHT = 13;
+
+
+    private final int TEXT_MAX_HEIGHT = 15;
+    private final int TEXT_MIN_HEIGHT = 10;
+    
+    private int nbModules = STD_MODULES_NUMBER;
+    private int textHeight = STD_TEXT_HEIGHT;
+    private final static int STD_APPLI_WIDTH = STD_WEEK_WIDTH * (STD_WEEKS_NUMBER + 2);
+    private int STD_APPLI_HEIGHT = STD_TEXT_HEIGHT * 3 * (STD_MODULES_NUMBER + 1);
+    private int appliWidth = STD_APPLI_WIDTH;
+    private int appliHeight = STD_APPLI_HEIGHT;
+    private int nbWeeks = STD_WEEKS_NUMBER;
+    private int activWidth = STD_ACTIV_WIDTH;
+    private int weekWidth = STD_WEEK_WIDTH;
+
+    /** Frame borders color */
+    private final Color ACTIVE_COLOR = new Color (0.6f, 0.6f, 0.9f);
+    /** Selected activity color */
+    private final Color REACTIVE_COLOR = new Color (0.7f, 0.9f, 0.5f);  
+    /** Grid color */
+    private final Color GRID_COLOR = Color.BLACK;  
+    /** Free module weeks color */
+    private final Color HOLLY_COLOR = new Color (1.f, 0.8f, 0.7f);
+    /** Inactive parts of weeks color */
+    private final Color INACTIVE_COLOR = new Color (0.5f, 0.5f, 0.5f);
+
+    private int verticalLineHeight = 60;
+    private boolean isButtonClicked = false;
+    
+
+      /** File manager */
+    private ShukanIO myIO = null;
+    /** Displayed data */
+    private ShukanData data = null;
+
+    /** Creates the shukan viewer */
+    public ShukanStudent(ShukanData data, ShukanIO myIO, int height){
+        this.data = data;
+        this.myIO = myIO;
+        this.height = height;
+
+        setBackground(Color.WHITE);
+        setPreferredSize(new Dimension(STD_APPLI_WIDTH, height));
+    }
+
+    @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_COLOR);
+        g2.fillRect(appliWidth - w, appliHeight - h, w, h);
+        drawBox (g2, appliWidth - w, appliHeight - h, w, h);
+        displayCalendar(g2);
+    }
+
+    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;
+        }
+    }
+
+    private void displayCalendar (Graphics2D g2) {
+        if (isButtonClicked == false){
+            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]);
+            }
+        }
+        else {
+            height = 95;
+            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]);
+            }
+
+        }
+        
+    }
+
+    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.drawString (text, (int) (posx + (width - fontMetrics.stringWidth (text)) / 2),
+                            appliHeight - (int) (posy + (height - fontHeight) / 2));
+    }
+
+    /** Draws a centered paragraph in the given area. */
+  private void drawText (Graphics2D g2, float posx, float posy,
+                            float width, float height, String[] text) {
+        if (text == null) 
+        return;
+        posy += (height + (text.length - 1) * fontHeight) / 2;
+
+        for (int i = 0; i < text.length; i ++)
+        {
+            drawText (g2, posx, posy, width, fontHeight, text[i]);
+            posy -= fontHeight;
+        }
+    }
+
+    /** 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);
+    }
-- 
GitLab