Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show amount of Points subtracterd by a button #74

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .idea/sonarlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

import javax.swing.JButton;
import javax.swing.JComponent;
Expand All @@ -32,6 +33,7 @@
import edu.kit.kastel.sdq.artemis4j.grading.Assessment;
import edu.kit.kastel.sdq.artemis4j.grading.penalty.CustomPenaltyRule;
import edu.kit.kastel.sdq.artemis4j.grading.penalty.MistakeType;
import edu.kit.kastel.sdq.artemis4j.grading.penalty.Points;
import edu.kit.kastel.sdq.artemis4j.grading.penalty.RatingGroup;
import edu.kit.kastel.sdq.artemis4j.grading.penalty.StackingPenaltyRule;
import edu.kit.kastel.sdq.artemis4j.grading.penalty.ThresholdPenaltyRule;
Expand Down Expand Up @@ -95,7 +97,11 @@ private void createMistakeButtons(ActiveAssessment assessment) {
var panel = new JBPanel<>(new MigLayout("fill, gap 0, wrap " + buttonsPerRow));
for (var mistakeType : ratingGroup.getMistakeTypes()) {
var button = new JButton(mistakeType.getButtonText().translateTo(LOCALE));
button.setToolTipText(mistakeType.getMessage().translateTo(LOCALE));

// no tooltip for custom comment
if (!mistakeType.isCustomAnnotation()) {
button.setToolTipText(mistakeType.getMessage().translateTo(LOCALE));
}
button.setMargin(JBUI.emptyInsets());

var iconRenderer = new MistakeTypeIconRenderer();
Expand Down Expand Up @@ -139,7 +145,7 @@ private void updateButtonIcons(Assessment assessment) {
var settings = ArtemisSettingsState.getInstance();
var mistakeType = assessmentButton.mistakeType();

String iconText;
StringBuilder iconText = new StringBuilder();
Color color;
Font font = JBFont.regular();

Expand All @@ -149,7 +155,7 @@ private void updateButtonIcons(Assessment assessment) {

switch (rule) {
case ThresholdPenaltyRule thresholdRule -> {
iconText = count + "/" + thresholdRule.getThreshold();
iconText.append(count).append("/").append(thresholdRule.getThreshold());
if (count >= thresholdRule.getThreshold()) {
color = settings.getFinishedAssessmentButtonColor();
font = font.deriveFont(Map.of(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON));
Expand All @@ -158,20 +164,29 @@ private void updateButtonIcons(Assessment assessment) {
}
}
case CustomPenaltyRule customPenaltyRule -> {
iconText = "C";
iconText.append("C");
color = settings.getActiveAssessmentButtonColor();
}
case StackingPenaltyRule stackingPenaltyRule -> {
iconText = String.valueOf(count);
iconText.append(count);
color = settings.getActiveAssessmentButtonColor();
}
}

// find out how many points this button subtracts
Optional<Points> pointsSubtractedByButton = assessment.calculatePointsForMistakeType(mistakeType);

// annotate the amount of points subtracted by this button
pointsSubtractedByButton.ifPresentOrElse(
points -> iconText.append(" | ").append(points.score()).append("P"),
() -> iconText.append(" | 0P"));

} else {
iconText = "R";
iconText.append("R");
color = settings.getReportingAssessmentButtonColor();
}

assessmentButton.iconRenderer().update(iconText, color);
assessmentButton.iconRenderer().update(iconText.toString(), color);
assessmentButton.button().setForeground(color);
assessmentButton.button().setFont(font);
}
Expand Down