1 package de.fzi.wim.guibase.graphview.lens;
2
3 import java.util.List;
4 import java.util.ArrayList;
5 import java.awt.geom.Point2D;
6
7 /***
8 * A collection of lenses, where each lens is a function that warps 2D space.
9 * This class has been inspired by the <a href="http://www.touchgraph.com/">TouchGraph</a> library.
10 */
11 public class LensSet extends AbstractLens implements LensListener {
12 /*** The list of lenses. */
13 protected List m_lenses;
14
15 /***
16 * Creates the lens set.
17 */
18 public LensSet() {
19 m_lenses=new ArrayList();
20 }
21 /***
22 * Adds the lens to the set.
23 *
24 * @param lens the lens added
25 */
26 public void addLens(Lens lens) {
27 m_lenses.add(lens);
28 lens.addLensListener(this);
29 }
30 /***
31 * Applies the lenses.
32 *
33 * @param point the point
34 */
35 public void applyLens(Point2D point) {
36 for (int i=0;i<m_lenses.size();i++) {
37 Lens lens=(Lens)m_lenses.get(i);
38 lens.applyLens(point);
39 }
40 }
41 /***
42 * Undoes the lenses.
43 *
44 * @param point the point
45 */
46 public void undoLens(Point2D point) {
47 for (int i=m_lenses.size()-1;i>=0;i--) {
48 Lens lens=(Lens)m_lenses.get(i);
49 lens.undoLens(point);
50 }
51 }
52 /***
53 * Called whenever the lens changes its parameters.
54 *
55 * @param lens the lens that changed its parameters
56 */
57 public void lensUpdated(Lens lens) {
58 fireLensUpdated();
59 }
60 }