From 1645bb275b4a2e3b84faf09bbd2a60e19f56b74f Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Fri, 1 Apr 2016 06:44:17 +0200 Subject: [PATCH] Clean code --- src/app/App.java | 12 ++- src/args/ArgsManager.java | 3 +- src/client/DriverJPanel.java | 30 ++++++++ src/client/GUI.java | 22 ------ .../{GUITypeA.java => JPanelTypeA.java} | 4 +- src/client/MainWindow.java | 74 ++++++++++++------- 6 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 src/client/DriverJPanel.java delete mode 100644 src/client/GUI.java rename src/client/{GUITypeA.java => JPanelTypeA.java} (94%) diff --git a/src/app/App.java b/src/app/App.java index 34c91ff..f652d66 100644 --- a/src/app/App.java +++ b/src/app/App.java @@ -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(); diff --git a/src/args/ArgsManager.java b/src/args/ArgsManager.java index 332553c..f43edde 100644 --- a/src/args/ArgsManager.java +++ b/src/args/ArgsManager.java @@ -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; + /** * diff --git a/src/client/DriverJPanel.java b/src/client/DriverJPanel.java new file mode 100644 index 0000000..a88af43 --- /dev/null +++ b/src/client/DriverJPanel.java @@ -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); +} \ No newline at end of file diff --git a/src/client/GUI.java b/src/client/GUI.java deleted file mode 100644 index 8c561ee..0000000 --- a/src/client/GUI.java +++ /dev/null @@ -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); -} \ No newline at end of file diff --git a/src/client/GUITypeA.java b/src/client/JPanelTypeA.java similarity index 94% rename from src/client/GUITypeA.java rename to src/client/JPanelTypeA.java index dcca028..15c9800 100644 --- a/src/client/GUITypeA.java +++ b/src/client/JPanelTypeA.java @@ -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 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)){ diff --git a/src/client/MainWindow.java b/src/client/MainWindow.java index f42ecef..f3fbf63 100644 --- a/src/client/MainWindow.java +++ b/src/client/MainWindow.java @@ -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