DetailedCourseView.java
1 |
|
2 |
import javax.swing.*; |
3 |
|
4 |
/** |
5 |
* This class creates a JPanel using the given course. This JPanel is then a detailed description of said course. |
6 |
* @author Maarten Vangeneugden - 1438256 |
7 |
*/ |
8 |
|
9 |
class DetailedCourseView extends AbstractView { |
10 |
private Course m_course; // The course of this class. |
11 |
public Course course() { |
12 |
return m_course; |
13 |
} |
14 |
private void setCourse(Course course) { // Sets the course, but also triggers to update the panel itself. This is necessary, since the panel will otherwise not be a representation of the course itself. |
15 |
m_course = course; |
16 |
setContent(); |
17 |
} |
18 |
|
19 |
private JPanel m_panel; // The panel that will represent the course. |
20 |
public JPanel panel() { |
21 |
return m_panel; |
22 |
} |
23 |
private void setPanel(JPanel panel) { |
24 |
m_panel = panel; |
25 |
} |
26 |
//There is no public panel setter. The panel can only be changed by modifying the course, since this panel represents the course. |
27 |
|
28 |
public DetailedCourseView(Course course) { |
29 |
super(course, null); |
30 |
setCourse(course); |
31 |
} |
32 |
|
33 |
/** |
34 |
* Will update the panel of the class according to the given course. |
35 |
* @pre The course of the class is not null. |
36 |
* @post The panel of the class is updated and is now an update representation of the given course. |
37 |
*/ |
38 |
private void setContent() { // Creates the content for this JPanel. Not that it's private; Its functionality may only be triggered by its own instance. |
39 |
// First, we handle the common members, since we know the base class can't be smaller than inherited classes. |
40 |
JLabel lblName = new JLabel("Naam: " + course().name()); |
41 |
JLabel lblID = new JLabel("ID: " + Integer.toString(course().ID())); |
42 |
JLabel lblStudyPoints = new JLabel("Studiepunten: " + Integer.toString(course().studyPoints())); |
43 |
JLabel lblSemester = new JLabel("Semester: " + Integer.toString(course().semester())); |
44 |
JLabel lblType = new JLabel(); // We wil fill this in later. |
45 |
|
46 |
JLabel lblPass = new JLabel(); |
47 |
if(course().creditAcquired()) |
48 |
lblPass.setText("Verworven credit"); |
49 |
else |
50 |
lblPass.setText("Credit niet verworven"); |
51 |
|
52 |
// Second, we do a RTTI on the given course by checking the instance type. (RTTI = RunTime Type Identification) |
53 |
if(course() instanceof MandatoryCourse) { |
54 |
lblType.setText("Verplicht vak - Jaar" + Integer.toString(((MandatoryCourse)course()).year())); |
55 |
} |
56 |
else if(course() instanceof ChoiceCourse) { |
57 |
lblType.setText("Keuzevak"); |
58 |
} |
59 |
|
60 |
// Third, we add all the labels to the panel. |
61 |
JPanel panel = new JPanel(); |
62 |
panel.add(lblName); |
63 |
panel.add(lblID); |
64 |
panel.add(lblStudyPoints); |
65 |
panel.add(lblSemester); |
66 |
panel.add(lblType); |
67 |
panel.add(lblPass); |
68 |
|
69 |
setPanel(panel); |
70 |
} |
71 |
|
72 |
private void update(Observable course, Object info) { |
73 |
setContent(course); |
74 |
} |
75 |
} |
76 |