Added javadoc to the gui elements

This commit is contained in:
Diego Waxemberg
2013-12-29 12:13:10 -05:00
parent c0632f6999
commit c61e24a8dc
4 changed files with 126 additions and 2 deletions
@@ -36,6 +36,10 @@ import com.limelight.input.gamepad.GamepadMapping;
import com.limelight.input.gamepad.GamepadMapping.Mapping; import com.limelight.input.gamepad.GamepadMapping.Mapping;
import com.limelight.settings.GamepadSettingsManager; import com.limelight.settings.GamepadSettingsManager;
/**
* A frame used to configure the gamepad mappings.
* @author Diego Waxemberg
*/
public class GamepadConfigFrame extends JFrame { public class GamepadConfigFrame extends JFrame {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -46,6 +50,10 @@ public class GamepadConfigFrame extends JFrame {
private GamepadMapping config; private GamepadMapping config;
private HashMap<Box, Mapping> componentMap; private HashMap<Box, Mapping> componentMap;
/**
* Constructs a new config frame. The frame is initially invisible and will <br>
* be made visible after all components are built by calling <code>build()</code>
*/
public GamepadConfigFrame() { public GamepadConfigFrame() {
super("Gamepad Settings"); super("Gamepad Settings");
System.out.println("Creating Settings Frame"); System.out.println("Creating Settings Frame");
@@ -56,6 +64,9 @@ public class GamepadConfigFrame extends JFrame {
} }
/**
* Builds all components of the config frame and sets the frame visible.
*/
public void build() { public void build() {
componentMap = new HashMap<Box, Mapping>(); componentMap = new HashMap<Box, Mapping>();
@@ -90,6 +101,9 @@ public class GamepadConfigFrame extends JFrame {
this.setVisible(true); this.setVisible(true);
} }
/*
* Creates the box that holds the button and checkboxes
*/
private Box createComponentBox(Mapping mapping) { private Box createComponentBox(Mapping mapping) {
Box componentBox = Box.createHorizontalBox(); Box componentBox = Box.createHorizontalBox();
@@ -127,6 +141,9 @@ public class GamepadConfigFrame extends JFrame {
} }
//TODO: make createInvertListener() and createTriggerListener() one method. TOO MUCH COPY PASTA! //TODO: make createInvertListener() and createTriggerListener() one method. TOO MUCH COPY PASTA!
/*
* Creates the listener for the invert checkbox
*/
private ItemListener createInvertListener() { private ItemListener createInvertListener() {
return new ItemListener() { return new ItemListener() {
@Override @Override
@@ -139,6 +156,9 @@ public class GamepadConfigFrame extends JFrame {
}; };
} }
/*
* Creates the listener for the trigger checkbox
*/
private ItemListener createTriggerListener() { private ItemListener createTriggerListener() {
return new ItemListener() { return new ItemListener() {
@Override @Override
@@ -152,6 +172,10 @@ public class GamepadConfigFrame extends JFrame {
} }
/*
* Creates the listener for the window.
* It will save configs on exit and restart controller threads
*/
private WindowListener createWindowListener() { private WindowListener createWindowListener() {
return new WindowAdapter() { return new WindowAdapter() {
@Override @Override
@@ -171,6 +195,9 @@ public class GamepadConfigFrame extends JFrame {
}; };
} }
/*
* Creates the listener for the map button
*/
private ActionListener createMapListener() { private ActionListener createMapListener() {
return new ActionListener() { return new ActionListener() {
@Override @Override
@@ -189,6 +216,9 @@ public class GamepadConfigFrame extends JFrame {
}; };
} }
/*
* Maps a gamepad component to the clicked component
*/
private void map(final Box toMap, final Gamepad pad) { private void map(final Box toMap, final Gamepad pad) {
if (mappingThread == null || !mappingThread.isAlive()) { if (mappingThread == null || !mappingThread.isAlive()) {
@@ -239,6 +269,9 @@ public class GamepadConfigFrame extends JFrame {
} }
/*
* Waits until the user chooses what to map to the clicked component
*/
private Component waitForNewMapping(Gamepad pad) { private Component waitForNewMapping(Gamepad pad) {
Component newMapping = null; Component newMapping = null;
@@ -266,6 +299,9 @@ public class GamepadConfigFrame extends JFrame {
return newMapping; return newMapping;
} }
/*
* Consumes any events left in the queue after the mapping has been made
*/
private void consumeEvents(final Gamepad pad) { private void consumeEvents(final Gamepad pad) {
// start a new thread to go through all of the remaining events // start a new thread to go through all of the remaining events
Thread consumeEvents = new Thread(new Runnable() { Thread consumeEvents = new Thread(new Runnable() {
@@ -287,6 +323,9 @@ public class GamepadConfigFrame extends JFrame {
consumeEvents.start(); consumeEvents.start();
} }
/*
* Helper method to get the box component that contains the given a mapping
*/
private Box getBox(Mapping mapping) { private Box getBox(Mapping mapping) {
for (Entry<Box, Mapping> entry : componentMap.entrySet()) { for (Entry<Box, Mapping> entry : componentMap.entrySet()) {
if (entry.getValue() == mapping) { if (entry.getValue() == mapping) {
@@ -296,6 +335,9 @@ public class GamepadConfigFrame extends JFrame {
return null; return null;
} }
/*
* Helper method to get the button out of the box component
*/
private JButton getButton(Box componentBox) { private JButton getButton(Box componentBox) {
for (java.awt.Component comp : componentBox.getComponents()) { for (java.awt.Component comp : componentBox.getComponents()) {
if (comp instanceof JButton) if (comp instanceof JButton)
@@ -304,6 +346,9 @@ public class GamepadConfigFrame extends JFrame {
return null; return null;
} }
/*
* Writes the current cofig to the configs on disk.
*/
private void updateConfigs() { private void updateConfigs() {
GamepadSettingsManager.writeSettings(config); GamepadSettingsManager.writeSettings(config);
} }
+21
View File
@@ -34,16 +34,28 @@ import com.limelight.nvstream.http.NvHTTP;
import com.limelight.settings.PreferencesManager; import com.limelight.settings.PreferencesManager;
import com.limelight.settings.PreferencesManager.Preferences; import com.limelight.settings.PreferencesManager.Preferences;
/**
* The main frame of Limelight that allows the user to specify the host and begin the stream.
* @author Diego Waxemberg
* <br>Cameron Gutman
*/
public class MainFrame { public class MainFrame {
private JTextField hostField; private JTextField hostField;
private JButton pair; private JButton pair;
private JButton stream; private JButton stream;
private JFrame limeFrame; private JFrame limeFrame;
/**
* Gets the actual JFrame this class creates
* @return the JFrame that is the main frame
*/
public JFrame getLimeFrame() { public JFrame getLimeFrame() {
return limeFrame; return limeFrame;
} }
/**
* Builds all components of the frame, including the frame itself and displays it to the user.
*/
public void build() { public void build() {
limeFrame = new JFrame("Limelight"); limeFrame = new JFrame("Limelight");
limeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); limeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -116,6 +128,9 @@ public class MainFrame {
limeFrame.setVisible(true); limeFrame.setVisible(true);
} }
/*
* Creates the menu bar for the user to go to preferences, mappings, etc.
*/
private JMenuBar createMenuBar() { private JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar(); JMenuBar menuBar = new JMenuBar();
JMenu optionsMenu = new JMenu("Options"); JMenu optionsMenu = new JMenu("Options");
@@ -144,6 +159,9 @@ public class MainFrame {
return menuBar; return menuBar;
} }
/*
* Creates the listener for the stream button- starts the stream process
*/
private ActionListener createStreamButtonListener() { private ActionListener createStreamButtonListener() {
return new ActionListener() { return new ActionListener() {
@Override @Override
@@ -159,6 +177,9 @@ public class MainFrame {
}; };
} }
/*
* Creates the listener for the pair button- requests a pairing with the specified host
*/
private ActionListener createPairButtonListener() { private ActionListener createPairButtonListener() {
return new ActionListener() { return new ActionListener() {
@Override @Override
@@ -16,12 +16,20 @@ import com.limelight.settings.PreferencesManager;
import com.limelight.settings.PreferencesManager.Preferences; import com.limelight.settings.PreferencesManager.Preferences;
import com.limelight.settings.PreferencesManager.Preferences.Resolution; import com.limelight.settings.PreferencesManager.Preferences.Resolution;
/**
* A frame that holds user preferences such as streaming resolution
* @author Diego Waxemberg
*/
public class PreferencesFrame extends JFrame { public class PreferencesFrame extends JFrame {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JComboBox resolution; private JComboBox resolution;
private JCheckBox fullscreen; private JCheckBox fullscreen;
private Preferences prefs; private Preferences prefs;
/**
* Construcs a new frame and loads the saved preferences.
* <br>The frame is not made visible until a call to <br>build()</br> is made.
*/
public PreferencesFrame() { public PreferencesFrame() {
super("Preferences"); super("Preferences");
this.setSize(200, 100); this.setSize(200, 100);
@@ -30,6 +38,9 @@ public class PreferencesFrame extends JFrame {
prefs = PreferencesManager.getPreferences(); prefs = PreferencesManager.getPreferences();
} }
/**
* Constructs all components of the frame and makes the frame visible to the user.
*/
public void build() { public void build() {
JPanel mainPanel = new JPanel(); JPanel mainPanel = new JPanel();
@@ -80,11 +91,17 @@ public class PreferencesFrame extends JFrame {
this.setVisible(true); this.setVisible(true);
} }
/*
* Checks if the preferences have changed from the cached preferences.
*/
private boolean prefsChanged() { private boolean prefsChanged() {
return (prefs.getResolution() != resolution.getSelectedItem()) || return (prefs.getResolution() != resolution.getSelectedItem()) ||
(prefs.getFullscreen() != fullscreen.isSelected()); (prefs.getFullscreen() != fullscreen.isSelected());
} }
/*
* Writes the preferences to the disk.
*/
private void writePreferences() { private void writePreferences() {
prefs.setFullscreen(fullscreen.isSelected()); prefs.setFullscreen(fullscreen.isSelected());
prefs.setResolution((Resolution)resolution.getSelectedItem()); prefs.setResolution((Resolution)resolution.getSelectedItem());
+43 -2
View File
@@ -28,6 +28,12 @@ import com.limelight.nvstream.NvConnection;
import com.limelight.nvstream.NvConnectionListener.Stage; import com.limelight.nvstream.NvConnectionListener.Stage;
import com.limelight.nvstream.StreamConfiguration; import com.limelight.nvstream.StreamConfiguration;
/**
* The frame to which the video is rendered
* @author Diego Waxemberg
* <br>Cameron Gutman
*
*/
public class StreamFrame extends JFrame { public class StreamFrame extends JFrame {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -37,17 +43,29 @@ public class StreamFrame extends JFrame {
private JLabel spinnerLabel; private JLabel spinnerLabel;
private Cursor noCursor; private Cursor noCursor;
private NvConnection conn; private NvConnection conn;
/**
* Frees the mouse ie. makes it visible and allowed to move outside the frame.
*/
public void freeMouse() { public void freeMouse() {
mouse.free(); mouse.free();
showCursor(); showCursor();
} }
/**
* Captures the mouse ie. makes it invisible and not allowed to leave the frame
*/
public void captureMouse() { public void captureMouse() {
mouse.capture(); mouse.capture();
hideCursor(); hideCursor();
} }
/**
* Builds the components of this frame with the specified configurations.
* @param conn the connection this frame belongs to
* @param streamConfig the configurations for this frame
* @param fullscreen if the frame should be made fullscreen
*/
public void build(NvConnection conn, StreamConfiguration streamConfig, boolean fullscreen) { public void build(NvConnection conn, StreamConfiguration streamConfig, boolean fullscreen) {
this.conn = conn; this.conn = conn;
@@ -74,6 +92,9 @@ public class StreamFrame extends JFrame {
this.setVisible(true); this.setVisible(true);
} }
/*
* Gets the best display mode for the system and desired configuration
*/
private DisplayMode getBestDisplay(DisplayMode[] configs) { private DisplayMode getBestDisplay(DisplayMode[] configs) {
Arrays.sort(configs, new Comparator<DisplayMode>() { Arrays.sort(configs, new Comparator<DisplayMode>() {
@Override @Override
@@ -99,6 +120,9 @@ public class StreamFrame extends JFrame {
return bestConfig; return bestConfig;
} }
/*
* Tries to make the frame fullscreen
*/
private void makeFullScreen() { private void makeFullScreen() {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (gd.isFullScreenSupported()) { if (gd.isFullScreenSupported()) {
@@ -125,7 +149,10 @@ public class StreamFrame extends JFrame {
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
} }
} }
/**
* Makes the mouse cursor invisible
*/
public void hideCursor() { public void hideCursor() {
if (noCursor == null) { if (noCursor == null) {
// Transparent 16 x 16 pixel cursor image. // Transparent 16 x 16 pixel cursor image.
@@ -140,11 +167,19 @@ public class StreamFrame extends JFrame {
this.getContentPane().setCursor(noCursor); this.getContentPane().setCursor(noCursor);
} }
/**
* Makes the mouse cursor visible
*/
public void showCursor() { public void showCursor() {
this.setCursor(Cursor.getDefaultCursor()); this.setCursor(Cursor.getDefaultCursor());
this.getContentPane().setCursor(Cursor.getDefaultCursor()); this.getContentPane().setCursor(Cursor.getDefaultCursor());
} }
/**
* Shows a progress bar with a label underneath that tells the user what
* loading stage the stream is at.
* @param stage the currently loading stage
*/
public void showSpinner(Stage stage) { public void showSpinner(Stage stage) {
if (spinner == null) { if (spinner == null) {
@@ -182,11 +217,17 @@ public class StreamFrame extends JFrame {
spinnerLabel.setText("Starting " + stage.getName() + "..."); spinnerLabel.setText("Starting " + stage.getName() + "...");
} }
/**
* Hides the spinner and the label
*/
public void hideSpinner() { public void hideSpinner() {
spinner.setVisible(false); spinner.setVisible(false);
spinnerLabel.setVisible(false); spinnerLabel.setVisible(false);
} }
/**
* Stops the stream and destroys the frame
*/
public void close() { public void close() {
dispose(); dispose();
conn.stop(); conn.stop();