diff --git a/src/eva2/gui/GenericStringListEditor.java b/src/eva2/gui/AbstractListSelectionEditor.java similarity index 68% rename from src/eva2/gui/GenericStringListEditor.java rename to src/eva2/gui/AbstractListSelectionEditor.java index 3abce0db..18780003 100644 --- a/src/eva2/gui/GenericStringListEditor.java +++ b/src/eva2/gui/AbstractListSelectionEditor.java @@ -5,65 +5,84 @@ import javax.swing.*; import eva2.server.go.individuals.codings.gp.AbstractGPNode; import eva2.server.go.individuals.codings.gp.GPArea; +import eva2.tools.EVAHELP; +import java.beans.PropertyEditorSupport; import java.beans.PropertyEditor; -import java.beans.PropertyChangeSupport; import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; +import java.lang.reflect.Array; import java.util.ArrayList; /** * Created by IntelliJ IDEA. * User: streiche - * Date: 23.03.2004 - * Time: 15:03:29 - * To change this template use File | Settings | File Templates. + * Date: 27.06.2003 + * Time: 11:41:01 + * To change this template use Options | File Templates. */ -public class GenericStringListEditor implements PropertyEditor { +public abstract class AbstractListSelectionEditor extends JPanel implements PropertyEditor { /** Handles property change notification */ private PropertyChangeSupport m_Support = new PropertyChangeSupport(this); /** The label for when we can't edit that type */ private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER); - /** The GPArea that is to be edited*/ - private PropertyStringList m_List; - + /** The gaphix stuff */ private JPanel m_CustomEditor, m_NodePanel; - private JCheckBox[] m_BlackCheck; + protected JCheckBox[] m_BlackCheck; - public GenericStringListEditor() { - // compiled code + public AbstractListSelectionEditor() { } /** This method will init the CustomEditor Panel */ private void initCustomEditor() { this.m_CustomEditor = new JPanel(); - this.m_CustomEditor.setPreferredSize(new Dimension(200, 200)); this.m_CustomEditor.setLayout(new BorderLayout()); - this.m_CustomEditor.add(new JLabel("Select:"), BorderLayout.NORTH); + this.m_CustomEditor.add(new JLabel("Choose the area:"), BorderLayout.NORTH); this.m_NodePanel = new JPanel(); this.m_CustomEditor.add(new JScrollPane(this.m_NodePanel), BorderLayout.CENTER); this.updateEditor(); } + /** + * Return the number of elements in the list. + * @return + */ + protected abstract int getElementCount(); + + /** + * Get the display name of an element. + * + * @param i + * @return + */ + protected abstract String getElementName(int i); + + /** + * Get the initial selection state of an element. + * + * @param i + * @return + */ + protected abstract boolean isElementAllowed(int i); + /** The object may have changed update the editor. */ private void updateEditor() { if (this.m_NodePanel != null) { - String[] strings = this.m_List.getStrings(); - boolean[] booleans = this.m_List.getSelection(); this.m_NodePanel.removeAll(); - this.m_NodePanel.setLayout(new GridLayout(strings.length, 1)); - this.m_BlackCheck = new JCheckBox[strings.length]; - for (int i = 0; i < strings.length; i++) { - this.m_BlackCheck[i] = new JCheckBox(strings[i], booleans[i]); + this.m_NodePanel.setLayout(new GridLayout(getElementCount(), 1)); + this.m_BlackCheck = new JCheckBox[getElementCount()]; + for (int i = 0; i < getElementCount(); i++) { + this.m_BlackCheck[i] = new JCheckBox(getElementName(i), isElementAllowed(i)); this.m_BlackCheck[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { - makeNodeList(); + performOnAction(); } }); this.m_NodePanel.add(this.m_BlackCheck[i]); @@ -71,31 +90,29 @@ public class GenericStringListEditor implements PropertyEditor { } } - /** This method checks the current BlackList and compiles it - * to a new ReducedList. + /** + * Perform actions when the selection state changes. */ - private void makeNodeList() { - for (int i = 0; i < this.m_BlackCheck.length; i++) { - this.m_List.setSelectionForElement(i, this.m_BlackCheck[i].isSelected()); - } - } + protected abstract void performOnAction(); + /** + * Set the base object, return true on success. + * @param o + * @return + */ + protected abstract boolean setObject(Object o); + /** This method will set the value of object that is to be edited. * @param o an object that must be an array. */ public void setValue(Object o) { - if (o instanceof PropertyStringList) { - this.m_List = (PropertyStringList) o; - this.updateEditor(); - } + if (setObject(o)) updateEditor(); } /** Retruns the current object. * @return the current object */ - public Object getValue() { - return this.m_List; - } + public abstract Object getValue(); public String getJavaInitializationString() { return "TEST"; @@ -146,7 +163,7 @@ public class GenericStringListEditor implements PropertyEditor { public void paintValue(Graphics gfx, Rectangle box) { FontMetrics fm = gfx.getFontMetrics(); int vpad = (box.height - fm.getAscent()) / 2; - String rep = "Select from available Elements"; + String rep = "Select from list"; gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 ); } /** Returns true because we do support a custom editor. diff --git a/src/eva2/gui/GenericAreaEditor.java b/src/eva2/gui/GenericAreaEditor.java index f9ec3c91..5628d029 100644 --- a/src/eva2/gui/GenericAreaEditor.java +++ b/src/eva2/gui/GenericAreaEditor.java @@ -1,21 +1,7 @@ package eva2.gui; - -import javax.swing.*; - import eva2.server.go.individuals.codings.gp.AbstractGPNode; import eva2.server.go.individuals.codings.gp.GPArea; -import eva2.tools.EVAHELP; - -import java.beans.PropertyEditorSupport; -import java.beans.PropertyEditor; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.awt.*; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.lang.reflect.Array; -import java.util.ArrayList; /** * Created by IntelliJ IDEA. @@ -24,75 +10,48 @@ import java.util.ArrayList; * Time: 11:41:01 * To change this template use Options | File Templates. */ -public class GenericAreaEditor extends JPanel implements PropertyEditor { +public class GenericAreaEditor extends AbstractListSelectionEditor { - /** Handles property change notification */ - private PropertyChangeSupport m_Support = new PropertyChangeSupport(this); - /** The label for when we can't edit that type */ - private JLabel m_Label = new JLabel("Can't edit", SwingConstants.CENTER); /** The GPArea that is to be edited*/ private GPArea m_AreaObject; - - /** The gaphix stuff */ - private JPanel m_CustomEditor, m_NodePanel; - private JCheckBox[] m_BlackCheck; - public GenericAreaEditor() { // compiled code } + + @Override + protected int getElementCount() { + return m_AreaObject.getCompleteList().size(); + } - /** This method will init the CustomEditor Panel - */ - private void initCustomEditor() { - this.m_CustomEditor = new JPanel(); - this.m_CustomEditor.setLayout(new BorderLayout()); - this.m_CustomEditor.add(new JLabel("Choose the area:"), BorderLayout.NORTH); - this.m_NodePanel = new JPanel(); - this.m_CustomEditor.add(new JScrollPane(this.m_NodePanel), BorderLayout.CENTER); - this.updateEditor(); - } + @Override + protected String getElementName(int i) { + AbstractGPNode an = (AbstractGPNode)m_AreaObject.getCompleteList().get(i); + return an.getName(); + } - /** The object may have changed update the editor. - */ - private void updateEditor() { - if (this.m_NodePanel != null) { + @Override + protected boolean isElementAllowed(int i) { + return ((Boolean)m_AreaObject.getBlackList().get(i)).booleanValue(); + } - ArrayList GPNodes = this.m_AreaObject.getCompleteList(); - ArrayList Allowed = this.m_AreaObject.getBlackList(); - this.m_NodePanel.removeAll(); - this.m_NodePanel.setLayout(new GridLayout(GPNodes.size(), 1)); - this.m_BlackCheck = new JCheckBox[GPNodes.size()]; - for (int i = 0; i < GPNodes.size(); i++) { - this.m_BlackCheck[i] = new JCheckBox((((AbstractGPNode)GPNodes.get(i))).getName(), ((Boolean)Allowed.get(i)).booleanValue()); - this.m_BlackCheck[i].addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ev) { - makeNodeList(); - } - }); - this.m_NodePanel.add(this.m_BlackCheck[i]); - } - } - } + @Override + protected void performOnAction() { + /** This method checks the current BlackList and compiles it + * to a new ReducedList. + */ + for (int i = 0; i < this.m_BlackCheck.length; i++) { + this.m_AreaObject.setBlackListElement(i, this.m_BlackCheck[i].isSelected()); + } + this.m_AreaObject.compileReducedList(); + } - /** This method checks the current BlackList and compiles it - * to a new ReducedList. - */ - private void makeNodeList() { - for (int i = 0; i < this.m_BlackCheck.length; i++) { - this.m_AreaObject.setBlackListElement(i, this.m_BlackCheck[i].isSelected()); - } - this.m_AreaObject.compileReducedList(); - } - - /** This method will set the value of object that is to be edited. - * @param o an object that must be an array. - */ - public void setValue(Object o) { + @Override + protected boolean setObject(Object o) { if (o instanceof GPArea) { this.m_AreaObject = (GPArea) o; - this.updateEditor(); - } - } + return true; + } else return false; + } /** Retruns the current object. * @return the current object @@ -100,71 +59,4 @@ public class GenericAreaEditor extends JPanel implements PropertyEditor { public Object getValue() { return this.m_AreaObject; } - - public String getJavaInitializationString() { - return "TEST"; - } - - /** - * - */ - public String getAsText() { - return null; - } - /** - * - */ - public void setAsText(String text) throws IllegalArgumentException { - throw new IllegalArgumentException(text); - } - /** - * - */ - public String[] getTags() { - return null; - } - /** - * - */ - public void addPropertyChangeListener(PropertyChangeListener l) { - m_Support.addPropertyChangeListener(l); - } - /** - * - */ - public void removePropertyChangeListener(PropertyChangeListener l) { - m_Support.removePropertyChangeListener(l); - } - /** Returns true since the Object can be shown - * @return true - */ - public boolean isPaintable() { - return true; - } - /** - * Paints a representation of the current classifier. - * - * @param gfx the graphics context to use - * @param box the area we are allowed to paint into - */ - public void paintValue(Graphics gfx, Rectangle box) { - FontMetrics fm = gfx.getFontMetrics(); - int vpad = (box.height - fm.getAscent()) / 2; - String rep = "Select from available GPNodes"; - gfx.drawString(rep, 2, fm.getHeight() + vpad - 3 ); - } - /** Returns true because we do support a custom editor. - * @return true - */ - public boolean supportsCustomEditor() { - return true; - } - - /** Returns the array editing component. - * @return a value of type 'java.awt.Component' - */ - public Component getCustomEditor() { - if (this.m_CustomEditor == null) this.initCustomEditor(); - return m_CustomEditor; - } } \ No newline at end of file diff --git a/src/eva2/gui/GenericObjectListSelectionEditor.java b/src/eva2/gui/GenericObjectListSelectionEditor.java new file mode 100644 index 00000000..65d0a636 --- /dev/null +++ b/src/eva2/gui/GenericObjectListSelectionEditor.java @@ -0,0 +1,50 @@ +package eva2.gui; + +/** + * An editor for a selectable List. + * + */ +public class GenericObjectListSelectionEditor extends AbstractListSelectionEditor { + private PropertySelectableList objList; + + public GenericObjectListSelectionEditor() { + // compiled code + } + + @Override + protected int getElementCount() { + return objList.size(); + } + + @Override + protected String getElementName(int i) { + return objList.get(i).toString(); + } + + @Override + protected boolean isElementAllowed(int i) { + return objList.isSelected(i); + } + + @Override + protected void performOnAction() { + for (int i = 0; i < this.m_BlackCheck.length; i++) { + objList.setSelectionForElement(i, this.m_BlackCheck[i].isSelected()); + } + } + + @Override + protected boolean setObject(Object o) { + if (o instanceof PropertySelectableList) { + this.objList = (PropertySelectableList) o; + return true; + } else return false; + } + + /** Retruns the current object. + * @return the current object + */ + public Object getValue() { + return objList; + } +} \ No newline at end of file diff --git a/src/eva2/gui/GenericStringListSelectionEditor.java b/src/eva2/gui/GenericStringListSelectionEditor.java new file mode 100644 index 00000000..30d55171 --- /dev/null +++ b/src/eva2/gui/GenericStringListSelectionEditor.java @@ -0,0 +1,65 @@ +package eva2.gui; + + +import javax.swing.*; + +import eva2.server.go.individuals.codings.gp.AbstractGPNode; +import eva2.server.go.individuals.codings.gp.GPArea; + +import java.beans.PropertyEditor; +import java.beans.PropertyChangeSupport; +import java.beans.PropertyChangeListener; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.util.ArrayList; + +/** + * TODO this should be redundant with the new GenericObjectListEditor. + * + * Created by IntelliJ IDEA. + * User: streiche + * Date: 23.03.2004 + * Time: 15:03:29 + * To change this template use File | Settings | File Templates. + */ +public class GenericStringListSelectionEditor extends AbstractListSelectionEditor { + private PropertyStringList m_List; + + @Override + protected int getElementCount() { + return m_List.getStrings().length; + } + + @Override + protected String getElementName(int i) { + return m_List.getStrings()[i]; + } + + @Override + protected boolean isElementAllowed(int i) { + return this.m_List.getSelection()[i]; + } + + @Override + protected void performOnAction() { + for (int i = 0; i < this.m_BlackCheck.length; i++) { + this.m_List.setSelectionForElement(i, this.m_BlackCheck[i].isSelected()); + } + } + + @Override + protected boolean setObject(Object o) { + if (o instanceof PropertyStringList) { + this.m_List = (PropertyStringList) o; + return true; + } else return false; + } + + /** Retruns the current object. + * @return the current object + */ + public Object getValue() { + return this.m_List; + } +} \ No newline at end of file diff --git a/src/eva2/gui/PropertyEditorProvider.java b/src/eva2/gui/PropertyEditorProvider.java index 1f7ccc6b..ae7ce298 100644 --- a/src/eva2/gui/PropertyEditorProvider.java +++ b/src/eva2/gui/PropertyEditorProvider.java @@ -1,11 +1,10 @@ package eva2.gui; import java.awt.Color; -import java.beans.BeanInfo; -import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.beans.PropertyEditor; import java.beans.PropertyEditorManager; +import java.util.List; import sun.beans.editors.BoolEditor; import sun.beans.editors.ByteEditor; @@ -170,11 +169,12 @@ public class PropertyEditorProvider { PropertyEditorManager.registerEditor(PropertyEpsilonThreshold.class , GenericEpsilonThresholdEditor.class); PropertyEditorManager.registerEditor(PropertyEpsilonConstraint.class , GenericEpsilonConstraintEditor.class); PropertyEditorManager.registerEditor(PropertyWeightedLPTchebycheff.class, GenericWeigthedLPTchebycheffEditor.class); - PropertyEditorManager.registerEditor(PropertyStringList.class , GenericStringListEditor.class); + PropertyEditorManager.registerEditor(PropertyStringList.class , GenericStringListSelectionEditor.class); PropertyEditorManager.registerEditor(PropertyFilePath.class , GenericFilePathEditor.class); PropertyEditorManager.registerEditor(PropertyRemoteServers.class , GenericRemoteServersEditor.class); PropertyEditorManager.registerEditor(PropertyOptimizationObjectives.class , GenericOptimizationObjectivesEditor.class); PropertyEditorManager.registerEditor(PropertyOptimizationObjectivesWithParam.class , GenericOptimizationObjectivesWithParamEditor.class); PropertyEditorManager.registerEditor(eva2.gui.MultiLineString.class, eva2.gui.MultiLineStringEditor.class); + PropertyEditorManager.registerEditor(PropertySelectableList.class, GenericObjectListSelectionEditor.class); } } diff --git a/src/eva2/gui/PropertySelectableList.java b/src/eva2/gui/PropertySelectableList.java new file mode 100644 index 00000000..be4d794b --- /dev/null +++ b/src/eva2/gui/PropertySelectableList.java @@ -0,0 +1,70 @@ +package eva2.gui; + +/** + * Created by IntelliJ IDEA. + * User: streiche + * Date: 23.03.2004 + * Time: 15:04:05 + * To change this template use File | Settings | File Templates. + */ +public class PropertySelectableList implements java.io.Serializable { + + private Object[] m_Objects; + private boolean[] m_Selection; + + public PropertySelectableList() { + } + + public PropertySelectableList(PropertySelectableList b) { + if (b.m_Objects != null) { + this.m_Objects = new Object[b.m_Objects.length]; + System.arraycopy(b.m_Objects, 0, this.m_Objects, 0, this.m_Objects.length); + } + if (b.m_Selection != null) { + this.m_Selection = new boolean[b.m_Selection.length]; + System.arraycopy(b.m_Selection, 0, this.m_Selection, 0, this.m_Selection.length); + } + } + + public Object clone() { + return (Object) new PropertySelectableList(this); + } + + public void setObjects(Object[] o) { + this.m_Objects = o; + this.m_Selection = new boolean[o.length]; + } + public Object[] getStrings() { + return this.m_Objects; + } + + public void setSelection(boolean[] selection) { + this.m_Selection = selection; + } + + public boolean[] getSelection() { + return this.m_Selection; + } + + public void setSelectionForElement(int index, boolean b) { + this.m_Selection[index] = b; + } + + public int size() { + if (m_Objects == null) return 0; + else return m_Objects.length; + } + + public Object get(int i) { + return m_Objects[i]; + } + + public boolean isSelected(int i) { + return m_Selection[i]; + } + + public void clear() { + m_Objects=null; + m_Selection=null; + } +} diff --git a/src/eva2/gui/PropertySheetPanel.java b/src/eva2/gui/PropertySheetPanel.java index 6b885687..a406175d 100644 --- a/src/eva2/gui/PropertySheetPanel.java +++ b/src/eva2/gui/PropertySheetPanel.java @@ -51,13 +51,7 @@ import eva2.tools.StringTools; * CLASS DECLARATION *==========================================================================*/ /** - * TODO: document those tricks somewhere - * Trick methods: - * String[] getGOEPropertyUpdateLinks() - * void hideHideable() - * void globalInfo() - * Trick statics: - * boolean hideFromGOE + * There are some trick methods interpreted here. Check EvA2Notes.txt. */ public class PropertySheetPanel extends JPanel implements PropertyChangeListener { public final static boolean TRACE = false; diff --git a/src/eva2/gui/TopoPlot.java b/src/eva2/gui/TopoPlot.java index c75d05b2..6ea3f63a 100644 --- a/src/eva2/gui/TopoPlot.java +++ b/src/eva2/gui/TopoPlot.java @@ -16,6 +16,7 @@ import wsi.ra.chart2d.*; import java.awt.*; import eva2.server.go.problems.Interface2DBorderProblem; +import eva2.tools.Mathematics; import wsi.ra.diagram.ColorBarCalculator; @@ -63,23 +64,21 @@ public class TopoPlot extends Plot { * Defines the topology (by setting a specific problem) and draws the topology */ public void setTopology(Interface2DBorderProblem problem) { - double sizeX = java.lang.Math.abs( problem.get2DBorder()[0][1]-problem.get2DBorder()[0][0]); - double sizeY = java.lang.Math.abs( problem.get2DBorder()[1][1]-problem.get2DBorder()[1][0]); - double rx, ry; - double rw = sizeX/gridx; - double rh = sizeY/gridy; + double[][] border = problem.get2DBorder(); + double[] sizeXY=Mathematics.shiftRange(border); + double deltaX = sizeXY[0]/gridx; + double deltaY = sizeXY[1]/gridy; double[] pos = new double[2]; //double fitRange = java.lang.Math.abs(problem.getMinFitness()-problem.getMaxFitness() ); double fitRange = 0, max = -Double.MAX_VALUE, min = Double.MAX_VALUE, tmp; for (int x=0; x max) max = tmp; - } // for y + for (int y=0; y max) max = tmp; + } // for y } // for x fitRange = java.lang.Math.abs(max - min); ColorBarCalculator colorBar = new ColorBarCalculator(colorScale); @@ -87,16 +86,15 @@ public class TopoPlot extends Plot { m_Frame.setVisible(false); for (int x=0; x