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 005 package graphlab.graph; 006 007 import graphlab.graph.graph.*; 008 import graphlab.graph.ui.GTabbedGraphPane; 009 import graphlab.library.util.Pair; 010 import graphlab.platform.core.BlackBoard; 011 012 import java.awt.*; 013 014 /** 015 * @author Azin Azadi 016 */ 017 public class GraphUtils { 018 //_____________________ Graph Renderer ___________________________ 019 /** 020 * @see graphlab.graph.graph.AbstractGraphRenderer#ignoreRepaints(Runnable,boolean) 021 */ 022 public void ignoreRepaints(AbstractGraphRenderer renderer, Runnable run, boolean repaintAfter) { 023 renderer.ignoreRepaints(run, repaintAfter); 024 } 025 026 //______________________ GTabbedGraphPane ______________________ 027 028 /** 029 * @see graphlab.graph.ui.GTabbedGraphPane#showNotificationMessage(String,graphlab.platform.core.BlackBoard,boolean) 030 */ 031 public static void showNotificationMessage(String message, BlackBoard b, boolean formatIt) { 032 GTabbedGraphPane.showNotificationMessage(message, b, formatIt); 033 } 034 035 /** 036 * @see graphlab.graph.ui.GTabbedGraphPane#setMessage(String,graphlab.platform.core.BlackBoard,boolean) 037 */ 038 public static void setMessage(String message, BlackBoard b, boolean formatIt) { 039 GTabbedGraphPane.setMessage(message, b, formatIt); 040 } 041 042 /** 043 * @see graphlab.graph.ui.GTabbedGraphPane#hideNotificationMessage(graphlab.platform.core.BlackBoard) 044 */ 045 public static void hideNotificationMessage(BlackBoard b) { 046 GTabbedGraphPane.hideNotificationMessage(b); 047 } 048 049 /** 050 * @see graphlab.graph.ui.GTabbedGraphPane#showTimeNotificationMessage(String,graphlab.platform.core.BlackBoard,long,boolean) 051 */ 052 public static void showTimeNotificationMessage(String message, final BlackBoard b, final long timeMillis, boolean formatIt) { 053 GTabbedGraphPane.showTimeNotificationMessage(message, b, timeMillis, formatIt); 054 } 055 056 //______________________ GraphControl ______________________ 057 /** 058 * @see graphlab.graph.graph.GraphControl#isPointOnVertex(graphlab.graph.graph.GraphModel,graphlab.graph.graph.VertexModel,graphlab.graph.graph.GraphPoint) 059 */ 060 public static boolean isPointOnVertex(GraphModel g, VertexModel v, GraphPoint p) { 061 return GraphControl.isPointOnVertex(g, v, p); 062 } 063 064 /** 065 * @see graphlab.graph.graph.GraphControl#mindistv(graphlab.graph.graph.GraphModel,graphlab.graph.graph.GraphPoint) 066 */ 067 public static Pair<VertexModel, Double> mindistv(GraphModel g, GraphPoint p) { 068 return GraphControl.mindistv(g, p); 069 } 070 071 /** 072 * @see graphlab.graph.graph.GraphControl#mindiste(graphlab.graph.graph.GraphModel,graphlab.graph.graph.GraphPoint) 073 */ 074 public static Pair<EdgeModel, Double> mindiste(GraphModel g, GraphPoint p) { 075 return GraphControl.mindiste(g, p); 076 } 077 078 //______________________ GraphModel ______________________ 079 /** 080 * @see graphlab.graph.graph.GraphModel#getColor(Integer) 081 */ 082 public static Color getColor(Integer i) { 083 return GraphModel.getColor(i); 084 } 085 086 /** 087 * @see graphlab.graph.graph.GraphModel#addGlobalUserDefinedAttribute(String,Object) 088 * @see graphlab.graph.graph.VertexModel#setUserDefinedAttribute(String,Object) 089 */ 090 public static void addGraphGlobalUserdefinedAttribute(String name, Object defaultvalue) { 091 GraphModel.addGlobalUserDefinedAttribute(name, defaultvalue); 092 } 093 094 /** 095 * @see graphlab.graph.graph.GraphModel#removeGlobalUserDefinedAttribute(String) 096 */ 097 public static void removeGraphGlobalUserdefinedAttribute(String name) { 098 GraphModel.removeGlobalUserDefinedAttribute(name); 099 } 100 101 //______________________ VertexModel ______________________ 102 /** 103 * @see graphlab.graph.graph.VertexModel#addGlobalUserDefinedAttribute(String,Object) 104 * @see graphlab.graph.graph.VertexModel#setUserDefinedAttribute(String,Object) 105 */ 106 public static void addVertexGlobalUserdefinedAttribute(String name, Object defaultvalue) { 107 VertexModel.addGlobalUserDefinedAttribute(name, defaultvalue); 108 } 109 110 /** 111 * @see graphlab.graph.graph.VertexModel#removeGlobalUserDefinedAttribute(String) 112 */ 113 public static void removeVertexGlobalUserdefinedAttribute(String name) { 114 VertexModel.removeGlobalUserDefinedAttribute(name); 115 } 116 117 //______________________ EdgeModel ______________________ 118 /** 119 * @see graphlab.graph.graph.EdgeModel#addGlobalUserDefinedAttribute(String,Object) 120 * @see graphlab.graph.graph.VertexModel#setUserDefinedAttribute(String,Object) 121 */ 122 public static void addEdgeGlobalUserdefinedAttribute(String name, Object defaultvalue) { 123 EdgeModel.addGlobalUserDefinedAttribute(name, defaultvalue); 124 } 125 126 /** 127 * @see graphlab.graph.graph.EdgeModel#removeGlobalUserDefinedAttribute(String) 128 */ 129 public static void removeEdgeGlobalUserdefinedAttribute(String name) { 130 EdgeModel.removeGlobalUserDefinedAttribute(name); 131 } 132 133 //______________________ GraphPoint ______________________ 134 135 /** 136 * creates a new graph point from the given point according too graph zoom, 137 * The input x and y are typically are directly from view, 138 * notice that inside the GraphLab everything are GraphPoint, so they are independent of zoom 139 * use this method only if you want to convert a view point to graph point! 140 * 141 * @param g the graph that zoom and center values are used from. 142 * @param viewx initial x potition 143 * @param viewy initial y position 144 * @return a0 GraphPoint object which have x and y acording to zoom and center 145 */ 146 public static GraphPoint createGraphPoint(GraphModel g, int viewx, int viewy) { 147 double factor = g.getZoomFactor(); 148 return new GraphPoint(viewx / factor, viewy / factor); 149 } 150 151 public static Point createViewPoint(GraphModel g, GraphPoint p) { 152 double factor = g.getZoomFactor(); 153 return new Point((int) (p.x * factor), (int) (p.y * factor)); 154 } 155 156 public static Rectangle createViewRectangle(GraphModel g, Rectangle r) { 157 double factor = g.getZoomFactor(); 158 return new Rectangle((int) (r.x * factor), (int) (r.y * factor), (int) (r.width * factor), (int) (r.height * factor)); 159 160 } 161 }