added javadoc to settings classes

This commit is contained in:
Diego Waxemberg
2013-12-29 13:16:02 -05:00
parent 2b7629398b
commit fdc2288d1e
3 changed files with 101 additions and 3 deletions

View File

@@ -4,10 +4,17 @@ import java.io.File;
import com.limelight.input.gamepad.GamepadMapping;
/**
* Manages the gamepad settings
* @author Diego Waxemberg
*/
public abstract class GamepadSettingsManager {
private static GamepadMapping cachedSettings;
/**
* Reads the gamepad settings from the gamepad file and caches the configuration
* @return the gamepad settings
*/
public static GamepadMapping getSettings() {
if (cachedSettings == null) {
System.out.println("Reading Gamepad Settings");
@@ -23,6 +30,10 @@ public abstract class GamepadSettingsManager {
return cachedSettings;
}
/**
* Writes the specified mapping to the gamepad file and updates the cached settings
* @param settings the new gamepad mapping to be written out
*/
public static void writeSettings(GamepadMapping settings) {
cachedSettings = settings;
System.out.println("Writing Gamepad Settings");

View File

@@ -3,9 +3,17 @@ package com.limelight.settings;
import java.io.File;
import java.io.Serializable;
/**
* Manages user preferences
* @author Diego Waxemberg
*/
public abstract class PreferencesManager {
private static Preferences cachedPreferences = null;
/**
* Writes the specified preferences to the preferences file and updates the cached preferences.
* @param prefs the preferences to be written out
*/
public static void writePreferences(Preferences prefs) {
System.out.println("Writing Preferences");
File prefFile = SettingsManager.getInstance().getSettingsFile();
@@ -14,6 +22,10 @@ public abstract class PreferencesManager {
cachedPreferences = prefs;
}
/**
* Reads the user preferences from the preferences file and caches them
* @return the user preferences
*/
public static Preferences getPreferences() {
if (cachedPreferences == null) {
System.out.println("Reading Preferences");
@@ -29,17 +41,31 @@ public abstract class PreferencesManager {
return cachedPreferences;
}
/**
* Represents a user's preferences
* @author Diego Waxemberg
*/
public static class Preferences implements Serializable {
private static final long serialVersionUID = -5575445156215348048L;
/**
* The possible resolutions for the stream
*/
public enum Resolution { RES_720_30("1280x720 (30Hz)"), RES_720_60("1280x720 (60Hz)"),
RES_1080_30("1920x1080 (30Hz)"), RES_1080_60("1920x1080 (60Hz)");
public String name;
/*
* Creates a new resolution with the specified name
*/
private Resolution(String name) {
this.name = name;
}
/**
* Gets the specified name for this resolution
* @return the specified name of this resolution
*/
@Override
public String toString() {
return name;
@@ -51,38 +77,67 @@ public abstract class PreferencesManager {
private String host;
/**
* construcs default preferences: 720p 30Hz fullscreen
* constructs default preferences: 720p 30Hz fullscreen
*/
public Preferences() {
this(Resolution.RES_720_30, true);
}
/**
* Constructs a preference with the specified values
* @param res the <code>Resolution</code> to use
* @param fullscreen whether to start the stream in fullscreen
*/
public Preferences(Resolution res, boolean fullscreen) {
this.res = res;
this.fullscreen = fullscreen;
this.host = "GeForce PC host";
}
/**
* The saved host in this preference
* @return the last used host
*/
public String getHost() {
return host;
}
/**
* Sets the host for this preference
* @param host the host to save
*/
public void setHost(String host) {
this.host = host;
}
/**
* Gets the resolution in this preference
* @return the stored resolution
*/
public Resolution getResolution() {
return res;
}
/**
* Gets whether to use fullscreen
* @return the stored fullscreen mode
*/
public boolean getFullscreen() {
return fullscreen;
}
/**
* Sets the resolution in this preference
* @param res the resolution to save
*/
public void setResolution(Resolution res) {
this.res = res;
}
/**
* Sets the fullscreen mode of this preference
* @param fullscreen whether to use fullscreen
*/
public void setFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
}

View File

@@ -9,8 +9,14 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Manages the settings files
* @author Diego Waxemberg
*/
public class SettingsManager {
/**
* Directory to which settings will be saved
*/
public static String SETTINGS_DIR = System.getProperty("user.home") + File.separator + "Limelight";
//directory to hold limelight settings
@@ -21,12 +27,19 @@ public class SettingsManager {
private static SettingsManager manager;
/*
* Constructs a manager that initializes the settings files
*/
private SettingsManager() {
settingsFile = new File(SETTINGS_DIR + File.separator + "settings.lime");
gamepadFile = new File(SETTINGS_DIR + File.separator + "gamepad.lime");
settingsDir = new File(SETTINGS_DIR);
}
/**
* Gets an instance of the manager, this is a singleton
* @return the instance of the manager
*/
public static SettingsManager getInstance() {
if (manager == null) {
manager = new SettingsManager();
@@ -34,6 +47,10 @@ public class SettingsManager {
return manager;
}
/**
* Gets the gamepad preference file, if the file does not exist, it is created first
* @return the gamepad preference file
*/
public File getGamepadFile() {
if (!settingsDir.exists()) {
settingsFile.mkdirs();
@@ -51,6 +68,10 @@ public class SettingsManager {
return gamepadFile;
}
/**
* Gets the settings file (user preferences), if the file does not exist, it is created first
* @return the settings file
*/
public File getSettingsFile() {
if (!settingsDir.exists()) {
settingsFile.mkdirs();
@@ -68,6 +89,12 @@ public class SettingsManager {
return settingsFile;
}
/**
* Reads the specified file as a settings file and returns the result.
* <br>A settings file must be a java serialized object
* @param file the file to read in
* @return the settings represented in this file
*/
public static Object readSettings(File file) {
ObjectInputStream ois = null;
Object settings = null;
@@ -100,6 +127,11 @@ public class SettingsManager {
return settings;
}
/**
* Writes the specified settings to the desired file
* @param file the file to write the settings to
* @param settings the settings to be written out
*/
public static void writeSettings(File file, Serializable settings) {
ObjectOutputStream ous = null;