diff --git a/src/com/limelight/input/KeyboardHandler.java b/src/com/limelight/input/KeyboardHandler.java index 688f7f6..496a081 100644 --- a/src/com/limelight/input/KeyboardHandler.java +++ b/src/com/limelight/input/KeyboardHandler.java @@ -7,16 +7,30 @@ import com.limelight.gui.StreamFrame; import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.input.KeyboardPacket; +/** + * Class that handles keyboard input + * @author Diego Waxemberg + */ public class KeyboardHandler implements KeyListener { private static KeyboardTranslator translator; private StreamFrame parent; + /** + * Constructs a new keyboard listener that will send key events to the specified connection + * and belongs to the specified frame + * @param conn the connection to send key events to + * @param parent the frame that owns this handler + */ public KeyboardHandler(NvConnection conn, StreamFrame parent) { translator = new KeyboardTranslator(conn); this.parent = parent; } + /** + * Invoked when a key is pressed and will send that key-down event to the host + * @param event the key-down event + */ @Override public void keyPressed(KeyEvent event) { short keyMap = translator.translate(event.getKeyCode()); @@ -53,6 +67,10 @@ public class KeyboardHandler implements KeyListener { translator.sendKeyDown(keyMap, modifier); } + /** + * Invoked when a key is released and will send that key-up event to the host + * @param event the key-up event + */ @Override public void keyReleased(KeyEvent event) { int modifiers = event.getModifiersEx(); @@ -80,6 +98,10 @@ public class KeyboardHandler implements KeyListener { translator.sendKeyUp(keyMap, modifier); } + /** + * Unimplemented + * @param event unused + */ @Override public void keyTyped(KeyEvent event) { } diff --git a/src/com/limelight/input/KeyboardTranslator.java b/src/com/limelight/input/KeyboardTranslator.java index 8b63a29..36f7853 100644 --- a/src/com/limelight/input/KeyboardTranslator.java +++ b/src/com/limelight/input/KeyboardTranslator.java @@ -5,14 +5,30 @@ import java.awt.event.KeyEvent; import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.input.KeycodeTranslator; +/** + * Class to translate a java key code into the codes GFE is expecting + * @author Diego Waxemberg + */ public class KeyboardTranslator extends KeycodeTranslator { - + + /** + * GFE's prefix for every key code + */ public static final short KEY_PREFIX = (short) 0x80; + /** + * Constructs a new translator for the specified connection + * @param conn the connection to which the translated codes are sent + */ public KeyboardTranslator(NvConnection conn) { super(conn); } + /** + * Translates the given keycode and returns the GFE keycode + * @param keycode the code to be translated + * @returns a GFE keycode for the given keycode + */ @Override public short translate(int keycode) { // change newline to carriage return diff --git a/src/com/limelight/input/MouseHandler.java b/src/com/limelight/input/MouseHandler.java index 4bfa8e5..7beada5 100644 --- a/src/com/limelight/input/MouseHandler.java +++ b/src/com/limelight/input/MouseHandler.java @@ -14,6 +14,10 @@ import com.limelight.gui.StreamFrame; import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.input.MouseButtonPacket; +/** + * Handles mouse input and sends them via the connection to the host + * @author Diego Waxemberg + */ public class MouseHandler implements MouseListener, MouseMotionListener { private NvConnection conn; private Robot robot; @@ -25,6 +29,11 @@ public class MouseHandler implements MouseListener, MouseMotionListener { private final double mouseThresh = 0.45; + /** + * Constructs a new handler for the specified connection and belonging to the specified frame + * @param conn the connection to which mouse events will be sent + * @param parent the frame that owns this handler + */ public MouseHandler(NvConnection conn, StreamFrame parent) { this.conn = conn; this.parent = parent; @@ -36,16 +45,27 @@ public class MouseHandler implements MouseListener, MouseMotionListener { size = new Dimension(); } + /** + * Frees the mouse, that is stops capturing events and allows it to move freely + */ public void free() { captureMouse = false; } + /** + * Starts capturing mouse events and limits its motion + */ public void capture() { moveMouse((int)parent.getLocationOnScreen().getX() + (size.width/2), (int)parent.getLocationOnScreen().getY() + (size.height/2)); captureMouse = true; } + /** + * Only used to hide the cursor when the user clicks back into the frame. + *
The event is not sent to the host + * @param e click event used to know that the cursor should now be hidden + */ @Override public void mouseClicked(MouseEvent e) { if (captureMouse) { @@ -53,10 +73,19 @@ public class MouseHandler implements MouseListener, MouseMotionListener { } } + /** + * Unimplemented + * @param e Unused + */ @Override public void mouseEntered(MouseEvent e) { } + /** + * Invoked when the mouse leaves the frame. + *
If this happens when we are capturing the mouse, the mouse is moved back to the center of the frame. + * @param e the event created by the mouse leaving the frame + */ @Override public void mouseExited(MouseEvent e) { if (captureMouse) { @@ -64,6 +93,11 @@ public class MouseHandler implements MouseListener, MouseMotionListener { } } + /** + * Invoked when a mouse button is pressed. + *
The button pressed is sent to the host if we are capturing the mouse. + * @param e event containing the mouse button that was pressed + */ @Override public void mousePressed(MouseEvent e) { if (captureMouse) { @@ -87,6 +121,11 @@ public class MouseHandler implements MouseListener, MouseMotionListener { } } + /** + * Invoked when a mouse button is released. + *
The button released is sent to the host if we are capturing the mouse. + * @param e event containing the mouse button that was released + */ @Override public void mouseReleased(MouseEvent e) { if (captureMouse) { @@ -110,6 +149,11 @@ public class MouseHandler implements MouseListener, MouseMotionListener { } } + /** + * Invoked when the mouse is dragged, that is moved while a button is held down. + *
This method simply calls the mouseMoved() method because GFE handles movements all the same + * when a button is held down or not. + */ @Override public void mouseDragged(MouseEvent e) { if (captureMouse) { @@ -117,6 +161,13 @@ public class MouseHandler implements MouseListener, MouseMotionListener { } } + /** + * Invoked when the mouse is moved. + *
The change in position is calculated and sent to the host. + *
If the mouse moves outside a certain boundary, the mouse is moved back to the center- this gives the user + * the illusion that they are controlling the mouse they see rather than their own. + * @param e the mouse move event containing the new location of the mouse + */ @Override public void mouseMoved(MouseEvent e) { if (captureMouse) { @@ -131,6 +182,10 @@ public class MouseHandler implements MouseListener, MouseMotionListener { } } + /* + * Checks if the mouse has moved outside the boundaries. + * If so, the mouse is moved back to the center. + */ private void checkBoundaries(MouseEvent e) { parent.getSize(size); @@ -162,6 +217,9 @@ public class MouseHandler implements MouseListener, MouseMotionListener { } } + /* + * Moves the mouse to the specified coordinates on-screen + */ private void moveMouse(int x, int y) { robot.mouseMove(x, y); lastX = x;