From 2c3ed99a3a79a98f6ef583b20bbf9d8ad7a56ded Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Fri, 27 Dec 2013 10:08:31 -0500 Subject: [PATCH] Removed deprecated method and renamed some classes. Created a new package to separate gamepad classes from keyboard/mouse classes --- src/com/limelight/Limelight.java | 8 ++--- src/com/limelight/gui/GamepadConfigFrame.java | 36 +++++++++---------- src/com/limelight/gui/MainFrame.java | 4 +-- .../input/{ => gamepad}/Gamepad.java | 8 ++--- .../GamepadComponent.java} | 11 ++---- .../input/{ => gamepad}/GamepadHandler.java | 2 +- .../GamepadListener.java} | 4 +-- .../input/{ => gamepad}/GamepadMapping.java | 15 ++++---- .../settings/GamepadSettingsManager.java | 2 +- 9 files changed, 41 insertions(+), 49 deletions(-) rename src/com/limelight/input/{ => gamepad}/Gamepad.java (95%) rename src/com/limelight/input/{ControllerComponent.java => gamepad/GamepadComponent.java} (78%) rename src/com/limelight/input/{ => gamepad}/GamepadHandler.java (98%) rename src/com/limelight/input/{ControllerListener.java => gamepad/GamepadListener.java} (97%) rename src/com/limelight/input/{ => gamepad}/GamepadMapping.java (81%) diff --git a/src/com/limelight/Limelight.java b/src/com/limelight/Limelight.java index 611e678..b3b70fe 100644 --- a/src/com/limelight/Limelight.java +++ b/src/com/limelight/Limelight.java @@ -12,7 +12,7 @@ import javax.swing.UIManager; import com.limelight.binding.PlatformBinding; import com.limelight.gui.MainFrame; 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.NvConnectionListener; import com.limelight.nvstream.StreamConfiguration; @@ -94,7 +94,7 @@ public class Limelight implements NvConnectionListener { PlatformBinding.getAudioRenderer(), PlatformBinding.getVideoDecoderRenderer()); - ControllerListener.startSendingInput(conn); + GamepadListener.startSendingInput(conn); } @@ -115,7 +115,7 @@ public class Limelight implements NvConnectionListener { } private static void startControllerListener() { - ControllerListener.startUp(); + GamepadListener.startUp(); } private static void createFrame() { @@ -178,7 +178,7 @@ public class Limelight implements NvConnectionListener { @Override public void connectionStarted() { streamFrame.hideSpinner(); - ControllerListener.startSendingInput(conn); + GamepadListener.startSendingInput(conn); } @Override diff --git a/src/com/limelight/gui/GamepadConfigFrame.java b/src/com/limelight/gui/GamepadConfigFrame.java index c9f80f5..e25ac65 100644 --- a/src/com/limelight/gui/GamepadConfigFrame.java +++ b/src/com/limelight/gui/GamepadConfigFrame.java @@ -22,19 +22,18 @@ import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.border.Border; import javax.swing.border.LineBorder; import net.java.games.input.Component; import net.java.games.input.Event; import net.java.games.input.EventQueue; -import com.limelight.input.ControllerComponent; -import com.limelight.input.ControllerListener; -import com.limelight.input.Gamepad; -import com.limelight.input.GamepadHandler; -import com.limelight.input.GamepadMapping; -import com.limelight.input.GamepadMapping.Mapping; +import com.limelight.input.gamepad.GamepadComponent; +import com.limelight.input.gamepad.GamepadListener; +import com.limelight.input.gamepad.Gamepad; +import com.limelight.input.gamepad.GamepadHandler; +import com.limelight.input.gamepad.GamepadMapping; +import com.limelight.input.gamepad.GamepadMapping.Mapping; import com.limelight.settings.GamepadSettingsManager; public class GamepadConfigFrame extends JFrame { @@ -60,12 +59,12 @@ public class GamepadConfigFrame extends JFrame { public void build() { componentMap = new HashMap(); - GridLayout layout = new GridLayout(ControllerComponent.values().length/2 + 1, 2); + GridLayout layout = new GridLayout(GamepadComponent.values().length/2 + 1, 2); layout.setHgap(60); layout.setVgap(3); JPanel mainPanel = new JPanel(layout); - ControllerComponent[] components = ControllerComponent.values(); + GamepadComponent[] components = GamepadComponent.values(); for (int i = 0; i < components.length; i++) { @@ -102,7 +101,7 @@ public class GamepadConfigFrame extends JFrame { mapButton.setMaximumSize(buttonSize); mapButton.setMinimumSize(buttonSize); mapButton.setPreferredSize(buttonSize); - mapButton.addActionListener(createListener()); + mapButton.addActionListener(createMapListener()); mapButton.setText(config.getMapping(mapping.contComp)); invertBox.setSelected(mapping.invert); @@ -110,7 +109,7 @@ public class GamepadConfigFrame extends JFrame { triggerBox.setSelected(mapping.trigger); 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(mapping.contComp.getLabel()); @@ -120,23 +119,20 @@ public class GamepadConfigFrame extends JFrame { componentBox.add(triggerBox); componentBox.add(Box.createHorizontalStrut(5)); - componentBox.setBorder(createBorder()); + componentBox.setBorder(new LineBorder(Color.GRAY, 1, true)); componentMap.put(componentBox, mapping); return componentBox; } - private Border createBorder() { - return new LineBorder(Color.GRAY, 1, true); - } //TODO: make createInvertListener() and createTriggerListener() one method. TOO MUCH COPY PASTA! private ItemListener createInvertListener() { return new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { 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); configChanged = true; } @@ -148,7 +144,7 @@ public class GamepadConfigFrame extends JFrame { @Override public void itemStateChanged(ItemEvent e) { 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); configChanged = true; } @@ -165,7 +161,7 @@ public class GamepadConfigFrame extends JFrame { } if (configChanged) { updateConfigs(); - ControllerListener.startUp(); + GamepadListener.startUp(); } if (shouldStartHandler) { GamepadHandler.startUp(); @@ -175,7 +171,7 @@ public class GamepadConfigFrame extends JFrame { }; } - private ActionListener createListener() { + private ActionListener createMapListener() { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -202,7 +198,7 @@ public class GamepadConfigFrame extends JFrame { buttonPressed.setSelected(true); - ControllerListener.stopListening(); + GamepadListener.stopListening(); if (GamepadHandler.isRunning()) { GamepadHandler.stopHandler(); diff --git a/src/com/limelight/gui/MainFrame.java b/src/com/limelight/gui/MainFrame.java index f0941f5..9af4c31 100644 --- a/src/com/limelight/gui/MainFrame.java +++ b/src/com/limelight/gui/MainFrame.java @@ -28,7 +28,7 @@ import org.xmlpull.v1.XmlPullParserException; import com.limelight.Limelight; 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.http.NvHTTP; import com.limelight.settings.PreferencesManager; @@ -51,7 +51,7 @@ public class MainFrame { @Override public void windowClosing(WindowEvent e) { super.windowClosing(e); - ControllerListener.stopListening(); + GamepadListener.stopListening(); } }); Container mainPane = limeFrame.getContentPane(); diff --git a/src/com/limelight/input/Gamepad.java b/src/com/limelight/input/gamepad/Gamepad.java similarity index 95% rename from src/com/limelight/input/Gamepad.java rename to src/com/limelight/input/gamepad/Gamepad.java index 42c779a..1f6b754 100644 --- a/src/com/limelight/input/Gamepad.java +++ b/src/com/limelight/input/gamepad/Gamepad.java @@ -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.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) { case LS_X: 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; if (value > 0.5F) { diff --git a/src/com/limelight/input/ControllerComponent.java b/src/com/limelight/input/gamepad/GamepadComponent.java similarity index 78% rename from src/com/limelight/input/ControllerComponent.java rename to src/com/limelight/input/gamepad/GamepadComponent.java index 183ca33..1775b28 100644 --- a/src/com/limelight/input/ControllerComponent.java +++ b/src/com/limelight/input/gamepad/GamepadComponent.java @@ -1,10 +1,10 @@ -package com.limelight.input; +package com.limelight.input.gamepad; import java.io.Serializable; 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), 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), @@ -15,7 +15,7 @@ public enum ControllerComponent implements Serializable { private JLabel label; private boolean analog; - private ControllerComponent(String name, boolean analog) { + private GamepadComponent(String name, boolean analog) { this.label = new JLabel(name); this.analog = analog; } @@ -27,9 +27,4 @@ public enum ControllerComponent implements Serializable { public boolean isAnalog() { return analog; } - - @Deprecated - public boolean sameAs(ControllerComponent other) { - return this.name().equals(other.name()); - } } diff --git a/src/com/limelight/input/GamepadHandler.java b/src/com/limelight/input/gamepad/GamepadHandler.java similarity index 98% rename from src/com/limelight/input/GamepadHandler.java rename to src/com/limelight/input/gamepad/GamepadHandler.java index 69d3ed3..9d8645d 100644 --- a/src/com/limelight/input/GamepadHandler.java +++ b/src/com/limelight/input/gamepad/GamepadHandler.java @@ -1,4 +1,4 @@ -package com.limelight.input; +package com.limelight.input.gamepad; import java.util.Collections; diff --git a/src/com/limelight/input/ControllerListener.java b/src/com/limelight/input/gamepad/GamepadListener.java similarity index 97% rename from src/com/limelight/input/ControllerListener.java rename to src/com/limelight/input/gamepad/GamepadListener.java index 0f5a6c1..29d5d92 100644 --- a/src/com/limelight/input/ControllerListener.java +++ b/src/com/limelight/input/gamepad/GamepadListener.java @@ -1,4 +1,4 @@ -package com.limelight.input; +package com.limelight.input.gamepad; import java.lang.reflect.Constructor; import java.util.LinkedList; @@ -8,7 +8,7 @@ import com.limelight.nvstream.NvConnection; import net.java.games.input.Controller; import net.java.games.input.ControllerEnvironment; -public class ControllerListener { +public class GamepadListener { private static Thread listenerThread; private static NvConnection conn; diff --git a/src/com/limelight/input/GamepadMapping.java b/src/com/limelight/input/gamepad/GamepadMapping.java similarity index 81% rename from src/com/limelight/input/GamepadMapping.java rename to src/com/limelight/input/gamepad/GamepadMapping.java index 8ff6fb2..9871431 100644 --- a/src/com/limelight/input/GamepadMapping.java +++ b/src/com/limelight/input/gamepad/GamepadMapping.java @@ -1,9 +1,10 @@ -package com.limelight.input; +package com.limelight.input.gamepad; import java.io.Serializable; import java.util.HashMap; import java.util.Map.Entry; + import net.java.games.input.Component; public class GamepadMapping implements Serializable { @@ -32,10 +33,10 @@ public class GamepadMapping implements Serializable { * @param contComp the component to get a mapping for * @return a mapping or an null if there is none */ - public Mapping get(ControllerComponent contComp) { + public Mapping get(GamepadComponent contComp) { //#allTheJank for (Entry entry : mapping.entrySet()) { - if (entry.getValue().contComp.sameAs(contComp)) { + if (entry.getValue().contComp == contComp) { return entry.getValue(); } } @@ -47,9 +48,9 @@ public class GamepadMapping implements Serializable { * @param contComp the component to get a mapping for * @return a mapping or an empty string if there is none */ - public String getMapping(ControllerComponent contComp) { + public String getMapping(GamepadComponent contComp) { for (Entry entry : mapping.entrySet()) { - if (entry.getValue().contComp.sameAs(contComp)) { + if (entry.getValue().contComp == contComp) { return entry.getKey(); } } @@ -59,11 +60,11 @@ public class GamepadMapping implements Serializable { public class Mapping implements Serializable { private static final long serialVersionUID = -8407172977953214242L; - public ControllerComponent contComp; + public GamepadComponent contComp; public boolean invert; public boolean trigger; - public Mapping(ControllerComponent contComp, boolean invert, boolean trigger) { + public Mapping(GamepadComponent contComp, boolean invert, boolean trigger) { this.contComp = contComp; this.invert = invert; this.trigger = trigger; diff --git a/src/com/limelight/settings/GamepadSettingsManager.java b/src/com/limelight/settings/GamepadSettingsManager.java index 5fad7cd..8341515 100644 --- a/src/com/limelight/settings/GamepadSettingsManager.java +++ b/src/com/limelight/settings/GamepadSettingsManager.java @@ -2,7 +2,7 @@ package com.limelight.settings; import java.io.File; -import com.limelight.input.GamepadMapping; +import com.limelight.input.gamepad.GamepadMapping; public abstract class GamepadSettingsManager { private static GamepadMapping cachedSettings;