oc.ProcessingTUIO.1.1.0.source-code.TuioDemoComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ProcessingTUIO Show documentation
Show all versions of ProcessingTUIO Show documentation
Tuio Processing, PapARt version.
The newest version!
/*
TUIO Java GUI Demo
Copyright (c) 2005-2014 Martin Kaltenbrunner
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
import javax.swing.*;
import TUIO.*;
public class TuioDemoComponent extends JComponent implements TuioListener {
private Hashtable objectList = new Hashtable();
private Hashtable cursorList = new Hashtable();
private Hashtable blobList = new Hashtable();
public static final int finger_size = 15;
public static final int object_size = 60;
public static final int table_size = 760;
public static int width, height;
private float scale = 1.0f;
public boolean verbose = false;
public void setSize(int w, int h) {
super.setSize(w,h);
width = w;
height = h;
scale = height/(float)TuioDemoComponent.table_size;
}
public void addTuioObject(TuioObject tobj) {
TuioDemoObject demo = new TuioDemoObject(tobj);
objectList.put(tobj.getSessionID(),demo);
if (verbose)
System.out.println("add obj "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());
}
public void updateTuioObject(TuioObject tobj) {
TuioDemoObject demo = (TuioDemoObject)objectList.get(tobj.getSessionID());
demo.update(tobj);
if (verbose)
System.out.println("set obj "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()+" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+" "+tobj.getRotationAccel());
}
public void removeTuioObject(TuioObject tobj) {
objectList.remove(tobj.getSessionID());
if (verbose)
System.out.println("del obj "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
}
public void addTuioCursor(TuioCursor tcur) {
if (!cursorList.containsKey(tcur.getSessionID())) {
cursorList.put(tcur.getSessionID(), tcur);
repaint();
}
if (verbose)
System.out.println("add cur "+tcur.getCursorID()+" ("+tcur.getSessionID()+") "+tcur.getX()+" "+tcur.getY());
}
public void updateTuioCursor(TuioCursor tcur) {
repaint();
if (verbose)
System.out.println("set cur "+tcur.getCursorID()+" ("+tcur.getSessionID()+") "+tcur.getX()+" "+tcur.getY()+" "+tcur.getMotionSpeed()+" "+tcur.getMotionAccel());
}
public void removeTuioCursor(TuioCursor tcur) {
cursorList.remove(tcur.getSessionID());
repaint();
if (verbose)
System.out.println("del cur "+tcur.getCursorID()+" ("+tcur.getSessionID()+")");
}
public void addTuioBlob(TuioBlob tblb) {
TuioDemoBlob demo = new TuioDemoBlob(tblb);
blobList.put(tblb.getSessionID(),demo);
if (verbose)
System.out.println("add blb "+tblb.getBlobID()+" ("+tblb.getSessionID()+") "+tblb.getX()+" "+tblb.getY()+" "+tblb.getAngle());
}
public void updateTuioBlob(TuioBlob tblb) {
TuioDemoBlob demo = (TuioDemoBlob)blobList.get(tblb.getSessionID());
demo.update(tblb);
if (verbose)
System.out.println("set blb "+tblb.getBlobID()+" ("+tblb.getSessionID()+") "+tblb.getX()+" "+tblb.getY()+" "+tblb.getAngle()+" "+tblb.getMotionSpeed()+" "+tblb.getRotationSpeed()+" "+tblb.getMotionAccel()+" "+tblb.getRotationAccel());
}
public void removeTuioBlob(TuioBlob tblb) {
blobList.remove(tblb.getSessionID());
if (verbose)
System.out.println("del blb "+tblb.getBlobID()+" ("+tblb.getSessionID()+")");
}
public void refresh(TuioTime frameTime) {
repaint();
}
public void paint(Graphics g) {
update(g);
}
public void update(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.setColor(Color.white);
g2.fillRect(0,0,width,height);
int w = (int)Math.round(width-scale*finger_size/2.0f);
int h = (int)Math.round(height-scale*finger_size/2.0f);
Enumeration cursors = cursorList.elements();
while (cursors.hasMoreElements()) {
TuioCursor tcur = cursors.nextElement();
if (tcur==null) continue;
ArrayList path = tcur.getPath();
TuioPoint current_point = path.get(0);
if (current_point!=null) {
// draw the cursor path
g2.setPaint(Color.blue);
for (int i=0;i objects = objectList.elements();
while (objects.hasMoreElements()) {
TuioDemoObject tobj = objects.nextElement();
if (tobj!=null) tobj.paint(g2, width,height);
}
}
}