Adding an enum editor for the GUI. Merge from MK branch rev. 157
This commit is contained in:
		@@ -4,6 +4,7 @@ package eva2;
 | 
			
		||||
 * Main product and version information strings.
 | 
			
		||||
 * 
 | 
			
		||||
 * --- Changelog
 | 
			
		||||
 * 2.030: Added an EnumEditor to access enums easily through the GUI.
 | 
			
		||||
 * 2.029: Tuned the 2d-graphs which now paints quicker and changes size depending on the
 | 
			
		||||
 * 			surrounding plot window. Added a preloader-thread to accelerate the GUI at starting time.
 | 
			
		||||
 * 2.028: Tuned the Population to sort only when necessary on calls to getBestN... Added StatisticsDummy.
 | 
			
		||||
@@ -29,7 +30,7 @@ package eva2;
 | 
			
		||||
public class EvAInfo {
 | 
			
		||||
	public static final String productName = "EvA 2";
 | 
			
		||||
	public static final String productLongName = "Evolutionary Algorithms Workbench 2";
 | 
			
		||||
	public static final String versionNum = new String ("2.029");
 | 
			
		||||
	public static final String versionNum = new String ("2.030");
 | 
			
		||||
	public static final String url = "http://www.ra.cs.uni-tuebingen.de/software/EvA2";
 | 
			
		||||
 | 
			
		||||
	public static final String propertyFile = "resources/EvA2.props";
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										81
									
								
								src/eva2/gui/EnumEditor.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								src/eva2/gui/EnumEditor.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,81 @@
 | 
			
		||||
package eva2.gui;
 | 
			
		||||
 | 
			
		||||
import java.awt.BorderLayout;
 | 
			
		||||
import java.awt.event.WindowAdapter;
 | 
			
		||||
import java.awt.event.WindowEvent;
 | 
			
		||||
import java.beans.PropertyEditorSupport;
 | 
			
		||||
 | 
			
		||||
import javax.swing.JFrame;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Created by IntelliJ IDEA.
 | 
			
		||||
 * User: streiche
 | 
			
		||||
 * Date: 27.06.2003
 | 
			
		||||
 * Time: 11:41:01
 | 
			
		||||
 * To change this template use Options | File Templates.
 | 
			
		||||
 */
 | 
			
		||||
public class EnumEditor extends PropertyEditorSupport {
 | 
			
		||||
	/** The Enum values that may be chosen */
 | 
			
		||||
	private Object[] 				values = null;
 | 
			
		||||
 | 
			
		||||
	public String getAsText() {
 | 
			
		||||
		return getValue().toString();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setValue(Object value) {
 | 
			
		||||
		if (value instanceof Enum) {
 | 
			
		||||
			values = ((Enum)value).getClass().getEnumConstants();
 | 
			
		||||
			super.setValue(value);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public void setAsText(String text) throws IllegalArgumentException {
 | 
			
		||||
		for (int i=0; i<values.length; i++) {
 | 
			
		||||
			if (text.equals(values[i].toString())) {
 | 
			
		||||
				setValue((Enum)values[i]);
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		throw new IllegalArgumentException("Invalid text for enum");
 | 
			
		||||
	}
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public String[] getTags() {
 | 
			
		||||
		String[] tags = new String[values.length];
 | 
			
		||||
		for (int i=0; i<tags.length; i++) tags[i]=values[i].toString();
 | 
			
		||||
		return tags;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Test the editor.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param args ignored
 | 
			
		||||
	 */
 | 
			
		||||
	public static void main(String [] args) {
 | 
			
		||||
		try {
 | 
			
		||||
			Enum<?> initial = TestEnum.asdf;
 | 
			
		||||
			EnumEditor ed = new EnumEditor();
 | 
			
		||||
			ed.setValue(initial);
 | 
			
		||||
			PropertyValueSelector ps = new PropertyValueSelector(ed);
 | 
			
		||||
			JFrame f = new JFrame();
 | 
			
		||||
			f.addWindowListener(new WindowAdapter() {
 | 
			
		||||
				public void windowClosing(WindowEvent e) {
 | 
			
		||||
					System.exit(0);
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
			f.getContentPane().setLayout(new BorderLayout());
 | 
			
		||||
			f.getContentPane().add(ps, BorderLayout.CENTER);
 | 
			
		||||
			f.pack();
 | 
			
		||||
			f.setVisible(true);
 | 
			
		||||
		} catch (Exception ex) {
 | 
			
		||||
			ex.printStackTrace();
 | 
			
		||||
			System.err.println(ex.getMessage());
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
enum TestEnum { asdf, sdf, asdfa};
 | 
			
		||||
@@ -38,6 +38,7 @@ public class PropertyEditorProvider {
 | 
			
		||||
//		if (TRACE)  System.out.println((editor == null ) ? "No editor from PEM" : ("Found " + editor.getClass()));
 | 
			
		||||
        if ((editor == null) && useDefaultGOE ) {
 | 
			
		||||
        	if (cls.isArray()) editor = new GenericArrayEditor();
 | 
			
		||||
        	else if (cls.isEnum()) editor = new EnumEditor();
 | 
			
		||||
        	else editor = new GenericObjectEditor();
 | 
			
		||||
//        	if (TRACE) System.out.println("using GOE/GAE");
 | 
			
		||||
        }
 | 
			
		||||
@@ -119,6 +120,7 @@ public class PropertyEditorProvider {
 | 
			
		||||
	        if (TRACE)  System.out.println((editor == null ) ? "No editor from PEM by type" : ("Found " + editor.getClass()));
 | 
			
		||||
	        if ((editor == null) && useDefaultGOE ) {
 | 
			
		||||
	        	if (type.isArray()) editor = new GenericArrayEditor();
 | 
			
		||||
	        	else if (type.isEnum()) editor = new EnumEditor();
 | 
			
		||||
	        	else editor = new GenericObjectEditor();
 | 
			
		||||
	        	if (TRACE) System.out.println("using GOE/GAE");
 | 
			
		||||
	        }
 | 
			
		||||
@@ -144,6 +146,7 @@ public class PropertyEditorProvider {
 | 
			
		||||
     */
 | 
			
		||||
    public static void installEditors() {
 | 
			
		||||
        PropertyEditorManager.registerEditor(SelectedTag.class, TagEditor.class);
 | 
			
		||||
        PropertyEditorManager.registerEditor(Enum.class, EnumEditor.class);
 | 
			
		||||
        PropertyEditorManager.registerEditor(int[].class, GenericArrayEditor.class);
 | 
			
		||||
        PropertyEditorManager.registerEditor(double[].class, GenericArrayEditor.class);
 | 
			
		||||
        PropertyEditorManager.registerEditor(InterfaceTerminator[].class, GenericArrayEditor.class);
 | 
			
		||||
 
 | 
			
		||||
@@ -114,11 +114,11 @@ public class TagEditor extends PropertyEditorSupport {
 | 
			
		||||
    try {
 | 
			
		||||
      PropertyEditorManager.registerEditor(SelectedTag.class,TagEditor.class);
 | 
			
		||||
      Tag [] tags =  {
 | 
			
		||||
	new Tag(1, "First option"),
 | 
			
		||||
	new Tag(2, "Second option"),
 | 
			
		||||
	new Tag(3, "Third option"),
 | 
			
		||||
	new Tag(4, "Fourth option"),
 | 
			
		||||
	new Tag(5, "Fifth option"),
 | 
			
		||||
	new Tag(0, "First option"),
 | 
			
		||||
	new Tag(1, "Second option"),
 | 
			
		||||
	new Tag(2, "Third option"),
 | 
			
		||||
	new Tag(3, "Fourth option"),
 | 
			
		||||
	new Tag(4, "Fifth option"),
 | 
			
		||||
      };
 | 
			
		||||
      SelectedTag initial = new SelectedTag(1, tags);
 | 
			
		||||
      TagEditor ce = new TagEditor();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user