DefaultButton refactor: adding visual improvements, existing Classes and Methods, introducing AppTheme interface
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
package GUI.Panels;
|
||||
|
||||
import GUI.PanelTheme;
|
||||
import GUI.AppTheme;
|
||||
import GUI.Panels.SubPanels.*;
|
||||
import Resources.CustomAssets.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
|
||||
public class ChooseRacePanel extends JPanel implements PanelTheme {
|
||||
public class ChooseRacePanel extends JPanel implements AppTheme {
|
||||
|
||||
private String[] raceOptions;
|
||||
|
||||
private String[] raceDescriptions;
|
||||
|
||||
private InfoPanel infoPanel;
|
||||
|
||||
private int raceIndex;
|
||||
private JButton backButton;
|
||||
private JButton continueButton;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public ChooseRacePanel(JButton backButton, JButton continueButton) {
|
||||
private DefaultButton[] raceOptionButtons;
|
||||
|
||||
public ChooseRacePanel(JButton backButton, DefaultButton continueButton) {
|
||||
super();
|
||||
this.backButton = backButton;
|
||||
this.continueButton = continueButton;
|
||||
raceIndex = 0;
|
||||
createRaces();
|
||||
this.infoPanel = new InfoPanel(raceOptions, raceDescriptions);
|
||||
|
||||
panelSetup();
|
||||
|
||||
add(createMasterPanel());
|
||||
createMasterPanel();
|
||||
|
||||
}
|
||||
|
||||
@@ -48,41 +48,49 @@ public class ChooseRacePanel extends JPanel implements PanelTheme {
|
||||
|
||||
}
|
||||
|
||||
private JPanel createMasterPanel() {
|
||||
private void createMasterPanel() {
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Step 1: Choose Race");
|
||||
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
lblNewLabel.setFont(new Font("Bodoni 72 Oldstyle", Font.PLAIN, 33));
|
||||
add(lblNewLabel, BorderLayout.NORTH);
|
||||
|
||||
JPanel racePanel = new JPanel();
|
||||
racePanel.setOpaque(false);
|
||||
racePanel.setLayout(null);
|
||||
|
||||
racePanel.add(infoPanel);
|
||||
JLabel title = new JLabel("Step 1: Choose Race");
|
||||
title.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
title.setFont(headerFont);
|
||||
title.setForeground(darkestBrown);
|
||||
add(title, BorderLayout.NORTH);
|
||||
|
||||
JPanel racePanel = new JPanel();
|
||||
racePanel.setOpaque(false);
|
||||
racePanel.setLayout(null);
|
||||
racePanel.add(infoPanel);
|
||||
racePanel.add(createRaceButtonPanel());
|
||||
|
||||
add(createNavPanel(), BorderLayout.SOUTH);
|
||||
|
||||
return racePanel;
|
||||
add(racePanel);
|
||||
add(createNavPanel(), BorderLayout.SOUTH);
|
||||
|
||||
}
|
||||
|
||||
private JPanel createRaceButtonPanel() {
|
||||
|
||||
JPanel raceBtnPanel = new JPanel(new GridLayout(raceOptions.length, 1, 15, 5));
|
||||
raceBtnPanel.setBackground(darkBrown);
|
||||
raceBtnPanel.setBounds(311, 6, 109, 394);
|
||||
JPanel buttonPanel = new JPanel(new GridLayout(raceOptions.length, 1, 0, 0));
|
||||
buttonPanel.setBackground(lightBrown);
|
||||
|
||||
buttonPanel.setBounds(585, 45, 135, 355);
|
||||
|
||||
raceOptionButtons = new DefaultButton[raceOptions.length];
|
||||
|
||||
|
||||
for (int i = 0; i < raceOptionButtons.length; i++) {
|
||||
|
||||
raceOptionButtons[i] = createButton(raceOptions[i], i);
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < raceOptions.length; i++) {
|
||||
|
||||
raceBtnPanel.add(createButton(raceOptions[i], i));
|
||||
buttonPanel.add(raceOptionButtons[i]);
|
||||
|
||||
}
|
||||
|
||||
return raceBtnPanel;
|
||||
return buttonPanel;
|
||||
|
||||
}
|
||||
|
||||
@@ -95,9 +103,9 @@ public class ChooseRacePanel extends JPanel implements PanelTheme {
|
||||
|
||||
private JPanel createNavPanel() {
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBackground(darkBrown);
|
||||
|
||||
JPanel panel = new JPanel(new GridLayout(1, 2, 30, 0));
|
||||
panel.setBackground(darkestBrown);
|
||||
panel.setBorder(new EmptyBorder(15, 150, 15, 150));
|
||||
panel.add(backButton);
|
||||
panel.add(continueButton);
|
||||
|
||||
@@ -105,30 +113,29 @@ public class ChooseRacePanel extends JPanel implements PanelTheme {
|
||||
|
||||
}
|
||||
|
||||
private JButton createButton(String raceName, int index) {
|
||||
private DefaultButton createButton(String raceName, int index) {
|
||||
|
||||
JButton button = new JButton(raceName);
|
||||
button.addActionListener(
|
||||
|
||||
e -> {
|
||||
|
||||
raceIndex = index;
|
||||
infoPanel.updateInfo(raceIndex);
|
||||
|
||||
}
|
||||
|
||||
);
|
||||
DefaultButton button = new DefaultButton(raceName);
|
||||
button.addActionListener(e -> updateButtons(raceIndex, index));
|
||||
|
||||
return button;
|
||||
|
||||
}
|
||||
|
||||
private void updateButtons(int lastIndex, int newIndex) {
|
||||
|
||||
raceOptionButtons[lastIndex].deSelect();
|
||||
raceOptionButtons[newIndex].select();
|
||||
|
||||
raceIndex = newIndex;
|
||||
infoPanel.updateInfo(raceIndex);
|
||||
|
||||
}
|
||||
|
||||
public int getRaceChoice() {
|
||||
|
||||
return raceIndex;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package GUI.Panels.SubPanels;
|
||||
|
||||
import GUI.PanelTheme;
|
||||
import GUI.AppTheme;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.BevelBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class InfoPanel extends JPanel implements PanelTheme {
|
||||
public class InfoPanel extends JPanel implements AppTheme {
|
||||
|
||||
private JTextArea[] descriptions;
|
||||
private String[] holderDescriptions;
|
||||
@@ -48,7 +48,7 @@ public class InfoPanel extends JPanel implements PanelTheme {
|
||||
|
||||
panelSetup();
|
||||
|
||||
add(descriptions[holderIndex]);
|
||||
add(descriptions[0]);
|
||||
add(portraits[holderIndex][getNextPortrait(holderIndex)]);
|
||||
|
||||
repaint();
|
||||
@@ -77,14 +77,16 @@ public class InfoPanel extends JPanel implements PanelTheme {
|
||||
private void panelSetup() {
|
||||
|
||||
setOpaque(false);
|
||||
setBounds(6, 6, 293, 394);
|
||||
setBounds(5, 5, 600, 400);
|
||||
setLayout(null);
|
||||
|
||||
JLabel infoLbl = new JLabel("Information");
|
||||
infoLbl.setFont(new Font("Bodoni 72", Font.PLAIN, 20));
|
||||
infoLbl.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
infoLbl.setBounds(92, 6, 105, 16);
|
||||
add(infoLbl);
|
||||
JLabel subHeader = new JLabel("Description");
|
||||
subHeader.setFont(subHeaderFont);
|
||||
subHeader.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
subHeader.setBounds(275, 10, 300, 35);
|
||||
subHeader.setForeground(darkestBrown);
|
||||
|
||||
add(subHeader);
|
||||
|
||||
}
|
||||
|
||||
@@ -101,8 +103,10 @@ public class InfoPanel extends JPanel implements PanelTheme {
|
||||
tmpDesc.setOpaque(false);
|
||||
tmpDesc.setEditable(false);
|
||||
tmpDesc.setFocusable(false);
|
||||
tmpDesc.setFont(new Font("Bodoni 72", Font.PLAIN, 10));
|
||||
tmpDesc.setBounds(6, 21, 281, 196);
|
||||
tmpDesc.setFont(paragraphFont);
|
||||
tmpDesc.setBounds(275, 45, 300, 355);
|
||||
tmpDesc.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
tmpDesc.setForeground(darkestBrown);
|
||||
|
||||
descriptions[i] = tmpDesc;
|
||||
|
||||
@@ -118,32 +122,17 @@ public class InfoPanel extends JPanel implements PanelTheme {
|
||||
|
||||
File imagesDir;
|
||||
|
||||
/*
|
||||
|
||||
WINDOWS:
|
||||
attempted
|
||||
dndBuilder/src/GUI/img/category/
|
||||
dndBuilder/src/GUI/img/category
|
||||
/dndBuilder/src/GUI/img/category
|
||||
/dndBuilder/src/GUI/img/category/
|
||||
GUI/img/category/
|
||||
/GUI/img/category/
|
||||
src/GUI/img/category/
|
||||
/src/GUI/img/category/
|
||||
|
||||
*/
|
||||
|
||||
if(OS.startsWith("Windows")) {
|
||||
|
||||
imagesDir = new File("dndBuilder\\src\\GUI\\img\\" + categoryHolder[i] + "\\");
|
||||
imagesDir = new File("dndBuilder\\src\\Resources\\Img\\" + categoryHolder[i] + "\\");
|
||||
|
||||
} else if (OS.startsWith("Mac")) {
|
||||
|
||||
imagesDir = new File("dndBuilder/src/GUI/img/" + categoryHolder[i] + "/");
|
||||
imagesDir = new File("dndBuilder/src/Resources/Img/" + categoryHolder[i] + "/");
|
||||
|
||||
} else if (OS.startsWith("Linux")) {
|
||||
|
||||
imagesDir = new File("dndBuilder/src/GUI/img/" + categoryHolder[i] + "/");
|
||||
imagesDir = new File("dndBuilder/src/Resources/Img/" + categoryHolder[i] + "/");
|
||||
|
||||
} else {
|
||||
|
||||
@@ -161,7 +150,7 @@ public class InfoPanel extends JPanel implements PanelTheme {
|
||||
portraits[i][index] = image(file);
|
||||
portraits[i][index].setOpaque(true);
|
||||
portraits[i][index].setBackground(lightBrown);
|
||||
portraits[i][index].setBounds(6, 229, 281, 159);
|
||||
portraits[i][index].setBounds(10, 45, 250, 355);
|
||||
|
||||
index++;
|
||||
|
||||
@@ -180,7 +169,7 @@ public class InfoPanel extends JPanel implements PanelTheme {
|
||||
try {
|
||||
|
||||
img = ImageIO.read(file);
|
||||
finalImg = img.getScaledInstance(281, 196, Image.SCALE_SMOOTH);
|
||||
finalImg = img.getScaledInstance(250, 375, Image.SCALE_SMOOTH);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user