Added new Annotation to replace the static globalInfo methods used everywhere.
OptimizationEditorPanel now reads the annotated class description for ToolTips.
This commit is contained in:
parent
e9d9709788
commit
8229b145ee
@ -5,6 +5,8 @@ import eva2.optimization.tools.FileTools;
|
||||
import eva2.tools.BasicResourceLoader;
|
||||
import eva2.tools.EVAHELP;
|
||||
import eva2.tools.SerializedObject;
|
||||
import eva2.util.annotation.Description;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@ -334,23 +336,35 @@ public class OptimizationEditorPanel extends JPanel implements ItemListener {
|
||||
|
||||
private String[] collectComboToolTips(List<Class<?>> instances, int maxLen) {
|
||||
String[] tips = new String[instances.size()];
|
||||
|
||||
for (int i = 0; i < tips.length; i++) {
|
||||
tips[i] = null;
|
||||
Class[] classParams = new Class[]{};
|
||||
|
||||
String tip = null;
|
||||
try {
|
||||
String tip = null;
|
||||
Method giMeth = instances.get(i).getDeclaredMethod("globalInfo", classParams);
|
||||
if (Modifier.isStatic(giMeth.getModifiers())) {
|
||||
tip = (String) giMeth.invoke(null, (Object[]) null);
|
||||
}
|
||||
if (tip != null) {
|
||||
if (tip.length() <= maxLen) {
|
||||
tips[i] = tip;
|
||||
} else {
|
||||
tips[i] = tip.substring(0, maxLen - 2) + "..";
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.finer(e.getMessage());
|
||||
}
|
||||
|
||||
// If the globalInfo method doesn't exist try to use the Annotation
|
||||
if(tip == null || tip.isEmpty()) {
|
||||
Description description = instances.get(i).getAnnotation(Description.class);
|
||||
if(description != null) {
|
||||
tip = description.text();
|
||||
}
|
||||
}
|
||||
|
||||
if (tip != null) {
|
||||
if (tip.length() <= maxLen) {
|
||||
tips[i] = tip;
|
||||
} else {
|
||||
tips[i] = tip.substring(0, maxLen - 2) + "..";
|
||||
}
|
||||
}
|
||||
}
|
||||
return tips;
|
||||
|
@ -11,6 +11,7 @@ import eva2.optimization.population.Population;
|
||||
import eva2.optimization.population.SolutionSet;
|
||||
import eva2.optimization.problems.F1Problem;
|
||||
import eva2.optimization.problems.InterfaceOptimizationProblem;
|
||||
import eva2.util.annotation.Description;
|
||||
|
||||
/**
|
||||
* The traditional genetic algorithms as devised by Holland. To only special
|
||||
@ -20,10 +21,9 @@ import eva2.optimization.problems.InterfaceOptimizationProblem;
|
||||
* Copyright: Copyright (c) 2003 Company: University of Tuebingen, Computer
|
||||
* Architecture
|
||||
*
|
||||
* @author Felix Streichert
|
||||
* @version: $Revision: 307 $ $Date: 2007-12-04 14:31:47 +0100 (Tue, 04 Dec
|
||||
* 2007) $ $Author: mkron $
|
||||
*/
|
||||
|
||||
@Description(text="This is a basic generational Genetic Algorithm.")
|
||||
public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
private Population population = new Population();
|
||||
@ -245,14 +245,6 @@ public class GeneticAlgorithm implements InterfaceOptimizer, java.io.Serializabl
|
||||
* ********************************************************************************************************************
|
||||
* These are for GUI
|
||||
*/
|
||||
/**
|
||||
* This method returns a global info string
|
||||
*
|
||||
* @return description
|
||||
*/
|
||||
public static String globalInfo() {
|
||||
return "This is a basic generational Genetic Algorithm.";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a naming String
|
||||
|
@ -43,6 +43,7 @@ import eva2.tools.chart2d.DElement;
|
||||
import eva2.tools.chart2d.DPoint;
|
||||
import eva2.tools.chart2d.DPointIcon;
|
||||
import eva2.tools.chart2d.DPointSet;
|
||||
import eva2.util.annotation.Description;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@ -93,6 +94,7 @@ import java.util.Vector;
|
||||
* Yilmaz. Particle Swarms for Multimodal Optimization. In: ICANNGA (1), Seiten
|
||||
* 366<EFBFBD>375, 2007
|
||||
*/
|
||||
@Description(text="A Niching Particle Swarm Optimizer")
|
||||
public class NichePSO implements InterfaceAdditionalPopulationInformer, InterfaceOptimizer, java.io.Serializable {
|
||||
|
||||
/**
|
||||
@ -317,7 +319,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
|
||||
/**
|
||||
* @tested junit, junit&, emp, ... (non-Javadoc)
|
||||
* @see javaeva.server.oa.go.Strategies.InterfaceOptimizer#init()
|
||||
* @see eva2.optimization.strategies.InterfaceOptimizer#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() { // (called right before next optimize/mutltirun)
|
||||
@ -366,7 +368,7 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
*/
|
||||
/**
|
||||
* @tested (non-Javadoc)
|
||||
* @see javaeva.server.oa.go.Strategies.InterfaceOptimizer#optimize()
|
||||
* @see eva2.optimization.strategies.InterfaceOptimizer#optimize()
|
||||
*/
|
||||
@Override
|
||||
public void optimize() {
|
||||
@ -932,14 +934,6 @@ public class NichePSO implements InterfaceAdditionalPopulationInformer, Interfac
|
||||
return representatives;
|
||||
}
|
||||
|
||||
/**
|
||||
* ********************************************************************************************************************
|
||||
* setter, getter: members
|
||||
*/
|
||||
public String globalInfo() {
|
||||
return "A Niching Particle Swarm Optimizer";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param size
|
||||
* @tested ps sets the !initial! size of the mainswarm population use this
|
||||
|
12
src/eva2/util/annotation/Description.java
Normal file
12
src/eva2/util/annotation/Description.java
Normal file
@ -0,0 +1,12 @@
|
||||
package eva2.util.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Annotation used in OptimizationEditorPanel to display Tooltips
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Description {
|
||||
String text();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user