00001 package edu.stanford.hci.r3.events.handlers;
00002
00003 import edu.stanford.hci.r3.events.EventHandler;
00004 import edu.stanford.hci.r3.events.PenEvent;
00005 import edu.stanford.hci.r3.pen.ink.InkStroke;
00006 import edu.stanford.hci.r3.util.DebugUtils;
00007
00019 public abstract class StrokeHandler extends EventHandler {
00020
00025 private PenEvent lastEvent;
00026
00030 private boolean penDownHappened = false;
00031
00032 private InkStroke stroke;
00033
00034 public InkStroke getStroke() {
00035 return stroke;
00036 }
00037
00041 public void handleEvent(PenEvent event) {
00042 if (event.isTypePenDown()) {
00043 stroke = new InkStroke();
00044 penDownHappened = true;
00045 } else if (event.isTypePenUp()) {
00046
00047 if (penDownHappened) {
00048 strokeArrived(lastEvent);
00049 penDownHappened = false;
00050 return;
00051 }
00052 }
00053
00054 if (event == null || event.getOriginalSample() == null) {
00055 DebugUtils.println("Event Object is NULL");
00056 } else {
00057 stroke.addSample(event.getOriginalSample());
00058 lastEvent = event;
00059 }
00060
00061
00062 }
00063
00067 public abstract void strokeArrived(PenEvent e);
00068
00069 public String toString() {
00070 return "StrokeHandler";
00071 }
00072 }