Refactor EVAHELP and remove it.

This commit is contained in:
Fabian Becker 2014-11-12 14:35:58 +01:00
parent 40df065a58
commit 014fd85beb
11 changed files with 34 additions and 177 deletions

View File

@ -3,8 +3,8 @@ package eva2.gui;
import eva2.gui.editor.GenericObjectEditor; import eva2.gui.editor.GenericObjectEditor;
import eva2.optimization.tools.FileTools; import eva2.optimization.tools.FileTools;
import eva2.tools.BasicResourceLoader; import eva2.tools.BasicResourceLoader;
import eva2.tools.EVAHELP;
import eva2.tools.SerializedObject; import eva2.tools.SerializedObject;
import eva2.tools.StringTools;
import eva2.util.annotation.Description; import eva2.util.annotation.Description;
import eva2.yaml.BeanSerializer; import eva2.yaml.BeanSerializer;
@ -320,7 +320,7 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
if (classesLongNames.size() > 1) { if (classesLongNames.size() > 1) {
classNameMap = new HashMap<>(); classNameMap = new HashMap<>();
for (String className : classesLongNames) { for (String className : classesLongNames) {
classNameMap.put(EVAHELP.cutClassName(className), className); classNameMap.put(StringTools.cutClassName(className), className);
} }
Vector<String> classesList = new Vector<>(classesLongNames); Vector<String> classesList = new Vector<>(classesLongNames);
objectChooser.setModel(new DefaultComboBoxModel(classesList)); objectChooser.setModel(new DefaultComboBoxModel(classesList));
@ -415,7 +415,6 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
+ "from the current classpath. Is the resource folder at the right place?\nIs the class abstract or the default constructor missing?", + "from the current classpath. Is the resource folder at the right place?\nIs the class abstract or the default constructor missing?",
"GenericObjectEditor", "GenericObjectEditor",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
EVAHELP.getSystemPropertyString();
} }
} }
} }

View File

@ -2,7 +2,7 @@ package eva2.gui;
import eva2.EvAInfo; import eva2.EvAInfo;
import eva2.tools.BasicResourceLoader; import eva2.tools.BasicResourceLoader;
import eva2.tools.EVAHELP; import eva2.tools.StringTools;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -37,9 +37,9 @@ public class PropertyDialog extends JDialog {
protected static String getFrameNameFromEditor(PropertyEditor editor) { protected static String getFrameNameFromEditor(PropertyEditor editor) {
if (editor.getValue().getClass().isArray()) { if (editor.getValue().getClass().isArray()) {
return "Array of " + EVAHELP.cutClassName(editor.getValue().getClass().getComponentType().getName()); return "Array of " + StringTools.cutClassName(editor.getValue().getClass().getComponentType().getName());
} else { } else {
return EVAHELP.cutClassName(editor.getValue().getClass().getName()); return StringTools.cutClassName(editor.getValue().getClass().getName());
} }
} }

View File

@ -1,6 +1,6 @@
package eva2.gui; package eva2.gui;
import eva2.tools.EVAHELP; import eva2.tools.StringTools;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -37,7 +37,7 @@ public class PropertyPanel extends JPanel {
public final void showDialog() { public final void showDialog() {
Window parent = (Window)this.getRootPane().getParent(); Window parent = (Window)this.getRootPane().getParent();
if (propertyDialog == null) { if (propertyDialog == null) {
propertyDialog = new PropertyDialog(parent, propertyEditor, EVAHELP.cutClassName(propertyEditor.getClass().getName())); propertyDialog = new PropertyDialog(parent, propertyEditor, StringTools.cutClassName(propertyEditor.getClass().getName()));
propertyDialog.setPreferredSize(new Dimension(500, 300)); propertyDialog.setPreferredSize(new Dimension(500, 300));
propertyDialog.setModal(true); propertyDialog.setModal(true);
propertyDialog.setVisible(true); propertyDialog.setVisible(true);

View File

@ -1,7 +1,7 @@
package eva2.gui; package eva2.gui;
import eva2.gui.editor.GenericObjectEditor; import eva2.gui.editor.GenericObjectEditor;
import eva2.tools.EVAHELP; import eva2.tools.StringTools;
import eva2.util.annotation.Description; import eva2.util.annotation.Description;
import eva2.util.annotation.Hidden; import eva2.util.annotation.Hidden;
import eva2.util.annotation.Parameter; import eva2.util.annotation.Parameter;
@ -664,7 +664,7 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
* @return * @return
*/ */
protected String getHelpFileName() { protected String getHelpFileName() {
return EVAHELP.cutClassName(className) + ".html"; return StringTools.cutClassName(className) + ".html";
} }
/** /**

View File

@ -1,8 +1,8 @@
package eva2.gui.editor; package eva2.gui.editor;
import eva2.gui.*; import eva2.gui.*;
import eva2.tools.EVAHELP;
import eva2.tools.SerializedObject; import eva2.tools.SerializedObject;
import eva2.tools.StringTools;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
@ -689,7 +689,7 @@ public class ArrayEditor extends JPanel implements PropertyEditor {
if (listModel.getSize() == 0) { if (listModel.getSize() == 0) {
rep = "Empty"; rep = "Empty";
} else { } else {
rep = listModel.getSize() + " of " + EVAHELP.cutClassName(elementClass.getName()); rep = listModel.getSize() + " of " + StringTools.cutClassName(elementClass.getName());
Object maybeName = BeanInspector.callIfAvailable(listModel.get(0), "getName", new Object[]{}); Object maybeName = BeanInspector.callIfAvailable(listModel.get(0), "getName", new Object[]{});
if (maybeName != null) { if (maybeName != null) {
rep = rep + " (" + maybeName + "...)"; rep = rep + " (" + maybeName + "...)";

View File

@ -6,7 +6,7 @@ import eva2.gui.HtmlDemo;
import eva2.gui.PropertyEditorProvider; import eva2.gui.PropertyEditorProvider;
import eva2.gui.PropertySheetPanel; import eva2.gui.PropertySheetPanel;
import eva2.gui.editor.GenericObjectEditor; import eva2.gui.editor.GenericObjectEditor;
import eva2.tools.EVAHELP; import eva2.tools.StringTools;
import eva2.util.annotation.Parameter; import eva2.util.annotation.Parameter;
import javax.swing.*; import javax.swing.*;
@ -20,7 +20,6 @@ import java.util.Hashtable;
* TODO * TODO
* This class should be unified with GenericObjectEditor. * This class should be unified with GenericObjectEditor.
*/ */
public abstract class AbstractObjectEditor implements PropertyEditor, java.beans.PropertyChangeListener { public abstract class AbstractObjectEditor implements PropertyEditor, java.beans.PropertyChangeListener {
/** /**
* Handles property change notification * Handles property change notification
@ -63,7 +62,6 @@ public abstract class AbstractObjectEditor implements PropertyEditor, java.beans
propertyChangeSupport.firePropertyChange("", backupObject, object); propertyChangeSupport.firePropertyChange("", backupObject, object);
} }
/********************************* PropertyEditor *************************/
/** /**
* Returns true since the Object can be shown * Returns true since the Object can be shown
* *
@ -153,8 +151,6 @@ public abstract class AbstractObjectEditor implements PropertyEditor, java.beans
*/ */
abstract public Class getClassType(); abstract public Class getClassType();
// abstract public Vector getClassesFromProperties();
/** /**
* This method returns a property panel to * This method returns a property panel to
* edit the parameters * edit the parameters
@ -169,7 +165,7 @@ public abstract class AbstractObjectEditor implements PropertyEditor, java.beans
result.setLayout(new BorderLayout()); result.setLayout(new BorderLayout());
result.setVisible(true); result.setVisible(true);
// Define the upper area containing the desription and the help button // Define the upper area containing the description and the help button
String globalInfo = this.getGlobalInfo(); String globalInfo = this.getGlobalInfo();
JTextArea jt = new JTextArea(); JTextArea jt = new JTextArea();
StringBuffer helpText; StringBuffer helpText;
@ -184,7 +180,7 @@ public abstract class AbstractObjectEditor implements PropertyEditor, java.beans
helpButton.addActionListener(new ActionListener() { helpButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent a) { public void actionPerformed(ActionEvent a) {
HtmlDemo temp = new HtmlDemo(EVAHELP.cutClassName(object.getClass().getName()) + ".html"); HtmlDemo temp = new HtmlDemo(StringTools.cutClassName(object.getClass().getName()) + ".html");
temp.show(); temp.show();
} }
}); });
@ -222,7 +218,7 @@ public abstract class AbstractObjectEditor implements PropertyEditor, java.beans
} }
public String getHelpFileName() { public String getHelpFileName() {
return EVAHELP.cutClassName(object.getClass().getName()) + ".html"; return StringTools.cutClassName(object.getClass().getName()) + ".html";
} }
/** /**

View File

@ -2,7 +2,6 @@ package eva2.optimization.tools;
import eva2.gui.editor.GenericObjectEditor; import eva2.gui.editor.GenericObjectEditor;
import eva2.tools.EVAHELP;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -330,7 +329,6 @@ public class GeneralGenericObjectEditorPanel extends JPanel implements ItemListe
+ "from the current classpath", + "from the current classpath",
"GenericObjectEditor", "GenericObjectEditor",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
EVAHELP.getSystemPropertyString();
} }
} }
} }

View File

@ -1,151 +0,0 @@
package eva2.tools;
import java.io.*;
import java.net.InetAddress;
import java.util.Enumeration;
import java.util.Properties;
/**
*
*/
public class EVAHELP {
private static long timestamp;
/**
*
*/
/**
*
*/
public static String getmyRUP() {
String Out = "";
String HostName = "";
try {
HostName = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
System.out.println("ERROR getting HostName EVAHELP " + e.getMessage());
}
try {
BufferedReader in = null;
Process pro = null;
String command = "rup " + HostName;
pro = Runtime.getRuntime().exec(command);
in = new BufferedReader(new InputStreamReader(pro.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
//System.out.println(line);
Out += line;
}
} catch (Exception e) {
System.out.println("Error in calling the command:" + e.getMessage());
}
return Out;
}
/**
*
*/
public static void setTimeStamp() {
timestamp = System.currentTimeMillis();
}
/**
*
*/
public static long getTimeStamp() {
return System.currentTimeMillis() - timestamp;
}
/**
*
*/
public static void returnForExit() {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("return for exit:");
try {
in.readLine();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
/**
*
*/
public static String getSystemPropertyString() {
StringBuilder sBuf = new StringBuilder();
Properties prop = System.getProperties();
Enumeration<?> list = prop.propertyNames();
while (list.hasMoreElements()) {
Object o = list.nextElement();
//System.out.println("o="+o.toString());
sBuf.append(o.toString());
sBuf.append(" = ");
sBuf.append(System.getProperty(o.toString()));
sBuf.append("\n");
}
return sBuf.toString();
}
/**
* @param longName The FQDN of a class
* @return Returns the class Name without package.
*/
public static String cutClassName(final String longName) {
final int dotPos = longName.lastIndexOf('.');
String className = longName;
if (dotPos != -1) {
className = className.substring(dotPos + 1);
}
return className; // now is shortName
}
/**
*
*/
public static void freeMemory() {
Runtime currR = Runtime.getRuntime();
long freeM = currR.freeMemory();
freeM /= 1024;
//System.out.println("Available memory : "+freeM+" Kbytes");
System.gc();
currR = Runtime.getRuntime();
freeM = currR.freeMemory();
freeM /= 1024;
//System.out.println("after gc:Available memory : "+freeM+" bytes");
}
/**
* Log a String to a log-file indicated by the file name. If the file
* exists, the String is appended.
*
* @param msg
* @param fileName
*/
public static void logString(String msg, String fileName) {
final File logFile = new File(fileName);
try {
BufferedWriter bW = new BufferedWriter(
new PrintWriter(new FileOutputStream(logFile, logFile.exists())));
bW.write(msg);
bW.close();
} catch (IOException ex) {
System.err.println("couldnt log to destination " + fileName + ": " + ex.getMessage());
}
}
/**
* Deletes the given file in the current directory. If the file does not
* exist nothing happens.
*
* @param fileName The name of the log file
*/
public static void clearLog(String fileName) {
File logFile = new File(fileName);
if (logFile.exists()) {
logFile.delete();
}
}
}

View File

@ -194,10 +194,6 @@ public class StringSelection implements Serializable {
return false; return false;
} }
return isSelected(selIndex); return isSelected(selIndex);
// for (int i=0; i<strObjects.length; i++) {
// if (strObjects[i].equals(str)) return isSelected(i);
// }
// return false;
} }
/** /**

View File

@ -477,5 +477,18 @@ public final class StringTools {
public static String upcaseFirst(final String word) { public static String upcaseFirst(final String word) {
return word.substring(0, 1).toUpperCase() + word.substring(1); return word.substring(0, 1).toUpperCase() + word.substring(1);
} }
/**
* @param value The string to cut
* @return Returns the class Name without package.
*/
public static String cutClassName(final String value) {
final int dotPos = value.lastIndexOf('.');
String className = value;
if (dotPos != -1) {
className = className.substring(dotPos + 1);
}
return className; // now is shortName
}
} }

View File

@ -80,4 +80,10 @@ public class StringToolsTest {
assertEquals("Camel", StringTools.upcaseFirst("camel")); assertEquals("Camel", StringTools.upcaseFirst("camel"));
assertEquals("UpWeGo", StringTools.upcaseFirst("upWeGo")); assertEquals("UpWeGo", StringTools.upcaseFirst("upWeGo"));
} }
@Test
public void testCutClassName() {
assertEquals("StringTools", StringTools.cutClassName("eva2.tools.StringTools"));
assertEquals("RandomClass", StringTools.cutClassName("eva2.optimization.operator.RandomClass"));
}
} }