View Javadoc

1   /*
2    * @(#)$Id: WiiReaderPanel.java
3    *
4    * Author       :   Arthur Vogels, arthur.vogels@gmail.com
5    *
6    * Purpose      :	Draws the data recorded by the WiiReader into
7    * 					planes and graphs on a JPanel.
8    *
9    *
10   * -----------------------------------------------------------------------
11   *
12   * Revision Information:
13   *
14   * Date             Who         	Reason
15   *
16   * Dec 16, 2008     arthurvogels    Initial Release
17   *
18   * -----------------------------------------------------------------------
19   *
20   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
21   *
22   * This software is the proprietary information of ETH Zurich.
23   * Use is subject to license terms.
24   * 
25   */
26  
27  package org.ximtec.igesture.io.wiimote;
28  
29  import java.awt.Cursor;
30  import java.awt.Graphics;
31  import java.util.List;
32  
33  import org.ximtec.igesture.core.Gesture;
34  import org.ximtec.igesture.core.GestureSample3D;
35  import org.ximtec.igesture.io.GestureDevicePanel;
36  import org.ximtec.igesture.util.RecordedGesture3DTool;
37  
38  public class WiiReaderPanel extends GestureDevicePanel {
39  
40  	private WiiReader reader;
41  	private GestureSample3D gs;
42  
43  	/**
44  	 * Constructor
45  	 * 
46  	 * @param reader
47  	 *            The WiiReader this WiiReaderPanel belongs to
48  	 */
49  	public WiiReaderPanel(WiiReader reader) {
50  		this.reader = reader;
51  		setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
52  	}	
53  	
54  	/**
55  	 * Override of the JPanel paintComponent method. Paints the gesture from
56  	 * reader in 3 planes onto the Graphics object
57  	 */
58  	@Override
59  	public void paintComponent(Graphics g) {
60  		
61  		if(gs != null)
62  		{
63  			RecordedGesture3DTool.paintGesture(gs.getGesture(), g, getWidth(), getHeight(), true);
64  		}
65  		else
66  		{
67  			RecordedGesture3DTool.paintStructure(g, getWidth(), getHeight(), true);
68  		}
69  	}
70  
71  	/**
72  	 * Returns the gesture drawn by this panel
73  	 * 
74  	 * @return The gesture drawn by this panel
75  	 */
76  	public GestureSample3D getGesture() {
77  		return gs;
78  	}
79  
80  	/**
81  	 * Sets the gesture to be drawn by this panel
82  	 * 
83  	 * @param gs
84  	 *            The gesture to be drawn by this panel
85  	 */
86  	public void setGesture(GestureSample3D gs) {
87  		//System.err.println("SAMPLE : " + gs.getName());
88  		this.gs = gs;
89  		if(gs != null){
90  			System.err.println("WiiReaderPanel.setGesture() Displaying: " + gs.getName());
91  		}
92  		else {
93  			System.err.println("WiiReaderPanel.setGesture() Displaying: null gesture");
94  		}
95  		this.paintComponent(this.getGraphics());
96  	}
97  	
98  	public void clear()
99  	{
100 		System.out.println("clearing");
101 		paintComponent(getGraphics());
102 	}
103 
104 	/* (non-Javadoc)
105 	 * @see org.ximtec.igesture.io.GestureEventListener#handleChunks(java.util.List)
106 	 */
107 	@Override
108 	public void handleChunks(List<?> chunks) {		
109 	}
110 
111 	/* (non-Javadoc)
112 	 * @see org.ximtec.igesture.io.GestureEventListener#handleGesture(org.ximtec.igesture.core.Gesture)
113 	 */
114 	@Override
115 	public void handleGesture(Gesture<?> gesture) {
116 		gs = (GestureSample3D) gesture;
117 		if(getGraphics() != null)
118 			paintComponent(getGraphics());
119 	}
120 
121 	
122 	
123 }