/
Arrow.java
executable file
·201 lines (172 loc) · 7.87 KB
/
Arrow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
*
* Arrow.java
*
* Author: David Pilo
*
*
Pilo's Visualization Tools for Scheme (PVTS). A Basic Visual Scheme Interpreter.
Copyright (C) 2007 David A. Pilo Mansion
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Contact information:
David Pilo
davidpilo@gmail.com
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class Arrow {
Conscell conscell;
SExpression sexpr;
static int antiColVarVARIANCE = 20;
int my_antiColVar;
int unitDraw = DrawingConscellsPanel.zoom;
int startX, startY, endX, endY;
static int antiColVar = 0;
static Random ran = new Random();
Arrow(Conscell c, SExpression s) {
conscell = c;
sexpr = s;
updateantiColVar();
my_antiColVar = antiColVar;
ArrowDB.addAndChangeColVar(this);
}
public int getColVar() {
return my_antiColVar;
}
public void setColVar(int i) {
my_antiColVar = i;
}
public static void updateantiColVar() {
antiColVar = ran.nextInt(antiColVarVARIANCE) - antiColVarVARIANCE/2;
//TextIO.putln("ran =" + my_antiColVar);
}
public void setXYs(int sX, int sY, int eX, int eY) {
startX = sX;
startY = sY;
endX = eX;
endY = eY;
}
public int getsX() {
return startX;
}
public int getsY() {
return startY;
}
public int geteX() {
return endX;
}
public int geteXY() {
return endY;
}
public void drawCdr(Graphics g) {
//updatemy_antiColVar();
if (conscell.getY() == sexpr.getY()) {
setXYs(conscell.getX() + (int)(1.5 * unitDraw),conscell.getY() - (int) (0.5 * unitDraw),sexpr.getX(),sexpr.getY()-(int)(0.5 * unitDraw));
g.drawLine(startX,startY,endX,endY);
g.drawLine(endX-3,endY-3,endX,endY);
if (startX == endX) // then vertical line
g.drawLine(endX+3,endY-3,endX,endY);
else
g.drawLine(endX-3,endY+3,endX,endY);
} else // that is the case when the conscells are not in the same "horizontal" line.
{
g.drawLine(conscell.getX() + (int)(1.5 * unitDraw),conscell.getY() - (int) (0.5 * unitDraw),conscell.getX() + (int)(2.5 * unitDraw),conscell.getY() - (int) (0.5 * unitDraw));
int tempX = sexpr.getX() - conscell.getX();
int tempY = sexpr.getY() - conscell.getY();
if (tempY > 0)
tempY = tempY - unitDraw;
else
tempY = tempY + unitDraw;
g.drawLine(conscell.getX() + (int)(2.5 * unitDraw),conscell.getY() - (int) (0.5 * unitDraw), conscell.getX() + (int)(2.5 * unitDraw), conscell.getY() - (int) (0.5 * unitDraw) + tempY+my_antiColVar);
g.drawLine(conscell.getX() + (int)(2.5 * unitDraw), conscell.getY() - (int) (0.5 * unitDraw) + tempY+my_antiColVar, conscell.getX() + (int)(2.5 * unitDraw) + tempX - (3 * unitDraw), conscell.getY() - (int) (0.5 * unitDraw) + tempY+my_antiColVar);
int temp = 0;
if (tempY > 0)
temp = unitDraw;
else
temp = (0 - unitDraw);
g.drawLine(conscell.getX() + (int)(2.5 * unitDraw) + tempX - (3 * unitDraw), conscell.getY() - (int) (0.5 * unitDraw) + tempY+my_antiColVar, conscell.getX() + (int)(2.5 * unitDraw) + tempX - (3 * unitDraw), conscell.getY() - (int) (0.5 * unitDraw) + tempY + temp);
setXYs(conscell.getX() + (int)(2.5 * unitDraw) + tempX - (3 * unitDraw), conscell.getY() - (int) (0.5 * unitDraw) + tempY + temp, conscell.getX() + (int)(2.5 * unitDraw) + tempX - (3 * unitDraw) + (unitDraw / 2), conscell.getY() - (int) (0.5 * unitDraw) + tempY + temp);
g.drawLine(startX,startY,endX,endY);
// g.drawLine(endX-3,endY-3,endX,endY);
// g.drawLine(endX-3,endY+3,endX,endY);
}
Polygon tmpPoly=new Polygon();
tmpPoly.addPoint(endX,endY);
tmpPoly.addPoint(endX-3,endY-3);
tmpPoly.addPoint(endX-3,endY+3);
tmpPoly.addPoint(endX,endY);
g.drawPolygon(tmpPoly);
g.fillPolygon(tmpPoly);
}
public void drawCar(Graphics g) {
int sx,sy,ex,ey;
//updatemy_antiColVar();
//int tempX,tempY;
if (sexpr.getClass().getName().equals("ListCC") && (!(((ListCC) sexpr).isEmpty()))) {
//TextIO.putln("its a list");
sx = conscell.getX() + (int)(0.5 * unitDraw);
sy = conscell.getY() - (int) (0.5 * unitDraw);
ex = ((ListCC) sexpr).getFirst().getX() + (int)(0.5 * unitDraw);
ey = ((ListCC) sexpr).getFirst().getY() - (int) (0.5 * unitDraw);
} else {
sx = conscell.getX() + (int) (0.5 * unitDraw);
sy = conscell.getY() - (int) (0.5 * unitDraw);
ex = sexpr.getX() + (int) (0.5 * unitDraw);
ey = sexpr.getY() - (int) (0.5 * unitDraw);
}
// int temp = 0;
if (ey == sy)
my_antiColVar = 0;
if ((ey - sy) > 0) {
g.drawLine(sx,sy,sx,ey - (unitDraw)+my_antiColVar);
g.drawLine(sx,ey - (unitDraw)+my_antiColVar, ex, ey - (unitDraw)+my_antiColVar);
setXYs(ex, ey - (unitDraw)+my_antiColVar,ex,ey - (unitDraw/2));
g.drawLine(startX,startY,endX,endY);
// g.drawLine(endX-3,endY-3,endX,endY);
//if (startX == endX) // then vertical line
// g.drawLine(endX+3,endY-3,endX,endY);
Polygon tmpPoly=new Polygon();
tmpPoly.addPoint(endX,endY);
tmpPoly.addPoint(endX+3,endY-3);
tmpPoly.addPoint(endX-3,endY-3);
tmpPoly.addPoint(endX,endY);
g.drawPolygon(tmpPoly);
g.fillPolygon(tmpPoly);
// else
// g.drawLine(endX-3,endY+3,endX,endY);
} else {
g.drawLine(sx,sy,sx,sy - (unitDraw)+my_antiColVar);
if (ex > sx)
g.drawLine(sx,sy-(unitDraw)+my_antiColVar,ex-(unitDraw)+my_antiColVar,sy-(unitDraw)+my_antiColVar);
else {
g.drawLine(sx,sy-(unitDraw)+my_antiColVar,ex,sy-(unitDraw)+my_antiColVar);
g.drawLine(ex,sy-(unitDraw)+my_antiColVar, ex-(unitDraw)+my_antiColVar,sy-(unitDraw)+my_antiColVar);
}
g.drawLine(ex-(unitDraw)+my_antiColVar,sy-(unitDraw)+my_antiColVar, ex - unitDraw+my_antiColVar, ey - unitDraw);
g.drawLine(ex - unitDraw+my_antiColVar, ey - unitDraw, ex, ey -unitDraw);
setXYs(ex, ey -unitDraw,ex,ey - (unitDraw/2));
g.drawLine(startX,startY,endX,endY);
// g.drawLine(endX-3,endY-3,endX,endY);
//if (startX == endX) // then vertical line
// g.drawLine(endX+3,endY-3,endX,endY);
Polygon tmpPoly=new Polygon();
tmpPoly.addPoint(endX,endY);
tmpPoly.addPoint(endX+3,endY-3);
tmpPoly.addPoint(endX-3,endY-3);
tmpPoly.addPoint(endX,endY);
g.drawPolygon(tmpPoly);
g.fillPolygon(tmpPoly);
}
}
}