001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.graph; 005 006 import graphlab.graph.graph.AbstractGraphRenderer; 007 import graphlab.graph.graph.FastRenderer; 008 import graphlab.graph.graph.GraphModel; 009 import graphlab.platform.core.BlackBoard; 010 011 import javax.swing.*; 012 import java.awt.*; 013 014 /** 015 * A Swing Graph component which can be used easily to show graphs, 016 * note that the resulting component will not have any editing capabilities, 017 * The Events (GraphEvent, VertexEvent, EdgeEvent) will be sent to blackboard and 018 * can be used from there. 019 * <p/> 020 * you should attach the relating actions (e.g. AddVertex, AddEdge, ...) to blackboard 021 * to have the editing. 022 * 023 * @author azin azadi 024 * @see graphlab.graph.event.GraphEvent 025 */ 026 public class JGraph extends JScrollPane { 027 private static final long serialVersionUID = -500431952321243220L; 028 private AbstractGraphRenderer view; 029 030 public JGraph(GraphModel g, AbstractGraphRenderer view) { 031 super(view); 032 this.g = g; 033 this.view = view; 034 view.setGraph(g); 035 } 036 037 public void scrollRectToVisible(Rectangle aRect) { 038 super.scrollRectToVisible(aRect); 039 } 040 041 public GraphModel getGraph() { 042 return g; 043 } 044 045 public AbstractGraphRenderer getGraphView() { 046 return view; 047 } 048 049 GraphModel g; 050 051 static int i = 0; 052 053 public static JGraph getNewComponent(BlackBoard b) { 054 GraphModel model = new GraphModel(); 055 AbstractGraphRenderer view = new FastRenderer(model, b); 056 model.setLabel("G" + (i++)); 057 return new JGraph(model, view); 058 } 059 060 public AbstractGraphRenderer getView() { 061 return view; 062 } 063 064 /** 065 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6333318 jscrollpane bug 066 */ 067 }