1 /*
2 * TouchGraph LLC. Apache-Style Software License
3 *
4 *
5 * Copyright (c) 2001-2002 Alexander Shapiro. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by
22 * TouchGraph LLC (http://www.touchgraph.com/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "TouchGraph" or "TouchGraph LLC" must not be used to endorse
27 * or promote products derived from this software without prior written
28 * permission. For written permission, please contact
29 * alex@touchgraph.com
30 *
31 * 5. Products derived from this software may not be called "TouchGraph",
32 * nor may "TouchGraph" appear in their name, without prior written
33 * permission of alex@touchgraph.com.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL TOUCHGRAPH OR ITS CONTRIBUTORS BE
39 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
43 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
44 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
45 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 * ====================================================================
47 *
48 */
49
50 package com.touchgraph.graphlayout;
51
52 import java.util.Vector;
53
54 /*** TGLensSet: A collection of lenses, where each lens is a function that
55 * warps 2D space.
56 *
57 * @author Alexander Shapiro
58 * @version 1.21 $Id: TGLensSet.java,v 1.1.1.1 2004/02/06 08:44:05 keesj Exp $
59 */
60 public class TGLensSet {
61
62 Vector lenses=new Vector();
63
64 public void addLens( TGAbstractLens l ) {
65 lenses.addElement(l);
66 }
67
68 public void applyLens( TGPoint2D p ) {
69 if (lenses.isEmpty()) return;
70 //else
71 for (int i=0; i<lenses.size(); i++) {
72 ((TGAbstractLens)lenses.elementAt(i)).applyLens(p);
73 }
74 }
75
76 public void undoLens( TGPoint2D p ) {
77 if (lenses.isEmpty()) return;
78 //else
79 for (int i=lenses.size()-1; i>=0; i--) {
80 ((TGAbstractLens) lenses.elementAt(i)).undoLens(p);
81 }
82 }
83
84 /*** Convert draw position to real position. */
85 public TGPoint2D convRealToDraw( TGPoint2D p ) {
86 TGPoint2D newp = new TGPoint2D(p);
87 applyLens(newp);
88 return newp;
89 }
90
91 /*** Convert draw position to real position. */
92 public TGPoint2D convRealToDraw( double x, double y ) {
93 TGPoint2D newp = new TGPoint2D(x,y);
94 applyLens(newp);
95 return newp;
96 }
97
98 /*** Convert real position to draw position. */
99 public TGPoint2D convDrawToReal( TGPoint2D p ) {
100 TGPoint2D newp = new TGPoint2D(p);
101 undoLens(newp);
102 return newp;
103 }
104
105 /*** Convert real position to draw position. */
106 public TGPoint2D convDrawToReal(double x, double y) {
107 TGPoint2D newp = new TGPoint2D(x, y);
108 undoLens(newp);
109 return newp;
110 }
111
112 } // end com.touchgraph.graphlayout.TGLensSet