front_processing/extern/TUIO_JAVA/src/TuioDemoObject.java
changeset 9 0f44b7360c8d
parent 0 6fefd4afe506
child 10 925b7ee746e3
equal deleted inserted replaced
8:e4e7db2435f8 9:0f44b7360c8d
     1 /*
     1 /*
     2 	TUIO Java Demo - part of the reacTIVision project
     2     TUIO Java Demo - part of the reacTIVision project
     3 	http://reactivision.sourceforge.net/
     3     http://reactivision.sourceforge.net/
     4 
     4 
     5 	Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
     5     Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
     6 
     6 
     7 	This program is free software; you can redistribute it and/or modify
     7     This program is free software; you can redistribute it and/or modify
     8 	it under the terms of the GNU General Public License as published by
     8     it under the terms of the GNU General Public License as published by
     9 	the Free Software Foundation; either version 2 of the License, or
     9     the Free Software Foundation; either version 2 of the License, or
    10 	(at your option) any later version.
    10     (at your option) any later version.
    11 
    11 
    12 	This program is distributed in the hope that it will be useful,
    12     This program is distributed in the hope that it will be useful,
    13 	but WITHOUT ANY WARRANTY; without even the implied warranty of
    13     but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    15 	GNU General Public License for more details.
    15     GNU General Public License for more details.
    16 
    16 
    17 	You should have received a copy of the GNU General Public License
    17     You should have received a copy of the GNU General Public License
    18 	along with this program; if not, write to the Free Software
    18     along with this program; if not, write to the Free Software
    19 	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    20 */
    20 */
    21 
    21 
    22 import javax.swing.*;
    22 import javax.swing.*;
    23 import java.awt.geom.*;
    23 import java.awt.geom.*;
    24 import java.awt.*;
    24 import java.awt.*;
    26 import java.util.*;
    26 import java.util.*;
    27 import TUIO.*;
    27 import TUIO.*;
    28 
    28 
    29 public class TuioDemoObject extends TuioObject {
    29 public class TuioDemoObject extends TuioObject {
    30 
    30 
    31 	private Shape square;
    31     private Shape square;
    32 
    32 
    33 	public TuioDemoObject(TuioObject tobj) {
    33     public TuioDemoObject(TuioObject tobj) {
    34 		super(tobj);
    34         super(tobj);
    35 		int size = TuioDemoComponent.object_size;
    35         int size = TuioDemoComponent.object_size;
    36 		square = new Rectangle2D.Float(-size/2,-size/2,size,size);
    36         square = new Rectangle2D.Float(-size/2,-size/2,size,size);
    37 		
    37         
    38 		AffineTransform transform = new AffineTransform();
    38         AffineTransform transform = new AffineTransform();
    39 		transform.translate(xpos,ypos);
    39         transform.translate(xpos,ypos);
    40 		transform.rotate(angle,xpos,ypos);
    40         transform.rotate(angle,xpos,ypos);
    41 		square = transform.createTransformedShape(square);
    41         square = transform.createTransformedShape(square);
    42 	}
    42     }
    43 	
    43     
    44 	public void paint(Graphics2D g, int width, int height) {
    44     public void paint(Graphics2D g, int width, int height) {
    45 	
    45     
    46 		float Xpos = xpos*width;
    46         float Xpos = xpos*width;
    47 		float Ypos = ypos*height;
    47         float Ypos = ypos*height;
    48 		float scale = height/(float)TuioDemoComponent.table_size;
    48         float scale = height/(float)TuioDemoComponent.table_size;
    49 
    49 
    50 		AffineTransform trans = new AffineTransform();
    50         AffineTransform trans = new AffineTransform();
    51 		trans.translate(-xpos,-ypos);
    51         trans.translate(-xpos,-ypos);
    52 		trans.translate(Xpos,Ypos);
    52         trans.translate(Xpos,Ypos);
    53 		trans.scale(scale,scale);
    53         trans.scale(scale,scale);
    54 		Shape s = trans.createTransformedShape(square);
    54         Shape s = trans.createTransformedShape(square);
    55 	
    55     
    56 		g.setPaint(Color.black);
    56         g.setPaint(Color.black);
    57 		g.fill(s);
    57         g.fill(s);
    58 		g.setPaint(Color.white);
    58         g.setPaint(Color.white);
    59 		g.drawString(symbol_id+"",Xpos-10,Ypos);
    59         g.drawString(symbol_id+"",Xpos-10,Ypos);
    60 	}
    60     }
    61 
    61 
    62 	public void update(TuioObject tobj) {
    62     public void update(TuioObject tobj) {
    63 		
    63         
    64 		float dx = tobj.getX() - xpos;
    64         float dx = tobj.getX() - xpos;
    65 		float dy = tobj.getY() - ypos;
    65         float dy = tobj.getY() - ypos;
    66 		float da = tobj.getAngle() - angle;
    66         float da = tobj.getAngle() - angle;
    67 
    67 
    68 		if ((dx!=0) || (dy!=0)) {
    68         if ((dx!=0) || (dy!=0)) {
    69 			AffineTransform trans = AffineTransform.getTranslateInstance(dx,dy);
    69             AffineTransform trans = AffineTransform.getTranslateInstance(dx,dy);
    70 			square = trans.createTransformedShape(square);
    70             square = trans.createTransformedShape(square);
    71 		}
    71         }
    72 		
    72         
    73 		if (da!=0) {
    73         if (da!=0) {
    74 			AffineTransform trans = AffineTransform.getRotateInstance(da,tobj.getX(),tobj.getY());
    74             AffineTransform trans = AffineTransform.getRotateInstance(da,tobj.getX(),tobj.getY());
    75 			square = trans.createTransformedShape(square);
    75             square = trans.createTransformedShape(square);
    76 		}
    76         }
    77 
    77 
    78 		super.update(tobj);
    78         super.update(tobj);
    79 	}
    79     }
    80 
    80 
    81 }
    81 }