summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2012-10-15 23:38:17 -0700
committerJesse Morgan <jesse@jesterpm.net>2012-10-15 23:38:17 -0700
commitca0b4614ae545e30b3f65b5414e7e7f535915c86 (patch)
tree3588b583a4689b97ed864a19af040f5a4fc1ae42 /src
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/MyClass.java16
-rw-r--r--src/net/tuschhcm/routercontrol/Preset.java39
-rw-r--r--src/net/tuschhcm/routercontrol/SwitcherApp.java75
-rw-r--r--src/net/tuschhcm/routercontrol/router/Router.java29
-rw-r--r--src/net/tuschhcm/routercontrol/router/ShinyBow5544Router.java37
-rw-r--r--src/net/tuschhcm/routercontrol/ui/ConsoleUI.java35
-rw-r--r--src/net/tuschhcm/routercontrol/ui/UserInterface.java42
7 files changed, 273 insertions, 0 deletions
diff --git a/src/MyClass.java b/src/MyClass.java
new file mode 100644
index 0000000..4fac53f
--- /dev/null
+++ b/src/MyClass.java
@@ -0,0 +1,16 @@
+import java.util.Enumeration;
+
+import gnu.io.CommPortIdentifier;
+
+public class MyClass {
+ public static void main(String... args) {
+ Enumeration ports = CommPortIdentifier.getPortIdentifiers();
+
+ while (ports.hasMoreElements()) {
+ CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
+
+ System.out.println(port.getName());
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/net/tuschhcm/routercontrol/Preset.java b/src/net/tuschhcm/routercontrol/Preset.java
new file mode 100644
index 0000000..e58fcf9
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/Preset.java
@@ -0,0 +1,39 @@
+package net.tuschhcm.routercontrol;
+
+/**
+ * Class to represent a router preset.
+ */
+public class Preset {
+
+ /**
+ * Load a preset from the given file.
+ *
+ * @param filename The file to load.
+ * @return the Preset object
+ */
+ public static Preset loadPresetFile(String filename) {
+ // TODO: Implement
+ return null;
+ }
+
+ /**
+ * Get the name of the preset.
+ *
+ * @return The preset name
+ */
+ public String getName() {
+ // TODO: Implement
+ return null;
+ }
+
+ /**
+ * Get an input for the given output.
+ *
+ * @param output
+ * @return Input number, or 0 if no change.
+ */
+ public int getInputForOutput(final int output) {
+ // TODO: Implement
+ return 0;
+ }
+}
diff --git a/src/net/tuschhcm/routercontrol/SwitcherApp.java b/src/net/tuschhcm/routercontrol/SwitcherApp.java
new file mode 100644
index 0000000..648d0b5
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/SwitcherApp.java
@@ -0,0 +1,75 @@
+package net.tuschhcm.routercontrol;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import net.tuschhcm.routercontrol.router.Router;
+import net.tuschhcm.routercontrol.router.ShinyBow5544Router;
+import net.tuschhcm.routercontrol.ui.ConsoleUI;
+import net.tuschhcm.routercontrol.ui.UserInterface;
+import net.tuschhcm.routercontrol.ui.UserInterface.Action;
+
+public class SwitcherApp {
+ /**
+ * The router I control.
+ */
+ private final Router mRouter;
+
+ /**
+ * My user interface.
+ */
+ private final UserInterface mUI;
+
+ /**
+ * My list of presets.
+ */
+ private final Map<Integer, Preset> mPresets;
+
+ /**
+ * Create a switcher app.
+ * @param portName the port name for the router.
+ */
+ public SwitcherApp(final String portName) {
+ mUI = new ConsoleUI();
+ mRouter = new ShinyBow5544Router(portName);
+ mPresets = new HashMap<Integer, Preset>();
+
+ // TODO: Load the presets
+
+ // TODO: Setup UI hooks
+ mUI.setPresetSelectionAction(new Action() {
+ public void onAction() {
+ handlePresetSelected();
+ }
+ });
+
+ // TODO: Send the presets to the UI
+ }
+
+ /**
+ * Start the application.
+ */
+ public void run() {
+ mUI.run();
+ }
+
+ /**
+ * Handles a preset selection.
+ */
+ private void handlePresetSelected() {
+ int selectedPreset = mUI.getSelectedPreset();
+ // TODO: What to do when the preset is selected
+ }
+
+ /**
+ * Entry-point for the application.
+ * @param args Command line arguments
+ */
+ public static void main(String[] args) {
+ // TODO: Parse command line arguments
+ String comPort = "COM1";
+
+ SwitcherApp app = new SwitcherApp(comPort);
+ app.run();
+ }
+}
diff --git a/src/net/tuschhcm/routercontrol/router/Router.java b/src/net/tuschhcm/routercontrol/router/Router.java
new file mode 100644
index 0000000..d6fe2dd
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/router/Router.java
@@ -0,0 +1,29 @@
+package net.tuschhcm.routercontrol.router;
+
+/**
+ * Interface specification for a router
+ */
+public interface Router {
+ /**
+ * Send the given input to the given output.
+ *
+ * @param output
+ * @param input
+ *
+ * @throws IllegalArgumentException if input or output are out of range.
+ */
+ public void switchInput(int output, int input) throws IllegalArgumentException;
+
+ /**
+ * Power on or power off the router
+ *
+ * @param True to turn on the router
+ */
+ public void setPower(boolean on);
+
+ /**
+ * Enable or disable physical controls
+ * @param enabled true to disable the controls.
+ */
+ public void setLockControls(boolean enabled);
+}
diff --git a/src/net/tuschhcm/routercontrol/router/ShinyBow5544Router.java b/src/net/tuschhcm/routercontrol/router/ShinyBow5544Router.java
new file mode 100644
index 0000000..ee60bfc
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/router/ShinyBow5544Router.java
@@ -0,0 +1,37 @@
+package net.tuschhcm.routercontrol.router;
+
+/**
+ * Router implementation for a ShinyBow SB-5544
+ *
+ */
+public class ShinyBow5544Router implements Router {
+
+ /**
+ * Create a new ShinyBow router using the given comm port.
+ *
+ * @param portName Com port name
+ */
+ public ShinyBow5544Router(final String portName) {
+
+ }
+
+ @Override
+ public void switchInput(int output, int input)
+ throws IllegalArgumentException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setPower(boolean on) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setLockControls(boolean enabled) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/net/tuschhcm/routercontrol/ui/ConsoleUI.java b/src/net/tuschhcm/routercontrol/ui/ConsoleUI.java
new file mode 100644
index 0000000..52baa65
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/ui/ConsoleUI.java
@@ -0,0 +1,35 @@
+package net.tuschhcm.routercontrol.ui;
+
+public class ConsoleUI implements UserInterface {
+
+ @Override
+ public void addPreset(int number, String name) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setPresetSelectionAction(Action action) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getSelectedPreset() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setControlsLockAction(Action action) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/net/tuschhcm/routercontrol/ui/UserInterface.java b/src/net/tuschhcm/routercontrol/ui/UserInterface.java
new file mode 100644
index 0000000..7a441c5
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/ui/UserInterface.java
@@ -0,0 +1,42 @@
+package net.tuschhcm.routercontrol.ui;
+
+/**
+ * Interface specification for the view.
+ */
+public interface UserInterface {
+ /**
+ * Tell the user interface about a preset.
+ *
+ * @param number Preset number
+ * @param name Preset name
+ */
+ public void addPreset(final int number, final String name);
+
+ /**
+ * Set the action handler called when a preset is selected.
+ * @param action
+ */
+ public void setPresetSelectionAction(final Action action);
+
+ /**
+ * @return the selected preset.
+ */
+ public int getSelectedPreset();
+
+ /**
+ * Handle toggling the control lock
+ */
+ public void setControlsLockAction(final Action action);
+
+ /**
+ * Start the user interface.
+ */
+ public void run();
+
+ /**
+ * Interface specification for an action handler.
+ */
+ public interface Action {
+ public void onAction();
+ }
+}