PenStrokeListener.java

00001 package edu.stanford.hci.r3.pen.streaming.listeners;
00002 
00003 import java.util.ArrayList;
00004 import java.util.List;
00005 
00006 import edu.stanford.hci.r3.pen.PenSample;
00007 import edu.stanford.hci.r3.pen.ink.InkStroke;
00008 import edu.stanford.hci.r3.util.DebugUtils;
00009 
00027 public abstract class PenStrokeListener implements PenListener {
00028 
00029         private List<PenSample> currentStroke;
00030 
00034         public void penDown(PenSample sample) {
00035                 // start a new stroke, which is just a list of PenSamples
00036                 currentStroke = new ArrayList<PenSample>();
00037                 currentStroke.add(sample);
00038                 DebugUtils.println(sample);
00039         }
00040 
00046         public abstract void penStroke(InkStroke stroke);
00047 
00048         /*
00049          * (non-Javadoc)
00050          * 
00051          * @see edu.stanford.hci.r3.pen.streaming.listeners.PenListener#penUp(edu.stanford.hci.r3.pen.PenSample)
00052          */
00053         public void penUp(PenSample sample) {
00054                 if (currentStroke == null) {
00055                         return;
00056                 }
00057                 
00058                 // end the stroke... Since the up sample is the same as the last sample, do not add it
00059                 final List<PenSample> stroke = currentStroke;
00060 
00061                 // this line will be useful if we decide to spawn a new thread to notify the
00062                 // PenStrokeListener
00063                 currentStroke = null;
00064 
00065                 // notify the PenStrokeListener
00066                 penStroke(new InkStroke(stroke));
00067         }
00068 
00072         public void sample(PenSample sample) {
00073                 currentStroke.add(sample);
00074                 DebugUtils.println(sample);
00075         }
00076 }

Generated on Sat Apr 14 18:21:37 2007 for R3 Paper Toolkit by  doxygen 1.4.7