/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford Mount Allison University 2001 File: Edge.java (author: Larry Barowski, Auburn University, 2/20/97) Description: This file is a heavily modified version of the original developed at Auburn University for the VGJ (Visualizing Graphs with Java) applet. This class draws an edge of a graph(category). */ //import statements import java.awt.Graphics; import java.awt.FontMetrics; import java.awt.Color; import java.lang.System; import java.util.Hashtable; import java.util.Enumeration; import java.lang.Math; public class Edge { protected Node head_, tail_; protected DPoint3[] points_; private DPoint3[] oldpoints_ = null; private boolean dummy_ = false; public boolean selected = false; private String label_; private int lineStyle_; private Color color_; //The below four lines determine line styles public static String styleNames[] = { "solid", "dashed", "dotted", "dashdot" }; public static Color styleColors[] = { Color.black, Color.blue, Color.green, Color.orange }; public static String styleLabels[] = { "solid (black)", "dashed (blue)", "dotted (green)", "dashdot (orange)" }; public static String stylePatterns[] = { "[1 0 0 0] 0", "[2 1 2 1] 0", "[1 1 1 1] 0", "[2 1 1 1] 0" }; //Just change this list to change the data types.**/ public static String defaultDataTypes_[] = { "Data1", "Data2" }; public Hashtable data_; /** * A general purpose data field. * Algorithms that operate on Edges can store any necessary data here. **/ public Object data; public Edge(Node tail, Node head, DPoint3[] points, boolean dummy) { head_ = head; tail_ = tail; points_ = points; if(points == null) points = new DPoint3[0]; dummy_ = dummy; label_ = new String(""); lineStyle_ = 0; color_ = Color.black; data_ = new Hashtable((int)((defaultDataTypes_.length + 1) * 1.5)); for(int i = 0; i < defaultDataTypes_.length; i++) data_.put(defaultDataTypes_[i], ""); } public Edge(Node tail, Node head, Edge from) { head_ = head; tail_ = tail; dummy_ = from.dummy_; label_ = from.label_; lineStyle_ = from.lineStyle_; color_ = from.color_; DPoint3[] frompoints = from.points(); points_ = new DPoint3[frompoints.length]; System.arraycopy(frompoints, 0, points_, 0, frompoints.length); data_ = new Hashtable((int)((defaultDataTypes_.length + 1) * 1.5)); for(int i = 0; i < defaultDataTypes_.length; i++) data_.put(defaultDataTypes_[i], ""); } public Edge(Node tail, Node head, GMLobject gml) { head_ = head; tail_ = tail; GMLobject edgegraphics = gml.getGMLSubObject("graphics", GMLobject.GMLlist, false); if(edgegraphics != null) { GMLobject point; int points_size = 10; // Arbitrary value. DPoint3[] points = new DPoint3[points_size]; DPoint3[] tmppoints; int pointnum = 0; for(point = edgegraphics.getGMLSubObject("Point", GMLobject.GMLlist, false); point != null; point = edgegraphics.getNextGMLSubObject()) { Double x, y, z; x = (Double)point.getValue("x", GMLobject.GMLreal); y = (Double)point.getValue("y", GMLobject.GMLreal); z = (Double)point.getValue("z", GMLobject.GMLreal); if(x != null && y != null) { if(pointnum >= points_size) { points_size = pointnum * 2; tmppoints = new DPoint3[points_size]; System.arraycopy(points, 0, tmppoints, 0, pointnum); points = tmppoints; } points[pointnum] = new DPoint3(x.doubleValue(), y.doubleValue(), 0.0); if(z != null) points[pointnum].z = z.doubleValue(); else points[pointnum].z = 0.0; pointnum++; } } points_ = new DPoint3[pointnum]; System.arraycopy(points, 0, points_, 0, pointnum); } else points_ = new DPoint3[0]; String label; if((label = (String)gml.getValue("label", GMLobject.GMLstring)) != null) label_ = label; else label = new String(); String style; lineStyle_ = 0; if((style = (String)gml.getValue("linestyle", GMLobject.GMLstring)) != null) { // System.out.println("style: " + style); for(int i = 0; i < styleNames.length; i++) if(styleNames[i].equals(style)) { lineStyle_ = i; break; } } /* String color; // added jan 23, 2004 by jesse if((color = (String)gml.getValue("color", GMLobject.GMLstring)) != null) { if (color.compareToIgnoreCase("red") == 0) color_ = Color.red; else if (color.compareToIgnoreCase("green") == 0) color_ = Color.green; else if (color.compareToIgnoreCase("blue") == 0) color_ = Color.blue; else color_ = Color.blue; }*/ data_ = new Hashtable((int)((defaultDataTypes_.length + 1) * 1.5)); for(int i = 0; i < defaultDataTypes_.length; i++) data_.put(defaultDataTypes_[i], ""); gml.setHashFromGML("data", GMLobject.GMLstring, data_); } public void setGMLvalues(GMLobject gml) { gml.setValue("target", GMLobject.GMLinteger, new Integer(head_.getIdObject().intValue())); gml.setValue("source", GMLobject.GMLinteger, new Integer(tail_.getIdObject().intValue())); gml.setValue("data", GMLobject.GMLlist, null); Enumeration keys = data_.keys(); while(keys.hasMoreElements()) { String key, value; key = (String)keys.nextElement(); value = (String)data_.get(key); if(value != null && value.length() != 0) { String datakey = "data." + key; gml.setValue(datakey, GMLobject.GMLstring, value); } } if(points_.length > 0) { GMLobject edgegraphics = new GMLobject("graphics", GMLobject.GMLlist); gml.addObjectToEnd(edgegraphics); int length = points_.length; for(int pt = 0; pt < length; pt++) { GMLobject point = new GMLobject("Point", GMLobject.GMLlist); edgegraphics.addObjectToEnd(point); point.setValue("z", GMLobject.GMLreal, new Double(points_[pt].z)); point.setValue("y", GMLobject.GMLreal, new Double(points_[pt].y)); point.setValue("x", GMLobject.GMLreal, new Double(points_[pt].x)); } } gml.setValue("label", GMLobject.GMLstring, label_); gml.setValue("linestyle", GMLobject.GMLstring, styleNames[lineStyle_]); } public void draw(Graphics graphics, Matrix44 transform, boolean inplane, boolean directed, boolean arrow_only, int quality, GraphCanvas canvas, int which_gr, Color c, boolean print, String hString) //This method draws an edge onto the specified canvas and it //calls the method that draws the label of the edge as rotating text { //local variables double scale = transform.scale; int npoints = points_.length; DPoint3 p1to, p2to; //opposite Edge variables Enumeration edges = canvas.graph_.getEdges(); Edge oppedge = (Edge)(edges.nextElement()); int numoppedge = 0; //set color and style of current edge graphics.setColor(color_); //If edge does not contain any user defined points //between the start and end node if(npoints == 0) { p1to = head_.getPosition3(); p2to = tail_.getPosition3(); } //If edge does contain any user defined points //between the start and end node else { p1to = points_[0]; p2to = points_[npoints - 1]; } //Define p1 and p2 DPoint3 p1 = tail_.intersectWithLineTo(p1to, inplane, quality); DPoint3 p2 = head_.intersectWithLineTo(p2to, inplane, quality); p1.transform(transform); p2.transform(transform); // Self edge with no intermediate points. if(head_ == tail_ && npoints == 0) { p2.x = p1.x + 1; p2.y = p1.y; } //-------------------------------DRAW EDGE---------------------------------- //Draw the edge part of the current arrow ie. "----" if(!arrow_only) { //Draw arrows which have the same object as their domain and //codomain as a arc if (head_ == tail_) { graphics.drawArc((int)p1.x-15, (int)p1.y-25, 25, 25, -45, 280); // Draw arrow. p1.x += 7; p1.y -= 4; DPoint3 from = new DPoint3(p1to); //DPoint3 from = new DPoint3(); from.x = p1.x + 15; from.y = p1.y - 25; //from.transform(transform); ///if((int)from.x == (int)p1.x && (int)from.y == (int)p1.y) // from.x += 10.0; drawArrow_(graphics, from, p1); } //Draw arrows which have different objects as their domain and //codomain using the following algorithm else if(npoints == 0) { int num_arrows = 1; //Initialize number of arrows to one int space = 0; //the integer space stores the space that //exists between the current edge and the middle edge boolean even = true; //boolean even determines which side (top or bottom) //that edge should be on when multiple edges occur int currarr = 0; boolean backwards; //parse through label to determine the number of objects //between given domain and codomain for (int i=0; i < label_.length(); i++) if(label_.charAt(i) == ',') num_arrows++; //Determine if any arrows are already drawn from current codomain //to domain ie. opposite direction boolean opparr = false; edges = canvas.graph_.getEdges(); numoppedge = 0; while(edges.hasMoreElements()) { Edge edge = (Edge)(edges.nextElement()); if ((edge.head_.getLabel().equals(tail_.getLabel())) && (edge.tail_.getLabel().equals(head_.getLabel())) && (!edge.label_.equals(label_))) { opparr = true; oppedge = edge; numoppedge = 1; } } if (opparr == true) { for (int i=0; i < oppedge.label_.length(); i++) if(oppedge.label_.charAt(i) == ',') numoppedge++; } if (num_arrows < numoppedge) backwards = true; else backwards = false; //Add numoppedge because opposite edges have to be redrawn when new //edge is drawn if (num_arrows != 0) num_arrows += numoppedge; int highlight = -1; if (hString != null) { if (numoppedge != 0) { if (backwards) highlight = getEdgeVal(label_ + "," + oppedge.label_, hString, graphics); else highlight = getEdgeVal(oppedge.label_ + "," + label_, hString, graphics); } else highlight = getEdgeVal(label_, hString, graphics); } //Set space for (int i=0; i < num_arrows; i++) { if (hString != null) { if (i == (highlight-1)) { //graphics.drawString(highlight-1 + numoppedge + " ", 50, 50); // graphics.setColor(c); // changed: should be "c" } // else if (highlight == -1) // graphics.setColor(Color.gray); // else // graphics.setColor(Color.black); } currarr = (i+1)/2; if (even == true) { space = 15 * currarr; even = false; } else if (even == false) { space = (-15)* currarr; even = true; } //Initialize points for three part edges ie. "\_/" double xm = (p1.x + p2.x)/2; double xm1 = (p1.x + xm)/2; double xm2 = (xm + p2.x)/2; double ym = (p1.y + p2.y)/2; double ym1 = (p1.y + ym)/2; double ym2 = (ym + p2.y)/2; //slope formula (y2-y1)/(x2-x1) double slope = (p2.y - p1.y)/(p2.x - p1.x); double newslope = 0; boolean n = false; if (slope < 0) { slope = slope * (-1); n = true; } if (slope <= 1) { newslope = 90*slope; } else { newslope = 90*(1-1/slope); } double spacexd = space * newslope/90; double spaceyd = space - spacexd; int spacey = 15; int spacex = 15; if (n == false) { if (slope < (1)) { spacey = space; spacex = -1* (int)spacexd; } else if (slope == (1)) { spacex = -space; spacey = space; space = -1 * space; } else { spacex = space; spacey = -1* (int)spaceyd; } } else { if (slope < (1)) { spacey = space; spacex = (int)spacexd; } else if (slope == (1)) { spacex = -space; spacey = space; space = -1 * space; } else { spacex = space; spacey = (int)spaceyd; } } //interior points of 3-segment edge //ie. points that connect angled segments with middle segment double mid1x = (xm1 + spacex + p1.x)/2; double mid1y = (ym1 + spacey + p1.y)/2; double mid2x = (xm2 + spacex + p2.x)/2; double mid2y = (ym2 + spacey + p2.y)/2; //max distance of edge from object double dist = 25; //find end points that are within the appropriate distance from //the domain and codomain objects. try { while (dist < Math.sqrt((double)(((int)p1.x - (int)mid1x) * ((int)p1.x- (int)mid1x) + ((int)p1.y- (int)mid1y) *((int)p1.y-(int)mid1y)))) { mid1x = (p1.x + mid1x)/2; mid1y = (p1.y + mid1y)/2; } while (dist < Math.sqrt((double)(((int)p2.x - (int)mid2x) * ((int)p2.x- (int)mid2x) + ((int)p2.y- (int)mid2y) *((int)p2.y-(int)mid2y)))) { mid2x = (p2.x + mid2x)/2; mid2y = (p2.y + mid2y)/2; } } catch(ArithmeticException a) { } // change the color here //Draw three part edge graphics.drawLine((int)mid1x, (int)mid1y, (int)xm1+spacex, (int)ym1+spacey); graphics.drawLine((int)xm1+spacex ,(int)ym1+spacey ,(int)xm2+spacex ,(int)ym2+spacey ); graphics.drawLine((int)mid2x, (int)mid2y, (int)xm2+spacex, (int)ym2+spacey); //-----------------------DRAW OPPOSITE ARROW-------------------------- if (i < (numoppedge) && !backwards || i >= (numoppedge) && backwards) { // Draw arrow. DPoint3 mid1 = new DPoint3(p2); mid1.x = mid1x; mid1.y = mid1y; DPoint3 from = new DPoint3(p1to); //DPoint3 from = new DPoint3(); from.x = xm1+spacex; from.y = ym1+spacey; //from.transform(transform); //if((int)from.x == (int)mid1.x && (int)from.y == (int)mid1.y) // from.x += 10.0; drawArrow_(graphics, from, mid1); } //-----------------------DRAW CURRENT ARROW--------------------------- else { // Draw arrow. DPoint3 mid2 = new DPoint3(p2); mid2.x = mid2x; mid2.y = mid2y; DPoint3 from = new DPoint3(p2to); //DPoint3 from = new DPoint3(p2to); from.x = xm2+spacex; from.y = ym2+spacey; //from.transform(transform); //if((int)from.x == (int)mid2.x && (int)from.y == (int)mid2.y) // from.x += 10.0; drawArrow_(graphics, from, mid2); } } } else { DPoint3 point = new DPoint3(points_[0]); point.transform(transform); graphics.drawLine((int)p1.x, (int)p1.y, (int)point.x, (int)point.y); DPoint3 oldpoint = new DPoint3(); for(int i = 1; i < npoints; i++) { oldpoint.move(point); point.move(points_[i]); point.transform(transform); graphics.drawLine((int)oldpoint.x, (int)oldpoint.y, (int)point.x, (int)point.y); } graphics.drawLine((int)point.x, (int)point.y, (int)p2.x, (int)p2.y); } } //------------------------DRAW SELECTION HANDLES---------------------------- if(!arrow_only && selected) { graphics.setColor(Color.red); graphics.drawRect((int)p1.x - 2, (int)p1.y - 2, 4, 4); if(head_ != tail_) // Not a self-edge. graphics.drawRect((int)p2.x - 2, (int)p2.y - 2, 4, 4); for(int pointindex = 0; pointindex < npoints; pointindex++) { p2.move(points_[pointindex]); p2.transform(transform); graphics.drawRect((int)p2.x - 2, (int)p2.y - 2, 4, 4); } graphics.setColor(Color.white); graphics.drawRect((int)p1.x - 1, (int)p1.y - 1, 2, 2); if(head_ != tail_) // Not a self-edge. graphics.drawRect((int)p2.x - 1, (int)p2.y - 1, 2, 2); for(int pointindex = 0; pointindex < npoints; pointindex++) { p2.move(points_[pointindex]); p2.transform(transform); graphics.drawRect((int)p2.x - 1, (int)p2.y - 1, 2, 2); } graphics.setColor(c); } //---------------------------------DRAW LABEL------------------------------- //Draw label for edge with different domain and codomain if(quality > 0 && label_ != null && label_.length() > 0 && head_ != tail_ ) { if(!arrow_only) { if(npoints == 0) { //Initial number of arrows to one and parse through label to //determine the number of objects between given domain and codomain int num_arrows = 1; String label2 = new String(); if (numoppedge != 0) { label2 = oppedge.label_ + "," + label_; } else label2 = label_; for (int i=0; i < label2.length(); i++) if(label2.charAt(i) == ',') num_arrows++; int space = 0; //the integer space stores the space that //exists between the current edge and the middle edge boolean even = true; int currlab = 0; for (int i=0; i < num_arrows; i++) { currlab = (i+1)/2; if (even == true) { space = 15 * currlab; even = false; } else if (even == false) { space = (-15)* currlab; even =true; } double xm = (p1.x + p2.x)/2; double xm1 = (p1.x + xm)/2; double xm2 = (xm + p2.x)/2; double ym = (p1.y + p2.y)/2; double ym1 = (p1.y + ym)/2; double ym2 = (ym + p2.y)/2; int temparr = 0; int startchar = 0; int endchar = label2.length(); for (int j=0; j < label2.length(); j++) { if(label2.charAt(j) == ',') { temparr++; if (temparr == (i)) startchar = j+1; if (temparr == (i+1)) endchar = j; } } String newlabel = label2.substring(startchar, endchar); char[] label = newlabel.toCharArray(); DPoint3 to; if(npoints == 0) to = new DPoint3(p2); else { to = new DPoint3(p1to); to.transform(transform); } if(p1.x == to.x && p1.y == to.y) to.x++; double center_x = (p1.x + to.x) / 2.0; double center_y = (p1.y + to.y) / 2.0; double theta = Math.atan2(-(to.y - p1.y), to.x - p1.x); //slope formula (y2-y1)/(x2-x1) double slope = (p2.y - p1.y)/(p2.x - p1.x); double newslope = 0; boolean n = false; if (slope < 0) { slope = slope * (-1); n = true; } if (slope <= 1) { newslope = 90*slope; } else { newslope = 90*(1-1/slope); } double spacexd = space * newslope/90; double spaceyd = space - spacexd; int spacey = 15; int spacex = 15; if (n == false) { if (slope < (1)) { spacey = space; spacex = -1* (int)spacexd; } else if (slope == (1)) { spacex = -space; spacey = space; space = -1 * space; } else { spacex = space; spacey = -1* (int)spaceyd; } } else { if (slope < (1)) { spacey = space; spacex = (int)spacexd; } else if (slope == (1)) { spacex = -space; spacey = space; space = -1 * space; } else { spacex = space; spacey = (int)spaceyd; } } if (print == true) { graphics.drawString(newlabel, ((int)xm1+spacex +(int)xm2+spacex)/2, ((int)ym1+spacey+(int)ym2+spacey)/2); } else canvas.drawRotatedText(newlabel, theta, ((int)xm1+spacex +(int)xm2+spacex)/2, ((int)ym1+spacey+(int)ym2+spacey)/2, graphics, which_gr); } } } } //draw label for self edge else if(quality > 0 && label_ != null && label_.length() > 0 && (head_ == tail_)) { for(int pointindex = 0; pointindex < npoints; pointindex++) { p2.move(points_[pointindex]); p2.transform(transform); } for(int pointindex = 0; pointindex < npoints; pointindex++) { p2.move(points_[pointindex]); p2.transform(transform); } p1.x = p2.x; p1.y = p2.y; char[] label = label_.toCharArray(); DPoint3 to; if(npoints == 0) to = new DPoint3(p2); else { to = new DPoint3(p1to); to.transform(transform); } if(p1.x == to.x && p1.y == to.y) to.x++; double center_x = (p1.x + to.x) / 2.0; double center_y = (p1.y + to.y) / 2.0; double xval = p1.x; double yval = p1.y - 25; double theta = Math.atan2(-(to.y - p1.y), to.x - p1.x); canvas.drawRotatedText(label_, theta, (int)xval, (int)yval, graphics, which_gr); } } private void drawArrow_(Graphics graphics, DPoint3 p1, DPoint3 p2) //Draw arrow head on edge { double dx = p1.x - p2.x; double dy = p1.y - p2.y; double length = Math.sqrt(dx * dx + dy * dy); DPoint p3 = new DPoint(p2.x, p2.y); double arrow_size = 6; // Move 5 pixels back. p3.x += arrow_size / length * dx; p3.y += arrow_size / length * dy; DPoint p4 = new DPoint(p3.x, p3.y); // Out 4 pixels. p4.x += arrow_size * .7 / length * dy; p4.y -= arrow_size * .7 / length * dx; p3.x -= arrow_size * .7 / length * dy; p3.y += arrow_size * .7 / length * dx; graphics.drawLine((int)p2.x, (int)p2.y, (int)p4.x, (int)p4.y); graphics.drawLine((int)p2.x, (int)p2.y, (int)p3.x, (int)p3.y); } public String toPS(Matrix44 transform, boolean inplane, boolean directed) { double scale = transform.scale; String result = new String(); int npoints = points_.length; DPoint3 p1to, p2to; if(npoints == 0) { p1to = head_.getPosition3(); p2to = tail_.getPosition3(); } else { p1to = points_[0]; p2to = points_[npoints - 1]; } DPoint3 p1 = tail_.intersectWithLineTo(p1to, inplane, 2); DPoint3 p2 = head_.intersectWithLineTo(p2to, inplane, 2); p1.transform(transform); p2.transform(transform); // Self edge with no intermediate points. if(head_ == tail_ && npoints == 0) { p2.x = p1.x + 1; p2.y = p1.y; } result += PSnum_(p1.x) + PSnum_(p1.y) + "moveto\n"; DPoint3 point = new DPoint3(); for(int i = 0; i < npoints; i++) { point.move(points_[i]); point.transform(transform); result += PSnum_(point.x) + PSnum_(point.y) + "lineto\n"; } result += PSnum_(p2.x) + PSnum_(p2.y) + "lineto\n"; result += stylePatterns[lineStyle_] + " setdash\n"; result += "stroke\n"; result += "[1 0 0 0] 0 setdash\n"; // Draw label. if(label_ != null && label_.length() > 0) { DPoint3 to; if(npoints == 0) to = new DPoint3(p2); else { to = new DPoint3(p1to); to.transform(transform); } if(p1.x == to.x && p1.y == to.y) to.x++; double center_x = (p1.x + to.x) / 2.0; double center_y = (p1.y + to.y) / 2.0; double dx = to.x - p1.x; double dy = to.y - p1.y; double angle = Math.atan2(dx, dy); angle = angle * 180.0 / Math.PI - 90.0; if(Math.abs(angle) > 90.0) angle += 180; result += "(" + psString_(label_) + ") " + center_x + " " + center_y + " " + angle + " slantlabel\n"; } // Draw arrow. if(directed) { DPoint3 from = new DPoint3(p2to); from.transform(transform); if((int)from.x == (int)p2.x && (int)from.y == (int)p2.y) from.x -= 10.0; result += arrowPS_(from, p2); } result += "\n"; return result; } // Add escape characters for PostScript. private StringBuffer psString_(String source) { int len = source.length(); StringBuffer result = new StringBuffer(len * 2); for(int i = 0; i < len; i++) { char chr = source.charAt(i); if(chr == '(' || chr == ')' || chr == '\\') result.append('\\'); if(chr >= 32 && chr < 128) result.append(chr); else { result.append("\\" + ((chr >> 6) & 7) + ((chr >> 3) & 7) + (chr & 7)); } } return result; } private String arrowPS_(DPoint3 p1, DPoint3 p2) { double dx = p1.x - p2.x; double dy = p1.y - p2.y; double length = Math.sqrt(dx * dx + dy * dy); dx /= length; dy /= length; return PSnum_(p2.x) + PSnum_(p2.y) + PSnum_(dx) + PSnum_(dy) + "arrow\n"; } private String PSnum_(double num) { if(num > 0.0) return String.valueOf(num) + " "; else if(num < 0.0) return String.valueOf(-num) + " neg "; else return "0 "; } public DPoint3[] points() { return points_; } public Node head() { return head_; } public Node tail() { return tail_; } public boolean isDummy() { return dummy_; } public void saveState() { oldpoints_ = new DPoint3[points_.length]; for(int i = 0; i < points_.length; i++) oldpoints_[i] = new DPoint3(points_[i]); } public void slide(Matrix44 moveTransform, Matrix44 viewTransform, int xoffs, int yoffs) { if(oldpoints_ == null) return; for(int i = 0; i < points_.length; i++) { points_[i].move(oldpoints_[i]); points_[i].transform(viewTransform); // Transform to screen coordinates. points_[i].x += xoffs; points_[i].y += yoffs; points_[i].transform(moveTransform); // Transform to graph coordinates. } } public String getLabel() { return label_; } public void setLabel(String label) { label_ = label; } public void setLineStyle(int line_style) { lineStyle_ = line_style; } public int getLineStyle() { return lineStyle_; } public int getEdgeVal(String labels, String currLabel, Graphics g) { int num_arrows = 1; /*if (numoppedge != 0) { label2 = oppedge.labe_ + "," + label_; } else label2 = label_;*/ for (int i=0; i < labels.length(); i++) if(labels.charAt(i) == ',') num_arrows++; //g.drawString(labels, 100, 100); //g.drawString(currLabel, 100, 120); for (int i=0; i < num_arrows; i++) { int temparr = 0; int startchar = 0; int endchar = labels.length(); for (int j=0; j < labels.length(); j++) { if(labels.charAt(j) == ',') { temparr++; if (temparr == (i)) startchar = j+1; if (temparr == (i+1)) endchar = j; } } String newlabel = labels.substring(startchar, endchar); //g.drawString(newlabel, 100, 120 + 10*endchar); if (newlabel.equals(currLabel)) { //g.drawString(labels + newlabel + " = " + currLabel + i, 100, 100); return(i+1); } } return(-1); } public void getEdgePresent(String labels, String currLabel, GraphCanvas functorFromCanvas, IniSettings ini, boolean colored) { int num_arrows = 1; /* if (numoppedge != 0) { label2 = oppedge.label_ + "," + label_; } else label2 = label_; */ for (int i=0; i < labels.length(); i++) if(labels.charAt(i) == ',') num_arrows++; //g.drawString(labels, 100, 100); //g.drawString(currLabel, 100, 120); for (int i=0; i < num_arrows; i++) { int temparr = 0; int startchar = 0; int endchar = labels.length(); for (int j=0; j < labels.length(); j++) { if(labels.charAt(j) == ',') { temparr++; if (temparr == (i)) startchar = j+1; if (temparr == (i+1)) endchar = j; } } String newlabel = labels.substring(startchar, endchar); //g.drawString(newlabel, 100, 120 + 10*endchar); if (newlabel.equals(currLabel)) { //Draw edge function if (colored) draw(functorFromCanvas.getGraphicsInternal_(), functorFromCanvas.viewTransform_, functorFromCanvas.xyPlane_, true, false, functorFromCanvas.quality_, functorFromCanvas, 1, ini.getAColor(), false, currLabel); else draw(functorFromCanvas.getGraphicsInternal_(), functorFromCanvas.viewTransform_, functorFromCanvas.xyPlane_, true, false, functorFromCanvas.quality_, functorFromCanvas, 1, Color.black, false, currLabel); } } } }