/* Notemap.zob * * Copyright (c) 2000-2001 Ted Nelson and Tuomas Lukka * Copyright (c) 2000-2001 Benjamin 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 Benjamin Fallenstein */ package org.gzigzag.module; import org.gzigzag.*; import java.util.*; import java.awt.*; /** The Map view */ public class Notemap implements FlobView, ZOb { public static final String rcsid = "$Id: Notemap.zob,v 1.1 2002/10/07 12:37:35 tuukkah Exp $"; public static boolean dbg = true; static void p(String s) { if(dbg) System.out.println(s); } static void pa(String s) { System.out.println(s); } STRUCTPARAMS { /** The maximum depth */ int maxdepth = 2; } static public String dim1 = "d.map-1", dim2 = "d.map-2"; /** A typed link between two cells. */ static public class Link { /** The direction of the link. May be 0, in case of no direction. */ int dir; ZZCell link, to, linkRoot; Color col = Color.blue; /** Constructor sets dir to zero if there is no direction. */ public Link(ZZCell link, int dir, ZZCell to) { this.link = link; this.to = to; // linkRoot = link.getRootclone(); // if(linkRoot.s("d.map-directed") != null) this.dir = dir; // else // dir = 0; } } /** Get the links from a given cell. */ static public Link[] getLinks(ZZCell from, ZZCell fromLink, boolean[] tilt) { Vector v = new Vector(); ZZCell c, d; int offs = -1; for(c = from.s(dim2); c != null && !c.equals(from); c = c.s(dim2)) { d = c.h(dim1, -1, true); if(d != null) { if(!c.equals(fromLink)) v.addElement(new Link(c, -1, d)); else offs = v.size(); } else ZZLogger.log("link without neg target: "+c); } tilt[0] = (fromLink == null) && (v.size() % 2 == 1); int negmiddle = v.size() / 2; for(c = from.s(dim1); c != null && !c.equals(from); c = c.s(dim1)) { d = c.h(dim2, -1, true); if(d != null) { if(!c.equals(fromLink)) v.addElement(new Link(c, 1, d)); else offs = v.size(); } else ZZLogger.log("link without pos target: "+c); } if(fromLink == null) offs = negmiddle; else if(offs < 0) throw new ZZError("fromLink not found"); Link[] res = new Link[v.size()]; if(offs == res.length) offs = 0; // end of array = beginning of array for(int i=offs; i 0 ? 10 : -10; } else if(dy == 0) { ax = dx > 0 ? 10 : -10; ay = 0; } else { double raise = dy / (double)dx; ax = (int)Math.sqrt(100/(raise*raise+1)); if(dx < 0) ax = -ax; ay = (int)(raise*ax); } fact.centerFlob(into, links[i].to, links[i].to, 1, p, 0, 0, 1); lb.l(lx, ly, p.x, p.y); if(links[i].dir < 0) ab.ar(mx+ax, my+ay, mx-ax, my-ay); else if(links[i].dir > 0) ab.ar(mx-ax, my-ay, mx+ax, my+ay); if(dpt < maxdepth) part(into, fact, links[i].to, links[i].link, x0, y0, dpt+1, p.x, p.y, arc, arc+arcd, xd, yd, false); } lb.endl(); ab.endl(); } public void raster(FlobSet into, FlobFactory fact, ZZCell view, String[] dims, ZZCell accursed) { Dimension size = into.getSize(); int x0 = size.width/2, xd = size.width / (2 * maxdepth); int y0 = size.height/2, yd = size.height / (2 * maxdepth); fact.centerFlob(into, accursed, accursed, 1, new Point(x0, y0), 0, 0, 1); part(into, fact, accursed, null, x0, y0, 1, x0, y0, -Math.PI/2, (Math.PI/2)*3, xd, yd, true); } static public ZZModule module = new ZZModule() { public void action(String id, ZZCell code, ZZCell target, ZZView view, ZZView cview, String key, Point pt, ZZScene xi) { if(id.equals("NEW")) { ZZCell vc = view.getViewcell(); ZZCell c = ZZCursorReal.get(vc).N(dim1).N(dim2, -1); ZZCursorReal.set(vc, c); } else if(id.equals("CNCT")) { ZZCell vc = view.getViewcell(); ZZCell acc = ZZCursorReal.get(vc); ZZCell[] marks = vc.readRank("d.mark", 1, false); for(int i=0; i