[go: up one dir, main page]

Menu

[r105]: / decker / view / UIText.java  Maximize  Restore  History

Download this file

88 lines (57 with data), 2.3 kB

 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
package decker.view;
import decker.model.*;
import java.awt.*;
/** displays a TEXT structure */
final class UIText extends DisplayedComponent
{
private String text;
private Color color;
private Font font;
private int y_offset;
UIText (final Value _component, final DisplayedComponent _parent, final DisplayedComponent current_clip_source) {
super(_component, _parent);
component.structure().addValueListener(this);
updateText();
super.update(CUSTOM_SIZE, current_clip_source);
child_count = 0; // cannot have children
}
void determineSize (final boolean width_already_determined, final boolean height_already_determined, final DisplayedComponent current_clip_source) {
final FontMetrics fm = AbstractView.getFontMetrics(font);
if (!width_already_determined)
w = fm.stringWidth(text);
if (!height_already_determined)
h = fm.getHeight();
}
void draw (final Graphics g) {
if (color != null)
g.setColor(color);
g.setFont(font);
g.drawString(text, x, y+y_offset);
}
public void eventValueChanged (final int index, final ArrayWrapper wrapper, final Value old_value, final Value new_value) {
System.out.println(index+" changed");
updateText();
super.eventValueChanged(index, wrapper, old_value, new_value);
}
public void eventValueChanged (final String variable_name, final Structure container, final Value old_value, final Value new_value) {
System.out.println(variable_name+" changed");
updateText();
super.eventValueChanged(variable_name, container, old_value, new_value);
}
void update (final int customSettings, final DisplayedComponent current_clip_source) {
super.update(customSettings|CUSTOM_SIZE, current_clip_source);
updateText();
}
private void updateText () {
final Structure t = component.structure();
Value v;
// fetch the text and its style settings
final String old_text = text;
text = t.get("text").toString();
// System.out.println("updating text "+old_text+" -> "+text);
v = t.get("font");
font = AbstractView.getFont((v.type() == Value.STRING)?v.string():"", null, false);
color = ((v=t.get("color")).type() == Value.STRING) ? AbstractView.getColor(v.string()) : null;
y_offset = AbstractView.getFontMetrics(font).getAscent();
}
}