First commit
This commit is contained in:
72
Homework 8/src/gui/CategoryField.java
Executable file
72
Homework 8/src/gui/CategoryField.java
Executable file
@@ -0,0 +1,72 @@
|
||||
package gui;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import grading.CompositeGrade;
|
||||
import grading.Grade;
|
||||
import grading.LeafGrade;
|
||||
|
||||
/**
|
||||
* A grouping of LeafGradeFields for a specific category of grades.
|
||||
*/
|
||||
public class CategoryField extends JPanel
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private List<LeafGradeField> fields;
|
||||
private CompositeGrade template;
|
||||
|
||||
/**
|
||||
* @param template The CompositeGrade to use as a default key and value.
|
||||
*/
|
||||
public CategoryField(final CompositeGrade template)
|
||||
{
|
||||
this.template = template;
|
||||
this.fields = new ArrayList<LeafGradeField>();
|
||||
setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
setBorder(BorderFactory.createTitledBorder(template.getKey()));
|
||||
|
||||
for (Grade grade : template.getComponents())
|
||||
{
|
||||
if (grade instanceof LeafGrade)
|
||||
{
|
||||
LeafGradeField field = new LeafGradeField((LeafGrade) grade);
|
||||
fields.add(field);
|
||||
add(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A new Grade object representing the composite grade of all fields in the category.
|
||||
*/
|
||||
public Grade getGrade()
|
||||
{
|
||||
CompositeGrade grade = new CompositeGrade(getKey());
|
||||
grade.setFilter(template.getFilter());
|
||||
grade.setStrategy(template.getStrategy());
|
||||
fields.forEach((field) -> grade.add(field.getGrade()));
|
||||
|
||||
return grade;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The key for this category
|
||||
*/
|
||||
public String getKey()
|
||||
{
|
||||
return template.getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears any text from all grades in this category.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
fields.forEach((field) -> field.reset());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user