//(c): Tuomas J. Lukka and Matti J. Katila package org.fenfire.view; import org.fenfire.*; import org.nongnu.libvob.*; import org.nongnu.libvob.impl.*; import org.nongnu.libvob.vobs.*; import org.nongnu.alph.*; import org.nongnu.alph.impl.*; import java.awt.Font; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Color; import java.util.*; /** A cell content view showing a cell's text. */ public class SimpleText extends TextHandler { public static final String rcsid = "$Id: SimpleText.java,v 1.1 2003/04/08 14:56:52 mudyc Exp $"; public static boolean dbg = false; private static void pa(String s) { System.out.println("SimpleText::"+s); } TextStyle style; private static Object KEY[] = new Object[20]; static { for(int i=0; i s.length()) offs = s.length(); int center = offs >= 0 ? offs : 0; int line = 0, p = center; while((p = s.lastIndexOf('\n', p-1)) > 0) line++; int brBefore = s.lastIndexOf('\n', center-1); if(brBefore < 0) brBefore = 0; else brBefore++; int brAfter = s.indexOf('\n', center); if(brAfter < 0) brAfter = s.length(); s = s.substring(brBefore, brAfter); offs -= brBefore; center -= brBefore; vs.coords.getSqSize(box, boxwh); float middle = boxwh[0] / 2.0f; // Made null-pointer exception in Pp when tried to animate towards empty scene java.awt.Point tmp_point = vs.coords.transformPoint(box, 0, 0, point); if (tmp_point == null) return; //float y0 = vs.coords.transformPoint(box, 0, 0, point).y; float y0 = tmp_point.y; float y1 = vs.coords.transformPoint(box, 0, boxwh[1], point).y; float h = y1-y0; float scale = style.getScaleByHeight(h); if(dbg) { pa("text: "+s); pa("scaled_h: "+h); pa("scale: "+scale); } float width = style.getWidth(s, scale) * boxwh[1]/h; float left = style.getWidth(s.substring(0, center), scale) * boxwh[1]/h; float right = width - left; // Possibly offset text so cursor is visible. float textOffset; if(width < boxwh[0]) textOffset = 0; else if(left < middle) textOffset = 0; else if(right < middle) textOffset = (- width + boxwh[0]); else textOffset = (- left + middle); Object key = (line < KEY.length) ? KEY[line] : new Integer(line+1); int offsetcs = vs.orthoCS(box, key, 0, textOffset, 0, 1, 1); */ // XXXplaceVob(c, vs, offsetcs, brBefore, brAfter, offs, context, boxwh[1], h, scale); placeVob(s, vs, box, 0,0,0,1); } static Object WH_KEY = new Object(); static Object CURS_KEY = new Object(); //LineVob cursorVob = new LineVob(0, 0, 0, 1, Color.black); protected void placeVob(String s, VobScene vs, int cs, int start, int end, int offs, float h) { // XXX should optimize for common case: no substring() TextVob vob = new TextVob(style, s); vs.map.put(vob, cs); //TextVob vob = new TextVob(style, Containment.getContainedText(c).substring(start, end)); //int cs_scaled = vs.orthoCS(cs, WH_KEY, 0, 0, 0, h, h); //vs.map.put(vob, cs_scaled); /* if(offs >= 0 && offs >= start && offs <= end) { float x = style.getWidth(Containment.getContainedText(c).substring(start, offs), scale); x *= h/scaled_h; int cs_cursor = vs.orthoCS(cs, CURS_KEY, -1, x+1, 0, 0, h); // v.map.put(new TextCursorVob(vob, offs), cs); vs.map.put(cursorVob, cs_cursor); } */ } }