Skip to content

Commit

Permalink
added CustomBorderedLabel class
Browse files Browse the repository at this point in the history
  • Loading branch information
akmsw committed Jul 9, 2023
1 parent 97acd49 commit 2d47e0b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package armameeldoparti.utils.common.custom.graphical;

import javax.swing.BorderFactory;
import javax.swing.JLabel;

/**
* Custom label class.
*
* <p>This class is used to instantiate a custom label that fits the overall program
* aesthetics.
*
* @author Bonino, Francisco Ignacio.
*
* @version 0.0.1
*
* @since v3.0
*/
public class CustomBorderedLabel extends JLabel {

// ---------------------------------------- Constructors --------------------------------------

/**
* Builds a basic empty label using the established program aesthetics.
*
* @param alignment The text alignment.
*/
public CustomBorderedLabel(int alignment) {
super();
setupGraphicalProperties(alignment);
}

/**
* Builds a basic label using the established program aesthetics.
*
* @param text The label text.
* @param alignment The text alignment.
*/
public CustomBorderedLabel(String text, int alignment) {
super(text);
setupGraphicalProperties(alignment);
}

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

/**
* Configures the graphical properties of the label in order to fit the program aesthetics.
*
* @param alignment The text alignment.
*/
private void setupGraphicalProperties(int alignment) {
setBorder(BorderFactory.createLoweredSoftBevelBorder());
setHorizontalAlignment(alignment);
}
}
14 changes: 5 additions & 9 deletions src/main/java/armameeldoparti/views/AnchoragesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import armameeldoparti.utils.common.CommonFields;
import armameeldoparti.utils.common.CommonFunctions;
import armameeldoparti.utils.common.Constants;
import armameeldoparti.utils.common.custom.graphical.CustomBorderedLabel;
import armameeldoparti.utils.common.custom.graphical.CustomScrollPane;
import armameeldoparti.utils.common.custom.graphical.CustomTextArea;
import java.util.ArrayList;
Expand All @@ -15,13 +16,11 @@
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
import lombok.Getter;
import lombok.NonNull;
import net.miginfocom.swing.MigLayout;
Expand Down Expand Up @@ -207,12 +206,9 @@ private void fillCheckboxesSet(@NonNull List<Player> playersSet,
*/
private void addCheckboxesSet(@NonNull List<JCheckBox> cbSet,
@NonNull String labelText) {
JLabel label = new JLabel(labelText);

label.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));

leftPanel.add(label, CommonFunctions.buildMigLayoutConstraints(Constants.MIG_LAYOUT_GROWX,
Constants.MIG_LAYOUT_SPAN));
leftPanel.add(new CustomBorderedLabel(labelText, SwingConstants.LEFT),
CommonFunctions.buildMigLayoutConstraints(Constants.MIG_LAYOUT_GROWX,
Constants.MIG_LAYOUT_SPAN));

cbSet.forEach(cb -> leftPanel.add(
cb,
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/armameeldoparti/views/HelpView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import armameeldoparti.models.ProgramView;
import armameeldoparti.utils.common.CommonFunctions;
import armameeldoparti.utils.common.Constants;
import armameeldoparti.utils.common.custom.graphical.CustomBorderedLabel;
import armameeldoparti.utils.common.custom.graphical.CustomScrollPane;
import armameeldoparti.utils.common.custom.graphical.CustomTextArea;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
Expand Down Expand Up @@ -131,10 +131,7 @@ private void addTextArea() {
* Adds the reading progress label.
*/
private void addPagesLabel() {
pagesCounter = new JLabel();

pagesCounter.setBorder(BorderFactory.createLoweredSoftBevelBorder());
pagesCounter.setHorizontalAlignment(SwingConstants.CENTER);
pagesCounter = new CustomBorderedLabel(SwingConstants.CENTER);

getMasterPanel().add(pagesCounter, Constants.MIG_LAYOUT_GROWX);
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/armameeldoparti/views/SkillPointsInputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import armameeldoparti.utils.common.CommonFields;
import armameeldoparti.utils.common.CommonFunctions;
import armameeldoparti.utils.common.Constants;
import armameeldoparti.utils.common.custom.graphical.CustomBorderedLabel;
import armameeldoparti.utils.common.custom.graphical.CustomSpinner;
import java.util.HashMap;
import java.util.List;
Expand All @@ -16,9 +17,8 @@
import javax.swing.JSpinner;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
import lombok.Getter;

/**
Expand Down Expand Up @@ -125,13 +125,10 @@ protected void addButtons() {
*/
private void addSpinners() {
for (Position position : Position.values()) {
JLabel positionLabel = new JLabel(CommonFields.getPositionsMap()
.get(position));

positionLabel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));

getMasterPanel().add(
positionLabel,
new CustomBorderedLabel(CommonFields.getPositionsMap()
.get(position),
SwingConstants.LEFT),
CommonFunctions.buildMigLayoutConstraints(Constants.MIG_LAYOUT_GROW,
Constants.MIG_LAYOUT_SPAN)
);
Expand Down

0 comments on commit 2d47e0b

Please sign in to comment.