Clean code and new release
This commit is contained in:
parent
58a70ad52d
commit
fbfa7d72b6
6 changed files with 90 additions and 65 deletions
Binary file not shown.
|
@ -1,74 +1,44 @@
|
|||
package org.manzerbredes.open_klm.app;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.SourceDataLine;
|
||||
import javax.sound.sampled.TargetDataLine;
|
||||
|
||||
import org.manzerbredes.open_klm.args.ArgsTypeA;
|
||||
import org.manzerbredes.open_klm.args.ArgsManager;
|
||||
import org.manzerbredes.open_klm.client.MainWindow;
|
||||
import org.manzerbredes.open_klm.drivers.*;
|
||||
import org.manzerbredes.open_klm.drivers.DriverTypeA.*;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{/*
|
||||
@Option(name="-leftColor",usage="Set the left color")
|
||||
public String leftColor=null;
|
||||
@Option(name="-middleColor",usage="Set the middle color")
|
||||
public String middleColor=null;
|
||||
@Option(name="-rightColor",usage="Set the right color")
|
||||
public String rightColor=null;
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
// Get driver
|
||||
DriverManager driverManager=new DriverManager();
|
||||
Driver aDriver=driverManager.getDevice();
|
||||
|
||||
public void parseArguments(){
|
||||
if(this.leftColor!=null || this.rightColor!=null || this.middleColor!=null){
|
||||
// If a driver is found run the program
|
||||
if(aDriver!=null){
|
||||
|
||||
// Parse argument
|
||||
ArgsManager argsManager=new ArgsManager();
|
||||
argsManager.parse(aDriver, args);
|
||||
|
||||
// Else run GUI
|
||||
try {
|
||||
DriverTypeA device=new Driver_1770_ff00();
|
||||
|
||||
if(this.leftColor==null)
|
||||
this.leftColor="OFF";
|
||||
if(this.middleColor==null)
|
||||
this.middleColor="OFF";
|
||||
if(this.rightColor==null)
|
||||
this.rightColor="OFF";
|
||||
device.setRegionColor(Region.LEFT, Color.valueOf(leftColor), Intensity.HIGH);
|
||||
device.setRegionColor(Region.MIDDLE, Color.valueOf(middleColor), Intensity.HIGH);
|
||||
device.setRegionColor(Region.RIGHT, Color.valueOf(rightColor), Intensity.HIGH);
|
||||
|
||||
} catch (Exception e) {
|
||||
MainWindow mw = new MainWindow(aDriver);
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
else{
|
||||
// Exit with error
|
||||
System.err.println("No driver avalaible for your system. Try as root !");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
|
||||
/*app.parseArguments();
|
||||
new MainWindow();*/
|
||||
/*DriverTypeA device=new Driver_1770_ff00();
|
||||
Driver a=(Driver) device;
|
||||
a.initDriver();
|
||||
device.setRegionColor(Region.LEFT, Color.RED, Intensity.HIGH);
|
||||
device.setRegionColor(Region.MIDDLE, Color.ORANGE, Intensity.HIGH);
|
||||
device.setRegionColor(Region.RIGHT, Color.PURPLE, Intensity.HIGH);
|
||||
device.setMode(Mode.WAVE);*/
|
||||
System.out.println("Parsing... "+ args.length);
|
||||
ArgsTypeA a=new ArgsTypeA();
|
||||
Driver aa=new Driver_1770_ff00();
|
||||
aa.initDriver();
|
||||
a.applyAndExit(aa, args);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,48 @@
|
|||
package org.manzerbredes.open_klm.args;
|
||||
|
||||
public interface ArgsManager{
|
||||
import org.manzerbredes.open_klm.drivers.Driver;
|
||||
import org.manzerbredes.open_klm.drivers.DriverTypeA;
|
||||
import org.manzerbredes.open_klm.drivers.Driver_1770_ff00;
|
||||
|
||||
/**
|
||||
*
|
||||
* Arguments manager
|
||||
*
|
||||
* @author Manzerbredes
|
||||
*
|
||||
*/
|
||||
public class ArgsManager{
|
||||
|
||||
/**
|
||||
* List of Arguments Parser available
|
||||
*/
|
||||
private Class<?>[] parsers={
|
||||
ArgsTypeA.class
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Parse the arguments and exit
|
||||
*
|
||||
* @param aDriver driver used to parse
|
||||
* @param args arguments to parse
|
||||
*/
|
||||
public void parse(Driver aDriver, String[] args){
|
||||
if(args.length>0){
|
||||
for(Class<?> argsParser : this.parsers){
|
||||
ArgsParser parser;
|
||||
try {
|
||||
parser = (ArgsParser) argsParser.newInstance();
|
||||
if(parser.getType().equals(aDriver.getType())){
|
||||
parser.applyAndExit(aDriver, args);
|
||||
}
|
||||
} catch (Exception e){
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -8,9 +8,16 @@ import org.manzerbredes.open_klm.drivers.Driver;
|
|||
* @author Manzerbredes
|
||||
*
|
||||
*/
|
||||
public interface Args{
|
||||
public interface ArgsParser{
|
||||
/**
|
||||
* Apply parsed argument and exit the program
|
||||
*/
|
||||
public void applyAndExit(Driver aDriver, String[] args);
|
||||
|
||||
/**
|
||||
* Get the type of the driver the parser should parse
|
||||
*
|
||||
* @return class that represent the type of the driver (DriverTypeA.class for example)
|
||||
*/
|
||||
public Class<?> getType();
|
||||
}
|
|
@ -16,7 +16,7 @@ import joptsimple.OptionSet;
|
|||
* @author Manzerbredes
|
||||
*
|
||||
*/
|
||||
public class ArgsTypeA implements Args{
|
||||
public class ArgsTypeA implements ArgsParser{
|
||||
/**
|
||||
* Define Keyboard primary color state
|
||||
*/
|
||||
|
@ -130,4 +130,10 @@ public class ArgsTypeA implements Args{
|
|||
driver.setMode(this.mode);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<?> getType() {
|
||||
return DriverTypeA.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -28,16 +28,15 @@ public class MainWindow extends JFrame {
|
|||
private Class<?> driverType;
|
||||
private DriverManager drvMan=new DriverManager();
|
||||
|
||||
public MainWindow() throws InstantiationException{
|
||||
public MainWindow(Driver aDriver) throws InstantiationException{
|
||||
this.initUI();
|
||||
Driver drv=drvMan.getDevice();
|
||||
if(drv==null){
|
||||
if(aDriver==null){
|
||||
System.err.println("No driver avalaible (try as root)");
|
||||
System.exit(1);
|
||||
}
|
||||
else{
|
||||
this.driverType=drv.getType();
|
||||
this.keyboardTypeA=(DriverTypeA) drv;
|
||||
this.driverType=aDriver.getType();
|
||||
this.keyboardTypeA=(DriverTypeA) aDriver;
|
||||
}
|
||||
|
||||
this.left=new JComboBox<>(Color.values());
|
||||
|
|
Loading…
Add table
Reference in a new issue