created mirror
This commit is contained in:
141
Modules/zaubertrank/ZaubertrankCellView.java
Normal file
141
Modules/zaubertrank/ZaubertrankCellView.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
ZaubertrankCellView.zob
|
||||
*
|
||||
* Copyright (c) 2001, Benja Fallenstein
|
||||
*
|
||||
* 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 Benja Fallenstein
|
||||
*/
|
||||
|
||||
package org.gzigzag;
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
|
||||
/** A cell view for showing one zaubertrank statement/entity/sentence etc.
|
||||
* This is assembled from a number of tokens.
|
||||
*/
|
||||
|
||||
public class ZaubertrankCellView extends FTextCellView {
|
||||
public static final String rcsid = "$Id: ZaubertrankCellView.java,v 1.1 2001/04/02 20:23:13 bfallenstein Exp $";
|
||||
public static boolean dbg = false;
|
||||
private static void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
private static void pa(String s) { ZZLogger.log(s); }
|
||||
|
||||
public static String zttext = "d.zt-text";
|
||||
public static String ztparams = "d.zt-params", ztvalue = "d.zt-value";
|
||||
public static String zttype = "d.zt-type";
|
||||
|
||||
|
||||
|
||||
/** Add the FText parts for the token at c0 to the vector. */
|
||||
final void addToken(Vector v, ZZCell c0, Color bg, int scale) {
|
||||
p("add token "+c0);
|
||||
/** The background color to pass on to subordinate tokens.
|
||||
* The background of an accursed token is the color of the cursor;
|
||||
* the backgrounds of the subordinate tokens are lighter.
|
||||
*/
|
||||
Color newBg = bg;
|
||||
|
||||
// See whether there's a cursor accursing the token, and take its color.
|
||||
Color col = ZZCursorReal.getAccursedColor(c0);
|
||||
/* This looks awkward when the cell the cellview's called with is used.
|
||||
if(col == null) {
|
||||
ZZCell parcell = c0.s(ztvalue, -1);
|
||||
if(parcell != null)
|
||||
col = ZZCursorReal.getAccursedColor(parcell);
|
||||
}
|
||||
*/
|
||||
if(col != null) {
|
||||
bg = col;
|
||||
newBg = col.brighter();
|
||||
}
|
||||
|
||||
// Add the token's text.
|
||||
for(ZZCell c = c0.getRootclone().s(zttext); c != null; c = c.s(zttext)) {
|
||||
if(c.getRootclone().equals(c))
|
||||
addCellPart(v, c, bg, scale);
|
||||
else
|
||||
addSubordinateToken(v, c0, c, newBg, scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
final void addSubordinateToken(Vector v, ZZCell c0, ZZCell c,
|
||||
Color bg, int scale) {
|
||||
p("add subtoken "+c0+" "+c);
|
||||
ZZCell root0 = c0.getRootclone(), root = c.getRootclone();
|
||||
|
||||
/** The distance between root and root0 on d.zt-params.
|
||||
*/
|
||||
int n = 0;
|
||||
|
||||
for(ZZCell d = root; d != root0; d = d.s(ztparams, -1)) {
|
||||
if(d == null)
|
||||
throw new SyntaxError("Found a param in a token's text which "
|
||||
+ "is not on the token's params list. Token: " + c0
|
||||
+ ", param: " + c);
|
||||
n++;
|
||||
}
|
||||
|
||||
ZZCell param = c0.s(ztparams, n), val = null;
|
||||
if(param != null) val = param.s(ztvalue);
|
||||
|
||||
if(val != null)
|
||||
addToken(v, val, bg, scale);
|
||||
else
|
||||
addTypeQuestion(v, root, param, bg, scale);
|
||||
}
|
||||
|
||||
|
||||
|
||||
final void addTypeQuestion(Vector v, ZZCell root, ZZCell param,
|
||||
Color bg, int scale) {
|
||||
p("add type question "+root+" "+param);
|
||||
if(param != null) {
|
||||
Color col = ZZCursorReal.getAccursedColor(param);
|
||||
if(col != null) bg = col;
|
||||
}
|
||||
|
||||
ZZCell type = root.h(zttype, true);
|
||||
if(type == null)
|
||||
throw new SyntaxError("No type assigned to param: " + param);
|
||||
addCellPart(v, type, bg, scale);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Get the FText for this cell at the given scale.
|
||||
* scale == fract * 1000.
|
||||
*/
|
||||
protected FText getFText(ZZCell c0, int scale) {
|
||||
ZZCell c = c0.s(ztvalue);
|
||||
if(c == null) return new FText(new FText.Part[0]);
|
||||
|
||||
Vector v = new Vector();
|
||||
addToken(v, c, null, scale);
|
||||
return new FText(v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Add a cell part to the vector of FText parts. */
|
||||
final void addCellPart(Vector v, ZZCell c, Color bg, int scale) {
|
||||
v.addElement(new FText.CellPart(c, 0, -1, f(scale), fm(scale),
|
||||
bg, null));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user