/* CellVobFactory.java * * Copyright (c) 1999-2000, Ted Nelson and Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Tuomas Lukka */ package gzz.view; import gzz.client.*; import gzz.*; import gzz.errors.*; import gzz.vob.*; import gzz.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, broken into lines. * Doesn't scroll, currently. */ public class LinebrokenCellContentView implements CellContentView { public static final String rcsid = "$Id: LinebrokenCellContentView.java,v 1.1 2002/09/18 12:04:46 benja Exp $"; public static boolean dbg = false; private static void p(String s) { if(dbg) pa(s); } private static void pa(String s) { System.err.println(s); } class Chain { Vob[] vobs = new Vob[20]; Object[] keys = new Object[20]; float[] widths = new float[20]; boolean[] mustBreak = new boolean[20]; int length = 0; void add(Vob v, Object key, float width) { if(++length > vobs.length) more(); vobs[length-1] = v; keys[length-1] = key; widths[length-1] = width; } void addBreak() { add(null, null, 0); mustBreak[length-1] = true; } void breakBefore(int pos) { if(pos == 0) return; mustBreak[pos-1] = true; } void more() { Vob[] nvobs = new Vob[vobs.length*2]; Object[] nkeys = new Object[keys.length*2]; float[] nwidths = new float[widths.length*2]; boolean[] nmustBreak = new boolean[mustBreak.length*2]; System.arraycopy(vobs, 0, nvobs, 0, vobs.length); System.arraycopy(keys, 0, nkeys, 0, keys.length); System.arraycopy(widths, 0, nwidths, 0, widths.length); System.arraycopy(mustBreak, 0, nmustBreak, 0, mustBreak.length); vobs = nvobs; widths = nwidths; keys = nkeys; mustBreak = nmustBreak; } void breakLines(float width) { if(length == 0) return; if(width <= 0) throw new IllegalArgumentException("width == "+width+" <= 0"); float x = 0; for(int i=0; i width) { breakBefore(i); x = widths[i]; } } } int getLineCount() { int lines = 1; for(int i=0; i= 0 && br >= 0) pos = sp
= 0) pos = sp; else if(br >= 0) pos = br; else pos = s.length(); addVobs(s, ch, last, pos, scale); if(pos == br) ch.addBreak(); pos++; } return ch; } protected void addVobs(String s, Chain ch, int start, int end, float scale) { Object key = new Integer(start+1472); s = s.substring(start, end); if(dbg) pa("addVobs: "+start+" "+end+" '"+s+"'"); TextVob vob = new TextVob(style, scale, s); ch.add(vob, key, style.getWidth(s, scale)); } }