Skip to content

Commit

Permalink
fixed custom checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
akmsw committed Jul 12, 2023
1 parent 1b22133 commit 5ec6cb4
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 71 deletions.
1 change: 0 additions & 1 deletion src/main/java/armameeldoparti/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ private static void setUpGeneralGraphicalProperties() {
UIManager.put("Button.foreground", Color.WHITE);
UIManager.put("CheckBox.background", Constants.GREEN_LIGHT);
UIManager.put("CheckBox.focus", Constants.GREEN_LIGHT);
UIManager.put("CheckBox.foreground", Constants.GREEN_DARK);
UIManager.put("ComboBox.focus", Color.WHITE);
UIManager.put("ComboBox.selectionBackground", Constants.GREEN_MEDIUM);
UIManager.put("ComboBox.selectionForeground", Color.WHITE);
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/armameeldoparti/utils/common/CommonFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import armameeldoparti.views.View;
import java.awt.Component;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -111,6 +114,7 @@ public static Component getComponentFromEvent(ActionEvent e) {
*
* @return The custom arrow button.
*/
@NonNull
public static JButton buildArrowButton(int orientation) {
JButton arrowButton = new BasicArrowButton(orientation,
Constants.GREEN_MEDIUM,
Expand All @@ -132,10 +136,42 @@ public static JButton buildArrowButton(int orientation) {
*
* @return The fully built component constraints.
*/
@NonNull
public static String buildMigLayoutConstraints(@NonNull String... constraints) {
return String.join(", ", constraints);
}

/**
* Given an icon filename, creates an ImageIcon with it.
*
* @param iconFileName Name of the icon file to use.
*
* @return The ImageIcon of the specified file.
*/
@NonNull
public static ImageIcon createImageIcon(@NonNull String iconFileName) {
return Objects.requireNonNull(
new ImageIcon(Constants.class
.getClassLoader()
.getResource(Constants.PATH_IMG + Constants.PATH_ICO + iconFileName))
);
}

/**
* Scales an icon to the specified width and height.
*
* @param icon Icon to scale.
* @param width New width.
* @param height New height.
*
* @return The scaled icon.
*/
@NonNull
public static ImageIcon scaleImageIcon(@NonNull ImageIcon icon, int width, int height) {
return new ImageIcon(icon.getImage()
.getScaledInstance(width, height, Image.SCALE_DEFAULT));
}

/**
* Gets the corresponding controller to the requested view.
*
Expand Down
60 changes: 21 additions & 39 deletions src/main/java/armameeldoparti/utils/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.awt.Color;
import java.awt.Image;
import java.util.Map;
import java.util.Objects;
import javax.swing.ImageIcon;

/**
Expand All @@ -30,6 +29,14 @@ public final class Constants {
*/
private static final int ICON_SCALE = 50;

private static final String FILENAME_ICON_CB_DISABLED_SELECTED = "cb_d_s.png";
private static final String FILENAME_ICON_CB_DISABLED_UNSELECTED = "cb_d_us.png";
private static final String FILENAME_ICON_CB_ENABLED_SELECTED_FOCUSED = "cb_e_s_f.png";
private static final String FILENAME_ICON_CB_ENABLED_SELECTED_PRESSED = "cb_e_s_p.png";
private static final String FILENAME_ICON_CB_ENABLED_SELECTED_UNFOCUSED = "cb_e_s_uf.png";
private static final String FILENAME_ICON_CB_ENABLED_UNSELECTED_FOCUSED = "cb_e_us_f.png";
private static final String FILENAME_ICON_CB_ENABLED_UNSELECTED_PRESSED = "cb_e_us_p.png";
private static final String FILENAME_ICON_CB_ENABLED_UNSELECTED_UNFOCUSED = "cb_e_us_uf.png";
private static final String MIG_LAYOUT_ALIGN = "align";
private static final String MSG_ERROR_BROWSER = "ERROR DE CONEXIÓN CON NAVEGADOR WEB";
private static final String MSG_ERROR_FATAL_INTERNAL = "ERROR FATAL INTERNO";
Expand All @@ -45,25 +52,17 @@ public final class Constants {
public static final int MIX_BY_SKILLS = 1;
public static final int MIX_RANDOM = 0;
public static final int SIZE_FONT_TITLE_LABEL = 40;
public static final int SIZE_FONT_AUTHOR_LABEL = SIZE_FONT_TITLE_LABEL - 10;
public static final int SIZE_FONT_AUTHOR_LABEL = 30;
public static final int SIZE_FONT_VERSION_LABEL = 16;
public static final int SKILL_INI = 1;
public static final int SKILL_MAX = 5;
public static final int SKILL_MIN = 1;
public static final int SKILL_STEP = 1;

public static final float FONT_SIZE = 18f;
public static final float FONT_SIZE = 16f;

public static final String ERROR_MESSAGE_TITLE = "¡Error!";
public static final String FILENAME_ICON_MAIN = "main_icon.png";
public static final String FILENAME_ICON_CB_DISABLED_SELECTED = "cb_d_s.png";
public static final String FILENAME_ICON_CB_DISABLED_UNSELECTED = "cb_d_us.png";
public static final String FILENAME_ICON_CB_ENABLED_SELECTED_FOCUSED = "cb_e_s_f.png";
public static final String FILENAME_ICON_CB_ENABLED_SELECTED_PRESSED = "cb_e_s_p.png";
public static final String FILENAME_ICON_CB_ENABLED_SELECTED_UNFOCUSED = "cb_e_s_uf.png";
public static final String FILENAME_ICON_CB_ENABLED_UNSELECTED_FOCUSED = "cb_e_us_f.png";
public static final String FILENAME_ICON_CB_ENABLED_UNSELECTED_PRESSED = "cb_e_us_p.png";
public static final String FILENAME_ICON_CB_ENABLED_UNSELECTED_UNFOCUSED = "cb_e_us_uf.png";
public static final String FILENAME_FONT = "comfortaa.ttf";
public static final String FILENAME_PDA = "dist.pda";
public static final String MIX_OPTION_RANDOM = "Aleatoriamente";
Expand Down Expand Up @@ -112,29 +111,31 @@ public final class Constants {
public static final Color GREEN_LIGHT = new Color(176, 189, 162);
public static final Color YELLOW_LIGHT = new Color(255, 238, 153);

public static final ImageIcon ICON = createImageIcon(FILENAME_ICON_MAIN);
public static final ImageIcon ICON_CB_DISABLED_SELECTED = createImageIcon(
public static final ImageIcon ICON = CommonFunctions.createImageIcon(
FILENAME_ICON_MAIN
);
public static final ImageIcon ICON_CB_D_S = CommonFunctions.createImageIcon(
FILENAME_ICON_CB_DISABLED_SELECTED
);
public static final ImageIcon ICON_CB_DISABLED_UNSELECTED = createImageIcon(
public static final ImageIcon ICON_CB_D_US = CommonFunctions.createImageIcon(
FILENAME_ICON_CB_DISABLED_UNSELECTED
);
public static final ImageIcon ICON_CB_ENABLED_SELECTED_FOCUSED = createImageIcon(
public static final ImageIcon ICON_CB_E_S_F = CommonFunctions.createImageIcon(
FILENAME_ICON_CB_ENABLED_SELECTED_FOCUSED
);
public static final ImageIcon ICON_CB_ENABLED_SELECTED_PRESSED = createImageIcon(
public static final ImageIcon ICON_CB_E_S_P = CommonFunctions.createImageIcon(
FILENAME_ICON_CB_ENABLED_SELECTED_PRESSED
);
public static final ImageIcon ICON_CB_ENABLED_SELECTED_UNFOCUSED = createImageIcon(
public static final ImageIcon ICON_CB_E_S_UF = CommonFunctions.createImageIcon(
FILENAME_ICON_CB_ENABLED_SELECTED_UNFOCUSED
);
public static final ImageIcon ICON_CB_ENABLED_UNSELECTED_FOCUSED = createImageIcon(
public static final ImageIcon ICON_CB_E_US_F = CommonFunctions.createImageIcon(
FILENAME_ICON_CB_ENABLED_UNSELECTED_FOCUSED
);
public static final ImageIcon ICON_CB_ENABLED_UNSELECTED_PRESSED = createImageIcon(
public static final ImageIcon ICON_CB_E_US_P = CommonFunctions.createImageIcon(
FILENAME_ICON_CB_ENABLED_UNSELECTED_PRESSED
);
public static final ImageIcon ICON_CB_ENABLED_UNSELECTED_UNFOCUSED = createImageIcon(
public static final ImageIcon ICON_CB_E_US_UF = CommonFunctions.createImageIcon(
FILENAME_ICON_CB_ENABLED_UNSELECTED_UNFOCUSED
);

Expand Down Expand Up @@ -174,23 +175,4 @@ public final class Constants {
private Constants() {
// Body not needed
}

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

/**
* Given an icon filename, creates an ImageIcon with it.
*
* @param iconFileName Name of the icon file to use.
*
* @return The ImageIcon of the specified file.
*/
private static ImageIcon createImageIcon(String iconFileName) {
return new ImageIcon(
Objects.requireNonNull(Constants.class
.getClassLoader()
.getResource(PATH_IMG + PATH_ICO + iconFileName),
Constants.MSG_ERROR_NULL_RESOURCE
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public CustomCheckBox(String text) {
* Configures the graphical properties of the checkbox in order to fit the program aesthetics.
*/
private void setUpGraphicalProperties() {
setIcon(Constants.ICON_CB_ENABLED_UNSELECTED_UNFOCUSED);
setSelectedIcon(Constants.ICON_CB_ENABLED_SELECTED_UNFOCUSED);
setDisabledIcon(Constants.ICON_CB_DISABLED_UNSELECTED);
setDisabledSelectedIcon(Constants.ICON_CB_DISABLED_SELECTED);
setRolloverIcon(Constants.ICON_CB_ENABLED_UNSELECTED_FOCUSED);
setRolloverSelectedIcon(Constants.ICON_CB_ENABLED_SELECTED_FOCUSED);
setPressedIcon(Constants.ICON_CB_ENABLED_UNSELECTED_PRESSED);
setIcon(Constants.ICON_CB_E_US_UF);
setSelectedIcon(Constants.ICON_CB_E_S_UF);
setDisabledIcon(Constants.ICON_CB_D_US);
setDisabledSelectedIcon(Constants.ICON_CB_D_S);
setRolloverIcon(Constants.ICON_CB_E_US_F);
setRolloverSelectedIcon(Constants.ICON_CB_E_S_F);
setPressedIcon(Constants.ICON_CB_E_US_P);
}
}
34 changes: 10 additions & 24 deletions src/main/java/armameeldoparti/views/MainMenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import armameeldoparti.utils.common.Constants;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.util.Objects;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
Expand Down Expand Up @@ -117,30 +114,19 @@ private void addBackground() {

/**
* Adds the background image to the panel.
*
* <p>TODO: The background image should not be scaled. If needed, the scale should not be
* hardcoded.
*/
private void addBackgroundImage() {
ImageIcon backgroundImageIcon = new ImageIcon(
Objects.requireNonNull(
getClass().getClassLoader()
.getResource(Constants.PATH_IMG
+ Constants.PATH_ICO
+ Constants.FILENAME_ICON_MAIN),
Constants.MSG_ERROR_NULL_RESOURCE
)
);

/*
* TODO:
* The background image should not be scaled. If needed, the scale should not be hardcoded.
*/
ImageIcon scaledBackgroundImage = new ImageIcon(
backgroundImageIcon.getImage()
.getScaledInstance(500, 500, Image.SCALE_DEFAULT)
getMasterPanel().add(
new JLabel(
"",
CommonFunctions.scaleImageIcon(Constants.ICON, 500, 500),
SwingConstants.CENTER
),
Constants.MIG_LAYOUT_GROWX
);

JLabel backgroundImageLabel = new JLabel("", scaledBackgroundImage, SwingConstants.CENTER);

getMasterPanel().add(backgroundImageLabel, Constants.MIG_LAYOUT_GROWX);
}

/**
Expand Down
Empty file modified src/main/res/img/icons/cb_d_s.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/img/icons/cb_e_s_f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/img/icons/cb_e_s_p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/img/icons/cb_e_s_uf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/img/icons/cb_e_us_f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/img/icons/cb_e_us_p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/img/icons/cb_e_us_uf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5ec6cb4

Please sign in to comment.