/
TextStatement.java
142 lines (123 loc) · 4.33 KB
/
TextStatement.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*******************************************************************************************************
*
* 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 = IKeyword.BACKGROUND,
type = IType.COLOR,
optional = true,
doc = @doc ("The color of the background of the text")),
@facet (
name = FONT,
type = { IType.FONT, IType.STRING },
optional = true,
doc = @doc ("the font used to draw the text, which can be built with the operator \"font\". ex : font:font(\"Helvetica\", 20 , #bold)")),
@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);
background = getFacet(IKeyword.BACKGROUND);
}
/** The message. */
final IExpression message;
/** The color. */
final IExpression color, category, font, background;
@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;
}
public Color getBackground(final IScope scope) {
GamaColor rgb = null;
if (background != null) { rgb = Cast.asColor(scope, background.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();
}
}