📄 visofgraph.java
字号:
edge ee = PNet.getEdge(i);
if (ee.getTFrom() == edge.TRANSITION && ee.getIFrom() == iDeleteTransition ||
ee.getTTo() == edge.TRANSITION && ee.getITo() == iDeleteTransition) {
PNet.removeEdge(ee);
}
}
PNet.removeTransition(t);
iDeleteTransition = -1;
}
else if (e != null) {
iDeleteNode = -1;
iDeleteTransition = -1;
nDeleteEdge = 0;
PNet.removeEdge(e);
}
else {
iDeleteNode = -1;
iDeleteTransition = -1;
nDeleteEdge = 0;
}
}
private void mouseDownEdit(Event evt) {
place n = getPlaceAtXY(evt.x, evt.y, null);
transition t = getTransitionAtXY(evt.x, evt.y, null);
edge e = getEdgeAtXY(evt.x, evt.y, null);
if (n != null) {
if (PlaceFra == null) {
PlaceFra = new PlaceFrame(n);
} else {
PlaceFra.setPlace(n);
}
PlaceFra.show();
this.repaint();
e = null;
}
if (t != null) {
if (TransFra == null) {
TransFra = new TransitionFrame(t);
} else {
TransFra.setTransition(t);
}
TransFra.show();
this.repaint();
e = null;
}
if (e != null) {
if (EdgeFra == null) {
EdgeFra = new EdgeFrame(e);
} else {
EdgeFra.setEdge(e);
}
EdgeFra.show();
this.repaint();
}
}
private void mouseMetaDrag(Event evt) {
if (dragingPlace != null) {
dragingPlace.setX(evt.x);
dragingPlace.setY(evt.y);
}
else if (dragingTransition != null) {
dragingTransition.setX(evt.x);
dragingTransition.setY(evt.y);
}
}
private void mouseDragEdge(Event evt) {
}
private void mouseMoveEdge(Event evt) {
place n = getPlaceAtXY(evt.x, evt.y, null);
transition t = getTransitionAtXY(evt.x, evt.y, null);
if (newEdgeFinished == false) {
if (n != null) {
Point p;
if (newEdge.getNumberOfPoints() > 1)
p = newEdge.getPoint(newEdge.getNumberOfPoints() - 2);
else
p = newEdge.getXYFrom(PNet);
newEdge.setLastPoint(p.x, p.y);
newEdge.setTTo(edge.PLACE);
newEdge.setITo(PNet.getIndexOf(n));
}
else if (t != null) {
Point p;
if (newEdge.getNumberOfPoints() > 1)
p = newEdge.getPoint(newEdge.getNumberOfPoints() - 2);
else
p = newEdge.getXYFrom(PNet);
newEdge.setLastPoint(p.x, p.y);
newEdge.setTTo(edge.TRANSITION);
newEdge.setITo(PNet.getIndexOf(t));
}
else {
newEdge.setLastPoint(evt.x, evt.y);
newEdge.setTTo(edge.NOTHING);
newEdge.setITo(0);
}
}
}
private void mouseMoveDelete(Event evt) {
place n = getPlaceAtXY(evt.x, evt.y, null);
transition t = getTransitionAtXY(evt.x, evt.y, null);
edge e = getEdgeAtXY(evt.x, evt.y, null);
if (n != null) {
iDeleteNode = PNet.getIndexOf(n);
iDeleteTransition = -1;
nDeleteEdge = 0;
for (int i = 0; i < PNet.numberOfEdges(); i++) {
edge ee = PNet.getEdge(i);
if (ee.getTFrom() == edge.PLACE && ee.getIFrom() == iDeleteNode ||
ee.getTTo() == edge.PLACE && ee.getITo() == iDeleteNode) {
iDeleteEdge[nDeleteEdge] = i;
nDeleteEdge++;
}
}
}
else if (t != null) {
iDeleteNode = -1;
iDeleteTransition = PNet.getIndexOf(t);
nDeleteEdge = 0;
for (int i = 0; i < PNet.numberOfEdges(); i++) {
edge ee = PNet.getEdge(i);
if (ee.getTFrom() == edge.TRANSITION && ee.getIFrom() == iDeleteTransition ||
ee.getTTo() == edge.TRANSITION && ee.getITo() == iDeleteTransition) {
iDeleteEdge[nDeleteEdge] = i;
nDeleteEdge++;
}
}
}
else if (e != null) {
iDeleteNode = -1;
iDeleteTransition = -1;
nDeleteEdge = 1;
iDeleteEdge[0] = PNet.getIndexOf(e);
}
else {
iDeleteNode = -1;
iDeleteTransition = -1;
nDeleteEdge = 0;
}
}
//
//
//
//
//
public place getPlaceAtXY(int x, int y, place IgnoreNode) {
place n = getClosestNode(x, y, IgnoreNode);
if (n == null)
return null;
if (n.distanceToOnePoint(x, y) < place.getRadius())
return n;
return null;
}
public transition getTransitionAtXY(int x, int y, transition IgnoreTransition) {
transition t = getClosestTransition(x, y, IgnoreTransition);
if (t == null)
return null;
if (t.distance(x, y) < (transition.getHeight() / 2))
return t;
return null;
}
public edge getEdgeAtXY(int x, int y, edge IgnoreEdge) {
edge e = getClosestEdge(x, y, IgnoreEdge);
if (e == null)
return null;
if (e.distance(x, y, PNet) < 10.0)
return e;
return null;
}
public place getClosestNode(int x, int y, place IgnoreNode) {
place n, cn;
double d;
double cd = Double.MAX_VALUE;
if (PNet.numberOfPlaces() == 0)
return null;
else
cn = PNet.getPlace(0);
for (int i = 0; i < PNet.numberOfPlaces(); i++) {
n = PNet.getPlace(i);
// Node is ignored, if it has the same index (-> nodes are the same)
if (! PNet.equal (n, IgnoreNode)) {
d = n.distanceToOnePoint((double) x, (double) y);
if (d < cd) {
cn = n;
cd = d;
}
}
}
return cn;
}
public transition getClosestTransition(int x, int y, transition IgnoreTrans) {
transition t, ct;
double d;
double cd = Double.MAX_VALUE;
if (PNet.numberOfTransitions() == 0)
return null;
else
ct = PNet.getTransition(0);
for (int i = 0; i < PNet.numberOfTransitions(); i++) {
t = PNet.getTransition(i);
// Transition is ignored, if it has the same index (-> Transitions
// are the same)
if (!PNet.equal (t, IgnoreTrans)) {
d = t.distance((double) x, (double) y);
if (d < cd) {
ct = t;
cd = d;
}
}
}
return ct;
}
public edge getClosestEdge(int x, int y, edge IgnoreEdge) {
edge e, ce;
double d;
double cd = Double.MAX_VALUE;
if (PNet.numberOfEdges() == 0)
return null;
else
ce = PNet.getEdge(0);
for (int i = 0; i < PNet.numberOfEdges(); i++) {
e = PNet.getEdge(i);
// Edge is ignored, if it has the same index ( => Edges
// are the same)
if (!PNet.equal (e, IgnoreEdge)) {
d = e.distance((double) x, (double) y, PNet);
if (d < cd) {
ce = e;
cd = d;
}
}
}
return ce;
}
private boolean tooCloseToPlace(int x, int y, place IgnoreNode) {
place n = getClosestNode(x, y, IgnoreNode);
if (n == null)
return false;
if (n.distanceToOnePoint(x, y) < (1.5 * place.getRadius()))
return true;
return false;
}
private boolean tooCloseToTransition(int x, int y, transition IgnoreTransition) {
transition t = getClosestTransition(x, y, IgnoreTransition);
if (t == null)
return false;
if (t.distance(x, y) < (1.5 * transition.getHeight()))
return true;
return false;
}
//
//
//
//
//
private void mouseUpEdge(Event evt) {
}
public void update(Graphics g) {
if (BackBuffer == null)
BackBuffer = createImage(ViewDim.width, ViewDim.height);
Graphics gBB = BackBuffer.getGraphics();
gBB.setColor(getBackground());
gBB.fillRect(0, 0, ViewDim.width, ViewDim.height);
gBB.setColor(Color.black);
drawPlaces(PNet, gBB);
drawTransitions(PNet, gBB);
drawEdges(PNet, gBB);
g.drawImage(BackBuffer, 0, 0, ViewDim.width, ViewDim.height, null);
}
public void paint(Graphics g) {
if (BackBuffer == null)
BackBuffer = createImage(ViewDim.width, ViewDim.height);
Graphics gBB = BackBuffer.getGraphics();
gBB.setColor(getBackground());
gBB.fillRect(0, 0, ViewDim.width, ViewDim.height);
gBB.setColor(Color.black);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -