29 |
import org.fenfire.swamp.*; |
import org.fenfire.swamp.*; |
30 |
import org.nongnu.alph.*; |
import org.nongnu.alph.*; |
31 |
import org.nongnu.libvob.*; |
import org.nongnu.libvob.*; |
32 |
|
import org.nongnu.libvob.linebreaking.*; |
33 |
import org.nongnu.libvob.vobs.*; |
import org.nongnu.libvob.vobs.*; |
34 |
|
|
35 |
/** A node function returning a vob that shows |
/** A node function returning a vob that shows |
42 |
public static boolean dbg = false; |
public static boolean dbg = false; |
43 |
private static void pa(String s) { System.out.println("TextNodeView::"+s); } |
private static void pa(String s) { System.out.println("TextNodeView::"+s); } |
44 |
|
|
45 |
|
final SimpleLinebreaker breaker = new SimpleLinebreaker(); |
46 |
|
|
47 |
final NodeFunction nodeContent; |
final NodeFunction nodeContent; |
48 |
final TextStyle style; |
final TextStyle style; |
49 |
final float scale; |
final float scale; |
50 |
|
|
51 |
|
final float width = 300; |
52 |
|
|
53 |
public TextNodeView(NodeFunction nodeContent, |
public TextNodeView(NodeFunction nodeContent, |
54 |
TextStyle style, |
TextStyle style, |
55 |
float scale) { |
float scale) { |
63 |
|
|
64 |
final Object objNode = node; |
final Object objNode = node; |
65 |
String s = enf.makeString(); |
String s = enf.makeString(); |
66 |
final TextVob vob = new TextVob(style, s, false); |
|
67 |
final float width = style.getWidth(s, scale); |
HChain ch = getChain(s); |
68 |
final float height = style.getHeight(scale); |
final HBroken br = breaker.breakLines(ch, width, scale); |
69 |
|
final float height = br.getHeight(); |
70 |
|
|
71 |
|
//final TextVob vob = new TextVob(style, s, false); |
72 |
|
//final float width = style.getWidth(s, scale); |
73 |
|
//final float height = style.getHeight(scale); |
74 |
|
|
75 |
if(dbg) { |
if(dbg) { |
76 |
pa("Textnodeview: '"+s+"' "+width+" "+height); |
pa("Textnodeview: '"+s+"' "+width+" "+height+" "+scale+" "+br); |
77 |
} |
} |
78 |
|
|
79 |
return new org.nongnu.libvob.lava.placeable.Placeable() { |
return new org.nongnu.libvob.lava.placeable.Placeable() { |
80 |
public void place(VobScene vs, int into) { |
public void place(VobScene vs, int into) { |
81 |
int scaled = vs.orthoCS(into, objNode, 0, |
br.put(vs, into); |
|
0, 0, height, height); |
|
|
vs.put(vob, scaled); |
|
82 |
} |
} |
83 |
|
|
84 |
public float getWidth() { return width; } |
public float getWidth() { return width; } |
85 |
public float getHeight() { return height; } |
public float getHeight() { return height; } |
86 |
}; |
}; |
87 |
} |
} |
88 |
|
|
89 |
|
|
90 |
|
protected HChain getChain(String s) { |
91 |
|
HChain ch = new LinebreakableChain(); |
92 |
|
|
93 |
|
int pos = 0; |
94 |
|
int last; |
95 |
|
while(pos < s.length()) { |
96 |
|
last = pos; |
97 |
|
int sp = s.indexOf(' ', pos); |
98 |
|
int br = s.indexOf('\n', pos); |
99 |
|
|
100 |
|
if(sp >= 0 && br >= 0) |
101 |
|
pos = sp<br ? sp+1 : br; |
102 |
|
else if(sp >= 0) pos = sp+1; |
103 |
|
else if(br >= 0) pos = br; |
104 |
|
else |
105 |
|
pos = s.length(); |
106 |
|
|
107 |
|
addVobs(s, ch, last, pos); |
108 |
|
if(pos == br) { |
109 |
|
ch.addBox(new HBox.Null(1)); |
110 |
|
ch.addBreak(); |
111 |
|
pos++; |
112 |
|
} |
113 |
|
} |
114 |
|
|
115 |
|
return ch; |
116 |
|
} |
117 |
|
|
118 |
|
protected void addVobs(String s, HChain ch, int start, int end) { |
119 |
|
Object key = new Integer(start+1472); |
120 |
|
s = s.substring(start, end); |
121 |
|
|
122 |
|
if(dbg) pa("addVobs: "+start+" "+end+" '"+s+"'"); |
123 |
|
TextVob vob = new TextVob(style, s, false, key); |
124 |
|
ch.addBox(vob); |
125 |
|
} |
126 |
} |
} |