1 31 32 package org.antlr.works.visualization.graphics.graph; 33 34 import org.antlr.analysis.NFAState; 35 import org.antlr.works.visualization.graphics.GContext; 36 import org.antlr.works.visualization.graphics.primitive.GDimension; 37 import org.antlr.works.visualization.graphics.shape.GLink; 38 import org.antlr.works.visualization.graphics.shape.GNode; 39 40 import java.awt.*; 41 import java.util.List ; 42 43 public class GGraph extends GGraphAbstract { 44 45 public GDimension dimension; 46 public List <GNode> nodes; 47 48 public String name; 49 50 public float offsetX = 0; 51 public float offsetY = 0; 52 53 public void setEnable(boolean flag) { 54 55 } 56 57 public void setContext(GContext context) { 58 super.setContext(context); 59 for (GNode node : nodes) { 60 node.setContext(context); 61 } 62 } 63 64 public void setName(String name) { 65 this.name = name; 66 } 67 68 public void setDimension(GDimension dimension) { 69 this.dimension = dimension; 70 } 71 72 public void setNodes(List <GNode> nodes) { 73 this.nodes = nodes; 74 } 75 76 public GDimension getDimension() { 77 return dimension; 78 } 79 80 public float getHeight() { 81 85 return Math.max(getDimension().getPixelHeight(context), context.getPixelArrowHeight()); 86 } 87 88 public float getWidth() { 89 return getDimension().getPixelWidth(context); 90 } 91 92 public void render(float ox, float oy) { 93 oy += getDimension().getPixelUp(context); 94 95 for (GNode node : nodes) { 96 node.render(ox, oy); 97 } 98 99 offsetX = ox; 100 offsetY = oy; 101 102 setRendered(true); 103 } 104 105 public void draw() { 106 context.nodeColor = Color.black; 107 context.linkColor = Color.black; 108 context.setLineWidth(1); 109 110 for (GNode node : nodes) { 111 node.drawNodeAndLink(); 112 } 113 114 if(context.drawdimension) { 115 context.setColor(Color.lightGray); 116 float width = getDimension().getPixelWidth(context); 117 float up = getDimension().getPixelUp(context); 118 float down = getDimension().getPixelDown(context); 119 if(up+down>0) 120 context.drawRect(offsetX, offsetY-up, width, up+down, false); 121 } 122 } 123 124 public GLink findLinkAtPosition(int x, int y) { 125 for (GNode node : nodes) { 126 for (GLink link : node.links) { 127 130 if (link.containsPoint(new Point(x, y)) && link.transition.label != null) 131 return link; 132 } 133 } 134 return null; 135 } 136 137 public GNode findNodeForStateNumber(int stateNumber) { 138 for (GNode node : nodes) { 139 if (node.state.stateNumber == stateNumber) { 140 return node; 141 } 142 } 143 return null; 144 } 145 146 public boolean containsAtLeastOneState(List states) { 147 for (GNode node : nodes) { 148 for (Object state1 : states) { 149 NFAState state = (NFAState) state1; 150 if (node.containsStateNumber(state.stateNumber)) 151 return true; 152 } 153 } 154 return false; 155 } 156 } 157 | Popular Tags |