Advertisement
Guest User

Details presentation methods and update

a guest
Aug 16th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1.  
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.JPanel;
  5. import javax.swing.Timer;
  6.  
  7.  
  8. /*show the glove-state values on command-line*/
  9. @SuppressWarnings("serial")
  10. public class ShowGloveValues extends JPanel{
  11.  
  12.     public final Glove glove;
  13.     public Timer pollTimer;
  14.     public static final int GLOVE_DELAY = 50;
  15.    
  16.    
  17.     /*print glove-values to the command-line*/
  18.     public ShowGloveValues(){
  19.        
  20.         /*init the glove*/
  21.         glove = new Glove();
  22.  
  23.         /*start to update the glove states*/
  24.         startPolling();
  25.  
  26.     }
  27.    
  28.    
  29.     /*show the hand position*/
  30.     private void showHandPosition(){
  31.        
  32.         final float vals[] = glove.getHandPosition();
  33.      
  34.         System.out.println("x-position: " + vals[0]);
  35.         System.out.println("y-position: " + vals[1]);
  36.         System.out.println("z-position: " + vals[2]);
  37.         System.out.println();
  38.     }
  39.    
  40.    
  41.     /*show the hand orientation*/
  42.     private void showHandOrientation(){
  43.        
  44.         final float vals[] = glove.getHandOrientation();
  45.        
  46.         System.out.println("pitch:" + vals[0]);
  47.         System.out.println("yaw:" + vals[1]);
  48.         System.out.println("roll:" + vals[2]);
  49.     }
  50.  
  51.    
  52.     private void showLedNumber(){
  53.        
  54.         final byte leds[] = glove.getVisibleLedPos();
  55.        
  56.         System.out.print("Led number: " + leds[0] + " ");
  57.     }
  58.    
  59.     private void showTrackedLed(){
  60.        
  61.         final int ledPos = glove.getTrackedLed();
  62.        
  63.         System.out.print ("Tracked Led: " + ledPos + " ");
  64.     }
  65.    
  66.     public  String showActiveLedPosX(){
  67.        
  68.         final float pos[][] = glove.getActiveLedPos();
  69.        
  70.         return  "" + pos[glove.getTrackedLed()][0];
  71.     }
  72.    
  73. /*update the glove and show the glove-state values*/    
  74. protected void startPolling(){
  75.  
  76.         final ActionListener pollPerformer = new ActionListener(){
  77.             public void actionPerformed(final ActionEvent e){
  78.  
  79.                 glove.update();
  80.                
  81.                 showActiveLedPosX();
  82.                
  83.                 /*exit by double-pressed D-button*/
  84.                 if (glove.isDpressed()) {
  85.                     pollTimer.stop();
  86.                     System.exit(0);
  87.                 }
  88.             }
  89.         };
  90.        
  91.     /*next update after GLOVE_DELAY ms*/    
  92.     pollTimer = new Timer(GLOVE_DELAY, pollPerformer);
  93.     pollTimer.start();  
  94.     }  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement