refactoring infopanel into a single class.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package GUI.Panels;
|
package GUI.Panels;
|
||||||
|
|
||||||
import GUI.img.*;
|
import GUI.Panels.SubPanels.DescriptionPanel;
|
||||||
|
import GUI.Panels.SubPanels.ImagePanel;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@@ -9,9 +10,11 @@ import javax.swing.border.*;
|
|||||||
|
|
||||||
public class ChooseRacePanel extends JPanel {
|
public class ChooseRacePanel extends JPanel {
|
||||||
|
|
||||||
private String[] raceOptions = {"Dragonborn", "Dwarf", "Elf", "Gnome", "HalfElf", "Halfling", "Halforc", "Human", "Tiefling"};
|
private String[] raceOptions;
|
||||||
|
|
||||||
|
private String[] raceDescriptions;
|
||||||
private ImagePanel imgPanel;
|
private ImagePanel imgPanel;
|
||||||
|
private DescriptionPanel descPanel;
|
||||||
|
|
||||||
// DEBUG: raceChoice to be deprecated after testing.
|
// DEBUG: raceChoice to be deprecated after testing.
|
||||||
private String raceChoice;
|
private String raceChoice;
|
||||||
@@ -26,7 +29,10 @@ public class ChooseRacePanel extends JPanel {
|
|||||||
super();
|
super();
|
||||||
this.backButton = backButton;
|
this.backButton = backButton;
|
||||||
this.continueButton = continueButton;
|
this.continueButton = continueButton;
|
||||||
|
raceOptions = new String[]{"Dragonborn", "Dwarf", "Elf", "Gnome", "HalfElf", "Halfling", "Halforc", "Human", "Tiefling"};
|
||||||
|
createRaceDescriptions();
|
||||||
imgPanel = new ImagePanel(raceOptions);
|
imgPanel = new ImagePanel(raceOptions);
|
||||||
|
descPanel = new DescriptionPanel(raceDescriptions);
|
||||||
|
|
||||||
panelSetup();
|
panelSetup();
|
||||||
|
|
||||||
@@ -34,6 +40,16 @@ public class ChooseRacePanel extends JPanel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createRaceDescriptions() {
|
||||||
|
|
||||||
|
raceDescriptions = new String[]{
|
||||||
|
|
||||||
|
"Born of dragons, as their name proclaims, the dragonborn walk proudly through a world that greets them with fearful incomprehension. Shaped by draconic gods or the dragons themselves, dragonborn originally hatched from dragon eggs as a unique race, combining the best attributes of dragons and humanoids. Some dragonborn are faithful servants to true dragons, others form the ranks of soldiers in great wars, and still others find themselves adrift, with no clear calling in life."
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel createMasterPanel() {
|
private JPanel createMasterPanel() {
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("Step 1: Choose Race");
|
JLabel lblNewLabel = new JLabel("Step 1: Choose Race");
|
||||||
@@ -46,8 +62,11 @@ public class ChooseRacePanel extends JPanel {
|
|||||||
racePanel.setLayout(null);
|
racePanel.setLayout(null);
|
||||||
|
|
||||||
|
|
||||||
imgPanel.setBounds(47, 67, 223, 301);
|
|
||||||
racePanel.add(imgPanel);
|
infoPanel.add(imgPanel);
|
||||||
|
infoPanel.add(descPanel);
|
||||||
|
|
||||||
|
racePanel.add(infoPanel);
|
||||||
|
|
||||||
racePanel.add(createRaceButtonPanel());
|
racePanel.add(createRaceButtonPanel());
|
||||||
|
|
||||||
@@ -104,6 +123,7 @@ public class ChooseRacePanel extends JPanel {
|
|||||||
raceChoice = raceName;
|
raceChoice = raceName;
|
||||||
raceIndex = index;
|
raceIndex = index;
|
||||||
imgPanel.updateImage(raceIndex);
|
imgPanel.updateImage(raceIndex);
|
||||||
|
descPanel.updateDescription(raceIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package GUI.Panels.SubPanels;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.BevelBorder;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DescriptionPanel extends JTextArea {
|
||||||
|
|
||||||
|
private JTextArea[] descriptions;
|
||||||
|
private String[] holderDescriptions;
|
||||||
|
|
||||||
|
|
||||||
|
public DescriptionPanel(String[] holderDescriptions) {
|
||||||
|
|
||||||
|
super();
|
||||||
|
panelSetup();
|
||||||
|
|
||||||
|
this.holderDescriptions = holderDescriptions;
|
||||||
|
createDescriptionPanels();
|
||||||
|
|
||||||
|
updateDescription(0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panelSetup() {
|
||||||
|
|
||||||
|
setOpaque(true);
|
||||||
|
setBackground(new Color(238, 232, 170));
|
||||||
|
setBounds(6, 229, 281, 159);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDescription(int holderIndex) {
|
||||||
|
|
||||||
|
removeAll();
|
||||||
|
|
||||||
|
add(descriptions[holderIndex]);
|
||||||
|
|
||||||
|
repaint();
|
||||||
|
revalidate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createDescriptionPanels() {
|
||||||
|
|
||||||
|
descriptions = new JTextArea[holderDescriptions.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < holderDescriptions.length; i++) {
|
||||||
|
|
||||||
|
JTextArea tmpDesc = new JTextArea();
|
||||||
|
tmpDesc.setText(holderDescriptions[i]);
|
||||||
|
tmpDesc.setWrapStyleWord(true);
|
||||||
|
tmpDesc.setLineWrap(true);
|
||||||
|
tmpDesc.setOpaque(false);
|
||||||
|
tmpDesc.setEditable(false);
|
||||||
|
tmpDesc.setFocusable(false);
|
||||||
|
tmpDesc.setFont(new Font("Bodoni 72", Font.PLAIN, 10));
|
||||||
|
|
||||||
|
/* setFont(new Font("Bodoni 72", Font.PLAIN, 10));
|
||||||
|
setHorizontalAlignment(SwingConstants.LEFT);
|
||||||
|
setBounds(6, 21, 281, 196);*/
|
||||||
|
|
||||||
|
descriptions[i] = tmpDesc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+16
-7
@@ -1,7 +1,8 @@
|
|||||||
package GUI.img;
|
package GUI.Panels.SubPanels;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.BevelBorder;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -10,19 +11,27 @@ import java.util.*;
|
|||||||
public class ImagePanel extends JPanel {
|
public class ImagePanel extends JPanel {
|
||||||
|
|
||||||
private JLabel[][] portraits;
|
private JLabel[][] portraits;
|
||||||
private String[] holder;
|
private String[] categoryHolder;
|
||||||
private int lastIndex;
|
private int lastIndex;
|
||||||
|
|
||||||
public ImagePanel(String[] holder) {
|
public ImagePanel(String[] categoryHolder) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
this.holder = holder;
|
this.categoryHolder = categoryHolder;
|
||||||
createPortraitsArray();
|
createPortraitsArray();
|
||||||
|
|
||||||
updateImage(0); // Default selection of the 0th element.
|
updateImage(0); // Default selection of the 0th element.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void panelSetup() {
|
||||||
|
|
||||||
|
setOpaque(false);
|
||||||
|
setBounds(6, 21, 281, 196);
|
||||||
|
setLayout(null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void updateImage(int holderIndex) {
|
public void updateImage(int holderIndex) {
|
||||||
|
|
||||||
removeAll();
|
removeAll();
|
||||||
@@ -49,11 +58,11 @@ public class ImagePanel extends JPanel {
|
|||||||
|
|
||||||
private void createPortraitsArray() {
|
private void createPortraitsArray() {
|
||||||
|
|
||||||
portraits = new JLabel[holder.length][];
|
portraits = new JLabel[categoryHolder.length][];
|
||||||
|
|
||||||
for (int i = 0; i < holder.length; i++) {
|
for (int i = 0; i < categoryHolder.length; i++) {
|
||||||
|
|
||||||
File imagesDir = new File("dndBuilder/src/GUI/img/" + holder[i] + "/");
|
File imagesDir = new File("dndBuilder/src/GUI/img/" + categoryHolder[i] + "/");
|
||||||
|
|
||||||
File[] dir = imagesDir.listFiles();
|
File[] dir = imagesDir.listFiles();
|
||||||
portraits[i] = new JLabel[dir.length];
|
portraits[i] = new JLabel[dir.length];
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package GUI.Panels.SubPanels;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.BevelBorder;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class InfoPanel extends JPanel {
|
||||||
|
|
||||||
|
private JTextArea[] descriptions;
|
||||||
|
private String[] holderDescriptions;
|
||||||
|
private JLabel[][] portraits;
|
||||||
|
private String[] categoryHolder;
|
||||||
|
private int lastIndex;
|
||||||
|
|
||||||
|
public InfoPanel(String[] categoryHolder, String[] holderDescriptions) {
|
||||||
|
|
||||||
|
super();
|
||||||
|
panelSetup();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panelSetup() {
|
||||||
|
|
||||||
|
setOpaque(false);
|
||||||
|
setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
||||||
|
setBounds(6, 6, 293, 394);
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user