001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.jung; 025 026 import java.awt.Event; 027 028 import javax.swing.event.ListDataEvent; 029 import javax.swing.event.ListDataListener; 030 031 import edu.uci.ics.jung.graph.Vertex; 032 import edu.uci.ics.jung.graph.impl.DirectedSparseGraph; 033 034 public class TopologyGraphWrapper extends DirectedSparseGraph implements ListDataListener { 035 036 public TopologyGraphWrapper(Object iTopology) { 037 038 Vertex v = null; 039 040 // if (iTopology instanceof Algorithm) { 041 // Algorithm a = (Algorithm) iTopology; 042 // v = new DirectedSparseVertex(); 043 // v.setUserDatum(Data.Label, a.getLabel(), UserData.SHARED); 044 // v.setUserDatum(Data.JDMPObject, a, UserData.SHARED); 045 // v.setUserDatum(Data.Type, "Algorithm", UserData.SHARED); 046 // addVertex(v); 047 // } 048 // 049 // for (Algorithm a : iTopology.getAlgorithms()) { 050 // v = new DirectedSparseVertex(); 051 // v.setUserDatum(Data.Label, a.getLabel(), UserData.SHARED); 052 // v.setUserDatum(Data.JDMPObject, a, UserData.SHARED); 053 // v.setUserDatum(Data.Type, "Algorithm", UserData.SHARED); 054 // addVertex(v); 055 // } 056 057 // for (Variable va : iTopology.getVariableList()) { 058 // v = new DirectedSparseVertex(); 059 // v.setUserDatum(Data.Label, va.getLabel(), UserData.SHARED); 060 // v.setUserDatum(Data.JDMPObject, va, UserData.SHARED); 061 // v.setUserDatum(Data.Type, "Variable", UserData.SHARED); 062 // addVertex(v); 063 // } 064 065 // for (Object o1 : getVertices()) { 066 // for (Object o2 : getVertices()) { 067 // Vertex v1 = (Vertex) o1; 068 // Vertex v2 = (Vertex) o2; 069 // CoreObject u1 = (CoreObject) v1.getUserDatum(Data.JDMPObject); 070 // CoreObject u2 = (CoreObject) v2.getUserDatum(Data.JDMPObject); 071 // if (u1 instanceof Algorithm && u2 instanceof Variable) { 072 // Algorithm a = (Algorithm) u1; 073 // Variable va = (Variable) u2; 074 // int index = a.getVariables().indexOf(va); 075 // if (index >= 0) { 076 // Edge e = null; 077 // switch (a.getEdgeDirectionForVariable(index)) { 078 // case Algorithm.INCOMING: 079 // e = new DirectedSparseEdge(v2, v1); 080 // break; 081 // case Algorithm.OUTGOING: 082 // e = new DirectedSparseEdge(v1, v2); 083 // break; 084 // case Algorithm.BIDIRECTIONAL: 085 // e = new DirectedSparseEdge(v1, v2); 086 // Edge e2 = new DirectedSparseEdge(v2, v1); 087 // addEdge(e2); 088 // break; 089 // } 090 // if (e != null) { 091 // e.setUserDatum(Data.Label, a.getEdgeLabelForVariable(index), 092 // UserData.SHARED); 093 // addEdge(e); 094 // } 095 // } 096 // } 097 // if (u1 instanceof Algorithm && u2 instanceof Algorithm) { 098 // Algorithm a = (Algorithm) u1; 099 // Algorithm a2 = (Algorithm) u2; 100 // int index = a.getIndexOfAlgorithm(a2); 101 // if (index >= 0) { 102 // Edge e = new DirectedSparseEdge(v1, v2); 103 // e.setUserDatum(Data.Label, a.getEdgeLabelForAlgorithm(index), 104 // UserData.SHARED); 105 // addEdge(e); 106 // } 107 // } 108 // } 109 // } 110 111 // iTopology.getVariableList().addListDataListener(this); 112 // iTopology.addAlgorithmListListener(this); 113 } 114 115 public void variableAdded(Event e) { 116 // Variable var = (Variable) e.getData(); 117 // Vertex v = new DirectedSparseVertex(); 118 // v.setUserDatum(Data.Label, var.getLabel(), UserData.SHARED); 119 // v.setUserDatum(Data.JDMPObject, var, UserData.SHARED); 120 // v.setUserDatum(Data.Type, "Variable", UserData.SHARED); 121 // addVertex(v); 122 } 123 124 // public void algorithmAdded(AlgorithmListEvent e) { 125 // Algorithm a = (Algorithm) e.getData(); 126 // Vertex v = new DirectedSparseVertex(); 127 // v.setUserDatum(Data.Label, a.getLabel(), UserData.SHARED); 128 // v.setUserDatum(Data.JDMPObject, a, UserData.SHARED); 129 // v.setUserDatum(Data.Type, "Algorithm", UserData.SHARED); 130 // addVertex(v); 131 // } 132 // 133 // public void algorithmRemoved(AlgorithmListEvent e) { 134 // 135 // } 136 // 137 // public void algorithmUpdated(AlgorithmListEvent e) { 138 // mGraphListenerHandler.handleAdd((Edge) null); 139 // } 140 141 public void contentsChanged(ListDataEvent e) { 142 // TODO Auto-generated method stub 143 144 } 145 146 public void intervalAdded(ListDataEvent e) { 147 // TODO Auto-generated method stub 148 149 } 150 151 public void intervalRemoved(ListDataEvent e) { 152 // TODO Auto-generated method stub 153 154 } 155 156 }