home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / ActView / ActiveViewer.jar / com / simeda / ActiveViewer / KeyReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-12-12  |  3.7 KB  |  147 lines

  1. package com.simeda.ActiveViewer;
  2.  
  3. import java.io.IOException;
  4. import java.util.Hashtable;
  5.  
  6. public class KeyReader implements Runnable {
  7.    public static final String keys_1 = ".,?!1@'-_():;^/%*#+<=>\"$";
  8.    public static final String keys_2 = "abc2";
  9.    public static final String keys_3 = "def3";
  10.    public static final String keys_4 = "ghi4";
  11.    public static final String keys_5 = "jkl5";
  12.    public static final String keys_6 = "mno6";
  13.    public static final String keys_7 = "pqrs7";
  14.    public static final String keys_8 = "tuv8";
  15.    public static final String keys_9 = "wxyz9";
  16.    public static final String keys_0 = " 0";
  17.    public static final Character numkey_0 = new Character('0');
  18.    public static final Character numkey_1 = new Character('1');
  19.    public static final Character numkey_2 = new Character('2');
  20.    public static final Character numkey_3 = new Character('3');
  21.    public static final Character numkey_4 = new Character('4');
  22.    public static final Character numkey_5 = new Character('5');
  23.    public static final Character numkey_6 = new Character('6');
  24.    public static final Character numkey_7 = new Character('7');
  25.    public static final Character numkey_8 = new Character('8');
  26.    public static final Character numkey_9 = new Character('9');
  27.    public static final Character numkey_pound = new Character('#');
  28.    public static final Character numkey_star = new Character('*');
  29.    Thread timer;
  30.    boolean isRunning;
  31.    boolean isCaps;
  32.    rfbProto rfb;
  33.    int lastKey;
  34.    int keyPosition;
  35.    Hashtable keys = new Hashtable();
  36.    Hashtable numKeys = new Hashtable();
  37.    vncCanvas theCanvas = null;
  38.  
  39.    public KeyReader(rfbProto var1, vncCanvas var2) {
  40.       this.rfb = var1;
  41.       this.theCanvas = var2;
  42.       this.keys.put(new Integer(48), " 0");
  43.       this.keys.put(new Integer(49), ".,?!1@'-_():;^/%*#+<=>\"$");
  44.       this.keys.put(new Integer(50), "abc2");
  45.       this.keys.put(new Integer(51), "def3");
  46.       this.keys.put(new Integer(52), "ghi4");
  47.       this.keys.put(new Integer(53), "jkl5");
  48.       this.keys.put(new Integer(54), "mno6");
  49.       this.keys.put(new Integer(55), "pqrs7");
  50.       this.keys.put(new Integer(56), "tuv8");
  51.       this.keys.put(new Integer(57), "wxyz9");
  52.       this.numKeys.put(new Integer(48), numkey_0);
  53.       this.numKeys.put(new Integer(49), numkey_1);
  54.       this.numKeys.put(new Integer(50), numkey_2);
  55.       this.numKeys.put(new Integer(51), numkey_3);
  56.       this.numKeys.put(new Integer(52), numkey_4);
  57.       this.numKeys.put(new Integer(53), numkey_5);
  58.       this.numKeys.put(new Integer(54), numkey_6);
  59.       this.numKeys.put(new Integer(55), numkey_7);
  60.       this.numKeys.put(new Integer(56), numkey_8);
  61.       this.numKeys.put(new Integer(57), numkey_9);
  62.       this.numKeys.put(new Integer(35), numkey_pound);
  63.       this.numKeys.put(new Integer(42), numkey_star);
  64.       this.lastKey = -1;
  65.    }
  66.  
  67.    public void run() {
  68.       try {
  69.          Thread.sleep(500L);
  70.       } catch (InterruptedException var2) {
  71.       }
  72.  
  73.       if (this.timer == Thread.currentThread()) {
  74.          this.doSend();
  75.          this.lastKey = -1;
  76.          this.keyPosition = 0;
  77.       }
  78.  
  79.    }
  80.  
  81.    public void toggleCaps() {
  82.       this.isCaps = !this.isCaps;
  83.    }
  84.  
  85.    public void doSend() {
  86.       String var1 = (String)this.keys.get(new Integer(this.lastKey));
  87.       int var2 = -1;
  88.       if (var1 == null) {
  89.          var2 = this.lastKey;
  90.       } else {
  91.          var2 = var1.charAt(this.keyPosition % var1.length());
  92.       }
  93.  
  94.       if (this.isCaps) {
  95.          var2 = Character.toUpperCase((char)var2);
  96.       }
  97.  
  98.       try {
  99.          this.rfb.writeKeyEvent(var2, true);
  100.       } catch (IOException var4) {
  101.          ((Throwable)var4).printStackTrace();
  102.       }
  103.  
  104.       this.theCanvas.currentLetter = '\uffff';
  105.       this.theCanvas.repaint();
  106.       this.theCanvas.serviceRepaints();
  107.    }
  108.  
  109.    public void pushKey(int var1) {
  110.       if (var1 != this.lastKey) {
  111.          if (this.lastKey != -1) {
  112.             this.doSend();
  113.          }
  114.  
  115.          this.lastKey = var1;
  116.          this.keyPosition = 0;
  117.          this.timer = new Thread(this);
  118.          this.timer.start();
  119.       } else {
  120.          ++this.keyPosition;
  121.          this.timer = new Thread(this);
  122.          this.timer.start();
  123.       }
  124.  
  125.       String var2 = (String)this.keys.get(new Integer(this.lastKey));
  126.       char var3 = var2.charAt(this.keyPosition % var2.length());
  127.       if (this.isCaps) {
  128.          var3 = Character.toUpperCase(var3);
  129.       }
  130.  
  131.       this.theCanvas.currentLetter = var3;
  132.       this.theCanvas.repaint();
  133.       this.theCanvas.serviceRepaints();
  134.    }
  135.  
  136.    public void pushNumericKey(int var1) {
  137.       char var2 = (Character)this.numKeys.get(new Integer(var1));
  138.  
  139.       try {
  140.          this.rfb.writeKeyEvent(var2, true);
  141.       } catch (IOException var4) {
  142.          ((Throwable)var4).printStackTrace();
  143.       }
  144.  
  145.    }
  146. }
  147.