User Tools

Site Tools


documentation:autoui

Automatic User Interface

Introduction

Capsis is now able to generate automatically the graphical user interface for the model parameters without writing specific java code.

Model parameters are displayed in a simple dialog box. The following type are supported :

  • Integer
  • Float/Double
  • String
  • Filename (String)
  • Enumeration
  • List

The generated dialog supports

  • Label translations.
  • Import/Export parameters from/to xml

Example

A initialization dialog :

import jeeb.lib.util.autoui.annotations.AutoUI;
import jeeb.lib.util.autoui.annotations.Editor;
import jeeb.lib.util.autoui.editors.FilenameEditor;
import capsis.kernel.AbstractSettings;
import capsis.kernel.GModel;
import capsis.kernel.GScene;
import capsis.kernel.InitialParameters;
 
@AutoUI(title="TestAutoUI.initializeScenario", translation="testautoui.Labels")
public class TestAutoUISettings extends AbstractSettings implements InitialParameters {
 
	public static final String SOME_VARIABLE = "defaultValue";
 
	@Editor
	public String someVariable = SOME_VARIABLE;
 
	@Editor(label = "A Filename", editorClass=FilenameEditor.class)
	public String filename;
 
	@Editor(label = "A Double")
	public Double param = 2.2;
 
	@Editor(min=-2, max=2, label = "an Integer")
	public int param2;
 
	public enum MyEnum {
		VAL1, VAL2, VAL3;
	}
 
	@Editor(label = "enumeration")
	public MyEnum e;
 
 
	@Editor(group="group1", label = "Another Double")
	public Double param3;
 
	/** 
	 * Subclass
	 * Diameter class cutting parameters
	 */
	@AutoUI(title="CutClass", translation="testautoui.Labels")
	static public class CutClass {
 
		@Editor
		public String label;
		@Editor
		public double percent;
 
		public CutClass() {}
		public CutClass(String l) {	label = l;	}
		public String toString() { return label + ": " + percent + "%"; }
	}
 
	@Editor(group="Thinning", elementClass=CutClass.class)
	public List<CutClass> cutClasses = new ArrayList<CutClass>();
 
 
 
	////////////////////////////// InitialParameters interface /////////////////////
	transient private GScene initScene;
 
	public void init (GModel model) throws Exception {	}
 
		// Set some other parameters here...
 
	}
 
	public GScene getInitScene () {return initScene;}
 
}

How to use AutoUI

Default Relay

When using default relay, Capsis build automatically initialization and evolution dialogs by using AutoUI annotations.

Specific Relay
class TestAutoUIRelay extends Relay
...
        /** Initialisation */
	public InitialParameters getInitialParameters () {
 
 
		TestAutoUISettings settings = (TestAutoUISettings settings) getModel().getSettings();
		AutoDialog<TestAutoUISettings> dlg = new AutoDialog<TestAutoUISettings>(settings);
		if (!dlg.isValidDialog ()) {
			dlg.dispose ();
			return null;
		}
 
		try {
			settings.init(getModel());
		} catch (Exception e) {
			Log.println (Log.ERROR, "Settings.init ()", e.toString (), e);
			JOptionPane.showMessageDialog (null, Translator.swap ("exceptionDuringInit"),
				Translator.swap ("Shared.warning"), JOptionPane.WARNING_MESSAGE );
			return null;
		}
 
		return settings;
	}
documentation/autoui.txt · Last modified: 2021/12/13 09:28 by 127.0.0.1