| Line | Hits | Source |
|---|---|---|
| 1 | /* | |
| 2 | * Copyright (c) 2005, the JUNG Project and the Regents of the University of | |
| 3 | * California All rights reserved. | |
| 4 | * | |
| 5 | * This software is open-source under the BSD license; see either "license.txt" | |
| 6 | * or http://jung.sourceforge.net/license.txt for a description. | |
| 7 | * | |
| 8 | * Created on Aug 23, 2005 | |
| 9 | */ | |
| 10 | ||
| 11 | package edu.uci.ics.jung.visualization.subLayout; | |
| 12 | ||
| 13 | import java.awt.geom.Point2D; | |
| 14 | import java.util.Collection; | |
| 15 | import java.util.Iterator; | |
| 16 | import java.util.LinkedHashSet; | |
| 17 | ||
| 18 | import edu.uci.ics.jung.graph.ArchetypeVertex; | |
| 19 | import edu.uci.ics.jung.graph.Vertex; | |
| 20 | import edu.uci.ics.jung.visualization.Layout; | |
| 21 | import edu.uci.ics.jung.visualization.LayoutDecorator; | |
| 22 | ||
| 23 | /** | |
| 24 | * Extends the base decorator class and overrides methods to | |
| 25 | * cause the location methods to check with the sublayouts | |
| 26 | * for location information | |
| 27 | * | |
| 28 | * @author Tom Nelson - RABA Technologies | |
| 29 | * | |
| 30 | * | |
| 31 | */ | |
| 32 | public class SubLayoutDecorator extends LayoutDecorator { | |
| 33 | ||
| 34 | 0 | final protected Collection subLayouts = new LinkedHashSet(); |
| 35 | ||
| 36 | public SubLayoutDecorator(Layout delegate) { | |
| 37 | 0 | super(delegate); |
| 38 | 0 | } |
| 39 | ||
| 40 | public void addSubLayout(SubLayout subLayout) { | |
| 41 | 0 | subLayouts.add(subLayout); |
| 42 | 0 | fireStateChanged(); |
| 43 | 0 | } |
| 44 | ||
| 45 | public boolean removeSubLayout(SubLayout subLayout) { | |
| 46 | 0 | boolean wasThere = subLayouts.remove(subLayout); |
| 47 | 0 | fireStateChanged(); |
| 48 | 0 | return wasThere; |
| 49 | } | |
| 50 | ||
| 51 | public void removeAllSubLayouts() { | |
| 52 | 0 | subLayouts.clear(); |
| 53 | 0 | fireStateChanged(); |
| 54 | 0 | } |
| 55 | ||
| 56 | protected Point2D getLocationInSubLayout(ArchetypeVertex v) { | |
| 57 | 0 | Point2D location = null; |
| 58 | 0 | for(Iterator iterator=subLayouts.iterator(); iterator.hasNext(); ) { |
| 59 | 0 | SubLayout subLayout = (SubLayout)iterator.next(); |
| 60 | 0 | location = subLayout.getLocation(v); |
| 61 | 0 | if(location != null) { |
| 62 | 0 | break; |
| 63 | } | |
| 64 | } | |
| 65 | 0 | return location; |
| 66 | } | |
| 67 | ||
| 68 | public Point2D getLocation(ArchetypeVertex v) { | |
| 69 | 0 | Point2D p = getLocationInSubLayout(v); |
| 70 | 0 | if(p != null) { |
| 71 | 0 | return p; |
| 72 | } else { | |
| 73 | 0 | return super.getLocation(v); |
| 74 | } | |
| 75 | } | |
| 76 | ||
| 77 | public void forceMove(Vertex picked, double x, double y) { | |
| 78 | 0 | Point2D p = getLocationInSubLayout(picked); |
| 79 | 0 | if(p != null) { |
| 80 | 0 | p.setLocation(x, y); |
| 81 | } else { | |
| 82 | 0 | super.forceMove(picked, x, y); |
| 83 | } | |
| 84 | 0 | fireStateChanged(); |
| 85 | 0 | } |
| 86 | ||
| 87 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |