Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SAE2.01 - Developpement application
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PIQUEREZ Corentin
SAE2.01 - Developpement application
Commits
ac400a9d
Commit
ac400a9d
authored
1 year ago
by
CHEVALIER Noemy
Browse files
Options
Downloads
Patches
Plain Diff
Création du fichier ShukanStudent
parent
e9fb91d1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
shukan/ShukanStudent.java
+198
-0
198 additions, 0 deletions
shukan/ShukanStudent.java
with
198 additions
and
0 deletions
shukan/ShukanStudent.java
0 → 100644
+
198
−
0
View file @
ac400a9d
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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment