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
|
/**
* Title: Primitive
* Description: An abstract class for Event Analysis Configurator graphical
* primitives
*/
package EAC;
import java.awt.*;
import java.io.*;
public abstract class Primitive {
// maximum number of outputs from any primitive
public final int MAX_OUTPUTS = 8;
// maximum number of inputs to a sink
public final int MAX_INPUTS = 8;
// where the primitive will be drawn
protected EACPanel canvas;
// anchor point of the graphical shape
protected Point anchor;
// associated label
protected EACLabel label;
public Primitive(EACPanel p) {
canvas = p;
} /* constructor */
public void setAnchor(Point p) {
anchor = p;
} /* setAnchor */
public Point getAnchor() {
return anchor;
} /* getAnchor */
public void setLabel(EACLabel l) {
label = l;
} /* setLabel */
public EACLabel getLabel() {
return label;
} /* getLabel */
public void restart() {
// no-op for most primitives
// overload as needed
} /* restart */
public void specialDraw() {
// no-op for some primitives
// overload as needed
} /* specialDraw */
public void specialUndraw() {
// no-op for some primitives
// overload as needed
} /* specialUndraw */
public void reconnect() {
// no-op for some primitives
// overload as needed
} /* reconnect */
public void selectedDraw() {
final int d = 4; // dimension of hotspot
Graphics g = canvas.getGraphics();
g.setColor(java.awt.Color.darkGray);
g.drawRect(upperLeft().x - (d/2),upperLeft().y - (d/2), d, d);
g.drawRect(lowerLeft().x - (d/2),lowerLeft().y - (d/2), d, d);
g.drawRect(upperRight().x - (d/2),upperRight().y - (d/2), d, d);
g.drawRect(lowerRight().x - (d/2),lowerRight().y - (d/2), d, d);
} /* selectedDraw */
// establish the top center point of the graphical shape
public abstract void setTop(Point p);
public abstract Point getTop();
public abstract boolean inBounds();
public abstract int addInput(Connector c) throws ConnectionException;
public abstract int addOutput(Connector c) throws ConnectionException;
public abstract Connector getInput(int i) throws ConnectionException;
public abstract Connector getOutput(int i) throws ConnectionException;
public abstract void removeInput(int i) throws ConnectionException;
public abstract void removeOutput(int i) throws ConnectionException;
public abstract int getInputCount() throws ConnectionException;
public abstract int getOutputCount() throws ConnectionException;
public abstract void event(Source s) throws ConnectionException;
public abstract void wakeup(long t) throws ConnectionException;
public abstract void draw() throws BoundsException;
public abstract void write(File f) throws java.io.IOException;
public abstract void read(File f) throws java.io.IOException;
public abstract boolean contains(Point p);
public abstract Point upperLeft();
public abstract Point lowerRight();
public abstract Point upperRight();
public abstract Point lowerLeft();
}
|