Skip to content

Commit

Permalink
moved methods from views to controllers, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
akmsw committed Jun 26, 2023
1 parent 228ec3c commit 6d62bcc
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 76 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![buildBadge](https://github.com/akmsw/armame-el-doparti/actions/workflows/maven.yml/badge.svg?branch=develop-v3.0)](https://github.com/akmsw/armame-el-doparti/actions/workflows/maven.yml)
[![issuesBadge](https://img.shields.io/github/issues/akmsw/armame-el-doparti.svg?logo=github)](https://github.com/akmsw/armame-el-doparti/issues)

[![checkStyleBadge](https://img.shields.io/badge/checkstyle%2010.12.0-passing-brightgreen)](https://checkstyle.sourceforge.io/)
[![checkStyleBadge](https://img.shields.io/badge/checkstyle%2010.12.1-passing-brightgreen)](https://checkstyle.sourceforge.io/)
[![sonarLintBadge](https://img.shields.io/badge/sonarlint-3-yellow?logo=sonarlint)](https://www.sonarlint.org/)
[![jUnit5Badge](https://img.shields.io/badge/junit%205.9.2-passing-brightgreen?logo=junit5)](https://junit.org/junit5/)

Expand Down Expand Up @@ -116,11 +116,7 @@ No se pueden anclar a un mismo equipo todos los jugadores de un mismo tipo (por
- Seleccionalo como opción predeterminada para la ejecución de archivos .jar

## 🔜 Próximamente
Si querés estar al tanto de qué cambios están planeados para las próximas versiones, te dejo acá los links a los proyectos:
- [v3.1](https://github.com/users/akmsw/projects/10/views/1)
- [v4.0](https://github.com/users/akmsw/projects/7/views/1)
- [v4.1](https://github.com/users/akmsw/projects/8/views/1)
- [v5.0](https://github.com/users/akmsw/projects/9/views/1)
Si querés estar al tanto de qué cambios están planeados para las próximas versiones, [acá](https://github.com/akmsw?query=is%3Aopen+sort%3Atitle-asc&tab=projects) vas a poder ver los detalles y metas planificadas.

## ⚠️ Reportes y sugerencias
Si el programa presenta algún error que debería ser reportado para arreglarlo, si se te ocurrió alguna nueva funcionalidad para agregar al programa, o si opinás que algo podría ser modificado, la sección de [issues](https://github.com/akmsw/armame-el-doparti/issues) está abierta para que hagas estos reportes y/o sugerencias. Es necesario tener una cuenta en GitHub para abrir un nuevo reporte en el repositorio. Para poder trabajar en eso lo más rápidamente posible, te proveo unas plantillas para cada caso donde te pido toda la información que necesito.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package armameeldoparti.controllers;

import armameeldoparti.models.Player;
import armameeldoparti.models.Position;
import armameeldoparti.models.ProgramView;
import armameeldoparti.utils.common.CommonFields;
import armameeldoparti.utils.common.CommonFunctions;
import armameeldoparti.utils.common.Constants;
import armameeldoparti.views.AnchoragesView;
import java.awt.Component;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
Expand Down Expand Up @@ -65,7 +67,21 @@ public void resetView() {
* Updates the checkboxes text with the players names.
*/
public void updateCheckBoxesText() {
((AnchoragesView) getView()).updateCheckBoxesText();
Map<Position, List<JCheckBox>> checkBoxesMap = ((AnchoragesView) getView()).getCheckBoxesMap();

for (Position position : Position.values()) {
for (int i = 0; i < CommonFields.getPlayersSets()
.get(position)
.size(); i++) {
checkBoxesMap.get(position)
.get(i)
.setText(CommonFields.getPlayersSets()
.get(position)
.get(i)
.getName());
}
}

getView().pack();
}

Expand Down
35 changes: 32 additions & 3 deletions src/main/java/armameeldoparti/controllers/ResultsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class ResultsController extends Controller {

// ---------------------------------------- Private constants ---------------------------------

/**
* Fixed table cells width (in pixels). This value depends on the program's font and the maximum
* player name length.
*/
private static final int FIXED_CELL_WIDTH = 250;
private static final int TABLE_COLUMNS = 3;

/**
Expand Down Expand Up @@ -105,9 +110,7 @@ public void setUp() {
setTableFormat();
fillTableFields();
updateTable();

((ResultsView) getView()).setTableCellsSize();

setTableCellsSize();
getView().pack();
}

Expand Down Expand Up @@ -215,6 +218,32 @@ public List<Team> bySkillsMix() {

// ---------------------------------------- Private methods -----------------------------------

/**
* Sets the ideal table cells size.
*/
public void setTableCellsSize() {
JTable table = ((ResultsView) getView()).getTable();

for (int column = 0; column < table.getColumnCount(); column++) {
table.getColumnModel()
.getColumn(column)
.setPreferredWidth(FIXED_CELL_WIDTH);
}

for (int i = 0; i < table.getRowCount(); i++) {
int rowHeight = table.getRowHeight();

for (int j = 0; j < table.getColumnCount(); j++) {
Component component = table.prepareRenderer(table.getCellRenderer(i, j), i, j);

rowHeight = Math.max(rowHeight, component.getPreferredSize()
.height);
}

table.setRowHeight(i, rowHeight);
}
}

/**
* Sets the table cells format, including text alignment and background and foreground colors.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package armameeldoparti.controllers;

import armameeldoparti.models.Player;
import armameeldoparti.models.Position;
import armameeldoparti.models.ProgramView;
import armameeldoparti.utils.common.CommonFields;
import armameeldoparti.utils.common.CommonFunctions;
import armameeldoparti.utils.common.Constants;
import armameeldoparti.views.SkillPointsInputView;
import java.util.Map;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import lombok.NonNull;

/**
Expand Down Expand Up @@ -85,7 +90,16 @@ public void backButtonEvent() {
* Updates the players name labels.
*/
public void updateNameLabels() {
((SkillPointsInputView) getView()).updateNameLabels();
Map<JSpinner, JLabel> labelsMap = ((SkillPointsInputView) getView()).getLabelsMap();
Map<Player, JSpinner> spinnersMap = ((SkillPointsInputView) getView()).getSpinnersMap();

for (Position position : Position.values()) {
for (Player player : CommonFields.getPlayersSets()
.get(position)) {
labelsMap.get(spinnersMap.get(player))
.setText(player.getName());
}
}

getView().pack();
}
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/armameeldoparti/views/AnchoragesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,6 @@ public AnchoragesView() {
initializeInterface();
}

// ---------------------------------------- Public methods ------------------------------------

/**
* Updates the checkboxes text with the players names.
*/
public void updateCheckBoxesText() {
for (Position position : Position.values()) {
for (int i = 0; i < CommonFields.getPlayersSets()
.get(position)
.size(); i++) {
checkBoxesMap.get(position)
.get(i)
.setText(CommonFields.getPlayersSets()
.get(position)
.get(i)
.getName());
}
}
}

// ---------------------------------------- Protected methods ---------------------------------

/**
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/armameeldoparti/views/ResultsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import armameeldoparti.utils.common.CommonFields;
import armameeldoparti.utils.common.CommonFunctions;
import armameeldoparti.utils.common.Constants;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JTable;
Expand All @@ -25,12 +24,6 @@
*/
public class ResultsView extends View {

/**
* Fixed table cells width (in pixels). This value depends on the program's font and the maximum
* player name length.
*/
private static final int FIXED_CELL_WIDTH = 250;

// ---------------------------------------- Private fields ------------------------------------

private @Getter @Setter JTable table;
Expand Down Expand Up @@ -62,30 +55,6 @@ public void initializeInterface() {
add(getMasterPanel());
}

/**
* Sets the ideal table cells size.
*/
public void setTableCellsSize() {
for (int column = 0; column < table.getColumnCount(); column++) {
table.getColumnModel()
.getColumn(column)
.setPreferredWidth(FIXED_CELL_WIDTH);
}

for (int i = 0; i < table.getRowCount(); i++) {
int rowHeight = table.getRowHeight();

for (int j = 0; j < table.getColumnCount(); j++) {
Component component = table.prepareRenderer(table.getCellRenderer(i, j), i, j);

rowHeight = Math.max(rowHeight, component.getPreferredSize()
.height);
}

table.setRowHeight(i, rowHeight);
}
}

// ---------------------------------------- Protected methods ---------------------------------

/**
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/armameeldoparti/views/SkillPointsInputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
*
* @since 06/03/2021
*/
@Getter
public class SkillPointsInputView extends View {

// ---------------------------------------- Private fields ------------------------------------

private final transient @Getter Map<Player, JSpinner> spinnersMap;
private final transient Map<Player, JSpinner> spinnersMap;
private final transient Map<JSpinner, JLabel> labelsMap;

// ---------------------------------------- Constructor ---------------------------------------
Expand Down Expand Up @@ -69,19 +70,6 @@ public void initializeInterface() {
pack();
}

/**
* Updates the labels with the players names.
*/
public void updateNameLabels() {
for (Position position : Position.values()) {
for (Player player : CommonFields.getPlayersSets()
.get(position)) {
labelsMap.get(spinnersMap.get(player))
.setText(player.getName());
}
}
}

// ---------------------------------------- Protected methods ---------------------------------

/**
Expand Down

0 comments on commit 6d62bcc

Please sign in to comment.