Skip to content
Snippets Groups Projects
Commit 68415d84 authored by BERRADA Louise's avatar BERRADA Louise
Browse files

Revert "Suppression barre élèves"

This reverts commit b8e0e6b5
parent 7a6961e0
No related branches found
No related tags found
No related merge requests found
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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment