Removed deprecated method and renamed some classes. Created a new package to separate gamepad classes from keyboard/mouse classes

This commit is contained in:
Diego Waxemberg
2013-12-27 10:08:31 -05:00
parent bc79e1ee06
commit 2c3ed99a3a
9 changed files with 41 additions and 49 deletions

View File

@@ -12,7 +12,7 @@ import javax.swing.UIManager;
import com.limelight.binding.PlatformBinding; import com.limelight.binding.PlatformBinding;
import com.limelight.gui.MainFrame; import com.limelight.gui.MainFrame;
import com.limelight.gui.StreamFrame; import com.limelight.gui.StreamFrame;
import com.limelight.input.ControllerListener; import com.limelight.input.gamepad.GamepadListener;
import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.NvConnection;
import com.limelight.nvstream.NvConnectionListener; import com.limelight.nvstream.NvConnectionListener;
import com.limelight.nvstream.StreamConfiguration; import com.limelight.nvstream.StreamConfiguration;
@@ -94,7 +94,7 @@ public class Limelight implements NvConnectionListener {
PlatformBinding.getAudioRenderer(), PlatformBinding.getAudioRenderer(),
PlatformBinding.getVideoDecoderRenderer()); PlatformBinding.getVideoDecoderRenderer());
ControllerListener.startSendingInput(conn); GamepadListener.startSendingInput(conn);
} }
@@ -115,7 +115,7 @@ public class Limelight implements NvConnectionListener {
} }
private static void startControllerListener() { private static void startControllerListener() {
ControllerListener.startUp(); GamepadListener.startUp();
} }
private static void createFrame() { private static void createFrame() {
@@ -178,7 +178,7 @@ public class Limelight implements NvConnectionListener {
@Override @Override
public void connectionStarted() { public void connectionStarted() {
streamFrame.hideSpinner(); streamFrame.hideSpinner();
ControllerListener.startSendingInput(conn); GamepadListener.startSendingInput(conn);
} }
@Override @Override

View File

@@ -22,19 +22,18 @@ import javax.swing.JCheckBox;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import net.java.games.input.Component; import net.java.games.input.Component;
import net.java.games.input.Event; import net.java.games.input.Event;
import net.java.games.input.EventQueue; import net.java.games.input.EventQueue;
import com.limelight.input.ControllerComponent; import com.limelight.input.gamepad.GamepadComponent;
import com.limelight.input.ControllerListener; import com.limelight.input.gamepad.GamepadListener;
import com.limelight.input.Gamepad; import com.limelight.input.gamepad.Gamepad;
import com.limelight.input.GamepadHandler; import com.limelight.input.gamepad.GamepadHandler;
import com.limelight.input.GamepadMapping; import com.limelight.input.gamepad.GamepadMapping;
import com.limelight.input.GamepadMapping.Mapping; import com.limelight.input.gamepad.GamepadMapping.Mapping;
import com.limelight.settings.GamepadSettingsManager; import com.limelight.settings.GamepadSettingsManager;
public class GamepadConfigFrame extends JFrame { public class GamepadConfigFrame extends JFrame {
@@ -60,12 +59,12 @@ public class GamepadConfigFrame extends JFrame {
public void build() { public void build() {
componentMap = new HashMap<Box, Mapping>(); componentMap = new HashMap<Box, Mapping>();
GridLayout layout = new GridLayout(ControllerComponent.values().length/2 + 1, 2); GridLayout layout = new GridLayout(GamepadComponent.values().length/2 + 1, 2);
layout.setHgap(60); layout.setHgap(60);
layout.setVgap(3); layout.setVgap(3);
JPanel mainPanel = new JPanel(layout); JPanel mainPanel = new JPanel(layout);
ControllerComponent[] components = ControllerComponent.values(); GamepadComponent[] components = GamepadComponent.values();
for (int i = 0; i < components.length; i++) { for (int i = 0; i < components.length; i++) {
@@ -102,7 +101,7 @@ public class GamepadConfigFrame extends JFrame {
mapButton.setMaximumSize(buttonSize); mapButton.setMaximumSize(buttonSize);
mapButton.setMinimumSize(buttonSize); mapButton.setMinimumSize(buttonSize);
mapButton.setPreferredSize(buttonSize); mapButton.setPreferredSize(buttonSize);
mapButton.addActionListener(createListener()); mapButton.addActionListener(createMapListener());
mapButton.setText(config.getMapping(mapping.contComp)); mapButton.setText(config.getMapping(mapping.contComp));
invertBox.setSelected(mapping.invert); invertBox.setSelected(mapping.invert);
@@ -110,7 +109,7 @@ public class GamepadConfigFrame extends JFrame {
triggerBox.setSelected(mapping.trigger); triggerBox.setSelected(mapping.trigger);
triggerBox.addItemListener(createTriggerListener()); triggerBox.addItemListener(createTriggerListener());
triggerBox.setToolTipText("If this component should act as a trigger."); triggerBox.setToolTipText("If this component should act as a trigger. (one-way axis)");
componentBox.add(Box.createHorizontalStrut(5)); componentBox.add(Box.createHorizontalStrut(5));
componentBox.add(mapping.contComp.getLabel()); componentBox.add(mapping.contComp.getLabel());
@@ -120,23 +119,20 @@ public class GamepadConfigFrame extends JFrame {
componentBox.add(triggerBox); componentBox.add(triggerBox);
componentBox.add(Box.createHorizontalStrut(5)); componentBox.add(Box.createHorizontalStrut(5));
componentBox.setBorder(createBorder()); componentBox.setBorder(new LineBorder(Color.GRAY, 1, true));
componentMap.put(componentBox, mapping); componentMap.put(componentBox, mapping);
return componentBox; return componentBox;
} }
private Border createBorder() {
return new LineBorder(Color.GRAY, 1, true);
}
//TODO: make createInvertListener() and createTriggerListener() one method. TOO MUCH COPY PASTA! //TODO: make createInvertListener() and createTriggerListener() one method. TOO MUCH COPY PASTA!
private ItemListener createInvertListener() { private ItemListener createInvertListener() {
return new ItemListener() { return new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JCheckBox clicked = (JCheckBox)e.getItem(); JCheckBox clicked = (JCheckBox)e.getItem();
ControllerComponent contComp = ControllerComponent.valueOf(clicked.getName()); GamepadComponent contComp = GamepadComponent.valueOf(clicked.getName());
config.get(contComp).invert = (e.getStateChange() == ItemEvent.SELECTED); config.get(contComp).invert = (e.getStateChange() == ItemEvent.SELECTED);
configChanged = true; configChanged = true;
} }
@@ -148,7 +144,7 @@ public class GamepadConfigFrame extends JFrame {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JCheckBox clicked = (JCheckBox)e.getItem(); JCheckBox clicked = (JCheckBox)e.getItem();
ControllerComponent contComp = ControllerComponent.valueOf(clicked.getName()); GamepadComponent contComp = GamepadComponent.valueOf(clicked.getName());
config.get(contComp).trigger = (e.getStateChange() == ItemEvent.SELECTED); config.get(contComp).trigger = (e.getStateChange() == ItemEvent.SELECTED);
configChanged = true; configChanged = true;
} }
@@ -165,7 +161,7 @@ public class GamepadConfigFrame extends JFrame {
} }
if (configChanged) { if (configChanged) {
updateConfigs(); updateConfigs();
ControllerListener.startUp(); GamepadListener.startUp();
} }
if (shouldStartHandler) { if (shouldStartHandler) {
GamepadHandler.startUp(); GamepadHandler.startUp();
@@ -175,7 +171,7 @@ public class GamepadConfigFrame extends JFrame {
}; };
} }
private ActionListener createListener() { private ActionListener createMapListener() {
return new ActionListener() { return new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@@ -202,7 +198,7 @@ public class GamepadConfigFrame extends JFrame {
buttonPressed.setSelected(true); buttonPressed.setSelected(true);
ControllerListener.stopListening(); GamepadListener.stopListening();
if (GamepadHandler.isRunning()) { if (GamepadHandler.isRunning()) {
GamepadHandler.stopHandler(); GamepadHandler.stopHandler();

View File

@@ -28,7 +28,7 @@ import org.xmlpull.v1.XmlPullParserException;
import com.limelight.Limelight; import com.limelight.Limelight;
import com.limelight.binding.PlatformBinding; import com.limelight.binding.PlatformBinding;
import com.limelight.input.ControllerListener; import com.limelight.input.gamepad.GamepadListener;
import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.NvConnection;
import com.limelight.nvstream.http.NvHTTP; import com.limelight.nvstream.http.NvHTTP;
import com.limelight.settings.PreferencesManager; import com.limelight.settings.PreferencesManager;
@@ -51,7 +51,7 @@ public class MainFrame {
@Override @Override
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
super.windowClosing(e); super.windowClosing(e);
ControllerListener.stopListening(); GamepadListener.stopListening();
} }
}); });
Container mainPane = limeFrame.getContentPane(); Container mainPane = limeFrame.getContentPane();

View File

@@ -1,6 +1,6 @@
package com.limelight.input; package com.limelight.input.gamepad;
import com.limelight.input.GamepadMapping.Mapping; import com.limelight.input.gamepad.GamepadMapping.Mapping;
import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.NvConnection;
import com.limelight.nvstream.input.ControllerPacket; import com.limelight.nvstream.input.ControllerPacket;
@@ -134,7 +134,7 @@ public class Gamepad {
} }
} }
private void handleAnalog(ControllerComponent contComp, float value) { private void handleAnalog(GamepadComponent contComp, float value) {
switch (contComp) { switch (contComp) {
case LS_X: case LS_X:
leftStickX = (short)Math.round(value * 0x7FFF); leftStickX = (short)Math.round(value * 0x7FFF);
@@ -160,7 +160,7 @@ public class Gamepad {
} }
} }
private void handleButtons(ControllerComponent contComp, float value) { private void handleButtons(GamepadComponent contComp, float value) {
boolean press = false; boolean press = false;
if (value > 0.5F) { if (value > 0.5F) {

View File

@@ -1,10 +1,10 @@
package com.limelight.input; package com.limelight.input.gamepad;
import java.io.Serializable; import java.io.Serializable;
import javax.swing.JLabel; import javax.swing.JLabel;
public enum ControllerComponent implements Serializable { public enum GamepadComponent implements Serializable {
BTN_A("Button 1 (A)", false), BTN_X("Button 2 (X)", false), BTN_Y("Button 3 (Y)", false), BTN_B("Button 4 (B)", false), BTN_A("Button 1 (A)", false), BTN_X("Button 2 (X)", false), BTN_Y("Button 3 (Y)", false), BTN_B("Button 4 (B)", false),
DPAD_UP("D-pad Up", false), DPAD_DOWN("D-pad Down", false), DPAD_LEFT("D-pad Left", false), DPAD_RIGHT("D-pad Right", false), DPAD_UP("D-pad Up", false), DPAD_DOWN("D-pad Down", false), DPAD_LEFT("D-pad Left", false), DPAD_RIGHT("D-pad Right", false),
LS_X("Left Stick X", true), LS_Y("Left Stick Y", true), RS_X("Right Stick X", true), RS_Y("Right Stick Y", true), LS_X("Left Stick X", true), LS_Y("Left Stick Y", true), RS_X("Right Stick X", true), RS_Y("Right Stick Y", true),
@@ -15,7 +15,7 @@ public enum ControllerComponent implements Serializable {
private JLabel label; private JLabel label;
private boolean analog; private boolean analog;
private ControllerComponent(String name, boolean analog) { private GamepadComponent(String name, boolean analog) {
this.label = new JLabel(name); this.label = new JLabel(name);
this.analog = analog; this.analog = analog;
} }
@@ -27,9 +27,4 @@ public enum ControllerComponent implements Serializable {
public boolean isAnalog() { public boolean isAnalog() {
return analog; return analog;
} }
@Deprecated
public boolean sameAs(ControllerComponent other) {
return this.name().equals(other.name());
}
} }

View File

@@ -1,4 +1,4 @@
package com.limelight.input; package com.limelight.input.gamepad;
import java.util.Collections; import java.util.Collections;

View File

@@ -1,4 +1,4 @@
package com.limelight.input; package com.limelight.input.gamepad;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.LinkedList; import java.util.LinkedList;
@@ -8,7 +8,7 @@ import com.limelight.nvstream.NvConnection;
import net.java.games.input.Controller; import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment; import net.java.games.input.ControllerEnvironment;
public class ControllerListener { public class GamepadListener {
private static Thread listenerThread; private static Thread listenerThread;
private static NvConnection conn; private static NvConnection conn;

View File

@@ -1,9 +1,10 @@
package com.limelight.input; package com.limelight.input.gamepad;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.java.games.input.Component; import net.java.games.input.Component;
public class GamepadMapping implements Serializable { public class GamepadMapping implements Serializable {
@@ -32,10 +33,10 @@ public class GamepadMapping implements Serializable {
* @param contComp the component to get a mapping for * @param contComp the component to get a mapping for
* @return a mapping or an null if there is none * @return a mapping or an null if there is none
*/ */
public Mapping get(ControllerComponent contComp) { public Mapping get(GamepadComponent contComp) {
//#allTheJank //#allTheJank
for (Entry<String, Mapping> entry : mapping.entrySet()) { for (Entry<String, Mapping> entry : mapping.entrySet()) {
if (entry.getValue().contComp.sameAs(contComp)) { if (entry.getValue().contComp == contComp) {
return entry.getValue(); return entry.getValue();
} }
} }
@@ -47,9 +48,9 @@ public class GamepadMapping implements Serializable {
* @param contComp the component to get a mapping for * @param contComp the component to get a mapping for
* @return a mapping or an empty string if there is none * @return a mapping or an empty string if there is none
*/ */
public String getMapping(ControllerComponent contComp) { public String getMapping(GamepadComponent contComp) {
for (Entry<String, Mapping> entry : mapping.entrySet()) { for (Entry<String, Mapping> entry : mapping.entrySet()) {
if (entry.getValue().contComp.sameAs(contComp)) { if (entry.getValue().contComp == contComp) {
return entry.getKey(); return entry.getKey();
} }
} }
@@ -59,11 +60,11 @@ public class GamepadMapping implements Serializable {
public class Mapping implements Serializable { public class Mapping implements Serializable {
private static final long serialVersionUID = -8407172977953214242L; private static final long serialVersionUID = -8407172977953214242L;
public ControllerComponent contComp; public GamepadComponent contComp;
public boolean invert; public boolean invert;
public boolean trigger; public boolean trigger;
public Mapping(ControllerComponent contComp, boolean invert, boolean trigger) { public Mapping(GamepadComponent contComp, boolean invert, boolean trigger) {
this.contComp = contComp; this.contComp = contComp;
this.invert = invert; this.invert = invert;
this.trigger = trigger; this.trigger = trigger;

View File

@@ -2,7 +2,7 @@ package com.limelight.settings;
import java.io.File; import java.io.File;
import com.limelight.input.GamepadMapping; import com.limelight.input.gamepad.GamepadMapping;
public abstract class GamepadSettingsManager { public abstract class GamepadSettingsManager {
private static GamepadMapping cachedSettings; private static GamepadMapping cachedSettings;