Skip to content

Commit

Permalink
Fixes #3400 by introducing the new 'text' statement in parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed May 8, 2022
1 parent 34ec62f commit e02fb9a
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 26 deletions.
11 changes: 10 additions & 1 deletion msi.gama.core/src/msi/gama/kernel/experiment/ExperimentPlan.java
Expand Up @@ -51,6 +51,7 @@
import msi.gama.runtime.GAMA;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaListFactory;
import msi.gama.util.GamaMapFactory;
import msi.gama.util.IList;
import msi.gaml.compilation.IDescriptionValidator;
Expand Down Expand Up @@ -229,6 +230,8 @@ public void validate(final IDescription desc) {
// private ItemList parametersEditors;
protected final Map<String, IParameter> parameters = GamaMapFactory.create();

protected final List<TextStatement> texts = GamaListFactory.create();

/** The explorable parameters. */
protected final Map<String, IParameter.Batch> explorableParameters = GamaMapFactory.create();

Expand Down Expand Up @@ -408,6 +411,7 @@ public void dispose() {
experimentOutputs = null;
}
parameters.clear();
texts.clear();
GAMA.releaseScope(myScope);
// FIXME Should be put somewhere around here, but probably not here
// exactly.
Expand Down Expand Up @@ -490,7 +494,9 @@ public void setChildren(final Iterable<? extends ISymbol> children) {
BatchOutput fileOutputDescription = null;
LayoutStatement layout = null;
for (final ISymbol s : children) {
if (s instanceof LayoutStatement) {
if (s instanceof TextStatement) {
texts.add((TextStatement) s);
} else if (s instanceof LayoutStatement) {
layout = (LayoutStatement) s;
} else if (s instanceof IExploration) {
exploration = (IExploration) s;
Expand Down Expand Up @@ -567,6 +573,7 @@ public synchronized void open(final Double seed) {
.informStatus(isTest() ? "Tests ready. Click run to begin." : " Batch ready. Click run to begin.");
getGui().updateExperimentState(scope);
}

}

@Override
Expand Down Expand Up @@ -735,6 +742,8 @@ protected IParameter.Batch checkGetParameter(final String parameterName) throws
@Override
public Map<String, IParameter> getParameters() { return parameters; }

public List<TextStatement> getTexts() { return texts; }

@Override
public SimulationAgent getCurrentSimulation() {
if (agent == null) return null;
Expand Down
Expand Up @@ -10,6 +10,7 @@
********************************************************************************************************/
package msi.gama.kernel.experiment;

import java.util.List;
import java.util.Map;

import msi.gama.kernel.batch.IExploration;
Expand Down Expand Up @@ -272,4 +273,6 @@ public interface IExperimentPlan extends ISpecies {
*/
boolean shouldBeBenchmarked();

List<TextStatement> getTexts();

}
130 changes: 130 additions & 0 deletions msi.gama.core/src/msi/gama/kernel/experiment/TextStatement.java
@@ -0,0 +1,130 @@
/*******************************************************************************************************
*
* WriteStatement.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package msi.gama.kernel.experiment;

import static msi.gama.common.interfaces.IKeyword.FONT;

import java.awt.Color;

import msi.gama.common.interfaces.IKeyword;
import msi.gama.precompiler.GamlAnnotations.doc;
import msi.gama.precompiler.GamlAnnotations.facet;
import msi.gama.precompiler.GamlAnnotations.facets;
import msi.gama.precompiler.GamlAnnotations.inside;
import msi.gama.precompiler.GamlAnnotations.symbol;
import msi.gama.precompiler.IConcept;
import msi.gama.precompiler.ISymbolKind;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaColor;
import msi.gama.util.GamaFont;
import msi.gaml.descriptions.IDescription;
import msi.gaml.expressions.IExpression;
import msi.gaml.operators.Cast;
import msi.gaml.statements.AbstractStatement;
import msi.gaml.types.GamaFontType;
import msi.gaml.types.IType;

/**
* Written by drogoul Modified on 6 févr. 2010
*
* @todo Description
*
*/

@symbol (
name = IKeyword.TEXT,
kind = ISymbolKind.SINGLE_STATEMENT,
with_sequence = false,
concept = { IConcept.GUI, IConcept.PARAMETER, IConcept.TEXT })
@inside (
kinds = { ISymbolKind.EXPERIMENT })
@facets (
value = { @facet (
name = IKeyword.COLOR,
type = IType.COLOR,
optional = true,
doc = @doc ("The color with wich the text will be displayed")),
@facet (
name = FONT,
type = { IType.FONT, IType.STRING },
optional = true,
doc = @doc ("the font used to draw the text, if any. Applying this facet to geometries or images has no effect. You can construct here your font with the operator \"font\". ex : font:font(\"Helvetica\", 20 , #plain)")),
@facet (
name = IKeyword.CATEGORY,
type = IType.LABEL,
optional = true,
doc = @doc ("a category label, used to group parameters in the interface")),
@facet (
name = IKeyword.MESSAGE,
type = IType.NONE,
optional = false,
doc = @doc ("the text to display.")), },
omissible = IKeyword.MESSAGE)
@doc (
value = "The statement makes an experiment display text in the parameters view.")
public class TextStatement extends AbstractStatement implements IExperimentDisplayable {

public TextStatement(final IDescription desc) {
super(desc);
message = getFacet(IKeyword.MESSAGE);
color = getFacet(IKeyword.COLOR);
category = getFacet(IKeyword.CATEGORY);
font = getFacet(IKeyword.FONT);
}

/** The message. */
final IExpression message;

/** The color. */
final IExpression color, category, font;

@Override
public Object privateExecuteIn(final IScope scope) throws GamaRuntimeException {
return null;
}

public String getText(final IScope scope) {
return Cast.asString(scope, message.value(scope));
}

public GamaFont getFont(final IScope scope) {
if (font == null) return null;
return GamaFontType.staticCast(scope, font.value(scope), false);
}

public Color getColor(final IScope scope) {
GamaColor rgb = null;
if (color != null) { rgb = Cast.asColor(scope, color.value(scope)); }
return rgb;
}

@Override
public String getTitle() { return ""; }

@Override
public String getUnitLabel(final IScope scope) {
return "";
}

@Override
public void setUnitLabel(final String label) {}

@Override
public boolean isDefinedInExperiment() { return true; }

@Override
public String getCategory() {
if (category == null) return IExperimentDisplayable.super.getCategory();
return category.literalValue();
}

}
@@ -1,6 +1,6 @@
/***
* Name: GUI Interactive Elements
* Author: Benoit Gaudou
* Author: Benoit Gaudou/Alexis Drogoul
* Description: This model illustrates the various possible interactive elements that can be used in the parameters pane.
* Tags: experiment, GUI, parameter
***/
Expand All @@ -13,7 +13,7 @@ global {
// In the simulation parameter view, their display can depend on their type or on other facets (e.g. min and max).

// Definition of a set of global parameters of several types.
int an_integer_with_limits <- 0;
int an_integer_without_limits <- 0;
int an_integer <-0;
float a_float_variable <- 0.0;
float another <- 10.0;
Expand Down Expand Up @@ -50,18 +50,27 @@ experiment "Show Parameters" type: gui {
string a_string_among_others <- "10";
int an_int_with_an_updated_slider <- 2;


// Texts can be inserted in the parameters pane to explain, for instance, how the model works
// Category: Explanation
//////////////////////////////////////////////
text "This is a simple text using default values" category: "Explanation";
text "This is a more elaborate text in a different color" color: #darkgreen category: "Explanation";
text "This is a text in a different font, in italic and a size of 12" category: "Explanation" color: #orange font: font("Helvetica",12,#italic);
text "This bold red text \rspans over \r3 lines." category: "Explanation" color: #red font: font("Helvetica",12,#bold);

// Category: Various types
//////////////////////////////////////////////
// When min: and max: facets are used, the input chooser for a numerical value appears as a slider.
parameter "An integer with limits" category:"Various types" var: an_integer_with_limits min: 0 max: 100 step: 1;
parameter "An integer with limits" category:"Various types" var: an_integer_without_limits min: 0 max: 100 step: 1;
// Without these facets, the parameter value chooser appears only as a textfield.
parameter "An integer without limit" category:"Various types" var: an_integer ;
parameter "Slider of a float" category:"Various types" var: a_float_variable min: 0.0 max: 100.0 step: 0.5;
parameter "Slider of a float with a color" category:"Various types" var: another min: 0.0 max: 100.0 step: 0.5 colors: [#red, #purple, #blue];
// When a variable of type boolean is a parameter, its input chooser appears as a check box.
parameter "Boolean variable" category:"Various types" var: a_boolean_variable;
parameter "Boolean variable with different colors" category:"Various types" var: a_boolean_variable2 colors: [#blue, #lightskyblue];
parameter "Boolean variable with the same colors" category:"Various types" var: a_boolean_variable3 colors: [#orange];
parameter "Boolean variable with the same colors" category:"Various types" var: a_boolean_variable3 colors: [#orange];
// A color parameter can be modified using a color chooser.
parameter "A color" category:"Various types" var: a_color;
// For any parameter, if the possible values are described using the among: facet, a ComboBox is used to choose the parameter value.
Expand Down
Expand Up @@ -17,6 +17,7 @@
import msi.gama.kernel.experiment.IExperimentDisplayable;
import msi.gama.kernel.experiment.IExperimentPlan;
import msi.gama.kernel.experiment.IParameter;
import msi.gama.kernel.experiment.TextStatement;
import msi.gama.metamodel.agent.IAgent;
import msi.gama.runtime.GAMA;
import msi.gama.runtime.IScope;
Expand Down Expand Up @@ -126,6 +127,8 @@ public void add(final Collection<? extends IExperimentDisplayable> params, final
}
});
}
} else if (var instanceof TextStatement) {
gp = EditorFactory.getInstance().create(scope, (TextStatement) var);
} else {
gp = EditorFactory.getInstance().create(scope, (UserCommandStatement) var,
(Command) e -> GAMA.getExperiment().getAgent().executeAction(scope -> {
Expand Down
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* ExperimentParametersView.java, in ummisco.gama.ui.experiment, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* ExperimentParametersView.java, in ummisco.gama.ui.experiment, is part of the source code of the GAMA modeling and
* simulation platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.ui.views.inspectors;

Expand Down Expand Up @@ -47,10 +47,10 @@ public class ExperimentParametersView extends AttributesEditorsView<String> impl

/** The Constant ID. */
public static final String ID = IGui.PARAMETER_VIEW_ID;

/** The Constant REVERT. */
public final static int REVERT = 0;

/** The experiment. */
private IExperimentPlan experiment;

Expand All @@ -77,6 +77,7 @@ public void addItem(final IExperimentPlan exp) {
final List<IExperimentDisplayable> params = new ArrayList<>(exp.getParameters().values());
params.addAll(exp.getExplorableParameters().values());
params.addAll(exp.getUserCommands());
params.addAll(exp.getTexts());
Collections.sort(params);
editors = new ExperimentsParametersList(exp.getAgent().getScope(), params);
final String expInfo = "Model " + experiment.getModel().getDescription().getTitle() + " / "
Expand Down Expand Up @@ -123,9 +124,7 @@ public boolean addItem(final String object) {
*
* @return the experiment
*/
public IExperimentPlan getExperiment() {
return experiment;
}
public IExperimentPlan getExperiment() { return experiment; }

@Override
public void stopDisplayingTooltips() {
Expand Down
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* EditorListener.java, in ummisco.gama.ui.shared, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* EditorListener.java, in ummisco.gama.ui.shared, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package ummisco.gama.ui.interfaces;

Expand All @@ -17,35 +17,46 @@

/**
* Written by drogoul Modified on 27 mai 2011
*
*
* @todo Description
*
*
*/
public interface EditorListener<T> {

/**
* Value modified.
*
* @param val the val
* @throws GamaRuntimeException the gama runtime exception
* @param val
* the val
* @throws GamaRuntimeException
* the gama runtime exception
*/
void valueModified(T val) throws GamaRuntimeException;

/**
* The Interface Command.
*/
public static interface Command extends EditorListener<Object>, SelectionListener {
public interface Command extends EditorListener<Object>, SelectionListener {

@Override
public default void valueModified(final Object o) {
default void valueModified(final Object o) {
this.widgetSelected(null);
}

@Override
public default void widgetDefaultSelected(final SelectionEvent o) {
default void widgetDefaultSelected(final SelectionEvent o) {
this.widgetSelected(null);
}

}

public interface Static extends EditorListener<Object>, SelectionListener {
@Override
default void valueModified(final Object o) {}

@Override
default void widgetDefaultSelected(final SelectionEvent o) {}

}

}
Expand Up @@ -15,6 +15,7 @@
import msi.gama.kernel.experiment.ExperimentParameter;
import msi.gama.kernel.experiment.IParameter;
import msi.gama.kernel.experiment.InputParameter;
import msi.gama.kernel.experiment.TextStatement;
import msi.gama.metamodel.agent.IAgent;
import msi.gama.metamodel.shape.GamaPoint;
import msi.gama.runtime.IScope;
Expand Down Expand Up @@ -364,4 +365,8 @@ public IParameterEditor create(final IScope scope, final UserCommandStatement co
final EditorListener.Command selectionAdapter) {
return new CommandEditor(scope, command, selectionAdapter);
}

public IParameterEditor create(final IScope scope, final TextStatement var) {
return new TextDisplayer(scope, var);
}
}

0 comments on commit e02fb9a

Please sign in to comment.