| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
package net.sourceforge.combean.adapters.jgraph; |
| 23 | |
|
| 24 | |
import org.jgraph.graph.AttributeMap; |
| 25 | |
import org.jgraph.graph.DefaultEdge; |
| 26 | |
import org.jgraph.graph.DefaultGraphCell; |
| 27 | |
import org.jgraph.graph.DefaultPort; |
| 28 | |
|
| 29 | |
import net.sourceforge.combean.interfaces.graph.NodeIterator; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 0 | public final class JGraphUtils { |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public static JGraphCellAsNode locateFirstNodeWithAttribute( |
| 49 | |
JGraphModelAsGraph g, |
| 50 | |
Object attributeKey, |
| 51 | |
Object queryValue ) |
| 52 | |
{ |
| 53 | 0 | JGraphCellAsNode result = null; |
| 54 | |
|
| 55 | 0 | NodeIterator itAllNodes = g.getAllNodesIterator(); |
| 56 | 0 | while (itAllNodes.hasNext()) { |
| 57 | 0 | JGraphCellAsNode v = (JGraphCellAsNode) itAllNodes.next(); |
| 58 | 0 | AttributeMap attribs = v.getGraphCell().getAttributes(); |
| 59 | 0 | Object value = attribs.get(attributeKey); |
| 60 | 0 | if (value != null && |
| 61 | |
queryValue.toString().equals(value.toString())) { |
| 62 | 0 | result = v; |
| 63 | 0 | break; |
| 64 | |
} |
| 65 | 0 | } |
| 66 | 0 | return result; |
| 67 | |
} |
| 68 | |
|
| 69 | |
public static DefaultGraphCell[] createGraphCells(int num) { |
| 70 | 39 | DefaultGraphCell[] result = new DefaultGraphCell[num]; |
| 71 | |
|
| 72 | 141 | for (int i = 0; i < num; i++) { |
| 73 | 102 | result[i] = new DefaultGraphCell(); |
| 74 | 102 | DefaultPort port = new DefaultPort(); |
| 75 | 102 | result[i].add(port); |
| 76 | |
} |
| 77 | |
|
| 78 | 39 | return result; |
| 79 | |
} |
| 80 | |
|
| 81 | |
public static DefaultEdge[] createEdges(DefaultGraphCell[] nodes, int[][] edges) { |
| 82 | 27 | DefaultEdge[] result = new DefaultEdge[edges.length]; |
| 83 | |
|
| 84 | 54 | for (int i = 0; i < edges.length; i++) { |
| 85 | 27 | result[i] = createEdge(nodes, edges[i][0], edges[i][1]); |
| 86 | |
} |
| 87 | |
|
| 88 | 27 | return result; |
| 89 | |
} |
| 90 | |
|
| 91 | |
public static DefaultEdge createEdge(DefaultGraphCell[] nodes, int from, int to) { |
| 92 | 81 | DefaultEdge result = new DefaultEdge(); |
| 93 | |
|
| 94 | 81 | result.setSource(nodes[from].getChildAt(0)); |
| 95 | 81 | result.setTarget(nodes[to].getChildAt(0)); |
| 96 | |
|
| 97 | 81 | return result; |
| 98 | |
} |
| 99 | |
} |