/* ApplitudeMgr.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 Benjamin Fallenstein */ package org.gzigzag; import java.awt.*; import java.util.*; /** Routines related to applitude management. * This handles registering and identification of applitudes. An applitude * has a name and a number of params. Currently, the only used param is * the View param, which is simply a view (as a ZOb). That ought to change * into something more sophisticated...
* Applitudes are associated with dimensions. If a cell is connected on one * of an applitude's dimensions, it is said to be "in" that applitude.
* XXX need to make this faster! */ public class ApplitudeMgr { public static final String rcsid = "$Id: ApplitudeMgr.java,v 1.10 2000/12/31 15:15:50 bfallenstein 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); } private static ZZCell getDimCell(ZZCell c0) { ZZSpace s = c0.getSpace(); ZZCell c = ZZDefaultSpace.findOnClientlist(s, "Applitudes", false); if(c == null) return putDefApps(s.getHomeCell()); return c.getOrNewCell("d.1", 1); } /** Get a list of all the applitudes a cell is in. */ static public ZZCell[] getApplitudes(ZZCell c) { ZZCell d = getDimCell(c); ZZCell app = null; boolean added = false; Vector v = new Vector(); for(d = d.s("d.2"); d != null; d = d.s("d.2")) { if(d.s("d.1") != null) { app = d.s("d.1"); added = false; } if(!added && (c.s(d.t()) != null || c.s(d.t(), -1) != null)) { v.addElement(app); added = true; } } ZZCell[] res = new ZZCell[v.size()]; for(int i=0; i * If the bindings cursor doesn't exist, it is created. If no applitude * is set or something else goes wrong, though, null is returned. */ static public ZZCell getAppBindsForWin(ZZCell win) { ZZCell app = getWindowApp(win); if(app == null) return null; ZZCell binds = win.intersect("d.app-bind", 1, app, "d.clone", 1); ZZCell c = null; if(binds != null) c = ZZCursorReal.get(binds); if(c != null) return c; // CREATE c = ZZDefaultSpace.findInheritableParam(app.s("d.1"), "Bindings"); if(c == null) return null; c = c.s("d.1"); if(c == null) return null; if(binds == null) { binds = app.zzclone(); win.insert("d.app-bind", 1, binds); } ZZCursorReal.set(binds, c); return c; } static public void setAppBindsForWin(ZZCell win, ZZCell to) { ZZCell app = getWindowApp(win); if(app == null) { ZZLogger.log("Argh: Tried to set app binds for win without app"); return; } ZZCell curs = win.intersect("d.app-bind", 1, app, "d.clone", 1); if(curs == null) { curs = app.zzclone(); win.insert("d.app-bind", 1, curs); } ZZCursorReal.set(curs, to); } /** Move to next or previous applitude for this window. */ static public void rotateWindowApp(ZZCell win, int dir) { ZZCell app = getWindowApp(win); if(dir < 0) { app = app.s("d.2", -1); if(app.s("d.2", -1) == null) app = app.h("d.2", 1); } else { if(app.s("d.2") != null) app = app.s("d.2"); else app = app.h("d.2").s("d.2"); } setWindowApp(win, app); pa("Set win "+win+" to app "+app); } }