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

440 add circle to scoring tables on pdf #442

Merged
merged 3 commits into from
May 18, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![GitHub last commit](https://img.shields.io/github/last-commit/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager)
[![CircleCI](https://circleci.com/gh/softwaremagico/KendoTournamentManager.svg?style=shield)](https://circleci.com/gh/softwaremagico/KendoTournamentManager)
[![Time](https://img.shields.io/badge/development-618h-blueviolet.svg)]()
[![Time](https://img.shields.io/badge/development-619.5h-blueviolet.svg)]()

[![Powered by](https://img.shields.io/badge/powered%20by%20java-orange.svg?logo=OpenJDK&logoColor=white)]()
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=kendo-tournament-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=kendo-tournament-backend)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ private String getDrawFight(FightDTO fightDTO, int duel) {
// Draw Fights
final String draw;
if (fightDTO.getDuels().get(duel).getWinner() == 0 && fightDTO.isOver()) {
draw = String.valueOf(Score.DRAW.getAbbreviation());
draw = String.valueOf(Score.DRAW.getPdfAbbreviation());
} else {
draw = String.valueOf(Score.EMPTY.getAbbreviation());
draw = String.valueOf(Score.EMPTY.getPdfAbbreviation());
}
return draw;
}
Expand All @@ -273,19 +273,19 @@ private String getFaults(FightDTO fightDTO, int duel, boolean leftTeam) {
faults = fightDTO.getDuels().get(duel).getCompetitor2Fault();
}
if (faults) {
faultSymbol = String.valueOf(Score.FAULT.getAbbreviation());
faultSymbol = String.valueOf(Score.FAULT.getPdfAbbreviation());
} else {
faultSymbol = String.valueOf(Score.EMPTY.getAbbreviation());
faultSymbol = String.valueOf(Score.EMPTY.getPdfAbbreviation());
}
return faultSymbol;
}

private String getScore(FightDTO fightDTO, int duel, int score, boolean leftTeam) {
try {
if (leftTeam) {
return String.valueOf(fightDTO.getDuels().get(duel).getCompetitor1Score().get(score).getAbbreviation());
return String.valueOf(fightDTO.getDuels().get(duel).getCompetitor1Score().get(score).getPdfAbbreviation());
} else {
return String.valueOf(fightDTO.getDuels().get(duel).getCompetitor2Score().get(score).getAbbreviation());
return String.valueOf(fightDTO.getDuels().get(duel).getCompetitor2Score().get(score).getPdfAbbreviation());
}
} catch (IndexOutOfBoundsException | NullPointerException e) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public abstract class ParentList extends PdfDocument {
protected static final int TABLE_BORDER = 0;
private static final float HEADER_SEPARATOR = 20f;

private static final int BOTTOM_PADDING = 15;
protected static final int BOTTOM_PADDING = 15;

private static final int FONT_BIG_EXTRA_SIZE = 10;
private static final int FONT_MEDIUM_EXTRA_SIZE = 6;
private static final int FONT_SMALL_EXTRA_SIZE = 4;
protected static final int FONT_SMALL_EXTRA_SIZE = 4;


/**
Expand Down Expand Up @@ -139,19 +139,29 @@ public PdfPCell getCell(String text, int border, BaseFont font, int colspan, int
return getCell(text, border, colspan, align, BaseColor.WHITE, font, PdfTheme.FONT_SIZE, Font.NORMAL);
}

public PdfPCell getCell(String text, int border, BaseFont font, int fontSize, Color color, int colspan, int align) {
return getCell(text, border, colspan, align, color, font, fontSize, Font.NORMAL);
}

public PdfPCell getCell(String text, BaseFont font, int colspan, int align, int fontType) {
return getCell(text, CELL_BORDER, colspan, align, BaseColor.WHITE, font, PdfTheme.FONT_SIZE, fontType);
}

protected Color getCellBorderColor() {
return Color.LIGHT_GRAY;
}

public PdfPCell getCell(String text, int border, int colspan, int align, Color color,
BaseFont font, int fontSize, int fontType) {
final Paragraph p = new Paragraph(text, new Font(font, fontSize, fontType));
final PdfPCell cell = new PdfPCell(p);
cell.setColspan(colspan);
cell.setBorderWidth(border);
cell.setBorderColor(Color.LIGHT_GRAY);
cell.setBorderColor(getCellBorderColor());
cell.setHorizontalAlignment(align);
cell.setBackgroundColor(color);
if (color != null) {
cell.setBackgroundColor(color);
}
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

return cell;
Expand All @@ -167,7 +177,7 @@ public PdfPCell getCell(String text, int border, int colspan, int align, Color c
* @return
*/
public PdfPCell getHeader(String text, int border, int align, int fontSize) {
final PdfPCell cell = getCell(text, border, getTableWidths().length, align, new Color(255, 255, 255), PdfTheme.getTitleFont(), fontSize, Font.BOLD);
final PdfPCell cell = getCell(text, border, getTableWidths().length, align, Color.WHITE, PdfTheme.getTitleFont(), fontSize, Font.BOLD);
cell.setPaddingBottom(BOTTOM_PADDING);
return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public abstract class PdfTheme {
public static final int FOOTER_FONT_SIZE = 8;

public static final int FONT_SIZE = 12;
public static final int SCORE_FONT_SIZE = 8;
public static final int SCORE_LIST_SIZE = 9;

public static final int HEADER_FONT_SIZE = FONT_SIZE + 15;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.softwaremagico.kt.pdf.events;

/*-
* #%L
* Kendo Tournament Manager (PDF)
* %%
* Copyright (C) 2021 - 2024 Softwaremagico
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/

import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;

import java.awt.Color;

/**
* Event for creating a transparent cell.
*/
public class FaultTriangleCellEvent implements PdfPCellEvent {

private static final int TRIANGLE_MARGIN = 6;
private static final int BOTTOM_MARGIN = 4;


@Override
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
final PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
cb.setColorStroke(Color.BLACK);
cb.setColorFill(Color.BLACK);
cb.moveTo(rect.getLeft() + TRIANGLE_MARGIN, rect.getBottom() + BOTTOM_MARGIN);
cb.lineTo(rect.getRight() - TRIANGLE_MARGIN, rect.getBottom() + BOTTOM_MARGIN);
cb.lineTo(rect.getLeft() + (rect.getRight() - rect.getLeft()) / 2, rect.getTop() - TRIANGLE_MARGIN
- (TRIANGLE_MARGIN - BOTTOM_MARGIN));
cb.closePathFillStroke();
cb.stroke();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.softwaremagico.kt.pdf.events;

/*-
* #%L
* Kendo Tournament Manager (PDF)
* %%
* Copyright (C) 2021 - 2024 Softwaremagico
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/

import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.PdfPTable;

import java.awt.Color;

/**
* Event for creating a transparent cell.
*/
public class ScoreCircleCellEvent implements PdfPCellEvent {

private static final int CIRCLE_MARGIN = 1;


@Override
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
final PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
cb.setColorStroke(Color.BLACK);
cb.setColorFill(Color.WHITE);
cb.circle(rect.getLeft() + (rect.getRight() - rect.getLeft()) / 2,
rect.getBottom() + (rect.getTop() - rect.getBottom()) / 2,
Math.min((rect.getRight() - rect.getLeft()) / 2, (rect.getTop() - rect.getBottom()) / 2) - CIRCLE_MARGIN);
cb.stroke();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import com.softwaremagico.kt.core.controller.models.FightDTO;
import com.softwaremagico.kt.core.controller.models.GroupDTO;
import com.softwaremagico.kt.core.controller.models.TournamentDTO;
import com.softwaremagico.kt.persistence.values.Score;
import org.springframework.context.MessageSource;

import java.awt.Color;
import java.util.List;
import java.util.Locale;

Expand All @@ -38,18 +40,23 @@ protected EmptyFightsList(MessageSource messageSource, Locale locale, Tournament
super(messageSource, locale, tournament, groups, shiaijo);
}

@Override
protected Color getCellBorderColor() {
return Color.BLACK;
}

@Override
protected String getDrawFight(FightDTO fightDTO, int duel) {
return "";
}

@Override
protected String getFaults(FightDTO fightDTO, int duel, boolean leftTeam) {
return "";
protected boolean getFaults(FightDTO fightDTO, int duel, boolean leftTeam) {
return false;
}

@Override
protected String getScore(FightDTO fightDTO, int duel, int score, boolean leftTeam) {
return "";
protected Score getScore(FightDTO fightDTO, int duel, int score, boolean leftTeam) {
return null;
}
}
Loading
Loading