summaryrefslogtreecommitdiff
path: root/java/EAC/Intersection.java
blob: 1e1beafb7702ace4cf16a610563d0aa810793e20 (plain)
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
/**
 *  Title:        Intersection
 *  Description:  A binary intersection operator class for the Event Analysis
 *                Configurator.  Acts as a sort of filter, combining two event
 *                streams into one.
 */
package EAC;
import java.awt.*;

public class Intersection extends Operator {

  // Where did the last event come from?
  protected Primitive last_event_source;

  public Intersection(EACPanel p) {
    super(p);
    last_event_source = null;
  } /* constructor */

  public void draw() throws BoundsException {
    // the intersection symbol
    final char iSymbol = '^';

    // subtle adjustments to position symbol within circle
    final int xTweak = 2;
    final int yTweak = -5;

    char symbol[] = new char[1];
    Graphics g = canvas.getGraphics();

    super.draw();
    symbol[0] = iSymbol;
    g.drawChars(symbol,0,1,
                anchor.x + (int) (DIAMETER / 2) - xTweak,
                anchor.y + (int) (DIAMETER / 2) - yTweak);
  } /* draw */

  public void event(Source s) throws ConnectionException {
    //System.out.println("Intersection event");
    if (last_event_source == null)
      last_event_source = s;
    else if (last_event_source != s) { // we've now gotten events from two distinct sources
      int i;

      last_event_source = null;
      for (i = 0; i < output_count; i++)
        output[i].event(s);
    } // else no-op, because this event is from the same source as the last event
  } /* event */

  public void write(File f) throws java.io.IOException {
    f.writeInt(f.INTERSECTION);
    f.writeInt(anchor.x);
    f.writeInt(anchor.y);
  } /* write */

  public void read(File f) throws java.io.IOException {
    anchor = new Point();
    anchor.x = f.readInt();
    anchor.y = f.readInt();
  } /* read */
}