Merging MK revs 304:309 - some editor updates, independent graph selection
This commit is contained in:
parent
014258e1a4
commit
173c75e73f
@ -4,6 +4,8 @@ package eva2;
|
|||||||
* Main product and version information strings.
|
* Main product and version information strings.
|
||||||
*
|
*
|
||||||
* --- Changelog
|
* --- Changelog
|
||||||
|
* 2.036: New graph selection mode for statistic plots: every property may be selected independently.
|
||||||
|
* A simple plot legend is produced in the graph window, which can be deactivated.
|
||||||
* 2.035: Reactivated some of the model-based functionality within the GO framework. Minor bugfixes.
|
* 2.035: Reactivated some of the model-based functionality within the GO framework. Minor bugfixes.
|
||||||
* 2.034: Adding a generic parameter control method for optimizers, currently used by PSO to adapt inertness depending
|
* 2.034: Adding a generic parameter control method for optimizers, currently used by PSO to adapt inertness depending
|
||||||
* on EvaluationTerminator or GenerationTerminator instances defining the number of function evaluations.
|
* on EvaluationTerminator or GenerationTerminator instances defining the number of function evaluations.
|
||||||
@ -17,7 +19,7 @@ package eva2;
|
|||||||
* is not available seems to never show up (as opposed to being printed to the console when X-forwarding is on)
|
* is not available seems to never show up (as opposed to being printed to the console when X-forwarding is on)
|
||||||
* and silently fill up the JVM-memory. I havent the faintest idea why there havnt been OutOfMemory exceptions
|
* and silently fill up the JVM-memory. I havent the faintest idea why there havnt been OutOfMemory exceptions
|
||||||
* earlier or whether and how the deadlocks have to do with it.
|
* earlier or whether and how the deadlocks have to do with it.
|
||||||
* The ingeniuos solution was: dont print anything to System.out, which is now done at verbosity 0.
|
* The ingenious solution was: dont print anything to System.out, which is now done at verbosity 0.
|
||||||
* 2.032: Some cosmetics, e.g. to AbstractEAIndividualComparator and older MOCCO classes.
|
* 2.032: Some cosmetics, e.g. to AbstractEAIndividualComparator and older MOCCO classes.
|
||||||
* 2.031: Some updates to the OptimizerFactory. Review of the MatlabInterface with adding an own options structure.
|
* 2.031: Some updates to the OptimizerFactory. Review of the MatlabInterface with adding an own options structure.
|
||||||
* Better access to the EvAClient, which now may have a RemoteStateListener added monitoring the optimization run.
|
* Better access to the EvAClient, which now may have a RemoteStateListener added monitoring the optimization run.
|
||||||
@ -56,7 +58,7 @@ package eva2;
|
|||||||
public class EvAInfo {
|
public class EvAInfo {
|
||||||
public static final String productName = "EvA 2";
|
public static final String productName = "EvA 2";
|
||||||
public static final String productLongName = "Evolutionary Algorithms Workbench 2";
|
public static final String productLongName = "Evolutionary Algorithms Workbench 2";
|
||||||
public static final String versionNum = new String ("2.035");
|
public static final String versionNum = new String ("2.036");
|
||||||
public static final String url = "http://www.ra.cs.uni-tuebingen.de/software/EvA2";
|
public static final String url = "http://www.ra.cs.uni-tuebingen.de/software/EvA2";
|
||||||
|
|
||||||
public static final String propertyFile = "resources/EvA2.props";
|
public static final String propertyFile = "resources/EvA2.props";
|
||||||
|
@ -1,22 +1,24 @@
|
|||||||
package eva2.gui;
|
package eva2.gui;
|
||||||
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Component;
|
||||||
import eva2.server.go.individuals.codings.gp.AbstractGPNode;
|
import java.awt.FontMetrics;
|
||||||
import eva2.server.go.individuals.codings.gp.GPArea;
|
import java.awt.Graphics;
|
||||||
import eva2.tools.EVAHELP;
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyEditorSupport;
|
|
||||||
import java.beans.PropertyEditor;
|
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.beans.PropertyChangeSupport;
|
import java.beans.PropertyChangeSupport;
|
||||||
import java.awt.*;
|
import java.beans.PropertyEditor;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ActionEvent;
|
import javax.swing.JCheckBox;
|
||||||
import java.lang.reflect.Array;
|
import javax.swing.JLabel;
|
||||||
import java.util.ArrayList;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA.
|
* Created by IntelliJ IDEA.
|
||||||
@ -30,12 +32,13 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
|
|||||||
/** Handles property change notification */
|
/** Handles property change notification */
|
||||||
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||||
/** The label for when we can't edit that type */
|
/** The label for when we can't edit that type */
|
||||||
private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
protected JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER);
|
||||||
|
|
||||||
/** The gaphix stuff */
|
/** The graphics stuff */
|
||||||
private JPanel m_CustomEditor, m_NodePanel;
|
private JPanel m_CustomEditor, m_NodePanel;
|
||||||
protected JCheckBox[] m_BlackCheck;
|
protected JCheckBox[] m_BlackCheck;
|
||||||
|
|
||||||
|
|
||||||
public AbstractListSelectionEditor() {
|
public AbstractListSelectionEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +47,7 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
|
|||||||
private void initCustomEditor() {
|
private void initCustomEditor() {
|
||||||
this.m_CustomEditor = new JPanel();
|
this.m_CustomEditor = new JPanel();
|
||||||
this.m_CustomEditor.setLayout(new BorderLayout());
|
this.m_CustomEditor.setLayout(new BorderLayout());
|
||||||
this.m_CustomEditor.add(new JLabel("Choose the area:"), BorderLayout.NORTH);
|
this.m_CustomEditor.add(new JLabel("Choose:"), BorderLayout.NORTH);
|
||||||
this.m_NodePanel = new JPanel();
|
this.m_NodePanel = new JPanel();
|
||||||
this.m_CustomEditor.add(new JScrollPane(this.m_NodePanel), BorderLayout.CENTER);
|
this.m_CustomEditor.add(new JScrollPane(this.m_NodePanel), BorderLayout.CENTER);
|
||||||
this.updateEditor();
|
this.updateEditor();
|
||||||
@ -65,12 +68,12 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
|
|||||||
protected abstract String getElementName(int i);
|
protected abstract String getElementName(int i);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the initial selection state of an element.
|
* Get the selection state of an element.
|
||||||
*
|
*
|
||||||
* @param i
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract boolean isElementAllowed(int i);
|
protected abstract boolean isElementSelected(int i);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object may have changed update the editor. This notifies change listeners automatically.
|
* The object may have changed update the editor. This notifies change listeners automatically.
|
||||||
@ -81,10 +84,10 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
|
|||||||
this.m_NodePanel.setLayout(new GridLayout(getElementCount(), 1));
|
this.m_NodePanel.setLayout(new GridLayout(getElementCount(), 1));
|
||||||
this.m_BlackCheck = new JCheckBox[getElementCount()];
|
this.m_BlackCheck = new JCheckBox[getElementCount()];
|
||||||
for (int i = 0; i < getElementCount(); i++) {
|
for (int i = 0; i < getElementCount(); i++) {
|
||||||
this.m_BlackCheck[i] = new JCheckBox(getElementName(i), isElementAllowed(i));
|
this.m_BlackCheck[i] = new JCheckBox(getElementName(i), isElementSelected(i));
|
||||||
this.m_BlackCheck[i].addActionListener(new ActionListener() {
|
this.m_BlackCheck[i].addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ev) {
|
public void actionPerformed(ActionEvent ev) {
|
||||||
if (performOnAction()) m_Support.firePropertyChange("AbstractListSelectionEditor", null, this);
|
if (actionOnSelect()) m_Support.firePropertyChange("AbstractListSelectionEditor", null, this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.m_NodePanel.add(this.m_BlackCheck[i]);
|
this.m_NodePanel.add(this.m_BlackCheck[i]);
|
||||||
@ -95,7 +98,7 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
|
|||||||
/**
|
/**
|
||||||
* Perform actions when the selection state changes. Return true if there was an actual change.
|
* Perform actions when the selection state changes. Return true if there was an actual change.
|
||||||
*/
|
*/
|
||||||
protected abstract boolean performOnAction();
|
protected abstract boolean actionOnSelect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the base object, return true on success. Make sure that the editor instance is
|
* Set the base object, return true on success. Make sure that the editor instance is
|
||||||
@ -113,45 +116,36 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
|
|||||||
if (setObject(o)) updateEditor();
|
if (setObject(o)) updateEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Retruns the current object.
|
/**
|
||||||
|
* Returns the current object.
|
||||||
* @return the current object
|
* @return the current object
|
||||||
*/
|
*/
|
||||||
public abstract Object getValue();
|
public abstract Object getValue();
|
||||||
|
|
||||||
public String getJavaInitializationString() {
|
public String getJavaInitializationString() {
|
||||||
return "TEST";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public String getAsText() {
|
public String getAsText() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setAsText(String text) throws IllegalArgumentException {
|
public void setAsText(String text) throws IllegalArgumentException {
|
||||||
throw new IllegalArgumentException(text);
|
throw new IllegalArgumentException(text);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public String[] getTags() {
|
public String[] getTags() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||||
m_Support.addPropertyChangeListener(l);
|
m_Support.addPropertyChangeListener(l);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||||
m_Support.removePropertyChangeListener(l);
|
m_Support.removePropertyChangeListener(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true since the Object can be shown
|
/** Returns true since the Object can be shown
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
@ -170,7 +164,9 @@ public abstract class AbstractListSelectionEditor extends JPanel implements Prop
|
|||||||
String rep = "Select from list";
|
String rep = "Select from list";
|
||||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||||
}
|
}
|
||||||
/** Returns true because we do support a custom editor.
|
|
||||||
|
/**
|
||||||
|
* Returns true because we do support a custom editor.
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
public boolean supportsCustomEditor() {
|
public boolean supportsCustomEditor() {
|
||||||
|
@ -326,6 +326,7 @@ public class BeanInspector {
|
|||||||
return meth.invoke(obj, args);
|
return meth.invoke(obj, args);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
System.err.println("Error on calling method "+mName + " on " + obj.getClass().getName());
|
System.err.println("Error on calling method "+mName + " on " + obj.getClass().getName());
|
||||||
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else return null;
|
} else return null;
|
||||||
|
@ -16,7 +16,7 @@ import javax.swing.JFrame;
|
|||||||
*/
|
*/
|
||||||
public class EnumEditor extends PropertyEditorSupport {
|
public class EnumEditor extends PropertyEditorSupport {
|
||||||
/** The Enum values that may be chosen */
|
/** The Enum values that may be chosen */
|
||||||
private Object[] values = null;
|
private Enum[] enumConstants;
|
||||||
|
|
||||||
public String getAsText() {
|
public String getAsText() {
|
||||||
return getValue().toString();
|
return getValue().toString();
|
||||||
@ -24,29 +24,33 @@ public class EnumEditor extends PropertyEditorSupport {
|
|||||||
|
|
||||||
public void setValue(Object value) {
|
public void setValue(Object value) {
|
||||||
if (value instanceof Enum) {
|
if (value instanceof Enum) {
|
||||||
values = ((Enum)value).getClass().getEnumConstants();
|
enumConstants = ((Enum)value).getClass().getEnumConstants();
|
||||||
|
// enumType = ((Enum)value);
|
||||||
|
super.setValue(value);
|
||||||
|
} else if (value.getClass().isArray() && value.getClass().getComponentType().isEnum() ) {
|
||||||
|
// values = value.getClass().getComponentType().getEnumConstants();
|
||||||
|
Enum<?>[] e = (Enum[])(value);
|
||||||
|
enumConstants =(Enum[]) e.getClass().getComponentType().getEnumConstants();
|
||||||
super.setValue(value);
|
super.setValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setAsText(String text) throws IllegalArgumentException {
|
public void setAsText(String text) throws IllegalArgumentException {
|
||||||
for (int i=0; i<values.length; i++) {
|
for (int i=0; i<enumConstants.length; i++) {
|
||||||
if (text.equals(values[i].toString())) {
|
if (text.equals(enumConstants[i].toString())) {
|
||||||
setValue((Enum)values[i]);
|
setValue((Enum)enumConstants[i]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Invalid text for enum");
|
throw new IllegalArgumentException("Invalid text for enum");
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
@Override
|
||||||
*/
|
|
||||||
public String[] getTags() {
|
public String[] getTags() {
|
||||||
String[] tags = new String[values.length];
|
if (getValue()==null) return null;
|
||||||
for (int i=0; i<tags.length; i++) tags[i]=values[i].toString();
|
String[] tags = new String[enumConstants.length];
|
||||||
|
for (int i=0; i<tags.length; i++) tags[i]=enumConstants[i].toString();
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
445
src/eva2/gui/GOEPanel.java
Normal file
445
src/eva2/gui/GOEPanel.java
Normal file
@ -0,0 +1,445 @@
|
|||||||
|
package eva2.gui;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.beans.PropertyChangeSupport;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.DefaultComboBoxModel;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import wsi.ra.jproxy.RMIProxyLocal;
|
||||||
|
import eva2.tools.EVAHELP;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GOEPanel extends JPanel implements ItemListener {
|
||||||
|
private Object m_Backup;
|
||||||
|
private PropertyChangeSupport m_Support;
|
||||||
|
private static boolean TRACE = false;
|
||||||
|
|
||||||
|
/** The chooser component */
|
||||||
|
private JComboBox m_ObjectChooser;
|
||||||
|
/** The component that performs classifier customization */
|
||||||
|
private PropertySheetPanel m_ChildPropertySheet;
|
||||||
|
/** The model containing the list of names to select from */
|
||||||
|
private DefaultComboBoxModel m_ObjectNames;
|
||||||
|
/** Open object from disk */
|
||||||
|
private JButton m_OpenBut;
|
||||||
|
/** Save object to disk */
|
||||||
|
private JButton m_SaveBut;
|
||||||
|
/** ok button */
|
||||||
|
public JButton m_okBut;
|
||||||
|
/** cancel button */
|
||||||
|
private JButton m_cancelBut;
|
||||||
|
/** edit source button */
|
||||||
|
// private JButton m_editSourceBut;
|
||||||
|
/** The filechooser for opening and saving object files */
|
||||||
|
private JFileChooser m_FileChooser;
|
||||||
|
/** Creates the GUI editor component */
|
||||||
|
private Vector<String> m_ClassesLongName;
|
||||||
|
private GenericObjectEditor m_goe = null;
|
||||||
|
// private String[] m_ClassesShortName;
|
||||||
|
// private SourceCodeEditor m_SourceCodeEditor;
|
||||||
|
// private PropertyDialog m_SourceCodeEditorFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GOEPanel(Object target, Object backup, PropertyChangeSupport support, GenericObjectEditor goe) {
|
||||||
|
Object m_Object = target;
|
||||||
|
m_Backup = backup;
|
||||||
|
m_Support = support;
|
||||||
|
m_goe = goe;
|
||||||
|
|
||||||
|
//System.out.println("GOEPanel.Constructor !!");
|
||||||
|
if (!(Proxy.isProxyClass(m_Object.getClass()))) m_Backup = copyObject(m_Object);
|
||||||
|
m_ObjectNames = new DefaultComboBoxModel(new String [0]);
|
||||||
|
m_ObjectChooser = new JComboBox(m_ObjectNames);
|
||||||
|
m_ObjectChooser.setEditable(false);
|
||||||
|
m_ChildPropertySheet = new PropertySheetPanel();
|
||||||
|
m_ChildPropertySheet.addPropertyChangeListener(
|
||||||
|
new PropertyChangeListener() {
|
||||||
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
|
m_Support.firePropertyChange("", m_Backup, m_goe.getValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
m_OpenBut = new JButton("Open...");
|
||||||
|
m_OpenBut.setToolTipText("Load a configured object");
|
||||||
|
m_OpenBut.setEnabled(true);
|
||||||
|
m_OpenBut.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Object object = openObject();
|
||||||
|
if (object != null) {
|
||||||
|
// setValue takes care of: Making sure obj is of right type,
|
||||||
|
// and firing property change.
|
||||||
|
m_goe.setValue(object);
|
||||||
|
// Need a second setValue to get property values filled in OK.
|
||||||
|
// Not sure why.
|
||||||
|
m_goe.setValue(object); // <- Hannes ?!?!?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_SaveBut = new JButton("Save...");
|
||||||
|
m_SaveBut.setToolTipText("Save the current configured object");
|
||||||
|
m_SaveBut.setEnabled(true);
|
||||||
|
m_SaveBut.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
saveObject(m_goe.getValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//
|
||||||
|
// m_editSourceBut = new JButton("Edit Source");
|
||||||
|
// m_editSourceBut.setToolTipText("Edit the Source");
|
||||||
|
// m_editSourceBut.setEnabled(false);
|
||||||
|
// m_editSourceBut.addActionListener(new ActionListener() {
|
||||||
|
// public void actionPerformed(ActionEvent e) {
|
||||||
|
// m_editSourceBut.setEnabled(false);
|
||||||
|
// m_SourceCodeEditor = new SourceCodeEditor();
|
||||||
|
// String className = m_Object.getClass().getName();
|
||||||
|
// m_SourceCodeEditor.editSource(EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className));
|
||||||
|
// m_SourceCodeEditorFrame = new PropertyDialog(m_SourceCodeEditor, "test", 50, 50);
|
||||||
|
// m_SourceCodeEditorFrame.pack();
|
||||||
|
// m_SourceCodeEditorFrame.addWindowListener(new WindowAdapter() {
|
||||||
|
// public void windowClosing (WindowEvent e) {
|
||||||
|
// m_SourceCodeEditor = null;
|
||||||
|
// m_editSourceBut.setEnabled(true);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// m_SourceCodeEditor.addPropertyChangeListener(new
|
||||||
|
// PropertyChangeListener() {
|
||||||
|
// public void propertyChange(PropertyChangeEvent evt) {
|
||||||
|
// sourceChanged();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
m_okBut = new JButton("OK");
|
||||||
|
m_okBut.setEnabled(true);
|
||||||
|
m_okBut.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
m_Backup = copyObject(m_goe.getValue());
|
||||||
|
if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) {
|
||||||
|
Window w = (Window) getTopLevelAncestor();
|
||||||
|
w.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_cancelBut = new JButton("Cancel");
|
||||||
|
m_cancelBut.setEnabled(false);
|
||||||
|
m_cancelBut.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (m_Backup != null) {
|
||||||
|
// m_Object = copyObject(m_Backup);
|
||||||
|
// TODO m_goe.setObject(m_Object);
|
||||||
|
m_goe.setValue(copyObject(m_Backup));
|
||||||
|
updateClassType();
|
||||||
|
updateChooser();
|
||||||
|
updateChildPropertySheet();
|
||||||
|
}
|
||||||
|
if ((getTopLevelAncestor() != null)
|
||||||
|
&& (getTopLevelAncestor() instanceof Window)) {
|
||||||
|
Window w = (Window) getTopLevelAncestor();
|
||||||
|
w.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
add(m_ObjectChooser, BorderLayout.NORTH); // important
|
||||||
|
add(m_ChildPropertySheet, BorderLayout.CENTER);
|
||||||
|
// Since we resize to the size of the property sheet, a scrollpane isn't
|
||||||
|
// typically needed
|
||||||
|
// add(new JScrollPane(m_ChildPropertySheet), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel okcButs = new JPanel();
|
||||||
|
okcButs.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||||
|
okcButs.setLayout(new GridLayout(1, 4, 5, 5));
|
||||||
|
okcButs.add(m_OpenBut);
|
||||||
|
okcButs.add(m_SaveBut);
|
||||||
|
okcButs.add(m_okBut);
|
||||||
|
// okcButs.add(m_editSourceBut);
|
||||||
|
//okcButs.add(m_cancelBut);
|
||||||
|
add(okcButs, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
if (m_goe.getClassType() != null) {
|
||||||
|
updateClassType();
|
||||||
|
updateChooser();
|
||||||
|
updateChildPropertySheet();
|
||||||
|
}
|
||||||
|
m_ObjectChooser.addItemListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens an object from a file selected by the user.
|
||||||
|
*
|
||||||
|
* @return the loaded object, or null if the operation was cancelled
|
||||||
|
*/
|
||||||
|
protected Object openObject() {
|
||||||
|
if (m_FileChooser == null) {
|
||||||
|
createFileChooser();
|
||||||
|
}
|
||||||
|
int returnVal = m_FileChooser.showOpenDialog(this);
|
||||||
|
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||||
|
File selected = m_FileChooser.getSelectedFile();
|
||||||
|
try {
|
||||||
|
ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(new FileInputStream(selected)));
|
||||||
|
Object obj = oi.readObject();
|
||||||
|
oi.close();
|
||||||
|
if (!m_goe.getClassType().isAssignableFrom(obj.getClass())) {
|
||||||
|
throw new Exception("Object not of type: " + m_goe.getClassType().getName());
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Couldn't read object: "
|
||||||
|
+ selected.getName()
|
||||||
|
+ "\n" + ex.getMessage(),
|
||||||
|
"Open object file",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Saves the current object to a file selected by the user.
|
||||||
|
* @param object The object to save.
|
||||||
|
*/
|
||||||
|
protected void saveObject(Object object) {
|
||||||
|
|
||||||
|
if (m_FileChooser == null) {
|
||||||
|
createFileChooser();
|
||||||
|
}
|
||||||
|
int returnVal = m_FileChooser.showSaveDialog(this);
|
||||||
|
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||||
|
File sFile = m_FileChooser.getSelectedFile();
|
||||||
|
try {
|
||||||
|
ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(sFile)));
|
||||||
|
oo.writeObject(object);
|
||||||
|
oo.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Couldn't write to file: "
|
||||||
|
+ sFile.getName()
|
||||||
|
+ "\n" + ex.getMessage(),
|
||||||
|
"Save object",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void createFileChooser() {
|
||||||
|
m_FileChooser = new JFileChooser(new File("/resources"));
|
||||||
|
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a copy of an object using serialization
|
||||||
|
* @param source the object to copy
|
||||||
|
* @return a copy of the source object
|
||||||
|
*/
|
||||||
|
protected Object copyObject(Object source) {
|
||||||
|
Object result = null;
|
||||||
|
try {
|
||||||
|
SerializedObject so = new SerializedObject(source);
|
||||||
|
result = so.getObject();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.err.println("GenericObjectEditor: Problem making backup object");
|
||||||
|
System.err.println(source.getClass().getName());
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used to hook an action listener to the ok button
|
||||||
|
* @param a The action listener.
|
||||||
|
*/
|
||||||
|
public void addOkListener(ActionListener a) {
|
||||||
|
m_okBut.addActionListener(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used to hook an action listener to the cancel button
|
||||||
|
* @param a The action listener.
|
||||||
|
*/
|
||||||
|
public void addCancelListener(ActionListener a) {
|
||||||
|
m_cancelBut.addActionListener(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used to remove an action listener from the ok button
|
||||||
|
* @param a The action listener
|
||||||
|
*/
|
||||||
|
public void removeOkListener(ActionListener a) {
|
||||||
|
m_okBut.removeActionListener(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used to remove an action listener from the cancel button
|
||||||
|
* @param a The action listener
|
||||||
|
*/
|
||||||
|
public void removeCancelListener(ActionListener a) {
|
||||||
|
m_cancelBut.removeActionListener(a);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected void updateClassType() {
|
||||||
|
if (TRACE) System.out.println("# updating class "+m_goe.getClassType().getName());
|
||||||
|
|
||||||
|
if (Proxy.isProxyClass(m_goe.getClassType())) {
|
||||||
|
if (TRACE) System.out.println("PROXY! original was " + ((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_goe.getValue()))).getOriginalClass().getName());
|
||||||
|
m_ClassesLongName = new Vector<String>(GenericObjectEditor.getClassesFromProperties(((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_goe.getValue()))).getOriginalClass().getName()));
|
||||||
|
} else {
|
||||||
|
m_ClassesLongName = new Vector<String>(GenericObjectEditor.getClassesFromProperties(m_goe.getClassType().getName()));
|
||||||
|
}
|
||||||
|
m_ObjectChooser.setModel(new DefaultComboBoxModel(m_ClassesLongName));
|
||||||
|
if (m_ClassesLongName.size() > 1) // testhu
|
||||||
|
add(m_ObjectChooser, BorderLayout.NORTH);
|
||||||
|
else
|
||||||
|
remove(m_ObjectChooser);
|
||||||
|
if (TRACE) System.out.println("# done updating class "+m_goe.getClassType().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateChooser() {
|
||||||
|
String objectName = /*EVAHELP.cutClassName*/ (m_goe.getValue().getClass().getName());
|
||||||
|
boolean found = false;
|
||||||
|
for (int i = 0; i < m_ObjectNames.getSize(); i++) {
|
||||||
|
if (TRACE) System.out.println("in updateChooser: looking at "+(String)m_ObjectNames.getElementAt(i));
|
||||||
|
if (objectName.equals((String)m_ObjectNames.getElementAt(i))) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
m_ObjectNames.addElement(objectName);
|
||||||
|
m_ObjectChooser.getModel().setSelectedItem(objectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Updates the child property sheet, and creates if needed */
|
||||||
|
public void updateChildPropertySheet() {
|
||||||
|
//System.err.println("GOE::updateChildPropertySheet()");
|
||||||
|
// Set the object as the target of the propertysheet
|
||||||
|
m_ChildPropertySheet.setTarget(m_goe.getValue());
|
||||||
|
// Adjust size of containing window if possible
|
||||||
|
if ((getTopLevelAncestor() != null)
|
||||||
|
&& (getTopLevelAncestor() instanceof Window)) {
|
||||||
|
((Window) getTopLevelAncestor()).pack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// public void sourceChanged() {
|
||||||
|
//
|
||||||
|
// //System.out.println("SOURCESTATECHANGED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ");
|
||||||
|
// String className = (String) m_ObjectChooser.getSelectedItem();
|
||||||
|
//
|
||||||
|
//// @todohannes: hack! ausbessern
|
||||||
|
// className = (String) m_ObjectChooser.getSelectedItem();
|
||||||
|
// try {
|
||||||
|
// if (m_userdefclasses == true) {
|
||||||
|
// className = m_Object.getClass().getName();
|
||||||
|
// Object[] para = new Object[] {};
|
||||||
|
// Object n = (Object) CompileAndLoad.getInstanceFull(
|
||||||
|
// EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className),
|
||||||
|
// className,
|
||||||
|
// para);
|
||||||
|
// setObject(n);
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// System.out.println("m_userdefclasses == false!!!!!");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// catch (Exception ex) {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the chooser selection is changed, ensures that the Object
|
||||||
|
* is changed appropriately.
|
||||||
|
*
|
||||||
|
* @param e a value of type 'ItemEvent'
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
String className = (String)m_ObjectChooser.getSelectedItem();
|
||||||
|
// m_editSourceBut.setEnabled(false);
|
||||||
|
// @todohannes: hack! ausbessern
|
||||||
|
// try {
|
||||||
|
// if (EvAClient.DYNAMICCLASSES_PROPERTIES.containsKey(className) && m_userdefclasses) {
|
||||||
|
// m_editSourceBut.setEnabled(true);
|
||||||
|
// }
|
||||||
|
// } catch (Exception e1) {
|
||||||
|
// System.out.println("Fehler !!! " + e1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @todohannes: hack! ausbessern
|
||||||
|
//
|
||||||
|
// if (this.m_SourceCodeEditorFrame != null) {
|
||||||
|
// m_SourceCodeEditorFrame.setVisible(false);
|
||||||
|
// m_SourceCodeEditorFrame = null;
|
||||||
|
// m_SourceCodeEditor = null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (TRACE) System.out.println("Event-Quelle: " + e.getSource().toString());
|
||||||
|
if ((e.getSource() == m_ObjectChooser) && (e.getStateChange() == ItemEvent.SELECTED)){
|
||||||
|
className = (String)m_ObjectChooser.getSelectedItem();
|
||||||
|
try {
|
||||||
|
// if (EvAClient.DYNAMICCLASSES_PROPERTIES.containsKey(className) && m_userdefclasses) {
|
||||||
|
// Object[] para = new Object[] {};
|
||||||
|
// String source = EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className);
|
||||||
|
// Object dummy = CompileAndLoad.getInstanceFull(source,className,para);
|
||||||
|
// setObject(dummy);
|
||||||
|
// } else {
|
||||||
|
if (TRACE) System.out.println(className);
|
||||||
|
// Object n = (Object)Class.forName(className, true, this.getClass().getClassLoader()).newInstance();
|
||||||
|
Object n = (Object)Class.forName(className).newInstance();
|
||||||
|
m_goe.setValue(n);
|
||||||
|
// TODO ? setObject(n);
|
||||||
|
// }
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.err.println("Exeption in itemStateChanged "+ex.getMessage());
|
||||||
|
System.err.println("Classpath is " + System.getProperty("java.class.path"));
|
||||||
|
ex.printStackTrace();
|
||||||
|
m_ObjectChooser.hidePopup();
|
||||||
|
m_ObjectChooser.setSelectedIndex(0);
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Could not create an example of\n"
|
||||||
|
+ className + "\n"
|
||||||
|
+ "from the current classpath. Is it abstract? Is the default constructor missing?",
|
||||||
|
"GenericObjectEditor",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
EVAHELP.getSystemPropertyString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // end of inner class
|
||||||
|
|
@ -11,9 +11,9 @@ import eva2.server.go.individuals.codings.gp.GPArea;
|
|||||||
* To change this template use Options | File Templates.
|
* To change this template use Options | File Templates.
|
||||||
*/
|
*/
|
||||||
public class GenericAreaEditor extends AbstractListSelectionEditor {
|
public class GenericAreaEditor extends AbstractListSelectionEditor {
|
||||||
|
|
||||||
/** The GPArea that is to be edited*/
|
/** The GPArea that is to be edited*/
|
||||||
private GPArea m_AreaObject;
|
private GPArea m_AreaObject;
|
||||||
|
|
||||||
public GenericAreaEditor() {
|
public GenericAreaEditor() {
|
||||||
// compiled code
|
// compiled code
|
||||||
}
|
}
|
||||||
@ -30,12 +30,12 @@ public class GenericAreaEditor extends AbstractListSelectionEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isElementAllowed(int i) {
|
protected boolean isElementSelected(int i) {
|
||||||
return ((Boolean)m_AreaObject.getBlackList().get(i)).booleanValue();
|
return ((Boolean)m_AreaObject.getBlackList().get(i)).booleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean performOnAction() {
|
protected boolean actionOnSelect() {
|
||||||
/** This method checks the current BlackList and compiles it
|
/** This method checks the current BlackList and compiles it
|
||||||
* to a new ReducedList.
|
* to a new ReducedList.
|
||||||
*/
|
*/
|
||||||
|
@ -31,6 +31,7 @@ import java.beans.PropertyChangeListener;
|
|||||||
import java.beans.PropertyChangeSupport;
|
import java.beans.PropertyChangeSupport;
|
||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import javax.swing.DefaultListCellRenderer;
|
import javax.swing.DefaultListCellRenderer;
|
||||||
import javax.swing.DefaultListModel;
|
import javax.swing.DefaultListModel;
|
||||||
@ -64,6 +65,8 @@ implements PropertyEditor {
|
|||||||
private DefaultListModel m_ListModel;
|
private DefaultListModel m_ListModel;
|
||||||
/** The property editor for the class we are editing */
|
/** The property editor for the class we are editing */
|
||||||
private PropertyEditor m_ElementEditor;
|
private PropertyEditor m_ElementEditor;
|
||||||
|
/** Cheat to handle selectable lists as well */
|
||||||
|
private PropertySelectableList selectableList = null;
|
||||||
/** Click this to delete the selected array values */
|
/** Click this to delete the selected array values */
|
||||||
private JButton m_DeleteBut = new JButton("Delete");
|
private JButton m_DeleteBut = new JButton("Delete");
|
||||||
/** Click to add the current object configuration to the array */
|
/** Click to add the current object configuration to the array */
|
||||||
@ -84,6 +87,8 @@ implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
m_ElementList.setModel(m_ListModel);
|
m_ElementList.setModel(m_ListModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectableList!=null) selectableList.setObjects(modelToArray(m_ListModel));
|
||||||
m_Support.firePropertyChange("", null, null);
|
m_Support.firePropertyChange("", null, null);
|
||||||
}
|
}
|
||||||
if (m_ElementList.getSelectedIndex() == -1) {
|
if (m_ElementList.getSelectedIndex() == -1) {
|
||||||
@ -103,6 +108,7 @@ implements PropertyEditor {
|
|||||||
m_ListModel.addElement(addObj);
|
m_ListModel.addElement(addObj);
|
||||||
}
|
}
|
||||||
m_ElementList.setModel(m_ListModel);
|
m_ElementList.setModel(m_ListModel);
|
||||||
|
if (selectableList!=null) selectableList.setObjects(modelToArray(m_ListModel));
|
||||||
m_Support.firePropertyChange("", null, null);
|
m_Support.firePropertyChange("", null, null);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
JOptionPane.showMessageDialog(GenericArrayEditor.this,"Could not create an object copy",null,JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(GenericArrayEditor.this,"Could not create an object copy",null,JOptionPane.ERROR_MESSAGE);
|
||||||
@ -111,6 +117,14 @@ implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private Object[] modelToArray(DefaultListModel listModel) {
|
||||||
|
Object[] os= new Object[listModel.size()];
|
||||||
|
for (int i=0; i<listModel.size(); i++) {
|
||||||
|
os[i]=listModel.get(i);
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
/** Listens to list items being selected and takes appropriate action */
|
/** Listens to list items being selected and takes appropriate action */
|
||||||
private ListSelectionListener m_InnerSelectionListener =
|
private ListSelectionListener m_InnerSelectionListener =
|
||||||
new ListSelectionListener() {
|
new ListSelectionListener() {
|
||||||
@ -182,9 +196,12 @@ implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
e.setValue(value);
|
e.setValue(value);
|
||||||
return new JPanel() {
|
return new JPanel() {
|
||||||
/**
|
// return new JCheckBox("", isSelected) {
|
||||||
*
|
// public void paintComponent(Graphics g) {
|
||||||
*/
|
// String name = (String)BeanInspector.callIfAvailable(value, "getName", new Object[]{});
|
||||||
|
// if (name==null) setText(value.getClass().getSimpleName());
|
||||||
|
// else setText(name);
|
||||||
|
// super.paintComponent(g);
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
Insets i = this.getInsets();
|
Insets i = this.getInsets();
|
||||||
Rectangle box = new Rectangle(i.left,i.top,
|
Rectangle box = new Rectangle(i.left,i.top,
|
||||||
@ -195,20 +212,7 @@ implements PropertyEditor {
|
|||||||
g.setColor(isSelected ? list.getSelectionForeground(): list.getForeground());
|
g.setColor(isSelected ? list.getSelectionForeground(): list.getForeground());
|
||||||
e.paintValue(g, box);
|
e.paintValue(g, box);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Dimension getPreferredSize() {
|
public Dimension getPreferredSize() {
|
||||||
// Dimension newPref = getPreferredSize();
|
|
||||||
// newPref.height = getFontMetrics(getFont()).getHeight() * 6 / 4; //6 / 4;
|
|
||||||
// newPref.width = newPref.height * 6; //5
|
|
||||||
// setPreferredSize(newPref);
|
|
||||||
|
|
||||||
|
|
||||||
// Font f = this.getFont();
|
|
||||||
// FontMetrics fm = this.getFontMetrics(f);
|
|
||||||
// return new Dimension(0, fm.getHeight());
|
|
||||||
|
|
||||||
Font f = this.getFont();
|
Font f = this.getFont();
|
||||||
FontMetrics fm = this.getFontMetrics(f);
|
FontMetrics fm = this.getFontMetrics(f);
|
||||||
Dimension newPref = new Dimension(0, fm.getHeight());
|
Dimension newPref = new Dimension(0, fm.getHeight());
|
||||||
@ -229,19 +233,26 @@ implements PropertyEditor {
|
|||||||
*
|
*
|
||||||
* @param o a value of type 'Object'
|
* @param o a value of type 'Object'
|
||||||
*/
|
*/
|
||||||
private void updateEditorType(Object o) {
|
private void updateEditorType(Object obj) {
|
||||||
|
|
||||||
// Determine if the current object is an array
|
// Determine if the current object is an array
|
||||||
m_ElementEditor = null; m_ListModel = null;
|
m_ElementEditor = null; m_ListModel = null;
|
||||||
removeAll();
|
removeAll();
|
||||||
|
|
||||||
if ((o != null) && (o.getClass().isArray())) {
|
if ((obj != null) && (obj.getClass().isArray() || (obj instanceof PropertySelectableList))) {
|
||||||
Class elementClass = o.getClass().getComponentType();
|
Object arrayInstance = obj;
|
||||||
|
if (!(obj.getClass().isArray())) {
|
||||||
|
arrayInstance=((PropertySelectableList)obj).getObjects();
|
||||||
|
selectableList = (PropertySelectableList)obj;
|
||||||
|
} else selectableList = null;
|
||||||
|
Class elementClass = arrayInstance.getClass().getComponentType();
|
||||||
PropertyEditor editor = PropertyEditorProvider.findEditor(elementClass);
|
PropertyEditor editor = PropertyEditorProvider.findEditor(elementClass);
|
||||||
|
if (editor instanceof EnumEditor) editor.setValue(obj);
|
||||||
Component view = null;
|
Component view = null;
|
||||||
ListCellRenderer lcr = new DefaultListCellRenderer();
|
ListCellRenderer lcr = new DefaultListCellRenderer();
|
||||||
if (editor != null) {
|
if (editor != null) {
|
||||||
if (editor instanceof GenericObjectEditor) {
|
if (editor instanceof GenericObjectEditor) {
|
||||||
|
// ((GenericObjectEditor) editor).getCustomEditor();
|
||||||
((GenericObjectEditor) editor).setClassType(elementClass);
|
((GenericObjectEditor) editor).setClassType(elementClass);
|
||||||
}
|
}
|
||||||
if (editor.isPaintable() && editor.supportsCustomEditor()) {
|
if (editor.isPaintable() && editor.supportsCustomEditor()) {
|
||||||
@ -262,8 +273,8 @@ implements PropertyEditor {
|
|||||||
// Create the ListModel and populate it
|
// Create the ListModel and populate it
|
||||||
m_ListModel = new DefaultListModel();
|
m_ListModel = new DefaultListModel();
|
||||||
m_ElementClass = elementClass;
|
m_ElementClass = elementClass;
|
||||||
for (int i = 0; i < Array.getLength(o); i++) {
|
for (int i = 0; i < Array.getLength(arrayInstance); i++) {
|
||||||
m_ListModel.addElement(Array.get(o,i));
|
m_ListModel.addElement(Array.get(arrayInstance,i));
|
||||||
}
|
}
|
||||||
m_ElementList.setCellRenderer(lcr);
|
m_ElementList.setCellRenderer(lcr);
|
||||||
m_ElementList.setModel(m_ListModel);
|
m_ElementList.setModel(m_ListModel);
|
||||||
@ -285,6 +296,7 @@ implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPreferredSize(new Dimension(300,300));
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setLayout(new BorderLayout());
|
panel.setLayout(new BorderLayout());
|
||||||
panel.add(view, BorderLayout.CENTER);
|
panel.add(view, BorderLayout.CENTER);
|
||||||
@ -325,10 +337,12 @@ implements PropertyEditor {
|
|||||||
* @return the current object array
|
* @return the current object array
|
||||||
*/
|
*/
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
|
|
||||||
if (m_ListModel == null) {
|
if (m_ListModel == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (selectableList!=null) {
|
||||||
|
return selectableList;
|
||||||
|
} else {
|
||||||
// Convert the listmodel to an array of strings and return it.
|
// Convert the listmodel to an array of strings and return it.
|
||||||
int length = m_ListModel.getSize();
|
int length = m_ListModel.getSize();
|
||||||
Object result = Array.newInstance(m_ElementClass, length);
|
Object result = Array.newInstance(m_ElementClass, length);
|
||||||
@ -337,6 +351,7 @@ implements PropertyEditor {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supposedly returns an initialization string to create a classifier
|
* Supposedly returns an initialization string to create a classifier
|
||||||
@ -370,7 +385,15 @@ implements PropertyEditor {
|
|||||||
FontMetrics fm = gfx.getFontMetrics();
|
FontMetrics fm = gfx.getFontMetrics();
|
||||||
int vpad = (box.height - fm.getAscent()) / 2;
|
int vpad = (box.height - fm.getAscent()) / 2;
|
||||||
// System.out.println(m_ListModel + " --- " + m_ElementClass);
|
// System.out.println(m_ListModel + " --- " + m_ElementClass);
|
||||||
String rep = m_ListModel.getSize() + " of " + EVAHELP.cutClassName(m_ElementClass.getName());
|
String rep;
|
||||||
|
if (m_ListModel.getSize() == 0) rep="Empty";
|
||||||
|
else {
|
||||||
|
rep = m_ListModel.getSize() + " of " + EVAHELP.cutClassName(m_ElementClass.getName());
|
||||||
|
Object maybeName = BeanInspector.callIfAvailable(m_ListModel.get(0), "getName", new Object[]{});
|
||||||
|
if (maybeName!=null) {
|
||||||
|
rep = rep + " ("+(String)maybeName + "...)";
|
||||||
|
}
|
||||||
|
}
|
||||||
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 );
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -74,405 +74,6 @@ public class GenericObjectEditor implements PropertyEditor {
|
|||||||
private Class<?> m_ClassType;
|
private Class<?> m_ClassType;
|
||||||
private GOEPanel m_EditorComponent;
|
private GOEPanel m_EditorComponent;
|
||||||
private boolean m_Enabled = true;
|
private boolean m_Enabled = true;
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GOEPanel extends JPanel implements ItemListener {
|
|
||||||
/** The chooser component */
|
|
||||||
private JComboBox m_ObjectChooser;
|
|
||||||
/** The component that performs classifier customization */
|
|
||||||
private PropertySheetPanel m_ChildPropertySheet;
|
|
||||||
/** The model containing the list of names to select from */
|
|
||||||
private DefaultComboBoxModel m_ObjectNames;
|
|
||||||
/** Open object from disk */
|
|
||||||
private JButton m_OpenBut;
|
|
||||||
/** Save object to disk */
|
|
||||||
private JButton m_SaveBut;
|
|
||||||
/** ok button */
|
|
||||||
public JButton m_okBut;
|
|
||||||
/** cancel button */
|
|
||||||
private JButton m_cancelBut;
|
|
||||||
/** edit source button */
|
|
||||||
// private JButton m_editSourceBut;
|
|
||||||
/** The filechooser for opening and saving object files */
|
|
||||||
private JFileChooser m_FileChooser;
|
|
||||||
/** Creates the GUI editor component */
|
|
||||||
private Vector<String> m_ClassesLongName;
|
|
||||||
// private String[] m_ClassesShortName;
|
|
||||||
// private SourceCodeEditor m_SourceCodeEditor;
|
|
||||||
// private PropertyDialog m_SourceCodeEditorFrame;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public GOEPanel() {
|
|
||||||
//System.out.println("GOEPanel.Constructor !!");
|
|
||||||
if (!(Proxy.isProxyClass(m_Object.getClass()))) m_Backup = copyObject(m_Object);
|
|
||||||
m_ObjectNames = new DefaultComboBoxModel(new String [0]);
|
|
||||||
m_ObjectChooser = new JComboBox(m_ObjectNames);
|
|
||||||
m_ObjectChooser.setEditable(false);
|
|
||||||
m_ChildPropertySheet = new PropertySheetPanel();
|
|
||||||
m_ChildPropertySheet.addPropertyChangeListener(
|
|
||||||
new PropertyChangeListener() {
|
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
|
||||||
m_Support.firePropertyChange("", m_Backup, m_Object);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
m_OpenBut = new JButton("Open...");
|
|
||||||
m_OpenBut.setToolTipText("Load a configured object");
|
|
||||||
m_OpenBut.setEnabled(true);
|
|
||||||
m_OpenBut.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Object object = openObject();
|
|
||||||
if (object != null) {
|
|
||||||
// setValue takes care of: Making sure obj is of right type,
|
|
||||||
// and firing property change.
|
|
||||||
setValue(object);
|
|
||||||
// Need a second setValue to get property values filled in OK.
|
|
||||||
// Not sure why.
|
|
||||||
setValue(object); // <- Hannes ?!?!?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_SaveBut = new JButton("Save...");
|
|
||||||
m_SaveBut.setToolTipText("Save the current configured object");
|
|
||||||
m_SaveBut.setEnabled(true);
|
|
||||||
m_SaveBut.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
saveObject(m_Object);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//
|
|
||||||
// m_editSourceBut = new JButton("Edit Source");
|
|
||||||
// m_editSourceBut.setToolTipText("Edit the Source");
|
|
||||||
// m_editSourceBut.setEnabled(false);
|
|
||||||
// m_editSourceBut.addActionListener(new ActionListener() {
|
|
||||||
// public void actionPerformed(ActionEvent e) {
|
|
||||||
// m_editSourceBut.setEnabled(false);
|
|
||||||
// m_SourceCodeEditor = new SourceCodeEditor();
|
|
||||||
// String className = m_Object.getClass().getName();
|
|
||||||
// m_SourceCodeEditor.editSource(EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className));
|
|
||||||
// m_SourceCodeEditorFrame = new PropertyDialog(m_SourceCodeEditor, "test", 50, 50);
|
|
||||||
// m_SourceCodeEditorFrame.pack();
|
|
||||||
// m_SourceCodeEditorFrame.addWindowListener(new WindowAdapter() {
|
|
||||||
// public void windowClosing (WindowEvent e) {
|
|
||||||
// m_SourceCodeEditor = null;
|
|
||||||
// m_editSourceBut.setEnabled(true);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// m_SourceCodeEditor.addPropertyChangeListener(new
|
|
||||||
// PropertyChangeListener() {
|
|
||||||
// public void propertyChange(PropertyChangeEvent evt) {
|
|
||||||
// sourceChanged();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
m_okBut = new JButton("OK");
|
|
||||||
m_okBut.setEnabled(true);
|
|
||||||
m_okBut.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
m_Backup = copyObject(m_Object);
|
|
||||||
if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) {
|
|
||||||
Window w = (Window) getTopLevelAncestor();
|
|
||||||
w.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_cancelBut = new JButton("Cancel");
|
|
||||||
m_cancelBut.setEnabled(false);
|
|
||||||
m_cancelBut.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (m_Backup != null) {
|
|
||||||
m_Object = copyObject(m_Backup);
|
|
||||||
setObject(m_Object);
|
|
||||||
updateClassType();
|
|
||||||
updateChooser();
|
|
||||||
updateChildPropertySheet();
|
|
||||||
}
|
|
||||||
if ((getTopLevelAncestor() != null)
|
|
||||||
&& (getTopLevelAncestor() instanceof Window)) {
|
|
||||||
Window w = (Window) getTopLevelAncestor();
|
|
||||||
w.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
add(m_ObjectChooser, BorderLayout.NORTH); // important
|
|
||||||
add(m_ChildPropertySheet, BorderLayout.CENTER);
|
|
||||||
// Since we resize to the size of the property sheet, a scrollpane isn't
|
|
||||||
// typically needed
|
|
||||||
// add(new JScrollPane(m_ChildPropertySheet), BorderLayout.CENTER);
|
|
||||||
|
|
||||||
JPanel okcButs = new JPanel();
|
|
||||||
okcButs.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
|
||||||
okcButs.setLayout(new GridLayout(1, 4, 5, 5));
|
|
||||||
okcButs.add(m_OpenBut);
|
|
||||||
okcButs.add(m_SaveBut);
|
|
||||||
okcButs.add(m_okBut);
|
|
||||||
// okcButs.add(m_editSourceBut);
|
|
||||||
//okcButs.add(m_cancelBut);
|
|
||||||
add(okcButs, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
if (m_ClassType != null) {
|
|
||||||
updateClassType();
|
|
||||||
updateChooser();
|
|
||||||
updateChildPropertySheet();
|
|
||||||
}
|
|
||||||
m_ObjectChooser.addItemListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens an object from a file selected by the user.
|
|
||||||
*
|
|
||||||
* @return the loaded object, or null if the operation was cancelled
|
|
||||||
*/
|
|
||||||
protected Object openObject() {
|
|
||||||
if (m_FileChooser == null) {
|
|
||||||
createFileChooser();
|
|
||||||
}
|
|
||||||
int returnVal = m_FileChooser.showOpenDialog(this);
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
||||||
File selected = m_FileChooser.getSelectedFile();
|
|
||||||
try {
|
|
||||||
ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(new FileInputStream(selected)));
|
|
||||||
Object obj = oi.readObject();
|
|
||||||
oi.close();
|
|
||||||
if (!m_ClassType.isAssignableFrom(obj.getClass())) {
|
|
||||||
throw new Exception("Object not of type: " + m_ClassType.getName());
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
JOptionPane.showMessageDialog(this,
|
|
||||||
"Couldn't read object: "
|
|
||||||
+ selected.getName()
|
|
||||||
+ "\n" + ex.getMessage(),
|
|
||||||
"Open object file",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Saves the current object to a file selected by the user.
|
|
||||||
* @param object The object to save.
|
|
||||||
*/
|
|
||||||
protected void saveObject(Object object) {
|
|
||||||
|
|
||||||
if (m_FileChooser == null) {
|
|
||||||
createFileChooser();
|
|
||||||
}
|
|
||||||
int returnVal = m_FileChooser.showSaveDialog(this);
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
|
||||||
File sFile = m_FileChooser.getSelectedFile();
|
|
||||||
try {
|
|
||||||
ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(sFile)));
|
|
||||||
oo.writeObject(object);
|
|
||||||
oo.close();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
JOptionPane.showMessageDialog(this,
|
|
||||||
"Couldn't write to file: "
|
|
||||||
+ sFile.getName()
|
|
||||||
+ "\n" + ex.getMessage(),
|
|
||||||
"Save object",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected void createFileChooser() {
|
|
||||||
m_FileChooser = new JFileChooser(new File("/resources"));
|
|
||||||
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a copy of an object using serialization
|
|
||||||
* @param source the object to copy
|
|
||||||
* @return a copy of the source object
|
|
||||||
*/
|
|
||||||
protected Object copyObject(Object source) {
|
|
||||||
Object result = null;
|
|
||||||
try {
|
|
||||||
SerializedObject so = new SerializedObject(source);
|
|
||||||
result = so.getObject();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.err.println("GenericObjectEditor: Problem making backup object");
|
|
||||||
System.err.println(source.getClass().getName());
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is used to hook an action listener to the ok button
|
|
||||||
* @param a The action listener.
|
|
||||||
*/
|
|
||||||
public void addOkListener(ActionListener a) {
|
|
||||||
m_okBut.addActionListener(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is used to hook an action listener to the cancel button
|
|
||||||
* @param a The action listener.
|
|
||||||
*/
|
|
||||||
public void addCancelListener(ActionListener a) {
|
|
||||||
m_cancelBut.addActionListener(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is used to remove an action listener from the ok button
|
|
||||||
* @param a The action listener
|
|
||||||
*/
|
|
||||||
public void removeOkListener(ActionListener a) {
|
|
||||||
m_okBut.removeActionListener(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is used to remove an action listener from the cancel button
|
|
||||||
* @param a The action listener
|
|
||||||
*/
|
|
||||||
public void removeCancelListener(ActionListener a) {
|
|
||||||
m_cancelBut.removeActionListener(a);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected void updateClassType() {
|
|
||||||
if (TRACE) System.out.println("# updating class "+m_ClassType.getName());
|
|
||||||
|
|
||||||
if (Proxy.isProxyClass(m_ClassType)) {
|
|
||||||
if (TRACE) System.out.println("PROXY! original was " + ((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName());
|
|
||||||
m_ClassesLongName = new Vector<String>(getClassesFromProperties(((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName()));
|
|
||||||
} else {
|
|
||||||
m_ClassesLongName = new Vector<String>(getClassesFromProperties(m_ClassType.getName()));
|
|
||||||
}
|
|
||||||
m_ObjectChooser.setModel(new DefaultComboBoxModel(m_ClassesLongName));
|
|
||||||
if (m_ClassesLongName.size() > 1) // testhu
|
|
||||||
add(m_ObjectChooser, BorderLayout.NORTH);
|
|
||||||
else
|
|
||||||
remove(m_ObjectChooser);
|
|
||||||
if (TRACE) System.out.println("# done updating class "+m_ClassType.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateChooser() {
|
|
||||||
String objectName = /*EVAHELP.cutClassName*/ (m_Object.getClass().getName());
|
|
||||||
boolean found = false;
|
|
||||||
for (int i = 0; i < m_ObjectNames.getSize(); i++) {
|
|
||||||
if (TRACE) System.out.println("in updateChooser: looking at "+(String)m_ObjectNames.getElementAt(i));
|
|
||||||
if (objectName.equals((String)m_ObjectNames.getElementAt(i))) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
m_ObjectNames.addElement(objectName);
|
|
||||||
m_ObjectChooser.getModel().setSelectedItem(objectName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Updates the child property sheet, and creates if needed */
|
|
||||||
public void updateChildPropertySheet() {
|
|
||||||
//System.err.println("GOE::updateChildPropertySheet()");
|
|
||||||
// Set the object as the target of the propertysheet
|
|
||||||
m_ChildPropertySheet.setTarget(m_Object);
|
|
||||||
// Adjust size of containing window if possible
|
|
||||||
if ((getTopLevelAncestor() != null)
|
|
||||||
&& (getTopLevelAncestor() instanceof Window)) {
|
|
||||||
((Window) getTopLevelAncestor()).pack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// public void sourceChanged() {
|
|
||||||
//
|
|
||||||
// //System.out.println("SOURCESTATECHANGED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ");
|
|
||||||
// String className = (String) m_ObjectChooser.getSelectedItem();
|
|
||||||
//
|
|
||||||
//// @todohannes: hack! ausbessern
|
|
||||||
// className = (String) m_ObjectChooser.getSelectedItem();
|
|
||||||
// try {
|
|
||||||
// if (m_userdefclasses == true) {
|
|
||||||
// className = m_Object.getClass().getName();
|
|
||||||
// Object[] para = new Object[] {};
|
|
||||||
// Object n = (Object) CompileAndLoad.getInstanceFull(
|
|
||||||
// EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className),
|
|
||||||
// className,
|
|
||||||
// para);
|
|
||||||
// setObject(n);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// System.out.println("m_userdefclasses == false!!!!!");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (Exception ex) {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When the chooser selection is changed, ensures that the Object
|
|
||||||
* is changed appropriately.
|
|
||||||
*
|
|
||||||
* @param e a value of type 'ItemEvent'
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void itemStateChanged(ItemEvent e) {
|
|
||||||
String className = (String)m_ObjectChooser.getSelectedItem();
|
|
||||||
// m_editSourceBut.setEnabled(false);
|
|
||||||
// @todohannes: hack! ausbessern
|
|
||||||
// try {
|
|
||||||
// if (EvAClient.DYNAMICCLASSES_PROPERTIES.containsKey(className) && m_userdefclasses) {
|
|
||||||
// m_editSourceBut.setEnabled(true);
|
|
||||||
// }
|
|
||||||
// } catch (Exception e1) {
|
|
||||||
// System.out.println("Fehler !!! " + e1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @todohannes: hack! ausbessern
|
|
||||||
//
|
|
||||||
// if (this.m_SourceCodeEditorFrame != null) {
|
|
||||||
// m_SourceCodeEditorFrame.setVisible(false);
|
|
||||||
// m_SourceCodeEditorFrame = null;
|
|
||||||
// m_SourceCodeEditor = null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (TRACE) System.out.println("Event-Quelle: " + e.getSource().toString());
|
|
||||||
if ((e.getSource() == m_ObjectChooser) && (e.getStateChange() == ItemEvent.SELECTED)){
|
|
||||||
className = (String)m_ObjectChooser.getSelectedItem();
|
|
||||||
try {
|
|
||||||
// if (EvAClient.DYNAMICCLASSES_PROPERTIES.containsKey(className) && m_userdefclasses) {
|
|
||||||
// Object[] para = new Object[] {};
|
|
||||||
// String source = EvAClient.DYNAMICCLASSES_PROPERTIES.getProperty(className);
|
|
||||||
// Object dummy = CompileAndLoad.getInstanceFull(source,className,para);
|
|
||||||
// setObject(dummy);
|
|
||||||
// } else {
|
|
||||||
if (TRACE) System.out.println(className);
|
|
||||||
// Object n = (Object)Class.forName(className, true, this.getClass().getClassLoader()).newInstance();
|
|
||||||
Object n = (Object)Class.forName(className).newInstance();
|
|
||||||
setObject(n);
|
|
||||||
// }
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.err.println("Exeption in itemStateChanged "+ex.getMessage());
|
|
||||||
System.err.println("Classpath is " + System.getProperty("java.class.path"));
|
|
||||||
ex.printStackTrace();
|
|
||||||
m_ObjectChooser.hidePopup();
|
|
||||||
m_ObjectChooser.setSelectedIndex(0);
|
|
||||||
JOptionPane.showMessageDialog(this,
|
|
||||||
"Could not create an example of\n"
|
|
||||||
+ className + "\n"
|
|
||||||
+ "from the current classpath. Is it abstract? Is the default constructor missing?",
|
|
||||||
"GenericObjectEditor",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
EVAHELP.getSystemPropertyString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // end of inner class
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the classes available for user selection from the properties or the classpath respectively
|
* Read the classes available for user selection from the properties or the classpath respectively
|
||||||
@ -677,6 +278,10 @@ public class GenericObjectEditor implements PropertyEditor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Class<?> getClassType() {
|
||||||
|
return m_ClassType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current object to be the default, taken as the first item in
|
* Sets the current object to be the default, taken as the first item in
|
||||||
* the chooser
|
* the chooser
|
||||||
@ -807,7 +412,7 @@ public class GenericObjectEditor implements PropertyEditor {
|
|||||||
if (methods[i].getName().equalsIgnoreCase("getName")) getNameMethod = i;
|
if (methods[i].getName().equalsIgnoreCase("getName")) getNameMethod = i;
|
||||||
}
|
}
|
||||||
} catch (IntrospectionException ex) {
|
} catch (IntrospectionException ex) {
|
||||||
System.out.println("PropertySheetPanel.setTarget(): Couldn't introspect");
|
System.err.println("PropertySheetPanel.setTarget(): Couldn't introspect");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (getNameMethod >= 0) {
|
if (getNameMethod >= 0) {
|
||||||
@ -878,7 +483,7 @@ public class GenericObjectEditor implements PropertyEditor {
|
|||||||
*/
|
*/
|
||||||
public Component getCustomEditor() {
|
public Component getCustomEditor() {
|
||||||
if (m_EditorComponent == null)
|
if (m_EditorComponent == null)
|
||||||
m_EditorComponent = new GOEPanel();
|
m_EditorComponent = new GOEPanel(m_Object, m_Backup, m_Support, this);
|
||||||
return m_EditorComponent;
|
return m_EditorComponent;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -886,7 +491,7 @@ public class GenericObjectEditor implements PropertyEditor {
|
|||||||
*/
|
*/
|
||||||
public void disableOK() {
|
public void disableOK() {
|
||||||
if (m_EditorComponent == null)
|
if (m_EditorComponent == null)
|
||||||
m_EditorComponent = new GOEPanel();
|
m_EditorComponent = new GOEPanel(m_Object, m_Backup, m_Support, this);
|
||||||
m_EditorComponent.m_okBut.setEnabled(false);
|
m_EditorComponent.m_okBut.setEnabled(false);
|
||||||
}
|
}
|
||||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||||
|
@ -7,9 +7,7 @@ package eva2.gui;
|
|||||||
public class GenericObjectListSelectionEditor extends AbstractListSelectionEditor {
|
public class GenericObjectListSelectionEditor extends AbstractListSelectionEditor {
|
||||||
private PropertySelectableList objList;
|
private PropertySelectableList objList;
|
||||||
|
|
||||||
public GenericObjectListSelectionEditor() {
|
public GenericObjectListSelectionEditor() {}
|
||||||
// compiled code
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getElementCount() {
|
protected int getElementCount() {
|
||||||
@ -22,12 +20,12 @@ public class GenericObjectListSelectionEditor extends AbstractListSelectionEdito
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isElementAllowed(int i) {
|
protected boolean isElementSelected(int i) {
|
||||||
return objList.isSelected(i);
|
return objList.isSelected(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean performOnAction() {
|
protected boolean actionOnSelect() {
|
||||||
boolean changed=false;
|
boolean changed=false;
|
||||||
for (int i = 0; i < this.m_BlackCheck.length; i++) {
|
for (int i = 0; i < this.m_BlackCheck.length; i++) {
|
||||||
if (objList.isSelected(i)!=this.m_BlackCheck[i].isSelected()) {
|
if (objList.isSelected(i)!=this.m_BlackCheck[i].isSelected()) {
|
||||||
|
83
src/eva2/gui/GenericSelectableArrayEditor.java
Normal file
83
src/eva2/gui/GenericSelectableArrayEditor.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package eva2.gui;
|
||||||
|
/*
|
||||||
|
* Title: EvA2
|
||||||
|
* Description:
|
||||||
|
* Copyright: Copyright (c) 2003
|
||||||
|
* Company: University of Tuebingen, Computer Architecture
|
||||||
|
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||||
|
* @version: $Revision: 235 $
|
||||||
|
* $Date: 2007-11-08 13:53:51 +0100 (Thu, 08 Nov 2007) $
|
||||||
|
* $Author: mkron $
|
||||||
|
*/
|
||||||
|
/*==========================================================================*
|
||||||
|
* IMPORTS
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.beans.PropertyChangeSupport;
|
||||||
|
import java.beans.PropertyEditor;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
|
import javax.swing.DefaultListCellRenderer;
|
||||||
|
import javax.swing.DefaultListModel;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.ListCellRenderer;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
|
import eva2.tools.EVAHELP;
|
||||||
|
import eva2.tools.SelectedTag;
|
||||||
|
/*==========================================================================*
|
||||||
|
* CLASS DECLARATION
|
||||||
|
*==========================================================================*/
|
||||||
|
public class GenericSelectableArrayEditor extends GenericArrayEditor {
|
||||||
|
protected JCheckBox[] m_BlackCheck;
|
||||||
|
|
||||||
|
public static void main(String [] args) {
|
||||||
|
try {
|
||||||
|
java.beans.PropertyEditorManager.registerEditor(SelectedTag.class,TagEditor.class);
|
||||||
|
java.beans.PropertyEditorManager.registerEditor(int [].class,GenericArrayEditor.class);
|
||||||
|
java.beans.PropertyEditorManager.registerEditor(double [].class,GenericArrayEditor.class);
|
||||||
|
GenericArrayEditor editor = new GenericArrayEditor();
|
||||||
|
|
||||||
|
|
||||||
|
int[] initial = { 3,45, 7};
|
||||||
|
editor.setValue(initial);
|
||||||
|
PropertyDialog pd = new PropertyDialog(editor,EVAHELP.cutClassName(editor.getClass().getName())
|
||||||
|
, 100, 100);
|
||||||
|
pd.setSize(200,200);
|
||||||
|
pd.addWindowListener(new WindowAdapter() {
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
editor.setValue(initial);
|
||||||
|
//ce.validate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.err.println(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ import sun.beans.editors.StringEditor;
|
|||||||
import eva2.server.go.InterfaceTerminator;
|
import eva2.server.go.InterfaceTerminator;
|
||||||
import eva2.server.go.individuals.codings.gp.GPArea;
|
import eva2.server.go.individuals.codings.gp.GPArea;
|
||||||
import eva2.tools.SelectedTag;
|
import eva2.tools.SelectedTag;
|
||||||
|
import eva2.tools.StringSelection;
|
||||||
|
|
||||||
public class PropertyEditorProvider {
|
public class PropertyEditorProvider {
|
||||||
final static boolean TRACE = false;
|
final static boolean TRACE = false;
|
||||||
@ -162,6 +163,7 @@ public class PropertyEditorProvider {
|
|||||||
|
|
||||||
// The Editor for the new GO
|
// The Editor for the new GO
|
||||||
|
|
||||||
|
PropertyEditorManager.registerEditor(StringSelection.class , StringSelectionEditor.class);
|
||||||
// // Traveling Salesman problem
|
// // Traveling Salesman problem
|
||||||
PropertyEditorManager.registerEditor(GPArea.class , GenericAreaEditor.class);
|
PropertyEditorManager.registerEditor(GPArea.class , GenericAreaEditor.class);
|
||||||
PropertyEditorManager.registerEditor(PropertyDoubleArray.class , GenericDoubleArrayEditor.class);
|
PropertyEditorManager.registerEditor(PropertyDoubleArray.class , GenericDoubleArrayEditor.class);
|
||||||
@ -175,6 +177,6 @@ public class PropertyEditorProvider {
|
|||||||
PropertyEditorManager.registerEditor(PropertyOptimizationObjectives.class , GenericOptimizationObjectivesEditor.class);
|
PropertyEditorManager.registerEditor(PropertyOptimizationObjectives.class , GenericOptimizationObjectivesEditor.class);
|
||||||
PropertyEditorManager.registerEditor(PropertyOptimizationObjectivesWithParam.class , GenericOptimizationObjectivesWithParamEditor.class);
|
PropertyEditorManager.registerEditor(PropertyOptimizationObjectivesWithParam.class , GenericOptimizationObjectivesWithParamEditor.class);
|
||||||
PropertyEditorManager.registerEditor(eva2.gui.MultiLineString.class, eva2.gui.MultiLineStringEditor.class);
|
PropertyEditorManager.registerEditor(eva2.gui.MultiLineString.class, eva2.gui.MultiLineStringEditor.class);
|
||||||
PropertyEditorManager.registerEditor(PropertySelectableList.class, GenericObjectListSelectionEditor.class);
|
PropertyEditorManager.registerEditor(PropertySelectableList.class, GenericArrayEditor.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,19 +10,23 @@ import java.beans.PropertyChangeSupport;
|
|||||||
* Time: 15:04:05
|
* Time: 15:04:05
|
||||||
* To change this template use File | Settings | File Templates.
|
* To change this template use File | Settings | File Templates.
|
||||||
*/
|
*/
|
||||||
public class PropertySelectableList implements java.io.Serializable {
|
public class PropertySelectableList<T> implements java.io.Serializable {
|
||||||
|
|
||||||
private Object[] m_Objects;
|
private T[] m_Objects;
|
||||||
private boolean[] m_Selection;
|
private boolean[] m_Selection;
|
||||||
private PropertyChangeSupport m_Support;
|
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
|
||||||
|
|
||||||
public PropertySelectableList() {
|
// public PropertySelectableList() {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
public PropertySelectableList(T[] initial) {
|
||||||
|
m_Objects = initial;
|
||||||
|
m_Selection = new boolean[initial.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropertySelectableList(PropertySelectableList b) {
|
public PropertySelectableList(PropertySelectableList<T> b) {
|
||||||
if (b.m_Objects != null) {
|
if (b.m_Objects != null) {
|
||||||
this.m_Objects = new Object[b.m_Objects.length];
|
this.m_Objects = b.m_Objects.clone();
|
||||||
System.arraycopy(b.m_Objects, 0, this.m_Objects, 0, this.m_Objects.length);
|
|
||||||
}
|
}
|
||||||
if (b.m_Selection != null) {
|
if (b.m_Selection != null) {
|
||||||
this.m_Selection = new boolean[b.m_Selection.length];
|
this.m_Selection = new boolean[b.m_Selection.length];
|
||||||
@ -31,15 +35,16 @@ public class PropertySelectableList implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return (Object) new PropertySelectableList(this);
|
return (Object) new PropertySelectableList<T>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setObjects(Object[] o) {
|
public void setObjects(T[] o) {
|
||||||
this.m_Objects = o;
|
this.m_Objects = o;
|
||||||
this.m_Selection = new boolean[o.length];
|
this.m_Selection = new boolean[o.length];
|
||||||
m_Support.firePropertyChange("PropertySelectableList", null, this);
|
m_Support.firePropertyChange("PropertySelectableList", null, this);
|
||||||
}
|
}
|
||||||
public Object[] getStrings() {
|
|
||||||
|
public T[] getObjects() {
|
||||||
return this.m_Objects;
|
return this.m_Objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +69,7 @@ public class PropertySelectableList implements java.io.Serializable {
|
|||||||
else return m_Objects.length;
|
else return m_Objects.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(int i) {
|
public T get(int i) {
|
||||||
return m_Objects[i];
|
return m_Objects[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +83,27 @@ public class PropertySelectableList implements java.io.Serializable {
|
|||||||
m_Support.firePropertyChange("PropertySelectableList", null, this);
|
m_Support.firePropertyChange("PropertySelectableList", null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Append an object at the end of the list and immediately select it.
|
||||||
|
// * @param o
|
||||||
|
// */
|
||||||
|
// public void addObject(T o) {
|
||||||
|
// if (m_Objects==null) {
|
||||||
|
// m_Objects=(T[]) new Object[]{o};
|
||||||
|
// m_Selection = new boolean[1];
|
||||||
|
// } else {
|
||||||
|
// T[] newOs = (T[])new Object[m_Objects.length+1];
|
||||||
|
// boolean[] newSs = new boolean[m_Selection.length+1];
|
||||||
|
// System.arraycopy(m_Objects, 0, newOs, 0, this.m_Objects.length);
|
||||||
|
// System.arraycopy(m_Selection, 0, newSs, 0, this.m_Selection.length);
|
||||||
|
// newOs[m_Objects.length]=o;
|
||||||
|
// newSs[m_Objects.length]=true;
|
||||||
|
// m_Objects=newOs;
|
||||||
|
// m_Selection=newSs;
|
||||||
|
// }
|
||||||
|
// m_Support.firePropertyChange("PropertySelectableList", null, this);
|
||||||
|
// }
|
||||||
|
|
||||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||||
m_Support.addPropertyChangeListener(l);
|
m_Support.addPropertyChangeListener(l);
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,8 @@ import java.beans.PropertyChangeSupport;
|
|||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
import java.beans.PropertyVetoException;
|
import java.beans.PropertyVetoException;
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@ -46,9 +44,7 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import eva2.gui.GenericObjectEditor.GOEPanel;
|
|
||||||
import eva2.tools.EVAHELP;
|
import eva2.tools.EVAHELP;
|
||||||
import eva2.tools.Mathematics;
|
|
||||||
import eva2.tools.StringTools;
|
import eva2.tools.StringTools;
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* CLASS DECLARATION
|
* CLASS DECLARATION
|
||||||
@ -761,6 +757,8 @@ public class PropertySheetPanel extends JPanel implements PropertyChangeListener
|
|||||||
o = getter.invoke(m_Target, args);
|
o = getter.invoke(m_Target, args);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
o = null;
|
o = null;
|
||||||
|
System.err.println(ex.getMessage());
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
if (TRACE) System.out.println("# cmp " + BeanInspector.toString(o) + "\n# vs. " + BeanInspector.toString(m_Values[i]));
|
if (TRACE) System.out.println("# cmp " + BeanInspector.toString(o) + "\n# vs. " + BeanInspector.toString(m_Values[i]));
|
||||||
if (o == m_Values[i] && (BeanInspector.isJavaPrimitive(o.getClass()))) {
|
if (o == m_Values[i] && (BeanInspector.isJavaPrimitive(o.getClass()))) {
|
||||||
|
76
src/eva2/gui/StringSelectionEditor.java
Normal file
76
src/eva2/gui/StringSelectionEditor.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package eva2.gui;
|
||||||
|
|
||||||
|
import eva2.tools.StringSelection;
|
||||||
|
|
||||||
|
public class StringSelectionEditor extends AbstractListSelectionEditor {
|
||||||
|
StringSelection strs;
|
||||||
|
|
||||||
|
public StringSelectionEditor() {
|
||||||
|
strs = new StringSelection(new String[]{});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean actionOnSelect() {
|
||||||
|
for (int i = 0; i < this.m_BlackCheck.length; i++) {
|
||||||
|
strs.setSelected(i, this.m_BlackCheck[i].isSelected());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getElementCount() {
|
||||||
|
return strs.getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getElementName(int i) {
|
||||||
|
return strs.getElement(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue() {
|
||||||
|
return strs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isElementSelected(int i) {
|
||||||
|
return strs.isSelected(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setObject(Object o) {
|
||||||
|
if (o instanceof StringSelection) {
|
||||||
|
strs = (StringSelection) o;
|
||||||
|
// m_AreaObject.addPropertyChangeListener(this);
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "StringSelection";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAsText() {
|
||||||
|
StringBuffer sbuf = new StringBuffer("{");
|
||||||
|
boolean first = true;
|
||||||
|
for (int i=0; i<getElementCount(); i++) {
|
||||||
|
if (isElementSelected(i)) {
|
||||||
|
if (!first) sbuf.append(", ");
|
||||||
|
sbuf.append(getElementName(i));
|
||||||
|
first=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sbuf.append("}");
|
||||||
|
return sbuf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAsText(String text) throws IllegalArgumentException {
|
||||||
|
for (int i=0; i<getElementCount(); i++) {
|
||||||
|
strs.setSelected(i, text.contains(getElementName(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -442,7 +442,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
|
|||||||
meanFitness = pop.getMeanFitness().clone();
|
meanFitness = pop.getMeanFitness().clone();
|
||||||
currentWorstFit = pop.getWorstIndividual().getFitness().clone();
|
currentWorstFit = pop.getWorstIndividual().getFitness().clone();
|
||||||
functionCalls = pop.getFunctionCalls();
|
functionCalls = pop.getFunctionCalls();
|
||||||
if (m_StatsParams.getPlotData().getSelectedTag().getID() == StatsParameter.PLOT_BEST_AND_MEASURES) {
|
if (GraphSelectionEnum.doPlotAvgDist(m_StatsParams.getGraphSelection())
|
||||||
|
|| GraphSelectionEnum.doPlotMaxPopDist(m_StatsParams.getGraphSelection())) {
|
||||||
double[] measures = pop.getPopulationMeasures();
|
double[] measures = pop.getPopulationMeasures();
|
||||||
if (measures != null) {
|
if (measures != null) {
|
||||||
avgPopDist = measures[0];
|
avgPopDist = measures[0];
|
||||||
|
31
src/eva2/server/stat/GraphSelectionEnum.java
Normal file
31
src/eva2/server/stat/GraphSelectionEnum.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package eva2.server.stat;
|
||||||
|
|
||||||
|
import eva2.tools.StringSelection;
|
||||||
|
|
||||||
|
public enum GraphSelectionEnum {
|
||||||
|
currentBest, currentWorst, runBest, bestFeasible, avgPopDistance, maxPopDistance;
|
||||||
|
|
||||||
|
public static boolean doPlotCurrentBest(StringSelection sel) {
|
||||||
|
return sel.isSelected(GraphSelectionEnum.currentBest.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean doPlotRunBest(StringSelection sel) {
|
||||||
|
return sel.isSelected(GraphSelectionEnum.runBest.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean doPlotWorst(StringSelection sel) {
|
||||||
|
return sel.isSelected(GraphSelectionEnum.currentWorst.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean doPlotBestFeasible(StringSelection sel) {
|
||||||
|
return sel.isSelected(GraphSelectionEnum.bestFeasible.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean doPlotAvgDist(StringSelection sel) {
|
||||||
|
return sel.isSelected(GraphSelectionEnum.avgPopDistance.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean doPlotMaxPopDist(StringSelection sel) {
|
||||||
|
return sel.isSelected(GraphSelectionEnum.maxPopDistance.ordinal());
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@ package eva2.server.stat;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eva2.tools.SelectedTag;
|
import eva2.tools.SelectedTag;
|
||||||
|
import eva2.tools.StringSelection;
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* INTERFACE DECLARATION
|
* INTERFACE DECLARATION
|
||||||
@ -44,8 +45,11 @@ public interface InterfaceStatisticsParameter {
|
|||||||
|
|
||||||
public List<String[]> getPlotDescriptions();
|
public List<String[]> getPlotDescriptions();
|
||||||
|
|
||||||
public SelectedTag getPlotData();
|
// public SelectedTag getPlotData();
|
||||||
public void setPlotData(SelectedTag newMethod);
|
// public void setPlotData(SelectedTag newMethod);
|
||||||
|
|
||||||
|
public StringSelection getGraphSelection();
|
||||||
|
public void setGraphSelection(StringSelection v);
|
||||||
|
|
||||||
public String getResultFilePrefix();
|
public String getResultFilePrefix();
|
||||||
public void SetResultFilePrefix(String x);
|
public void SetResultFilePrefix(String x);
|
||||||
|
@ -32,6 +32,7 @@ import eva2.server.EvAServer;
|
|||||||
import eva2.server.go.PopulationInterface;
|
import eva2.server.go.PopulationInterface;
|
||||||
import eva2.server.go.problems.InterfaceAdditionalPopulationInformer;
|
import eva2.server.go.problems.InterfaceAdditionalPopulationInformer;
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
|
import eva2.tools.StringSelection;
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* CLASS DECLARATION
|
* CLASS DECLARATION
|
||||||
@ -54,6 +55,7 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
|
|||||||
|
|
||||||
private MainAdapterClient m_MainAdapterClient; // the connection to the client MainAdapter
|
private MainAdapterClient m_MainAdapterClient; // the connection to the client MainAdapter
|
||||||
private JTextoutputFrameInterface m_ProxyPrinter;
|
private JTextoutputFrameInterface m_ProxyPrinter;
|
||||||
|
private StringSelection lastGraphSelection;
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
protected static String m_MyHostName = null;
|
protected static String m_MyHostName = null;
|
||||||
@ -103,6 +105,9 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
|
|||||||
public synchronized void startOptPerformed(String infoString, int runNumber, Object goParams) {
|
public synchronized void startOptPerformed(String infoString, int runNumber, Object goParams) {
|
||||||
super.startOptPerformed(infoString, runNumber, goParams);
|
super.startOptPerformed(infoString, runNumber, goParams);
|
||||||
m_GraphInfoString = infoString;
|
m_GraphInfoString = infoString;
|
||||||
|
if (runNumber == 0) {
|
||||||
|
lastGraphSelection = (StringSelection)m_StatsParams.getGraphSelection().clone();
|
||||||
|
}
|
||||||
|
|
||||||
// m_TextCounter = m_StatisticsParameter.GetTextoutput();
|
// m_TextCounter = m_StatisticsParameter.GetTextoutput();
|
||||||
m_PlotCounter = m_StatsParams.GetPlotoutput();
|
m_PlotCounter = m_StatsParams.GetPlotoutput();
|
||||||
@ -151,7 +156,7 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void maybeShowProxyPrinter() {
|
public void maybeShowProxyPrinter() {
|
||||||
if (m_ProxyPrinter != null) m_ProxyPrinter.setShow((m_StatsParams).isShowTextOutput());
|
if (m_ProxyPrinter != null) m_ProxyPrinter.setShow(m_StatsParams.isShowTextOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initPlots(List<String[]> description) {
|
protected void initPlots(List<String[]> description) {
|
||||||
@ -198,11 +203,11 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
|
|||||||
|
|
||||||
private void plotFitnessPoint(int graph, int subGraph, int x, double y) {
|
private void plotFitnessPoint(int graph, int subGraph, int x, double y) {
|
||||||
if (m_FitnessGraph == null) {
|
if (m_FitnessGraph == null) {
|
||||||
EVAERROR.WARNING("fitness graph is null!");
|
EVAERROR.WARNING("fitness graph is null! (StatisticsWithGUI)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (graph >= m_FitnessGraph.length || subGraph >= m_FitnessGraph[graph].length) {
|
if (graph >= m_FitnessGraph.length || subGraph >= m_FitnessGraph[graph].length) {
|
||||||
EVAERROR.WARNING("tried to plot to invalid graph!");
|
EVAERROR.WARNING("tried to plot to invalid graph! (StatisticsWithGUI)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean isValidGraph = m_FitnessFrame[graph].isValid();
|
boolean isValidGraph = m_FitnessFrame[graph].isValid();
|
||||||
@ -219,40 +224,39 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
|
|||||||
// Plots
|
// Plots
|
||||||
m_PlotCounter--;
|
m_PlotCounter--;
|
||||||
|
|
||||||
int fitnessplot_setting = m_StatsParams.getPlotData().getSelectedTag().getID();
|
// int fitnessplot_setting = m_StatsParams.getPlotData().getSelectedTag().getID();
|
||||||
|
|
||||||
if (m_PlotCounter == 0) {
|
if (m_PlotCounter == 0) {
|
||||||
m_PlotCounter = m_StatsParams.GetPlotoutput();
|
m_PlotCounter = m_StatsParams.GetPlotoutput();
|
||||||
boolean doPlotBest = (fitnessplot_setting == StatsParameter.PLOT_BEST)
|
// boolean doPlotBest = (fitnessplot_setting == StatsParameter.PLOT_BEST)
|
||||||
|| (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_WORST)
|
// || (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_WORST)
|
||||||
|| (fitnessplot_setting == StatsParameter.PLOT_CURBEST_AND_RUNBEST)
|
// || (fitnessplot_setting == StatsParameter.PLOT_CURBEST_AND_RUNBEST)
|
||||||
|| (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_MEASURES);
|
// || (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_MEASURES);
|
||||||
boolean doPlotWorst = (fitnessplot_setting == StatsParameter.PLOT_WORST)
|
// boolean doPlotWorst = (fitnessplot_setting == StatsParameter.PLOT_WORST)
|
||||||
|| (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_WORST);
|
// || (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_WORST);
|
||||||
boolean doPlotMeasures = (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_MEASURES);
|
// boolean doPlotMeasures = (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_MEASURES);
|
||||||
boolean doPlotBestFeasible = false;
|
|
||||||
// TODO <-- das hier besser?
|
boolean doPlotCurrentBest = GraphSelectionEnum.doPlotCurrentBest(lastGraphSelection);
|
||||||
// Oder erstmal ganz weg und dafür gesamtergebnis berechnen (textfenster)
|
boolean doPlotRunBest = GraphSelectionEnum.doPlotRunBest(lastGraphSelection);
|
||||||
// ZB: wie oft wurde feasible sol. gefunden (analog convergence counter)
|
boolean doPlotWorst= GraphSelectionEnum.doPlotWorst(lastGraphSelection);
|
||||||
// Durchschnitt: erste feasible sol., fitness der feasible sol...
|
boolean doPlotBestFeasible = GraphSelectionEnum.doPlotBestFeasible(lastGraphSelection);
|
||||||
|
boolean doPlotAvgDist= GraphSelectionEnum.doPlotAvgDist(lastGraphSelection);
|
||||||
|
boolean doPlotMaxPopDist= GraphSelectionEnum.doPlotMaxPopDist(lastGraphSelection);
|
||||||
|
|
||||||
int subGraph=0;
|
int subGraph=0;
|
||||||
if (doPlotBest) {
|
if (doPlotCurrentBest) plotFitnessPoint(0, subGraph++, functionCalls, currentBestFit[0]);
|
||||||
plotFitnessPoint(0, subGraph++, functionCalls, currentBestFit[0]);
|
if (doPlotRunBest) plotFitnessPoint(0, subGraph++, functionCalls, bestRunIndividual.getFitness()[0]);
|
||||||
if (fitnessplot_setting == StatsParameter.PLOT_CURBEST_AND_RUNBEST) plotFitnessPoint(0, subGraph++, functionCalls, bestRunIndividual.getFitness()[0]);
|
|
||||||
}
|
if (doPlotWorst) {// schlechteste Fitness plotten
|
||||||
if (doPlotWorst) {
|
|
||||||
// schlechteste Fitness plotten
|
|
||||||
m_PlotCounter = m_StatsParams.GetPlotoutput();
|
|
||||||
if (currentWorstFit == null) {
|
if (currentWorstFit == null) {
|
||||||
System.err.println("m_WorstFitness==null in plotStatisticsPerformed");
|
System.err.println("m_WorstFitness==null in plotStatisticsPerformed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plotFitnessPoint(0, subGraph++ , functionCalls, currentWorstFit[0]);
|
plotFitnessPoint(0, subGraph++ , functionCalls, currentWorstFit[0]);
|
||||||
}
|
}
|
||||||
if (doPlotMeasures) {
|
if (doPlotAvgDist) plotFitnessPoint(0, subGraph++, functionCalls, avgPopDist);
|
||||||
plotFitnessPoint(0, subGraph++, functionCalls, avgPopDist);
|
if (doPlotMaxPopDist) plotFitnessPoint(0, subGraph++, functionCalls, maxPopDist);
|
||||||
plotFitnessPoint(0, subGraph++, functionCalls, maxPopDist);
|
|
||||||
}
|
|
||||||
if (doPlotBestFeasible && currentBestFeasibleFit!=null) {
|
if (doPlotBestFeasible && currentBestFeasibleFit!=null) {
|
||||||
plotFitnessPoint(0, subGraph++, functionCalls, currentBestFeasibleFit[0]);
|
plotFitnessPoint(0, subGraph++, functionCalls, currentBestFeasibleFit[0]);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import java.util.ArrayList;
|
|||||||
import eva2.gui.GenericObjectEditor;
|
import eva2.gui.GenericObjectEditor;
|
||||||
import eva2.tools.SelectedTag;
|
import eva2.tools.SelectedTag;
|
||||||
import eva2.tools.Serializer;
|
import eva2.tools.Serializer;
|
||||||
|
import eva2.tools.StringSelection;
|
||||||
import eva2.tools.Tag;
|
import eva2.tools.Tag;
|
||||||
|
|
||||||
|
|
||||||
@ -29,18 +30,18 @@ import eva2.tools.Tag;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class StatsParameter implements InterfaceStatisticsParameter, Serializable {
|
public class StatsParameter implements InterfaceStatisticsParameter, Serializable {
|
||||||
public final static int PLOT_BEST = 0;
|
// public final static int PLOT_BEST = 0;
|
||||||
public final static int PLOT_WORST = 1;
|
// public final static int PLOT_WORST = 1;
|
||||||
public final static int PLOT_BEST_AND_WORST = 2;
|
// public final static int PLOT_BEST_AND_WORST = 2;
|
||||||
public final static int PLOT_BEST_AND_MEASURES = 3;
|
// public final static int PLOT_BEST_AND_MEASURES = 3;
|
||||||
public final static int PLOT_CURBEST_AND_RUNBEST = 4;
|
// public final static int PLOT_CURBEST_AND_RUNBEST = 4;
|
||||||
public final static Tag[] TAGS_PLOT_FITNESS = {
|
// public final static Tag[] TAGS_PLOT_FITNESS = {
|
||||||
new Tag(PLOT_BEST, "plot best fitness"),
|
// new Tag(PLOT_BEST, "plot best fitness"),
|
||||||
new Tag(PLOT_WORST, "plot worst fitness"),
|
// new Tag(PLOT_WORST, "plot worst fitness"),
|
||||||
new Tag(PLOT_BEST_AND_WORST, "both best and worst"),
|
// new Tag(PLOT_BEST_AND_WORST, "both best and worst"),
|
||||||
new Tag(PLOT_BEST_AND_MEASURES, "both best and population measures"),
|
// new Tag(PLOT_BEST_AND_MEASURES, "both best and population measures"),
|
||||||
new Tag(PLOT_CURBEST_AND_RUNBEST, "current best and best of run")
|
// new Tag(PLOT_CURBEST_AND_RUNBEST, "current best and best of run")
|
||||||
};
|
// };
|
||||||
|
|
||||||
public final static int VERBOSITY_NONE = 0;
|
public final static int VERBOSITY_NONE = 0;
|
||||||
public final static int VERBOSITY_FINAL = 1;
|
public final static int VERBOSITY_FINAL = 1;
|
||||||
@ -54,7 +55,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
|
|||||||
SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window");
|
SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window");
|
||||||
private int verboK = 10;
|
private int verboK = 10;
|
||||||
|
|
||||||
private int m_PlotFitness = PLOT_BEST;
|
// private int m_PlotFitness = PLOT_BEST;
|
||||||
private int m_Textoutput = 0;
|
private int m_Textoutput = 0;
|
||||||
private int m_Plotoutput = 1;
|
private int m_Plotoutput = 1;
|
||||||
private int m_MultiRuns = 1;
|
private int m_MultiRuns = 1;
|
||||||
@ -65,6 +66,8 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
|
|||||||
private boolean showAdditionalProblemInfo = false;
|
private boolean showAdditionalProblemInfo = false;
|
||||||
private double m_ConvergenceRateThreshold=0.001;
|
private double m_ConvergenceRateThreshold=0.001;
|
||||||
|
|
||||||
|
private StringSelection graphSel = new StringSelection(GraphSelectionEnum.currentBest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -101,24 +104,30 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
|
|||||||
* @return a list of String arrays describing the selected plot options
|
* @return a list of String arrays describing the selected plot options
|
||||||
*/
|
*/
|
||||||
public ArrayList<String[]> getPlotDescriptions() {
|
public ArrayList<String[]> getPlotDescriptions() {
|
||||||
ArrayList<String[]> desc = new ArrayList<String[]>();
|
ArrayList<String> desc = new ArrayList<String>();
|
||||||
switch (getPlotData().getSelectedTagID()) {
|
for (int i=0; i<GraphSelectionEnum.values().length; i++) {
|
||||||
case StatsParameter.PLOT_BEST_AND_WORST:
|
if (graphSel.isSelected(i)) desc.add(graphSel.getElement(i));
|
||||||
desc.add(new String[] {"Best", "Worst"});
|
}
|
||||||
break;
|
ArrayList<String[]> alist = new ArrayList<String[]>();
|
||||||
case StatsParameter.PLOT_BEST:
|
alist.add(desc.toArray(new String[desc.size()]));
|
||||||
desc.add(new String[] {"Best"});
|
return alist;
|
||||||
break;
|
// switch (getPlotData().getSelectedTagID()) {
|
||||||
case StatsParameter.PLOT_WORST:
|
// case StatsParameter.PLOT_BEST_AND_WORST:
|
||||||
desc.add(new String[] {"Worst"});
|
// desc.add(new String[] {"Best", "Worst"});
|
||||||
break;
|
// break;
|
||||||
case StatsParameter.PLOT_BEST_AND_MEASURES:
|
// case StatsParameter.PLOT_BEST:
|
||||||
desc.add(new String[] {"Best", "AvgDist", "MaxDist"});
|
// desc.add(new String[] {"Best"});
|
||||||
break;
|
// break;
|
||||||
case StatsParameter.PLOT_CURBEST_AND_RUNBEST:
|
// case StatsParameter.PLOT_WORST:
|
||||||
desc.add(new String[] {"Cur.Best", "Run Best"});
|
// desc.add(new String[] {"Worst"});
|
||||||
break; }
|
// break;
|
||||||
return desc;
|
// case StatsParameter.PLOT_BEST_AND_MEASURES:
|
||||||
|
// desc.add(new String[] {"Best", "AvgDist", "MaxDist"});
|
||||||
|
// break;
|
||||||
|
// case StatsParameter.PLOT_CURBEST_AND_RUNBEST:
|
||||||
|
// desc.add(new String[] {"Cur.Best", "Run Best"});
|
||||||
|
// break; }
|
||||||
|
// return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,7 +145,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
|
|||||||
m_useStatPlot = Source.m_useStatPlot;
|
m_useStatPlot = Source.m_useStatPlot;
|
||||||
m_Textoutput = Source.m_Textoutput;
|
m_Textoutput = Source.m_Textoutput;
|
||||||
m_Plotoutput = Source.m_Plotoutput;
|
m_Plotoutput = Source.m_Plotoutput;
|
||||||
m_PlotFitness = Source.m_PlotFitness;
|
// m_PlotFitness = Source.m_PlotFitness;
|
||||||
m_MultiRuns = Source.m_MultiRuns;
|
m_MultiRuns = Source.m_MultiRuns;
|
||||||
m_ResultFilePrefix = Source.m_ResultFilePrefix;
|
m_ResultFilePrefix = Source.m_ResultFilePrefix;
|
||||||
verboK = Source.verboK;
|
verboK = Source.verboK;
|
||||||
@ -251,35 +260,6 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
|
|||||||
return "Plotting each fitness graph separate if multiruns > 1.";
|
return "Plotting each fitness graph separate if multiruns > 1.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public SelectedTag getPlotData() {
|
|
||||||
return new SelectedTag(m_PlotFitness, TAGS_PLOT_FITNESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void setPlotData(SelectedTag newMethod) {
|
|
||||||
m_PlotFitness = newMethod.getSelectedTag().getID();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public String plotDataTipText() {
|
|
||||||
return "The data to be plotted: best fitness, worst fitness or average/max distance in population.";
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// *
|
|
||||||
// */
|
|
||||||
// public String plotObjectivesTipText() {
|
|
||||||
// return "The individual of which the objectives are plotted.";
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -413,4 +393,15 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
|
|||||||
return "Set the output destination; to deactivate output, set verbosity to none.";
|
return "Set the output destination; to deactivate output, set verbosity to none.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StringSelection getGraphSelection() {
|
||||||
|
return graphSel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGraphSelection(StringSelection v) {
|
||||||
|
graphSel = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String graphSelectionTipText() {
|
||||||
|
return "Select the graphs to be plotted.";
|
||||||
|
}
|
||||||
}
|
}
|
@ -819,6 +819,18 @@ public class Mathematics {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the given value lies within the interval in every dimension.
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @param range
|
||||||
|
* @return true if the vector lies within the range, else false
|
||||||
|
*/
|
||||||
|
public static boolean isInRange(double v, double lower, double upper) {
|
||||||
|
if (v<lower || (v>upper)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the vector of interval length values in any dimension.
|
* Return the vector of interval length values in any dimension.
|
||||||
* ret[i]=range[i][1]-range[i][0];
|
* ret[i]=range[i][1]-range[i][0];
|
||||||
@ -860,6 +872,21 @@ public class Mathematics {
|
|||||||
return viols;
|
return viols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project the value to the range given.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* @param min
|
||||||
|
* @param max
|
||||||
|
* @return the closest value to v within [min,max]
|
||||||
|
*/
|
||||||
|
public static double projectValue(double v, double min, double max) {
|
||||||
|
if (v<min) {
|
||||||
|
return min;
|
||||||
|
} else if (v>max) {
|
||||||
|
return max;
|
||||||
|
} else return v;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the average length of the range intervals over all dimensions.
|
* Calculate the average length of the range intervals over all dimensions.
|
||||||
|
@ -16,6 +16,10 @@ public class Pair<S, T> implements Serializable {
|
|||||||
public S head;
|
public S head;
|
||||||
public T tail;
|
public T tail;
|
||||||
|
|
||||||
|
public Object clone() {
|
||||||
|
return new Pair<S,T>(head, tail);
|
||||||
|
}
|
||||||
|
|
||||||
public Pair(S head, T tail) {
|
public Pair(S head, T tail) {
|
||||||
this.head = head;
|
this.head = head;
|
||||||
this.tail = tail;
|
this.tail = tail;
|
||||||
|
79
src/eva2/tools/StringSelection.java
Normal file
79
src/eva2/tools/StringSelection.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package eva2.tools;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of Strings that can be selected and deselected. May be created directly from an Enum.
|
||||||
|
*
|
||||||
|
* @author mkron
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StringSelection implements Serializable {
|
||||||
|
private String[] strObjects;
|
||||||
|
boolean[] selStates;
|
||||||
|
|
||||||
|
public StringSelection(String[] sArr) {
|
||||||
|
strObjects = sArr;
|
||||||
|
selStates=new boolean[sArr.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringSelection(String[] sArr, int initialSel) {
|
||||||
|
this(sArr);
|
||||||
|
if (initialSel<getLength()) setSelected(initialSel, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringSelection(Enum<?> e) {
|
||||||
|
strObjects = new String[e.getClass().getEnumConstants().length];
|
||||||
|
selStates = new boolean[strObjects.length];
|
||||||
|
for (int i = 0; i < strObjects.length; i++) {
|
||||||
|
strObjects[i] = e.getClass().getEnumConstants()[i].toString();
|
||||||
|
}
|
||||||
|
setSelected(e.ordinal(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringSelection(StringSelection stringSelection) {
|
||||||
|
strObjects = stringSelection.strObjects.clone();
|
||||||
|
selStates = stringSelection.selStates.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object clone() {
|
||||||
|
return new StringSelection(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return strObjects.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getElement(int i) {
|
||||||
|
return strObjects[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getStrings() {
|
||||||
|
return strObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelected(int i) {
|
||||||
|
return selStates[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given enum is selected (as its string representation)
|
||||||
|
* within the instance.
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isSelected(Enum<?> e) {
|
||||||
|
if (isSelected(e.ordinal())) {
|
||||||
|
return e.toString().equals(strObjects[e.ordinal()]);
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(int i, boolean v) {
|
||||||
|
selStates[i]=v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleSelected(int i) {
|
||||||
|
selStates[i]=!selStates[i];
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user