/* DO NOT EDIT THIS FILE. THIS FILE WAS GENERATED FROM ../Modules/awtool/AwtMetrics.zob, * EDIT THAT FILE INSTEAD! * All changes to this file will be lost. */ /* AwtMetrics.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 Kimmo Wideroos */ package org.gzigzag.module; import org.gzigzag.*; import java.util.*; import java.awt.*; /** Abstract class for different metrics (in order to get different * focus+context effects) */ public abstract class AwtMetrics extends ZObCellRepr implements ZOb { 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); } /** UNDOCUMENTED. *

Default value:

 { 400, 400 };
. * @structparam 1 */ public int[] RealView = { 400, 400 };/** UNDOCUMENTED. *

Default value:

 { 400, 400 };
. * @structparam 1 */ public int[] VirtualView = { 400, 400 };/** UNDOCUMENTED. *

Default value:

 { 0.0, 0.0 };
. * @structparam 1 */ public double[] Origo = { 0.0, 0.0 };/** UNDOCUMENTED. *

Default value:

 { 200, 200 };
. * @structparam 1 */ public int[] FocusOrigo = { 200, 200 };/** UNDOCUMENTED. *

Default value:

 true;
. * @structparam 1 */ public boolean GridOn = true; /* AUTOGENERATED! */ static final private int fullmask = 31; /* AUTOGENERATED! */ public String readParams(ZZCell start) { int m = 0; try { if(start != null) m = readParams(start, 0); } catch(Throwable t) { ZZLogger.exc(t); } finally { } if((m & fullmask) != fullmask) { // not all parameters present - no problem right now. } return ""; } /* AUTOGENERATED! */ private int readParams(ZZCell start, int mask) { ZZCell n = start; while(n != null) { String s = n.getText(); // Tests autogenerated from members. if(s.equals("RealView")) { mask |= 1; try { // count rank int i=-1; for(ZZCell c = n; c!=null; c=c.s("d.1")) i++; // XXX check range RealView = new int[i]; i=0; for(ZZCell c = n.s("d.1"); c!=null; c=c.s("d.1")) { s = c.getText(); RealView[i] = Integer.parseInt(s); ; i++; } } catch(Exception e) { ZZLogger.exc(e); } } else if(s.equals("VirtualView")) { mask |= 2; try { // count rank int i=-1; for(ZZCell c = n; c!=null; c=c.s("d.1")) i++; // XXX check range VirtualView = new int[i]; i=0; for(ZZCell c = n.s("d.1"); c!=null; c=c.s("d.1")) { s = c.getText(); VirtualView[i] = Integer.parseInt(s); ; i++; } } catch(Exception e) { ZZLogger.exc(e); } } else if(s.equals("Origo")) { mask |= 4; try { // count rank int i=-1; for(ZZCell c = n; c!=null; c=c.s("d.1")) i++; // XXX check range Origo = new double[i]; i=0; for(ZZCell c = n.s("d.1"); c!=null; c=c.s("d.1")) { s = c.getText(); Origo[i] = (Double.valueOf(s)).doubleValue();; i++; } } catch(Exception e) { ZZLogger.exc(e); } } else if(s.equals("FocusOrigo")) { mask |= 8; try { // count rank int i=-1; for(ZZCell c = n; c!=null; c=c.s("d.1")) i++; // XXX check range FocusOrigo = new int[i]; i=0; for(ZZCell c = n.s("d.1"); c!=null; c=c.s("d.1")) { s = c.getText(); FocusOrigo[i] = Integer.parseInt(s); ; i++; } } catch(Exception e) { ZZLogger.exc(e); } } else if(s.equals("GridOn")) { mask |= 16; try { ZZCell c = n.s("d.1"); s = c.getText(); if(s.equals("true")) GridOn=true; else if(s.equals("false")) GridOn=false; else { /* XXX ??? */ } } catch(Exception e) { ZZLogger.exc(e); } } else { } // grab that last "else" ZZCell h = n.h("d.3"); if(h != null && h != n) { // recurse mask |= readParams(h, mask); } n = n.s("d.2"); } return mask; } static ZZCell FocusedCell = null; double FocusCoefficient = focusCoefficientMinimum(); abstract double focusCoefficientMinimum(); abstract double focusCoefficientMaximum(); public double[] RealViewd() { return new double[] { (double)RealView[0], (double)RealView[1] }; } public double[] RealViewHalfd() { return new double[] { (double)RealView[0]*0.5, (double)RealView[1]*0.5 }; } public void setRealView(int x, int y, boolean adjustFocus) { if(adjustFocus) { double[] rvd = RealViewd(); double newfox = ((double)(x*FocusOrigo[0]))/rvd[0]; double newfoy = ((double)(y*FocusOrigo[1]))/rvd[1]; setFocusOrigo((int)newfox, (int)newfoy); } RealView[0] = x; RealView[1] = y; } public void setRealView(Dimension d, boolean adjustFocus) { setRealView(d.width, d.height, adjustFocus); } public double[] VirtualViewd() { return new double[] { (double)VirtualView[0], (double)VirtualView[1] }; } public double[] VirtualViewHalfd() { return new double[] { (double)VirtualView[0]*0.5, (double)VirtualView[1]*0.5 }; } public void setVirtualView(int x, int y) { VirtualView[0] = x; VirtualView[1] = y; } public void setOrigo(double ox, double oy) { Origo[0] = ox; Origo[1] = oy; } public void moveOrigo(double dox, double doy) { Origo[0] += dox; Origo[1] += doy; } public double[] FocusOrigod() { return new double[] { (double)FocusOrigo[0], (double)FocusOrigo[1] }; } public void setFocusOrigo(int fox, int foy) { setFocusOrigo(fox, foy, null); } public void setFocusOrigo(int fox, int foy, ZZCell focusCell) { FocusOrigo[0] = fox; FocusOrigo[1] = foy; if(focusCell != null && focusCell == FocusedCell) { FocusCoefficient += 1.0; if(FocusCoefficient > focusCoefficientMaximum()) FocusCoefficient = focusCoefficientMaximum(); } else { FocusCoefficient = focusCoefficientMinimum(); FocusedCell = focusCell; } } public void init(ZZCell start, Dimension rv, Dimension vv, double ox, double oy) { setCell(start); setRealView(rv.width, rv.height, false); setVirtualView(vv.width, vv.height); setOrigo(ox, oy); setFocusOrigo(rv.width>>1, rv.height>>1); } public AwtMetrics() { } public AwtMetrics(ZZCell start, Dimension rv, Dimension vv, double ox, double oy) { init(start, rv, vv, ox, oy); } private Point mapToUnfocusedRealView(double x, double y) { int rx, ry; double[] vvhd = VirtualViewHalfd(), rvhd = RealViewHalfd(); rx = (int)(( (x-Origo[0]) * vvhd[0]) + rvhd[0]); ry = (int)(( (y-Origo[1]) * vvhd[1]) + rvhd[1]); return new Point(rx, ry); } /** mapping from 'virtualview' (=modelview, coordinates * -1.0