/* 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); } STRUCTPARAMS { int[] RealView = { 400, 400 }; int[] VirtualView = { 400, 400 }; double[] Origo = { 0.0, 0.0 }; int[] FocusOrigo = { 200, 200 }; boolean GridOn = true; } 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