From 2c827324285501bd22cf3353ccda2b96db04d09d Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Fri, 11 Oct 2013 16:21:46 +0200 Subject: [PATCH] Refactoring and proper naming for all the things \o/ --- src/eva2/client/EvAComAdapter.java | 40 +++++++------------ src/eva2/gui/EvATreeSelectionListener.java | 8 ++-- src/eva2/gui/Main.java | 11 +++-- ...anel.java => OptimizationEditorPanel.java} | 17 ++++---- src/eva2/gui/editor/GOEPanel.java | 2 +- src/eva2/gui/editor/GenericObjectEditor.java | 8 ++-- src/eva2/optimization/ModuleServer.java | 26 ++++-------- 7 files changed, 44 insertions(+), 68 deletions(-) rename src/eva2/gui/{GOEPanel.java => OptimizationEditorPanel.java} (95%) diff --git a/src/eva2/client/EvAComAdapter.java b/src/eva2/client/EvAComAdapter.java index 610adda2..2d4a874b 100644 --- a/src/eva2/client/EvAComAdapter.java +++ b/src/eva2/client/EvAComAdapter.java @@ -1,30 +1,22 @@ package eva2.client; -/* - * Title: EvA2 - * Description: - * Copyright: Copyright (c) 2003 - * Company: University of Tuebingen, Computer Architecture - * @author Holger Ulmer, Felix Streichert, Hannes Planatscher - * @version: $Revision: 320 $ - * $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $ - * $Author: mkron $ - */ + import eva2.gui.LoggingPanel; import eva2.optimization.EvAMainAdapter; import eva2.optimization.EvAMainAdapterImpl; import eva2.optimization.go.InterfaceOptimizationParameters; import eva2.optimization.modules.ModuleAdapter; +import java.util.logging.Logger; + /** * */ public class EvAComAdapter { - + private final static Logger LOGGER = Logger.getLogger(EvAComAdapter.class.getName()); private LoggingPanel loggingPanel; private EvAMainAdapterImpl localMainAdapter; - private boolean runLocally = false; - private static EvAComAdapter m_instance; + private static EvAComAdapter instance; /** * @@ -37,14 +29,14 @@ public class EvAComAdapter { * */ public static EvAComAdapter getInstance() { - if (m_instance == null) { - m_instance = new EvAComAdapter(); + if (instance == null) { + instance = new EvAComAdapter(); } - return (EvAComAdapter) m_instance; + return instance; } /** - * Creates the ModulAdapters RMI Object on the server + * Creates the ModuleAdapters RMI Object on the server * * @return */ @@ -72,15 +64,13 @@ public class EvAComAdapter { * @return */ public String[] getModuleNameList() { - String[] list; - list = getLocalMainAdapter().getModuleNameList(); - if (loggingPanel != null) { - loggingPanel.logMessage("List of modules available:"); - } + String[] list = getLocalMainAdapter().getModuleNameList(); + LOGGER.info("List of modules available:"); + if (list != null) { - for (int i = 0; i < list.length; i++) { - if ((String) list[i] != null && loggingPanel != null) { - loggingPanel.logMessage((String) list[i]); + for (String item : list) { + if (!item.isEmpty() && loggingPanel != null) { + LOGGER.info(item); } } } diff --git a/src/eva2/gui/EvATreeSelectionListener.java b/src/eva2/gui/EvATreeSelectionListener.java index 04bdced8..fdbf950b 100644 --- a/src/eva2/gui/EvATreeSelectionListener.java +++ b/src/eva2/gui/EvATreeSelectionListener.java @@ -59,11 +59,11 @@ public class EvATreeSelectionListener implements TreeSelectionListener, Property EvATreeNode leafNode = (EvATreeNode) tp.getLastPathComponent(); // goe.setValue(leafNode.getUserObject()); Component editComp = goe.getCustomEditor(); - if (editComp instanceof GOEPanel) { - // update the object in the main GOEPanel - ((GOEPanel) editComp).setTarget(leafNode.getUserObject()); + if (editComp instanceof OptimizationEditorPanel) { + // update the object in the main OptimizationEditorPanel + ((OptimizationEditorPanel) editComp).setTarget(leafNode.getUserObject()); } else { - System.err.println("Error, unable to notify custom editor of type " + editComp.getClass() + ", expected GOEPanel (EvATreeSelectionListener)"); + System.err.println("Error, unable to notify custom editor of type " + editComp.getClass() + ", expected OptimizationEditorPanel (EvATreeSelectionListener)"); } } diff --git a/src/eva2/gui/Main.java b/src/eva2/gui/Main.java index 5b66372e..30785e77 100644 --- a/src/eva2/gui/Main.java +++ b/src/eva2/gui/Main.java @@ -50,7 +50,7 @@ public class Main extends JFrame implements OptimizationStateListener { private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); - // Hosts: + // Configurable module: private ModuleAdapter currentModuleAdapter = null; // Help: @@ -104,7 +104,6 @@ public class Main extends JFrame implements OptimizationStateListener { * @param paramsFile * @param autorun * @param nosplash - * @see #EvAClient(String, java.awt.Window, String, boolean, boolean, boolean) */ public Main(final String hostName, final String paramsFile, boolean autorun, boolean nosplash) { this(hostName, null, paramsFile, null, autorun, nosplash, false, false); @@ -207,7 +206,7 @@ public class Main extends JFrame implements OptimizationStateListener { } - comAdapter = EvAComAdapter.getInstance(); + this.comAdapter = EvAComAdapter.getInstance(); splashScreenTime = 2500; SwingUtilities.invokeLater(initRunnable = new Runnable() { @@ -789,11 +788,11 @@ public class Main extends JFrame implements OptimizationStateListener { return (currentModuleAdapter != null) && (currentModuleAdapter instanceof AbstractModuleAdapter) && ((AbstractModuleAdapter) currentModuleAdapter).isOptRunning(); } - private void loadSpecificModule(String selectedModule, InterfaceOptimizationParameters goParams) { + private void loadSpecificModule(String selectedModule, InterfaceOptimizationParameters optimizationParameters) { ModuleAdapter newModuleAdapter = null; // try { - newModuleAdapter = comAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2"); + newModuleAdapter = comAdapter.getModuleAdapter(selectedModule, optimizationParameters, withGUI ? null : "EvA2"); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error loading module.", e); EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); @@ -811,7 +810,7 @@ public class Main extends JFrame implements OptimizationStateListener { System.setProperty("java.class.path", cp + System.getProperty("path.separator") + dir); ReflectPackage.resetDynCP(); comAdapter.updateLocalMainAdapter(); - loadSpecificModule(selectedModule, goParams); // end recursive call! handle with care! + loadSpecificModule(selectedModule, optimizationParameters); // end recursive call! handle with care! return; } } else { diff --git a/src/eva2/gui/GOEPanel.java b/src/eva2/gui/OptimizationEditorPanel.java similarity index 95% rename from src/eva2/gui/GOEPanel.java rename to src/eva2/gui/OptimizationEditorPanel.java index 779d903c..a24ba0f3 100644 --- a/src/eva2/gui/GOEPanel.java +++ b/src/eva2/gui/OptimizationEditorPanel.java @@ -5,7 +5,6 @@ import eva2.optimization.tools.FileTools; import eva2.tools.BasicResourceLoader; import eva2.tools.EVAHELP; import eva2.tools.SerializedObject; -import org.reflections.Reflections; import java.awt.*; import java.awt.event.ActionEvent; @@ -27,8 +26,8 @@ import javax.swing.plaf.basic.BasicComboBoxRenderer; /** * */ -public class GOEPanel extends JPanel implements ItemListener { - private static final Logger LOGGER = Logger.getLogger(GOEPanel.class.getName()); +public class OptimizationEditorPanel extends JPanel implements ItemListener { + private static final Logger LOGGER = Logger.getLogger(OptimizationEditorPanel.class.getName()); private Object backupObject; private PropertyChangeSupport propChangeSupport; @@ -71,14 +70,14 @@ public class GOEPanel extends JPanel implements ItemListener { /** * */ - public GOEPanel(Object target, Object backup, PropertyChangeSupport support, GenericObjectEditor goe) { + public OptimizationEditorPanel(Object target, Object backup, PropertyChangeSupport support, GenericObjectEditor goe) { this(target, backup, support, goe, false); } /** * */ - public GOEPanel(Object target, Object backup, PropertyChangeSupport support, GenericObjectEditor goe, boolean withCancel) { + public OptimizationEditorPanel(Object target, Object backup, PropertyChangeSupport support, GenericObjectEditor goe, boolean withCancel) { Object m_Object = target; backupObject = backup; propChangeSupport = support; @@ -91,7 +90,7 @@ public class GOEPanel extends JPanel implements ItemListener { } catch (OutOfMemoryError err) { backupObject = null; System.gc(); - System.err.println("Could not create backup object: not enough memory (GOEPanel backup of " + m_Object + ")"); + System.err.println("Could not create backup object: not enough memory (OptimizationEditorPanel backup of " + m_Object + ")"); } comboBoxModel = new DefaultComboBoxModel(new String[0]); objectChooser = new JComboBox(comboBoxModel); @@ -145,7 +144,7 @@ public class GOEPanel extends JPanel implements ItemListener { /* * ToDo: This is really ugly. Find a way to make this better. */ - Container container = GOEPanel.this.getParent(); + Container container = OptimizationEditorPanel.this.getParent(); while (!(container instanceof JDialog)) { container = container.getParent(); } @@ -168,7 +167,7 @@ public class GOEPanel extends JPanel implements ItemListener { /* * ToDo: This is really ugly. Find a way to make this better. */ - Container container = GOEPanel.this.getParent(); + Container container = OptimizationEditorPanel.this.getParent(); while (!(container instanceof JDialog)) { container = container.getParent(); } @@ -312,7 +311,7 @@ public class GOEPanel extends JPanel implements ItemListener { List classesLongNames; ArrayList> instances = new ArrayList>(5); classesLongNames = GenericObjectEditor.getClassesFromProperties(genericObjectEditor.getClassType().getName(), instances); - LOGGER.finest("Selected type for GOEPanel: " + genericObjectEditor.getClassType().getName()); + LOGGER.finest("Selected type for OptimizationEditorPanel: " + genericObjectEditor.getClassType().getName()); if (classesLongNames.size() > 1) { classNameMap = new HashMap(); for (String className : classesLongNames) { diff --git a/src/eva2/gui/editor/GOEPanel.java b/src/eva2/gui/editor/GOEPanel.java index 1b678c64..d226cda2 100644 --- a/src/eva2/gui/editor/GOEPanel.java +++ b/src/eva2/gui/editor/GOEPanel.java @@ -90,7 +90,7 @@ public class GOEPanel extends JPanel implements ItemListener { } catch (OutOfMemoryError err) { backupObject = null; System.gc(); - System.err.println("Could not create backup object: not enough memory (GOEPanel backup of " + m_Object + ")"); + System.err.println("Could not create backup object: not enough memory (OptimizationEditorPanel backup of " + m_Object + ")"); } comboBoxModel = new DefaultComboBoxModel(new String[0]); objectChooser = new JComboBox(comboBoxModel); diff --git a/src/eva2/gui/editor/GenericObjectEditor.java b/src/eva2/gui/editor/GenericObjectEditor.java index d72339f1..942ea902 100644 --- a/src/eva2/gui/editor/GenericObjectEditor.java +++ b/src/eva2/gui/editor/GenericObjectEditor.java @@ -6,7 +6,7 @@ package eva2.gui.editor; */ import eva2.EvAInfo; -import eva2.gui.GOEPanel; +import eva2.gui.OptimizationEditorPanel; import eva2.tools.ReflectPackage; import java.awt.Component; @@ -36,7 +36,7 @@ public class GenericObjectEditor implements PropertyEditor { private Object m_Backup; private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); private Class classType; - private GOEPanel editorComponent; + private OptimizationEditorPanel editorComponent; private boolean isEnabled = true; /** @@ -473,7 +473,7 @@ public class GenericObjectEditor implements PropertyEditor { @Override public Component getCustomEditor() { if (editorComponent == null) { - editorComponent = new GOEPanel(m_Object, m_Backup, propertyChangeSupport, this); + editorComponent = new OptimizationEditorPanel(m_Object, m_Backup, propertyChangeSupport, this); } return editorComponent; } @@ -483,7 +483,7 @@ public class GenericObjectEditor implements PropertyEditor { */ public void disableOKCancel() { if (editorComponent == null) { - editorComponent = new GOEPanel(m_Object, m_Backup, + editorComponent = new OptimizationEditorPanel(m_Object, m_Backup, propertyChangeSupport, this); } editorComponent.setEnabledOkCancelButtons(false); diff --git a/src/eva2/optimization/ModuleServer.java b/src/eva2/optimization/ModuleServer.java index f75a9600..1ec7a65a 100644 --- a/src/eva2/optimization/ModuleServer.java +++ b/src/eva2/optimization/ModuleServer.java @@ -1,16 +1,5 @@ package eva2.optimization; -/* - * Title: EvA2 - * Description: - * Copyright: Copyright (c) 2003 - * Company: University of Tuebingen, Computer Architecture - * @author Holger Ulmer, Felix Streichert, Hannes Planatscher - * @version: $Revision: 320 $ - * $Date: 2007-12-06 16:05:11 +0100 (Thu, 06 Dec 2007) $ - * $Author: mkron $ - */ - import eva2.optimization.go.InterfaceOptimizationParameters; import eva2.optimization.modules.GOModuleAdapter; import eva2.optimization.modules.ModuleAdapter; @@ -107,7 +96,7 @@ public class ModuleServer { * * @return the loaded module adapter instance */ - public ModuleAdapter createModuleAdapter(String selectedModuleName, InterfaceOptimizationParameters goParams, String noGuiLogFile) { + public ModuleAdapter createModuleAdapter(String selectedModuleName, InterfaceOptimizationParameters optimizationParameters, String noGuiLogFile) { moduleAdapterCounter++; String adapterName = "ERROR MODULADAPTER !!"; String moduleName = null; @@ -132,8 +121,8 @@ public class ModuleServer { /* create a module instance */ int constrIndex = 0; - if ((goParams == null && noGuiLogFile == null) || !module.equals(GOModuleAdapter.class)) { - if (goParams != null) { + if ((optimizationParameters == null && noGuiLogFile == null) || !module.equals(GOModuleAdapter.class)) { + if (optimizationParameters != null) { System.err.println("Cant set params - no matching constructor found for " + adapterName + " (ModuleServer)"); } if (noGuiLogFile != null) { @@ -148,21 +137,20 @@ public class ModuleServer { moduleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para); } else { Object[] param = new Object[4]; - param[0] = (String) adapterName; - param[1] = (InterfaceOptimizationParameters) goParams; - param[2] = (String) noGuiLogFile; + param[0] = adapterName; + param[1] = optimizationParameters; + param[2] = noGuiLogFile; while ((constructorArr[constrIndex].getParameterTypes().length != 4) && (constrIndex < constructorArr.length)) { constrIndex++; } moduleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(param); } - // m_RunnungModules.add(m_ModuleAdapter); } catch (Exception ex) { LOGGER.log(Level.SEVERE, "Error in RMI-Moduladapter initialization", ex); EVAERROR.EXIT("Error in RMI-Moduladapter initialization: " + ex.getMessage()); return null; } - return (ModuleAdapter) moduleAdapter; + return moduleAdapter; } }