Implements args

This commit is contained in:
manzerbredes 2016-03-30 21:05:37 +02:00
parent 386bc35abb
commit f9764bba46
4 changed files with 76 additions and 5 deletions

View file

@ -68,9 +68,6 @@ public class App
device.setRegionColor(Region.MIDDLE, Color.ORANGE, Intensity.HIGH);
device.setRegionColor(Region.RIGHT, Color.PURPLE, Intensity.HIGH);
device.setMode(Mode.NORMAL);
}
}

16
src/args/Args.java Normal file
View file

@ -0,0 +1,16 @@
package org.manzerbredes.open_klm.args;
import org.manzerbredes.open_klm.drivers.Driver;
/**
* All arguments parser must implement this interface
*
* @author Manzerbredes
*
*/
public interface Args{
/**
* Apply parsed argument and exit the program
*/
public void applyAndExit(Driver aDriver, String[] args);
}

View file

@ -1,6 +1,64 @@
package org.manzerbredes.open_klm.args;
import java.util.HashMap;
public class ArgsTypeA{
import org.javatuples.Pair;
import org.manzerbredes.open_klm.drivers.Driver;
import org.manzerbredes.open_klm.drivers.DriverTypeA;
import org.manzerbredes.open_klm.drivers.DriverTypeA.*;
/**
* Parse args for DriverTypeA
*
* @author Manzerbredes
*
*/
public class ArgsTypeA implements Args{
/**
* Define Keyboard primary color state
*/
private HashMap<Region, Pair<Color,Intensity>> primaryColorsState=new HashMap<>();
/**
* Define Keyboard secondary color state (for wave)
*/
private HashMap<Region, Pair<Color,Intensity>> secondaryColorsState=new HashMap<>();
/**
* Define Keyboard mode state
*/
private Mode mode=Mode.NORMAL;
/**
* Build a ArgsTypeA
*
* @param driver The driver to use
*/
public ArgsTypeA(){
// Init primary color state
this.primaryColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.HIGH));
this.primaryColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.HIGH));
this.primaryColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.HIGH));
// Init secondary color state
this.secondaryColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.LOW));
this.secondaryColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.LOW));
this.secondaryColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.OFF, Intensity.LOW));
// Init mode
this.mode=Mode.NORMAL;
}
@Override
public void applyAndExit(Driver aDriver, String[] args){
if(aDriver.getType().equals(DriverTypeA.class)){
//TODO Parse and apply args with args4j
System.exit(0);
}
// Error invalid driver
System.exit(1);
}
}

View file

@ -51,7 +51,7 @@ public class MainWindow extends JFrame {
Color leftRegion=(Color) left.getSelectedItem();
Color middleRegion=(Color) middle.getSelectedItem();
Color rightRegion=(Color) right.getSelectedItem();
keyboardTypeA.setRegionColor(Region.LEFT, leftRegion, Intensity.HIGH);
keyboardTypeA.setRegionColor(Region.MIDDLE, middleRegion, Intensity.HIGH);
keyboardTypeA.setRegionColor(Region.RIGHT, rightRegion, Intensity.HIGH);