Penlets.com provides resources for users and developers of the Pulse smart pen from LiveScribe.

 

Subscribe: RSS Feed - Developers Group

Tutorial

Capturing Drawn Shapes

Tutorial by Robert Hanson

Page 1 » Page 2


In this tutorial I show you how you can capture shapes drawn by the pen, and then use that data to determine when the pen is inside or outside of a drawn shape. I will also touch on how you can detect intersecting shapes and the nature of the intersection.

As our sample penlet, we will allow the user to draw a circle on the page and grab the points that make up the circle. We then let the user touch the pen to the paper and let the user know if the pen point is inside or outside of the circle..

Project Setup

To begin, we will need to create a new project and create a basic penlet class. If you don't already know how to do this you can refer to Penlets 101. The basic penlet extends the Penlet class and defines two fields; display to store the OLED Display object, and label to store a ScrollLabel .

For this tutorial we will be using the following imports.

import com.livescribe.afp.PageInstance;
import com.livescribe.display.Display;
import com.livescribe.event.PenTipListener;
import com.livescribe.event.StrokeListener;
import com.livescribe.geom.Polygon;
import com.livescribe.geom.Stroke;
import com.livescribe.penlet.Penlet;
import com.livescribe.penlet.PenletStateChangeException;
import com.livescribe.penlet.Region;
import com.livescribe.storage.StrokeStorage;
import com.livescribe.ui.ScrollLabel;

In addition to the basic boiler-plate penlet code, you need to override the canProcessOpenPaperEvents method and return true to indicate that this penlet can receive stroke events.

public boolean canProcessOpenPaperEvents ()
{
    return true;
}

Penlet Activation and Deactivation

When the penlet is activated we want to display the message "Draw a circle" so that the user knows what to do. In addition to this we need to register a StrokeListener and PenTipListener .

For simplicity we will have our penlet class implement these interfaces itself, instead of creating a second class to handle that responsibility. We will implement the required methods in a little bit, but for now you can alter the class definition to look like this.

public class AreaCapture extends Penlet
	implements PenTipListener, StrokeListener

When our penlet is activated we will display some instructions to the user and register this class as both a PenTipListener and a StrokeListener . On deactivation we will unregister them.

public void activateApp (int reason, Object[] args)
{
    this.display.setCurrent(label);
    this.label.draw("Draw a circle", true);

    this.context.addStrokeListener(this);
    this.context.addPenTipListener(this);
}

public void deactivateApp (int reasons)
{
    this.context.removeStrokeListener(this);
    this.context.removePentipListener(this);
}

Now we need to get into implementing the interfaces and get to what this tutorial is really about.


Page 1 » Page 2


Comments (View)
blog comments powered by Disqus

Project Information

Tested for use with: PreRelease-SDK

Download the source code for this tutorial.
Download Source Code (zip)

New Tutorials

Using a Shared Library
Learn how to create a library of utils that you can share between projects.

Capturing Drawn Shapes
Learn how to capture shapes drawn by the pen and determine relationships.

Penlets 101
Never written a penlet before? Then start here with Penlets 101!

Creating a Custom Vocabulary
Learn how to create a custom vocabulary for your ICR applications.

Using Properties Files
J2ME lacks a Properties class. In this tutorial we roll our own, along with split and chomp functions.