From 5d8eafe9e8c36c86f9b4c33f32305866dd898f3e Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Sun, 27 Mar 2016 14:40:42 +0200 Subject: Add state class --- src/device/Keyboard.java | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'src/device/Keyboard.java') diff --git a/src/device/Keyboard.java b/src/device/Keyboard.java index 4acf4a1..cc7d8f9 100644 --- a/src/device/Keyboard.java +++ b/src/device/Keyboard.java @@ -10,27 +10,20 @@ public class Keyboard{ * Device driver */ private Driver device; - + /** - * Define Keyboard color state + * Keyboard State */ - private HashMap KeyboardColor=new HashMap<>(); + private KeyboardState state; - /** - * Define Keyboard mode state - */ - private Mode mode=Mode.NORMAL; - /** * Build a keyboard access + * + * @throws InstantiationException Throw if failed to instanciate driver */ - public Keyboard(){ - try { - this.device=new Driver(); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + public Keyboard() throws InstantiationException{ + this.device=new Driver(); + this.state=new KeyboardState(); } @@ -42,10 +35,8 @@ public class Keyboard{ * @param intensity Intensity wanted */ public void setColor(Color color, Intensity intensity){ - // Save state - this.KeyboardColor.put(Region.LEFT, color); - this.KeyboardColor.put(Region.MIDDLE, color); - this.KeyboardColor.put(Region.RIGHT, color); + //Save state + this.state.setColor(color, intensity); // Set color this.device.setColor(Region.LEFT, color, intensity); @@ -53,7 +44,7 @@ public class Keyboard{ this.device.setColor(Region.RIGHT, color, intensity); // Apply color - this.device.commit(this.mode); + this.device.commit(this.state.getMode()); } @@ -67,13 +58,13 @@ public class Keyboard{ */ public void setRegionColor(Region region, Color color, Intensity intensity){ // Save state - this.KeyboardColor.put(region, color); + this.state.setRegionColor(region, color, intensity); // Set color this.device.setColor(region, color, intensity); // Apply color - this.device.commit(this.mode); + this.device.commit(this.state.getMode()); } -- cgit v1.2.3