feat: add THEGamepad to the "edit controller" dialog

This commit is contained in:
lantzelot-swe 2023-11-11 00:20:06 +01:00
parent 5115fb00f6
commit 5667ab5e1c
14 changed files with 763 additions and 83 deletions

View File

@ -51,7 +51,7 @@ public class BaseDialog extends JDialog
getRootPane().setDefaultButton(getOkButton());
}
protected void addContent(JPanel panel)
protected void addContent(JComponent panel)
{
getBackgroundPanel().add(panel, BorderLayout.CENTER);
}

View File

@ -3,39 +3,64 @@ package se.lantz.gui.gamepad;
import java.awt.Dimension;
import java.awt.Frame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import se.lantz.gui.BaseDialog;
import se.lantz.model.JoystickModel;
public class GamePadDialog extends BaseDialog
{
private GamepadBackgroundPanel panel;
private JTabbedPane tabbedPane;
private USBControllerBackgroundPanel usbControlerBackroundPanel;
private TheGamepadBackgroundPanel theGamePadBackroundPanel;
private JoystickModel model;
private Dimension dialogSize = new Dimension(660, 790);
private Dimension dialogSize = new Dimension(660, 810);
public GamePadDialog(Frame owner, JoystickModel model)
{
super(owner);
//Create a separate model so that changes can be cancelled
this.model = new JoystickModel(model.isPort1());
setTitle("Edit joystick/gamepad configuration");
addContent(getGamepadBackgroundPanel());
setTitle("Edit THEGamepad/USB Controller configuration");
addContent(getTabbedPane());
this.setPreferredSize(dialogSize);
this.setResizable(false);
//Set initial values to the model
this.model.setConfigStringFromDb(model.getConfigString());
}
private GamepadBackgroundPanel getGamepadBackgroundPanel()
private USBControllerBackgroundPanel getUSBControllerBackgroundPanel()
{
if (panel == null)
if (usbControlerBackroundPanel == null)
{
panel = new GamepadBackgroundPanel(model);
usbControlerBackroundPanel = new USBControllerBackgroundPanel(model);
}
return panel;
return usbControlerBackroundPanel;
}
private TheGamepadBackgroundPanel getTheGamepadBackgroundPanel()
{
if (theGamePadBackroundPanel == null)
{
theGamePadBackroundPanel = new TheGamepadBackgroundPanel(model);
}
return theGamePadBackroundPanel;
}
public String getJoyConfigString()
{
return this.model.getConfigString();
}
private JTabbedPane getTabbedPane()
{
if (tabbedPane == null)
{
tabbedPane = new JTabbedPane();
tabbedPane.addTab("THEGamepad", getTheGamepadBackgroundPanel());
tabbedPane.addTab("Alternative USB controller", getUSBControllerBackgroundPanel());
}
return tabbedPane;
}
}

View File

@ -8,13 +8,13 @@ import javax.swing.JPanel;
import se.lantz.model.JoystickModel;
public class GamepadBackgroundPanel extends JPanel
public class TheGamepadBackgroundPanel extends JPanel
{
private GamePadInfoPanel gamePadInfoPanel;
private GamePadImagePanel gamePadImagePanel;
private GamePadMappingPanel gamePadMappingPanel;
private TheGamepadInfoPanel gamePadInfoPanel;
private TheGamepadImagePanel gamePadImagePanel;
private TheGamepadMappingPanel gamePadMappingPanel;
private JoystickModel model;
public GamepadBackgroundPanel(JoystickModel model) {
public TheGamepadBackgroundPanel(JoystickModel model) {
this.model = model;
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
@ -45,21 +45,21 @@ public class GamepadBackgroundPanel extends JPanel
gbc_gamePadMappingPanel.gridy = 1;
add(getGamePadMappingPanel(), gbc_gamePadMappingPanel);
}
private GamePadInfoPanel getGamePadInfoPanel() {
private TheGamepadInfoPanel getGamePadInfoPanel() {
if (gamePadInfoPanel == null) {
gamePadInfoPanel = new GamePadInfoPanel();
gamePadInfoPanel = new TheGamepadInfoPanel();
}
return gamePadInfoPanel;
}
private GamePadImagePanel getGamePadImagePanel() {
private TheGamepadImagePanel getGamePadImagePanel() {
if (gamePadImagePanel == null) {
gamePadImagePanel = new GamePadImagePanel();
gamePadImagePanel = new TheGamepadImagePanel();
}
return gamePadImagePanel;
}
private GamePadMappingPanel getGamePadMappingPanel() {
private TheGamepadMappingPanel getGamePadMappingPanel() {
if (gamePadMappingPanel == null) {
gamePadMappingPanel = new GamePadMappingPanel(model, getGamePadImagePanel());
gamePadMappingPanel = new TheGamepadMappingPanel(model, getGamePadImagePanel());
}
return gamePadMappingPanel;
}

View File

@ -0,0 +1,129 @@
package se.lantz.gui.gamepad;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TheGamepadImagePanel extends JPanel
{
public enum TheGamepadButton
{
UP("Up", Character.toString(0x1f815)), DOWN("Down", Character.toString(0x1f817)),
LEFT("Left", Character.toString(0x1f814)), RIGHT("Right", Character.toString(0x1f816)), A("A", "TL"), B("B", "Right Fire"),
X("X", "TR"), Y("Y", "Left Fire"), LSB("LSB", "A"), RSB("RSB", "B"), MENU("Menu", "C");
public final String label;
public final String joyMapping;
private TheGamepadButton(String label, String joyMapping)
{
this.label = label;
this.joyMapping = joyMapping;
}
}
ImageIcon gamepadImage = new ImageIcon(getClass().getResource("/se/lantz/TheGamepad.png"));
private JLabel imageLabel;
private TheGamepadButton currentButton = null;
public TheGamepadImagePanel()
{
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints gbc_imageLabel = new GridBagConstraints();
gbc_imageLabel.insets = new Insets(20, 0, 0, 0);
gbc_imageLabel.weightx = 1.0;
gbc_imageLabel.weighty = 1.0;
gbc_imageLabel.anchor = GridBagConstraints.NORTH;
gbc_imageLabel.gridx = 0;
gbc_imageLabel.gridy = 0;
add(getImageLabel(), gbc_imageLabel);
}
private JLabel getImageLabel()
{
if (imageLabel == null)
{
imageLabel = new JLabel()
{
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
//Draw for currently focused button
drawForButton(g);
}
};
imageLabel.setIcon(gamepadImage);
}
return imageLabel;
}
public void setCurrentButtonAndRepaint(TheGamepadButton button)
{
this.currentButton = button;
this.repaint();
}
private void drawForButton(Graphics g)
{
if (currentButton == null)
{
return;
}
Graphics2D graphics2D = (Graphics2D) g;
graphics2D.setStroke(new BasicStroke(3.0f));
graphics2D.setColor(Color.red);
switch (currentButton)
{
case UP:
graphics2D.drawOval(55, 50, 22, 22);
break;
case DOWN:
graphics2D.drawOval(53, 84, 22, 22);
break;
case LEFT:
graphics2D.drawOval(40, 66, 22, 22);
break;
case RIGHT:
graphics2D.drawOval(72, 66, 22, 22);
break;
case A:
graphics2D.drawOval(253, 89, 22, 22);
break;
case B:
graphics2D.drawOval(276, 68, 22, 22);
break;
case MENU:
graphics2D.drawRect(122, 92, 25, 25);
break;
case LSB:
graphics2D.drawRect(47, 15, 25, 20);
break;
case RSB:
graphics2D.drawRect(253, 15, 25, 20);
break;
case X:
graphics2D.drawOval(230, 67, 22, 22);
break;
case Y:
graphics2D.drawOval(250, 46, 22, 22);
break;
default:
break;
}
}
}

View File

@ -0,0 +1,77 @@
package se.lantz.gui.gamepad;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TheGamepadInfoPanel extends JPanel
{
ImageIcon compImage = new ImageIcon(getClass().getResource("/se/lantz/TheGamepadMapping.png"));
private JLabel infoLabel;
private JLabel compImageLabel;
private JLabel extraButtonsInfoLabel;
public TheGamepadInfoPanel()
{
setBackground(Color.WHITE);
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints gbc_infoLabel = new GridBagConstraints();
gbc_infoLabel.fill = GridBagConstraints.HORIZONTAL;
gbc_infoLabel.weightx = 1.0;
gbc_infoLabel.insets = new Insets(0, 10, 0, 10);
gbc_infoLabel.gridx = 0;
gbc_infoLabel.gridy = 0;
add(getInfoLabel(), gbc_infoLabel);
GridBagConstraints gbc_compImageLabel = new GridBagConstraints();
gbc_compImageLabel.insets = new Insets(0, 0, 10, 0);
gbc_compImageLabel.weighty = 1.0;
gbc_compImageLabel.weightx = 1.0;
gbc_compImageLabel.gridx = 0;
gbc_compImageLabel.gridy = 1;
add(getCompImageLabel(), gbc_compImageLabel);
GridBagConstraints gbc_extraButtonsInfoLabel = new GridBagConstraints();
gbc_extraButtonsInfoLabel.insets = new Insets(0, 10, 10, 10);
gbc_extraButtonsInfoLabel.fill = GridBagConstraints.HORIZONTAL;
gbc_extraButtonsInfoLabel.gridx = 0;
gbc_extraButtonsInfoLabel.gridy = 2;
add(getExtraButtonsInfoLabel(), gbc_extraButtonsInfoLabel);
}
private JLabel getInfoLabel()
{
if (infoLabel == null)
{
infoLabel =
new JLabel("<html><h3>THEGamepad</h3><p>THEGamepad from Retro Games is compatible with THEC64, THEC64 Mini, THEA500 Mini, PC, Mac & Linux. Compared with THEC64 Joystick, functions translate as follows:<br><br></html>");
}
return infoLabel;
}
private JLabel getCompImageLabel()
{
if (compImageLabel == null)
{
compImageLabel = new JLabel();
compImageLabel.setBackground(Color.WHITE);
compImageLabel.setIcon(compImage);
}
return compImageLabel;
}
private JLabel getExtraButtonsInfoLabel()
{
if (extraButtonsInfoLabel == null)
{
extraButtonsInfoLabel =
new JLabel("<html><br>Below are the functions for THEC64 Joystick shown in parenthesis for comparison.<br></html>");
}
return extraButtonsInfoLabel;
}
}

View File

@ -0,0 +1,220 @@
package se.lantz.gui.gamepad;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.Beans;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import se.lantz.gui.KeySelectionComboBox;
import se.lantz.gui.gamepad.TheGamepadImagePanel.TheGamepadButton;
import se.lantz.model.JoystickModel;
public class TheGamepadMappingComponent extends JPanel
{
private JLabel buttonTextLabel;
private KeySelectionComboBox keySelectionComboBox;
private JLabel joyMapLabel;
private TheGamepadButton button;
private JoystickModel model;
private TheGamepadImagePanel imagePanel;
public TheGamepadMappingComponent(TheGamepadButton button, JoystickModel model, TheGamepadImagePanel imagePanel)
{
this.button = button;
this.model = model;
this.imagePanel = imagePanel;
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints gbc_buttonTextLabel = new GridBagConstraints();
gbc_buttonTextLabel.anchor = GridBagConstraints.WEST;
gbc_buttonTextLabel.insets = new Insets(5, 5, 0, 5);
gbc_buttonTextLabel.gridx = 0;
gbc_buttonTextLabel.gridy = 0;
add(getButtonTextLabel(), gbc_buttonTextLabel);
GridBagConstraints gbc_keySelectionComboBox = new GridBagConstraints();
gbc_keySelectionComboBox.weighty = 1.0;
gbc_keySelectionComboBox.gridwidth = 2;
gbc_keySelectionComboBox.insets = new Insets(0, 4, 5, 5);
gbc_keySelectionComboBox.anchor = GridBagConstraints.NORTHWEST;
gbc_keySelectionComboBox.gridx = 0;
gbc_keySelectionComboBox.gridy = 1;
add(getKeySelectionComboBox(), gbc_keySelectionComboBox);
GridBagConstraints gbc_joyMapLabel = new GridBagConstraints();
gbc_joyMapLabel.anchor = GridBagConstraints.WEST;
gbc_joyMapLabel.weightx = 1.0;
gbc_joyMapLabel.insets = new Insets(5, 0, 0, 5);
gbc_joyMapLabel.gridx = 1;
gbc_joyMapLabel.gridy = 0;
add(getJoyMapLabel(), gbc_joyMapLabel);
if (!Beans.isDesignTime())
{
model.addPropertyChangeListener((e) -> modelChanged());
}
}
private void modelChanged()
{
switch (button)
{
case UP:
getKeySelectionComboBox().setSelectedCode(model.getUp());
break;
case DOWN:
getKeySelectionComboBox().setSelectedCode(model.getDown());
break;
case LEFT:
getKeySelectionComboBox().setSelectedCode(model.getLeft());
break;
case RIGHT:
getKeySelectionComboBox().setSelectedCode(model.getRight());
break;
case Y:
getKeySelectionComboBox().setSelectedCode(model.getLeftFire());
break;
case B:
getKeySelectionComboBox().setSelectedCode(model.getRightFire());
break;
case A:
getKeySelectionComboBox().setSelectedCode(model.getTl());
break;
case X:
getKeySelectionComboBox().setSelectedCode(model.getTr());
break;
case LSB:
getKeySelectionComboBox().setSelectedCode(model.getA());
break;
case RSB:
getKeySelectionComboBox().setSelectedCode(model.getB());
break;
case MENU:
getKeySelectionComboBox().setSelectedCode(model.getC());
break;
default:
break;
}
}
private JLabel getButtonTextLabel()
{
if (buttonTextLabel == null)
{
buttonTextLabel = new JLabel(button.label);
}
return buttonTextLabel;
}
private KeySelectionComboBox getKeySelectionComboBox()
{
if (keySelectionComboBox == null)
{
keySelectionComboBox = new KeySelectionComboBox(model);
keySelectionComboBox.addActionListener(e -> {
switch (button)
{
case UP:
model.setUp(keySelectionComboBox.getSelectedCode());
break;
case DOWN:
model.setDown(keySelectionComboBox.getSelectedCode());
break;
case LEFT:
model.setLeft(keySelectionComboBox.getSelectedCode());
break;
case RIGHT:
model.setRight(keySelectionComboBox.getSelectedCode());
break;
case Y:
model.setLeftFire(keySelectionComboBox.getSelectedCode());
break;
case B:
model.setRightFire(keySelectionComboBox.getSelectedCode());
break;
case A:
model.setTl(keySelectionComboBox.getSelectedCode());
break;
case X:
model.setTr(keySelectionComboBox.getSelectedCode());
break;
case LSB:
model.setA(keySelectionComboBox.getSelectedCode());
break;
case RSB:
model.setB(keySelectionComboBox.getSelectedCode());
break;
case MENU:
model.setC(keySelectionComboBox.getSelectedCode());
break;
default:
break;
}
});
keySelectionComboBox.addMouseListener(new MouseAdapter()
{
@Override
public void mouseExited(MouseEvent e)
{
if (!keySelectionComboBox.hasFocus())
{
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner instanceof KeySelectionComboBox)
{
TheGamepadMappingComponent focusedMappingComponent = (TheGamepadMappingComponent) SwingUtilities
.getAncestorOfClass(TheGamepadMappingComponent.class, focusOwner);
if (focusedMappingComponent != null)
{
imagePanel.setCurrentButtonAndRepaint(focusedMappingComponent.button);
}
}
else
{
imagePanel.setCurrentButtonAndRepaint(null);
}
}
}
@Override
public void mouseEntered(MouseEvent me)
{
imagePanel.setCurrentButtonAndRepaint(button);
}
});
keySelectionComboBox.addFocusListener(new FocusAdapter()
{
@Override
public void focusGained(FocusEvent e)
{
imagePanel.setCurrentButtonAndRepaint(button);
}
@Override
public void focusLost(FocusEvent e)
{
imagePanel.setCurrentButtonAndRepaint(null);
}
});
}
return keySelectionComboBox;
}
private JLabel getJoyMapLabel()
{
if (joyMapLabel == null)
{
joyMapLabel = new JLabel("(" + button.joyMapping + ")");
}
return joyMapLabel;
}
}

View File

@ -0,0 +1,163 @@
package se.lantz.gui.gamepad;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import se.lantz.gui.gamepad.TheGamepadImagePanel.TheGamepadButton;
import se.lantz.gui.gamepad.USBControllerImagePanel.USBControllerButton;
import se.lantz.model.JoystickModel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
public class TheGamepadMappingPanel extends JPanel
{
private TheGamepadMappingComponent upComponent;
private JoystickModel model;
private TheGamepadMappingComponent downComponent;
private TheGamepadMappingComponent leftComponent;
private TheGamepadMappingComponent rightComponent;
private TheGamepadMappingComponent xComponent;
private TheGamepadMappingComponent yComponent;
private TheGamepadMappingComponent aComponent;
private TheGamepadMappingComponent bComponent;
private TheGamepadMappingComponent leftTriggerComponent;
private TheGamepadMappingComponent rightTriggerComponent;
private TheGamepadMappingComponent backGuideComponent;
private TheGamepadMappingComponent leftShoulderComponent;
private TheGamepadMappingComponent rightShoulderComponent;
private TheGamepadMappingComponent leftStickComponent;
private TheGamepadMappingComponent rightStickComponent;
private TheGamepadImagePanel imagePanel;
public TheGamepadMappingPanel(JoystickModel model, TheGamepadImagePanel imagePanel)
{
this.model = model;
this.imagePanel = imagePanel;
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
gridBagLayout.columnWeights = new double[]{1.0, 1.0};
setLayout(gridBagLayout);
GridBagConstraints gbc_upComponent = new GridBagConstraints();
gbc_upComponent.fill = GridBagConstraints.BOTH;
gbc_upComponent.gridx = 0;
gbc_upComponent.gridy = 0;
add(getUpComponent(), gbc_upComponent);
GridBagConstraints gbc_downgComponent = new GridBagConstraints();
gbc_downgComponent.fill = GridBagConstraints.BOTH;
gbc_downgComponent.gridx = 0;
gbc_downgComponent.gridy = 1;
add(getDowngComponent(), gbc_downgComponent);
GridBagConstraints gbc_leftComponent = new GridBagConstraints();
gbc_leftComponent.fill = GridBagConstraints.BOTH;
gbc_leftComponent.gridx = 0;
gbc_leftComponent.gridy = 2;
add(getMappingComponent_2(), gbc_leftComponent);
GridBagConstraints gbc_rightComponent = new GridBagConstraints();
gbc_rightComponent.fill = GridBagConstraints.BOTH;
gbc_rightComponent.gridx = 0;
gbc_rightComponent.gridy = 3;
add(getRightComponent(), gbc_rightComponent);
GridBagConstraints gbc_xComponent = new GridBagConstraints();
gbc_xComponent.fill = GridBagConstraints.BOTH;
gbc_xComponent.gridx = 1;
gbc_xComponent.gridy = 2;
add(getXComponent(), gbc_xComponent);
GridBagConstraints gbc_yComponent = new GridBagConstraints();
gbc_yComponent.fill = GridBagConstraints.BOTH;
gbc_yComponent.gridx = 1;
gbc_yComponent.gridy = 3;
add(getYComponent(), gbc_yComponent);
GridBagConstraints gbc_aComponent = new GridBagConstraints();
gbc_aComponent.fill = GridBagConstraints.BOTH;
gbc_aComponent.gridx = 1;
gbc_aComponent.gridy = 0;
add(getAComponent(), gbc_aComponent);
GridBagConstraints gbc_bComponent = new GridBagConstraints();
gbc_bComponent.fill = GridBagConstraints.BOTH;
gbc_bComponent.gridx = 1;
gbc_bComponent.gridy = 1;
add(getBComponent(), gbc_bComponent);
GridBagConstraints gbc_leftTriggerComponent = new GridBagConstraints();
gbc_leftTriggerComponent.fill = GridBagConstraints.BOTH;
gbc_leftTriggerComponent.gridx = 0;
gbc_leftTriggerComponent.gridy = 4;
add(getLeftTriggerComponent(), gbc_leftTriggerComponent);
GridBagConstraints gbc_rightTriggerComponent = new GridBagConstraints();
gbc_rightTriggerComponent.fill = GridBagConstraints.BOTH;
gbc_rightTriggerComponent.gridx = 1;
gbc_rightTriggerComponent.gridy = 4;
add(getRightTriggerComponent(), gbc_rightTriggerComponent);
GridBagConstraints gbc_backGuideComponent = new GridBagConstraints();
gbc_backGuideComponent.fill = GridBagConstraints.BOTH;
gbc_backGuideComponent.gridx = 0;
gbc_backGuideComponent.gridy = 5;
add(getBackGuideComponent(), gbc_backGuideComponent);
}
private TheGamepadMappingComponent getUpComponent() {
if (upComponent == null) {
upComponent = new TheGamepadMappingComponent(TheGamepadButton.UP, model, imagePanel);
}
return upComponent;
}
private TheGamepadMappingComponent getDowngComponent() {
if (downComponent == null) {
downComponent = new TheGamepadMappingComponent(TheGamepadButton.DOWN, model, imagePanel);
}
return downComponent;
}
private TheGamepadMappingComponent getMappingComponent_2() {
if (leftComponent == null) {
leftComponent = new TheGamepadMappingComponent(TheGamepadButton.LEFT, model, imagePanel);
}
return leftComponent;
}
private TheGamepadMappingComponent getRightComponent() {
if (rightComponent == null) {
rightComponent = new TheGamepadMappingComponent(TheGamepadButton.RIGHT, model, imagePanel);
}
return rightComponent;
}
private TheGamepadMappingComponent getXComponent() {
if (xComponent == null) {
xComponent = new TheGamepadMappingComponent(TheGamepadButton.X, model, imagePanel);
}
return xComponent;
}
private TheGamepadMappingComponent getYComponent() {
if (yComponent == null) {
yComponent = new TheGamepadMappingComponent(TheGamepadButton.Y, model, imagePanel);
}
return yComponent;
}
private TheGamepadMappingComponent getAComponent() {
if (aComponent == null) {
aComponent = new TheGamepadMappingComponent(TheGamepadButton.A, model, imagePanel);
}
return aComponent;
}
private TheGamepadMappingComponent getBComponent() {
if (bComponent == null) {
bComponent = new TheGamepadMappingComponent(TheGamepadButton.B, model, imagePanel);
}
return bComponent;
}
private TheGamepadMappingComponent getLeftTriggerComponent() {
if (leftTriggerComponent == null) {
leftTriggerComponent = new TheGamepadMappingComponent(TheGamepadButton.LSB, model, imagePanel);
}
return leftTriggerComponent;
}
private TheGamepadMappingComponent getRightTriggerComponent() {
if (rightTriggerComponent == null) {
rightTriggerComponent = new TheGamepadMappingComponent(TheGamepadButton.RSB, model, imagePanel);
}
return rightTriggerComponent;
}
private TheGamepadMappingComponent getBackGuideComponent() {
if (backGuideComponent == null) {
backGuideComponent = new TheGamepadMappingComponent(TheGamepadButton.MENU, model, imagePanel);
}
return backGuideComponent;
}
}

View File

@ -0,0 +1,66 @@
package se.lantz.gui.gamepad;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JPanel;
import se.lantz.model.JoystickModel;
public class USBControllerBackgroundPanel extends JPanel
{
private USBControllerInfoPanel gamePadInfoPanel;
private USBControllerImagePanel gamePadImagePanel;
private USBControllerMappingPanel gamePadMappingPanel;
private JoystickModel model;
public USBControllerBackgroundPanel(JoystickModel model) {
this.model = model;
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints gbc_gamePadInfoPanel = new GridBagConstraints();
gbc_gamePadInfoPanel.gridwidth = 2;
gbc_gamePadInfoPanel.insets = new Insets(0, 0, 5, 0);
gbc_gamePadInfoPanel.anchor = GridBagConstraints.NORTHWEST;
gbc_gamePadInfoPanel.weightx = 1.0;
gbc_gamePadInfoPanel.fill = GridBagConstraints.BOTH;
gbc_gamePadInfoPanel.gridx = 0;
gbc_gamePadInfoPanel.gridy = 0;
add(getGamePadInfoPanel(), gbc_gamePadInfoPanel);
GridBagConstraints gbc_gamePadImagePanel = new GridBagConstraints();
gbc_gamePadImagePanel.anchor = GridBagConstraints.NORTHWEST;
gbc_gamePadImagePanel.insets = new Insets(0, 0, 5, 10);
gbc_gamePadImagePanel.weightx = 1.0;
gbc_gamePadImagePanel.fill = GridBagConstraints.BOTH;
gbc_gamePadImagePanel.gridx = 1;
gbc_gamePadImagePanel.gridy = 1;
add(getGamePadImagePanel(), gbc_gamePadImagePanel);
GridBagConstraints gbc_gamePadMappingPanel = new GridBagConstraints();
gbc_gamePadMappingPanel.insets = new Insets(0, 10, 0, 0);
gbc_gamePadMappingPanel.weighty = 1.0;
gbc_gamePadMappingPanel.weightx = 1.0;
gbc_gamePadMappingPanel.anchor = GridBagConstraints.NORTHWEST;
gbc_gamePadMappingPanel.fill = GridBagConstraints.BOTH;
gbc_gamePadMappingPanel.gridx = 0;
gbc_gamePadMappingPanel.gridy = 1;
add(getGamePadMappingPanel(), gbc_gamePadMappingPanel);
}
private USBControllerInfoPanel getGamePadInfoPanel() {
if (gamePadInfoPanel == null) {
gamePadInfoPanel = new USBControllerInfoPanel();
}
return gamePadInfoPanel;
}
private USBControllerImagePanel getGamePadImagePanel() {
if (gamePadImagePanel == null) {
gamePadImagePanel = new USBControllerImagePanel();
}
return gamePadImagePanel;
}
private USBControllerMappingPanel getGamePadMappingPanel() {
if (gamePadMappingPanel == null) {
gamePadMappingPanel = new USBControllerMappingPanel(model, getGamePadImagePanel());
}
return gamePadMappingPanel;
}
}

View File

@ -17,9 +17,9 @@ import javax.swing.JPanel;
import se.lantz.util.FileManager;
public class GamePadImagePanel extends JPanel
public class USBControllerImagePanel extends JPanel
{
public enum GamePadButton
public enum USBControllerButton
{
UP("Up", Character.toString(0x1f815)), DOWN("Down", Character.toString(0x1f817)),
LEFT("Left", Character.toString(0x1f814)), RIGHT("Right", Character.toString(0x1f816)), A("A", "A"), B("B", "B"),
@ -30,7 +30,7 @@ public class GamePadImagePanel extends JPanel
public final String label;
public final String joyMapping;
private GamePadButton(String label, String joyMapping)
private USBControllerButton(String label, String joyMapping)
{
this.label = label;
this.joyMapping = joyMapping;
@ -40,9 +40,9 @@ public class GamePadImagePanel extends JPanel
ImageIcon gamepadImage = new ImageIcon(getClass().getResource("/se/lantz/logitech.png"));
private JLabel imageLabel;
private GamePadButton currentButton = null;
private USBControllerButton currentButton = null;
public GamePadImagePanel()
public USBControllerImagePanel()
{
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
@ -77,7 +77,7 @@ public class GamePadImagePanel extends JPanel
return imageLabel;
}
public void setCurrentButtonAndRepaint(GamePadButton button)
public void setCurrentButtonAndRepaint(USBControllerButton button)
{
this.currentButton = button;
this.repaint();

View File

@ -11,7 +11,7 @@ import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Color;
public class GamePadInfoPanel extends JPanel
public class USBControllerInfoPanel extends JPanel
{
ImageIcon compImage = new ImageIcon(getClass().getResource("/se/lantz/joystick-comp.png"));
@ -19,7 +19,7 @@ public class GamePadInfoPanel extends JPanel
private JLabel compImageLabel;
private JLabel extraButtonsInfoLabel;
public GamePadInfoPanel()
public USBControllerInfoPanel()
{
setBackground(Color.WHITE);
GridBagLayout gridBagLayout = new GridBagLayout();

View File

@ -16,19 +16,19 @@ import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import se.lantz.gui.KeySelectionComboBox;
import se.lantz.gui.gamepad.GamePadImagePanel.GamePadButton;
import se.lantz.gui.gamepad.USBControllerImagePanel.USBControllerButton;
import se.lantz.model.JoystickModel;
public class MappingComponent extends JPanel
public class USBControllerMappingComponent extends JPanel
{
private JLabel buttonTextLabel;
private KeySelectionComboBox keySelectionComboBox;
private JLabel joyMapLabel;
private GamePadButton button;
private USBControllerButton button;
private JoystickModel model;
private GamePadImagePanel imagePanel;
private USBControllerImagePanel imagePanel;
public MappingComponent(GamePadButton button, JoystickModel model, GamePadImagePanel imagePanel)
public USBControllerMappingComponent(USBControllerButton button, JoystickModel model, USBControllerImagePanel imagePanel)
{
this.button = button;
this.model = model;
@ -193,7 +193,7 @@ public class MappingComponent extends JPanel
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner instanceof KeySelectionComboBox)
{
MappingComponent focusedMappingComponent = (MappingComponent)SwingUtilities.getAncestorOfClass(MappingComponent.class, focusOwner);
USBControllerMappingComponent focusedMappingComponent = (USBControllerMappingComponent)SwingUtilities.getAncestorOfClass(USBControllerMappingComponent.class, focusOwner);
if (focusedMappingComponent != null)
{
imagePanel.setCurrentButtonAndRepaint(focusedMappingComponent.button);

View File

@ -3,32 +3,32 @@ package se.lantz.gui.gamepad;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import se.lantz.gui.gamepad.GamePadImagePanel.GamePadButton;
import se.lantz.gui.gamepad.USBControllerImagePanel.USBControllerButton;
import se.lantz.model.JoystickModel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
public class GamePadMappingPanel extends JPanel
public class USBControllerMappingPanel extends JPanel
{
private MappingComponent upComponent;
private USBControllerMappingComponent upComponent;
private JoystickModel model;
private MappingComponent downComponent;
private MappingComponent leftComponent;
private MappingComponent rightComponent;
private MappingComponent xComponent;
private MappingComponent yComponent;
private MappingComponent aComponent;
private MappingComponent bComponent;
private MappingComponent leftTriggerComponent;
private MappingComponent rightTriggerComponent;
private MappingComponent backGuideComponent;
private MappingComponent leftShoulderComponent;
private MappingComponent rightShoulderComponent;
private MappingComponent leftStickComponent;
private MappingComponent rightStickComponent;
private GamePadImagePanel imagePanel;
private USBControllerMappingComponent downComponent;
private USBControllerMappingComponent leftComponent;
private USBControllerMappingComponent rightComponent;
private USBControllerMappingComponent xComponent;
private USBControllerMappingComponent yComponent;
private USBControllerMappingComponent aComponent;
private USBControllerMappingComponent bComponent;
private USBControllerMappingComponent leftTriggerComponent;
private USBControllerMappingComponent rightTriggerComponent;
private USBControllerMappingComponent backGuideComponent;
private USBControllerMappingComponent leftShoulderComponent;
private USBControllerMappingComponent rightShoulderComponent;
private USBControllerMappingComponent leftStickComponent;
private USBControllerMappingComponent rightStickComponent;
private USBControllerImagePanel imagePanel;
public GamePadMappingPanel(JoystickModel model, GamePadImagePanel imagePanel)
public USBControllerMappingPanel(JoystickModel model, USBControllerImagePanel imagePanel)
{
this.model = model;
this.imagePanel = imagePanel;
@ -114,93 +114,93 @@ public class GamePadMappingPanel extends JPanel
gbc_rightStickComponent.gridy = 7;
add(getRightStickComponent(), gbc_rightStickComponent);
}
private MappingComponent getUpComponent() {
private USBControllerMappingComponent getUpComponent() {
if (upComponent == null) {
upComponent = new MappingComponent(GamePadButton.UP, model, imagePanel);
upComponent = new USBControllerMappingComponent(USBControllerButton.UP, model, imagePanel);
}
return upComponent;
}
private MappingComponent getDowngComponent() {
private USBControllerMappingComponent getDowngComponent() {
if (downComponent == null) {
downComponent = new MappingComponent(GamePadButton.DOWN, model, imagePanel);
downComponent = new USBControllerMappingComponent(USBControllerButton.DOWN, model, imagePanel);
}
return downComponent;
}
private MappingComponent getMappingComponent_2() {
private USBControllerMappingComponent getMappingComponent_2() {
if (leftComponent == null) {
leftComponent = new MappingComponent(GamePadButton.LEFT, model, imagePanel);
leftComponent = new USBControllerMappingComponent(USBControllerButton.LEFT, model, imagePanel);
}
return leftComponent;
}
private MappingComponent getRightComponent() {
private USBControllerMappingComponent getRightComponent() {
if (rightComponent == null) {
rightComponent = new MappingComponent(GamePadButton.RIGHT, model, imagePanel);
rightComponent = new USBControllerMappingComponent(USBControllerButton.RIGHT, model, imagePanel);
}
return rightComponent;
}
private MappingComponent getXComponent() {
private USBControllerMappingComponent getXComponent() {
if (xComponent == null) {
xComponent = new MappingComponent(GamePadButton.X, model, imagePanel);
xComponent = new USBControllerMappingComponent(USBControllerButton.X, model, imagePanel);
}
return xComponent;
}
private MappingComponent getYComponent() {
private USBControllerMappingComponent getYComponent() {
if (yComponent == null) {
yComponent = new MappingComponent(GamePadButton.Y, model, imagePanel);
yComponent = new USBControllerMappingComponent(USBControllerButton.Y, model, imagePanel);
}
return yComponent;
}
private MappingComponent getAComponent() {
private USBControllerMappingComponent getAComponent() {
if (aComponent == null) {
aComponent = new MappingComponent(GamePadButton.A, model, imagePanel);
aComponent = new USBControllerMappingComponent(USBControllerButton.A, model, imagePanel);
}
return aComponent;
}
private MappingComponent getBComponent() {
private USBControllerMappingComponent getBComponent() {
if (bComponent == null) {
bComponent = new MappingComponent(GamePadButton.B, model, imagePanel);
bComponent = new USBControllerMappingComponent(USBControllerButton.B, model, imagePanel);
}
return bComponent;
}
private MappingComponent getLeftTriggerComponent() {
private USBControllerMappingComponent getLeftTriggerComponent() {
if (leftTriggerComponent == null) {
leftTriggerComponent = new MappingComponent(GamePadButton.LEFT_TRIGGER, model, imagePanel);
leftTriggerComponent = new USBControllerMappingComponent(USBControllerButton.LEFT_TRIGGER, model, imagePanel);
}
return leftTriggerComponent;
}
private MappingComponent getRightTriggerComponent() {
private USBControllerMappingComponent getRightTriggerComponent() {
if (rightTriggerComponent == null) {
rightTriggerComponent = new MappingComponent(GamePadButton.RIGHT_TRIGGER, model, imagePanel);
rightTriggerComponent = new USBControllerMappingComponent(USBControllerButton.RIGHT_TRIGGER, model, imagePanel);
}
return rightTriggerComponent;
}
private MappingComponent getBackGuideComponent() {
private USBControllerMappingComponent getBackGuideComponent() {
if (backGuideComponent == null) {
backGuideComponent = new MappingComponent(GamePadButton.BACK_GUIDE, model, imagePanel);
backGuideComponent = new USBControllerMappingComponent(USBControllerButton.BACK_GUIDE, model, imagePanel);
}
return backGuideComponent;
}
private MappingComponent getLeftShoulderComponent() {
private USBControllerMappingComponent getLeftShoulderComponent() {
if (leftShoulderComponent == null) {
leftShoulderComponent = new MappingComponent(GamePadButton.LEFT_SHOULDER, model, imagePanel);
leftShoulderComponent = new USBControllerMappingComponent(USBControllerButton.LEFT_SHOULDER, model, imagePanel);
}
return leftShoulderComponent;
}
private MappingComponent getRightShoulderComponent() {
private USBControllerMappingComponent getRightShoulderComponent() {
if (rightShoulderComponent == null) {
rightShoulderComponent = new MappingComponent(GamePadButton.RIGHT_SHOULDER, model, imagePanel);
rightShoulderComponent = new USBControllerMappingComponent(USBControllerButton.RIGHT_SHOULDER, model, imagePanel);
}
return rightShoulderComponent;
}
private MappingComponent getLeftStickComponent() {
private USBControllerMappingComponent getLeftStickComponent() {
if (leftStickComponent == null) {
leftStickComponent = new MappingComponent(GamePadButton.LEFT_STICK, model, imagePanel);
leftStickComponent = new USBControllerMappingComponent(USBControllerButton.LEFT_STICK, model, imagePanel);
}
return leftStickComponent;
}
private MappingComponent getRightStickComponent() {
private USBControllerMappingComponent getRightStickComponent() {
if (rightStickComponent == null) {
rightStickComponent = new MappingComponent(GamePadButton.RIGHT_STICK, model, imagePanel);
rightStickComponent = new USBControllerMappingComponent(USBControllerButton.RIGHT_STICK, model, imagePanel);
}
return rightStickComponent;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB