View Javadoc

1   /**
2    * 
3    */
4   package org.ximtec.igesture.io.tuio;
5   
6   import java.awt.Color;
7   import java.awt.Graphics;
8   import java.util.List;
9   
10  import org.sigtec.ink.Note;
11  import org.ximtec.igesture.core.Gesture;
12  import org.ximtec.igesture.core.GestureSample;
13  import org.ximtec.igesture.core.GestureSample3D;
14  import org.ximtec.igesture.io.GestureDevicePanel;
15  import org.ximtec.igesture.util.RecordedGesture3DTool;
16  import org.ximtec.igesture.util.additions3d.RecordedGesture3D;
17  
18  /**
19   * @author Bjorn Puype, bpuype@gmail.com
20   *
21   */
22  public class TuioReaderPanel extends GestureDevicePanel {
23  	
24  	private ITuioReader reader;
25  	private GestureSample gestureSample;
26  	private GestureSample3D gestureSample3D;
27  	
28  	public static final int TYPE_2D = 1;
29  	public static final int TYPE_3D = 2;
30  	
31  	private int type;
32  	
33  	public TuioReaderPanel()
34  	{
35  		gestureSample = new GestureSample("", new Note());
36  		gestureSample3D = new GestureSample3D("", new RecordedGesture3D());
37  	}
38  	
39  	public TuioReaderPanel(ITuioReader device, int type)
40  	{
41  		reader = device;
42  		gestureSample = new GestureSample("", new Note());
43  		gestureSample3D = new GestureSample3D("", new RecordedGesture3D());
44  		this.type = type;
45  	}
46  	
47  	public void clear()
48  	{
49  		gestureSample = new GestureSample("", new Note());
50  		gestureSample3D = new GestureSample3D("", new RecordedGesture3D());
51  	}
52  	
53  	public GestureSample getGesture()
54  	{
55  		return gestureSample;
56  	}
57  	
58  	public GestureSample3D getGesture3D()
59  	{
60  		return gestureSample3D;
61  	}
62  	
63  	@Override
64  	public void paintComponent(Graphics g)
65  	{
66  		if(type == TYPE_2D)
67  		{
68  			g.setColor(Color.WHITE);
69  			g.fillRect(0, 0, getWidth(), getHeight());
70  			g.setColor(Color.BLACK);
71  			if(gestureSample != null)//gestureSample != new GestureSample("", new Note())
72  			{
73  				gestureSample.getGesture().scaleTo(getWidth()-10, getHeight()-10);
74  				gestureSample.getGesture().moveTo(5,5);
75  				gestureSample.getGesture().paint(g);
76  			}
77  				
78  //			g.drawString("2D", getWidth()/2, getHeight()/2);
79  		}
80  		else if(type == TYPE_3D)
81  		{
82  			if(gestureSample3D != null) //gestureSample3D != new GestureSample3D("", new RecordedGesture3D())
83  				RecordedGesture3DTool.paintGesture(gestureSample3D.getGesture(), g, getWidth(), getHeight(), true);
84  			else
85  				RecordedGesture3DTool.paintStructure(g, getWidth(), getHeight(), true);
86  		}
87  		else
88  		{
89  			g.drawString("TO IMPLEMENT", 0, getHeight()/2);
90  		}
91  	}
92  	
93  	/* (non-Javadoc)
94  	 * @see org.ximtec.igesture.io.GestureEventListener#handleChunks(java.util.List)
95  	 */
96  	@Override
97  	public void handleChunks(List<?> chunks) {
98  		// TODO Auto-generated method stub
99  
100 	}
101 
102 	/* (non-Javadoc)
103 	 * @see org.ximtec.igesture.io.GestureEventListener#handleGesture(org.ximtec.igesture.core.Gesture)
104 	 */
105 	@Override
106 	public void handleGesture(Gesture<?> gesture) {
107 		if(gesture instanceof GestureSample)
108 		{
109 			gestureSample = (GestureSample) gesture;
110 			type = TYPE_2D;
111 		}
112 		else if(gesture instanceof GestureSample3D)
113 		{
114 			gestureSample3D = (GestureSample3D) gesture;
115 			type = TYPE_3D;
116 		}
117 		if(getGraphics() != null)
118 			paintComponent(getGraphics());
119 	}
120 
121 }