added a menu item for preferences and created a framework for preferences

still requires some implementation before fully functional.
This commit is contained in:
Diego Waxemberg
2013-12-20 16:55:30 -05:00
parent 1f536d555a
commit 86d5eca367
5 changed files with 231 additions and 64 deletions

View File

@@ -1,16 +1,10 @@
package com.limelight.settings;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import com.limelight.input.GamepadMapping;
public class GamepadSettingsManager {
public abstract class GamepadSettingsManager {
private static GamepadMapping cachedSettings;
@@ -18,35 +12,8 @@ public class GamepadSettingsManager {
if (cachedSettings == null) {
System.out.println("Reading Gamepad Settings");
File gamepadFile = SettingsManager.getInstance().getGamepadFile();
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(gamepadFile));
GamepadMapping savedSettings = (GamepadMapping)ois.readObject();
cachedSettings = savedSettings;
} catch (ClassNotFoundException e) {
System.out.println("Saved file is not of the correct type. It might have been modified externally.");
} catch (FileNotFoundException e) {
System.out.println("Could not find gamepad settings file");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Could not read gamepad settings file");
e.printStackTrace();
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
System.out.println("Could not close gamepad settings file");
e.printStackTrace();
}
}
}
GamepadMapping savedMapping = (GamepadMapping)SettingsManager.readSettings(gamepadFile);
cachedSettings = savedMapping;
}
if (cachedSettings == null) {
System.out.println("Unable to get gamepad settings. Using an empty mapping instead.");
@@ -61,31 +28,8 @@ public class GamepadSettingsManager {
System.out.println("Writing Gamepad Settings");
File gamepadFile = SettingsManager.getInstance().getGamepadFile();
ObjectOutputStream ous = null;
try {
ous = new ObjectOutputStream(new FileOutputStream(gamepadFile));
ous.writeObject(settings);
} catch (FileNotFoundException e) {
System.out.println("Could not find gamepad settings file");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Could not write gamepad settings file");
e.printStackTrace();
} finally {
if (ous != null) {
try {
ous.close();
} catch (IOException e) {
System.out.println("Unable to close gamepad settings file");
e.printStackTrace();
}
}
}
SettingsManager.writeSettings(gamepadFile, settings);
}
}