Clean code

This commit is contained in:
manzerbredes 2016-04-01 06:44:17 +02:00
parent 53a8cefdbb
commit 1645bb275b
6 changed files with 90 additions and 55 deletions

View file

@ -4,12 +4,20 @@ import org.manzerbredes.open_klm.args.ArgsManager;
import org.manzerbredes.open_klm.client.MainWindow;
import org.manzerbredes.open_klm.drivers.*;
/**
* Hello world!
* Open KLM Application
*
*/
public class App
{
/**
* Entry point
*
* @param args
*/
public static void main( String[] args )
{
// Get driver
@ -25,7 +33,7 @@ public class App
// Else run GUI
try {
MainWindow mw = new MainWindow(aDriver);
new MainWindow(aDriver);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();

View file

@ -1,8 +1,7 @@
package org.manzerbredes.open_klm.args;
import org.manzerbredes.open_klm.drivers.Driver;
import org.manzerbredes.open_klm.drivers.DriverTypeA;
import org.manzerbredes.open_klm.drivers.Driver_1770_ff00;
/**
*

View file

@ -0,0 +1,30 @@
package org.manzerbredes.open_klm.client;
import org.manzerbredes.open_klm.drivers.Driver;
/**
* JPanel for a specific driver. Each panel who manage
* a driver must implement this interface.
*
* @author Manzerbredes
*
*/
public interface DriverJPanel{
/**
* Get the type of driver handled by the JPanel
*
* @return class Class that represent the type of the driver the JPanel handle
*/
public Class<?> getType();
/**
*
* Init the JPanel with a driver (driver must have the correct type)
*
* @param driver The driver to manage
* @return True if success to init, False else
*/
public boolean initUI(Driver driver);
}

View file

@ -1,22 +0,0 @@
package org.manzerbredes.open_klm.client;
import org.manzerbredes.open_klm.drivers.Driver;
public interface GUI{
/**
* Get the type of driver the GUI handle
*
* @return class that represent the type of the driver the GUI handle
*/
public Class<?> getType();
/**
*
* Init the GUI with driver
*
* @param driver
* @return
*/
public boolean initGUI(Driver driver);
}

View file

@ -15,7 +15,7 @@ import org.manzerbredes.open_klm.drivers.DriverTypeA.Color;
import org.manzerbredes.open_klm.drivers.DriverTypeA.Intensity;
import org.manzerbredes.open_klm.drivers.DriverTypeA.Region;
public class GUITypeA extends JPanel implements GUI{
public class JPanelTypeA extends JPanel implements DriverJPanel{
private JComboBox<Color> left;
@ -25,7 +25,7 @@ public class GUITypeA extends JPanel implements GUI{
private DriverTypeA keyboardTypeA;
@Override
public boolean initGUI(Driver driver){
public boolean initUI(Driver driver){
if(driver.getType().equals(DriverTypeA.class)){

View file

@ -1,43 +1,51 @@
package org.manzerbredes.open_klm.client;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.*;
import org.manzerbredes.open_klm.drivers.*;
import org.manzerbredes.open_klm.drivers.DriverTypeA.*;
/**
* Main Window
*
* @author Manzerbredes
*
*/
public class MainWindow extends JFrame {
/**
* Define serial Version UID
*/
private static final long serialVersionUID = 8058826286308946977L;
private Class<?>[] availableGUI={
GUITypeA.class
/**
* Contain all JPanel corresponding to each driver type
*/
private Class<?>[] driverJPanels={
JPanelTypeA.class
};
public MainWindow(Driver aDriver){
// Configure MainWindow
this.setTitle("Open KLM");
this.setSize(700, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
for(int i=0;i<this.availableGUI.length;i++){
/**
* Build a main window
* @param aDriver
*/
public MainWindow(Driver aDriver){
// Configure main window
this.initUI();
// Add driver panel
for(int i=0;i<this.driverJPanels.length;i++){
try {
GUI gui=(GUI) availableGUI[i].newInstance();
if(gui.getType().equals(aDriver.getType())){
if(gui.initGUI(aDriver)){
this.add((JPanel) gui);
// Build a panel
DriverJPanel driverJPanel=(DriverJPanel) driverJPanels[i].newInstance();
// If the panel have the same type of the driver try to init it
if(driverJPanel.getType().equals(aDriver.getType())){
// If init success add it to the main window
if(driverJPanel.initUI(aDriver)){
this.add((JPanel) driverJPanel);
}
}
@ -46,9 +54,21 @@ public class MainWindow extends JFrame {
}
}
// Display the main window
this.setVisible(true);
}
/**
* Configure main window
*/
private void initUI(){
// Configure MainWindow
this.setTitle("Open KLM");
this.setSize(700, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}