Files
gzz-mirror/Modules/prez/PrezRaster.zob
2026-09-14 20:19:29 -04:00

174 lines
4.2 KiB
Java

/*
Prez.java
*
* Copyright (c) 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 and Asko Soukka
*/
package org.gzigzag.module;
import org.gzigzag.*;
import java.awt.*;
import java.util.*;
import java.io.*;
/** A simple presentation raster.
* The structure is described along three dimensions:
* hierarchy, sibling and cross-reference (x, y and z).
* On these, the hierarchy is arranged as a corner list with an empty
* corner cell, and the cross-references are simply siblings
* connected.
*/
public class PrezRaster implements FlobView, ZOb {
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); }
STRUCTPARAMS {
/** The vstream raster used for the header. */
ZOb hdrvs // VStreamRaster
= new RankTextView() {{
width = 650;
dim = "d.foo";
}};
/** The vstream raster used for the items. */
ZOb txtvs // RankTextView
= new RankTextView() {{
width = 500;
dim = "d.foo";
}};
/** The vstream raster used for the crossrefs. */
ZOb xrefvs // RankTextView
= new RankTextView() {{
width = 500;
dim = "d.foo";
}};
/** The amount to shift the header. */
int hdrindent
= 30;
/** The amount to shift the items. */
int indent
= 50;
/** The amount to space the items. */
int space
= 30;
int topmargin
= 120;
int afterhdr
= 0;
ScalableFont hdrfont
= new ScalableFont("SansSerif", Font.PLAIN, 32);
ScalableFont txtfont
= new ScalableFont("SansSerif", Font.PLAIN, 24);
ScalableFont xreffont
= new ScalableFont("SansSerif", Font.PLAIN, 10);
int hdrwidth
= 650;
int txtwidth
= 500;
}
String next = "d.2";
String hier = "d.1";
String cross = "d.3";
public void raster(FlobSet into, FlobFactory fact,
ZZCell view, String[] dims, ZZCell accursed) {
hier = dims[0];
next = dims[1];
cross = dims[2];
ZZCell hdr = null;
/* Something to work with circular ranks.
* Goes rank backwards and gets the first available cell
* on the negative direction on the hier-dimension.
* Otherwise gets the accursed cell. */
hdr = accursed.s(hier, -1);
int i = -1;
while (hdr == null) {
if (accursed.s(next, i) == null) break;
hdr = accursed.s(next, i).s(hier, -1);
if (i < -20) break;
i--;
}
if (hdr == null) hdr = accursed;
RankTextView hdrvs = (RankTextView)this.hdrvs;
RankTextView txtvs = (RankTextView)this.txtvs;
RankTextView xrefvs = (RankTextView)this.xrefvs;
hdrvs.font = hdrfont;
txtvs.font = txtfont;
xrefvs.font = xreffont;
hdrvs.width = hdrwidth;
txtvs.width = txtwidth;
hdrvs.readParams(null);
txtvs.readParams(null);
xrefvs.readParams(null);
int y = topmargin;
Rectangle bds = hdrvs.raster(into, hdr, 0, false,
hdrindent, y);
p("Raster 1: "+bds);
y += bds.height + afterhdr;
ZZCell cur = hdr.s(hier, 1);
if(cur == null) return;
LoopDetector l = new LoopDetector();
while(true) {
cur = cur.s(next, 1);
if(cur == null) break;
if(cur == hdr.s(hier, 1)) break;
l.detect(cur);
bds = txtvs.raster(into, cur, 0, false, indent, y);
p("Raster n: "+bds);
// indicate that there is more
if(cur.s(hier, 1) != null) {
into.add(new LineDecor(bds.x+bds.width, bds.y,
bds.x+bds.width, bds.y+bds.height,
Color.blue, 1));
}
if(cur.s(cross, -1) != null)
xrefvs.raster(into, cur.s(cross,-1),
0, false, 400, bds.y-15);
if(cur.s(cross, 1) != null)
xrefvs.raster(into, cur.s(cross,1),
0, false, 400, bds.y+bds.height+5);
y += bds.height + space;
}
}
}
// vim: set syntax=java :