/* ZZDefaultSpace.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 */ /* * `He looks as though someone hit him on the head,' said Chidder. * `No-one did, did they?' * Arthur shook his head. Teppic's face was locked in a gentle * grin. Whatever his eyes were focused on wasn't occupying the usual * set of dimensions. * Terry Pratchett, Pyramids, p.78 */ package org.gzigzag; import java.awt.*; import java.util.*; /** A "simple" class to create a default space starting at a cell. * NOT FINISHED. *
* This class is kind of a center for things to be changed later. * It could be thought of as a bad design but the very point is that * in order to find the change-sensitive places, you grep the source * for ZZDefaultSpace and find out what places do what. *
* It is not meant to remain here once things start settling down - probably.
* Or possibly something like it will, defining a schema somewhere for things,
* and other places just reference the schema - adaptive programming, anyone?
* Actually, after we bootstrap, it'll definitely be gone.
*/
public class ZZDefaultSpace {
public static final String rcsid = "$Id: ZZDefaultSpace.java,v 1.143.2.2 2002/02/16 15:19:25 tuukkah Exp $";
public static boolean dbg = false;
static final void p(String s) { if(dbg) System.out.println(s); }
static final void pa(String s) { System.out.println(s); }
public static final String dimListDimen = "d.2";
public static final String sysList = "d.system";
// XXX See if abstracting this out would make sense...
static class ZP {
class StrCell {
String name; ZZCell val;
StrCell(String name, ZZCell val) { this.name = name; this.val = val; }
}
String name;
String type;
Vector pars = new Vector();
ZP(String name, String type) { this.name = name; this.type = type; }
void ap(String name) {
pars.addElement(new String[] {name});
}
void ap(String name, String val) {
pars.addElement(new String[] {name, val});
}
void ap(String name, ZZCell val) {
pars.addElement(new StrCell(name, val));
}
void ap(String name, String val, String val2) {
pars.addElement(new String[] {name, val, val2});
}
void inh(ZZCell inhfrom) {
pars.addElement(inhfrom);
}
ZZCell ins(ZZCell c) {
ZZCell h = c.N("d.2", 1);
ZZCell ret = h;
h.setText(name); h = h.N("d.1", 1);
h.setText(type); h = h.N("d.1", 1);
for(Enumeration e = pars.elements();
e.hasMoreElements(); ) {
Object el = e.nextElement();
if(el instanceof String[]) {
String[] a = (String[])el;
h = h.N("d.2", 1);
h.setText(a[0]);
ZZCell cur = h;
for(int i=1; i
* The return value may be null in the case that there is a
* d.cursor-cargo attached to the cell
*/
static public ZZCell getPossDerefCell(ZZCell c) {
ZZCell cur = c;
// XXX LoopDetector
while(true) {
ZZCell m = ZZCursorReal.get(c);
if(m==null) return cur;
cur = m;
}
}
// XXX NOTE: THIS GOES NEGWARDS - SPACE <-> SCROLL MAPPING
// MUST BE SAVED BETWEEN RESTARTS
static public ZZCell findScrollCell(ZZCell root, String id) {
ZZCell c = root;
c = c.findText("d.2", -1, "Scrolls");
if(c==null) throw new ZZError("No scrolls!");
c = c.findText("d.1", 1, id);
return c;
}
// Currently: go along
static public ZZCell findInheritableParam(ZZCell start, String id) {
ZZCell n = start;
while(n!=null) {
if(n.getText().equals(id)) return n;
ZZCell h; h = n.h("d.3", -1);
if(h!=null && h!=n) {
h = findInheritableParam(h, id);
if(h!=null) return h;
}
n = n.s("d.2", 1);
}
return null;
}
static public Font findInheritableParamFont(ZZCell start, String id,
Font def) {
ZZCell fo = findInheritableParam(start, id);
if(fo!=null) {
fo = fo.s("d.1",1);
String name = fo.getText();
fo = fo.s("d.1",1);
int size = Integer.parseInt(fo.getText());
return new Font(name,Font.PLAIN,size);
}
return def;
}
static public float[] paramFloatA(ZZCell start, String id, float[] def,
int nmin) {
ZZCell p = findInheritableParam(start, id);
if(p==null) return def;
ZZCell[] r = p.readRank("d.1", 1, false);
if(r.length < nmin) return def;
float[] arr = new float[r.length];
for(int i=0; i