Skip to content

Commit

Permalink
Improved team titles, borders, faults
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaremagico committed May 18, 2024
1 parent 046b08a commit 897b48b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 20 deletions.
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-618.5h-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 @@ -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 @@ -177,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
@@ -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
Expand Up @@ -51,8 +51,8 @@ protected String getDrawFight(FightDTO fightDTO, int duel) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.softwaremagico.kt.pdf.BaseColor;
import com.softwaremagico.kt.pdf.ParentList;
import com.softwaremagico.kt.pdf.PdfTheme;
import com.softwaremagico.kt.pdf.events.FaultTriangleCellEvent;
import com.softwaremagico.kt.pdf.events.ScoreCircleCellEvent;
import com.softwaremagico.kt.persistence.values.Score;
import com.softwaremagico.kt.persistence.values.TournamentType;
Expand All @@ -58,7 +59,7 @@
* Creates a sheet with all fights and all its score. The scope is to have a report after the tournament is finished.
*/
public class FightSummary extends ParentList {
private static final float[] TABLE_WIDTH = {0.29f, 0.03f, 0.08f, 0.08f, 0.04f, 0.08f, 0.08f, 0.03f, 0.29f};
private static final float[] TABLE_WIDTH = {0.29f, 0.03f, 0.08f, 0.08f, 0.02f, 0.08f, 0.08f, 0.03f, 0.29f};
private static final int DEFAULT_CELL_HEIGHT = 50;
private static final int FIGHT_BORDER = 1;
private final MessageSource messageSource;
Expand Down Expand Up @@ -86,13 +87,11 @@ protected String getDrawFight(FightDTO fightDTO, int duel) {
}
}

protected String getFaults(FightDTO fightDTO, int duel, boolean leftTeam) {
protected boolean getFaults(FightDTO fightDTO, int duel, boolean leftTeam) {
if (leftTeam) {
return fightDTO.getDuels().get(duel).getCompetitor1Fault() ? String.valueOf(Score.FAULT.getPdfAbbreviation())
: String.valueOf(Score.EMPTY.getPdfAbbreviation());
return fightDTO.getDuels().get(duel).getCompetitor1Fault();
} else {
return fightDTO.getDuels().get(duel).getCompetitor2Fault() ? String.valueOf(Score.FAULT.getPdfAbbreviation())
: String.valueOf(Score.EMPTY.getPdfAbbreviation());
return fightDTO.getDuels().get(duel).getCompetitor2Fault();
}
}

Expand All @@ -115,7 +114,9 @@ private PdfPTable fightTable(FightDTO fightDTO, boolean first) throws DocumentEx
table.addCell(getEmptyRow(DEFAULT_CELL_HEIGHT));
}

table.addCell(getHeader3(fightDTO.getTeam1().getName() + " - " + fightDTO.getTeam2().getName(), 0));
table.addCell(getTeamHeader(fightDTO.getTeam1().getName(), TABLE_WIDTH.length / 2));
table.addCell(getTeamHeader("", 1));
table.addCell(getTeamHeader(fightDTO.getTeam2().getName(), TABLE_WIDTH.length / 2));

for (int i = 0; i < fightDTO.getTournament().getTeamSize(); i++) {
// Team 1
Expand All @@ -124,39 +125,51 @@ private PdfPTable fightTable(FightDTO fightDTO, boolean first) throws DocumentEx
if (competitor != null) {
name = NameUtils.getLastnameNameIni(competitor);
}
table.addCell(getCell(name, FIGHT_BORDER, PdfTheme.getHandwrittenFont(), PdfTheme.SCORE_LIST_SIZE, Color.WHITE, 1, Element.ALIGN_LEFT));

final PdfPCell team1NameCell = getCell(name, FIGHT_BORDER, PdfTheme.getHandwrittenFont(), PdfTheme.SCORE_LIST_SIZE, Color.WHITE, 1, Element.ALIGN_LEFT);
team1NameCell.setBorder(PdfPCell.BOTTOM);
table.addCell(team1NameCell);

// Faults
table.addCell(getCell(getFaults(fightDTO, i, true), FIGHT_BORDER, PdfTheme.getHandwrittenFont(), 1, Element.ALIGN_CENTER));
table.addCell(getFaultCell(fightDTO, i, true));

// Points
table.addCell(getScoreCell(fightDTO, i, 1, true));
table.addCell(getScoreCell(fightDTO, i, 0, true));

table.addCell(getCell(getDrawFight(fightDTO, i), FIGHT_BORDER, PdfTheme.getHandwrittenFont(),
PdfTheme.SCORE_FONT_SIZE, null, 1, Element.ALIGN_CENTER));
final PdfPCell drawCell = getCell(getDrawFight(fightDTO, i), FIGHT_BORDER, PdfTheme.getHandwrittenFont(),
PdfTheme.SCORE_FONT_SIZE, null, 1, Element.ALIGN_CENTER);
drawCell.setBorder(0);
table.addCell(drawCell);

// Points Team 2
table.addCell(getScoreCell(fightDTO, i, 0, false));
table.addCell(getScoreCell(fightDTO, i, 1, false));

// Faults
table.addCell(getCell(getFaults(fightDTO, i, false), FIGHT_BORDER, PdfTheme.getHandwrittenFont(), 1,
Element.ALIGN_CENTER));
table.addCell(getFaultCell(fightDTO, i, false));

// Team 2
competitor = fightDTO.getTeam2().getMembers().get(i);
name = "";
if (competitor != null) {
name = NameUtils.getLastnameNameIni(competitor);
}
table.addCell(getCell(name, FIGHT_BORDER, PdfTheme.getHandwrittenFont(), 1, Element.ALIGN_RIGHT));
final PdfPCell team2NameCell = getCell(name, FIGHT_BORDER, PdfTheme.getHandwrittenFont(), 1, Element.ALIGN_RIGHT);
team2NameCell.setBorder(PdfPCell.BOTTOM);
table.addCell(team2NameCell);
}
table.addCell(getEmptyRow(DEFAULT_CELL_HEIGHT));

return table;
}

public PdfPCell getTeamHeader(String text, int colspan) {
final PdfPCell cell = getCell(text, 0, colspan, Element.ALIGN_CENTER, Color.WHITE, PdfTheme.getTitleFont(), PdfTheme.FONT_SIZE + FONT_SMALL_EXTRA_SIZE, Font.BOLD);
cell.setPaddingBottom(BOTTOM_PADDING);
return cell;
}


private PdfPCell getScoreCell(FightDTO fightDTO, int index, int scoreIndex, boolean leftCompetitor) {
final Score score = getScore(fightDTO, index, scoreIndex, leftCompetitor);
Expand All @@ -169,6 +182,17 @@ private PdfPCell getScoreCell(FightDTO fightDTO, int index, int scoreIndex, bool
}


private PdfPCell getFaultCell(FightDTO fightDTO, int index, boolean leftCompetitor) {
final boolean fault = getFaults(fightDTO, index, leftCompetitor);
final PdfPCell pdfPCell = getCell("", FIGHT_BORDER,
PdfTheme.getHandwrittenFont(), PdfTheme.SCORE_FONT_SIZE, null, 1, Element.ALIGN_CENTER);
if (fault) {
pdfPCell.setCellEvent(new FaultTriangleCellEvent());
}
return pdfPCell;
}


@Override
public void createBodyRows(Document document, PdfPTable mainTable, float width, float height, PdfWriter writer,
BaseFont font, int fontSize) {
Expand Down

0 comments on commit 897b48b

Please sign in to comment.