jmce - 1_02

jmce.swing
Class KeyboardMatrix

java.lang.Object
  extended by jmce.sim.AbstractHardware
      extended by jmce.sim.AbstractPeripheral
          extended by jmce.swing.KeyboardMatrix
All Implemented Interfaces:
java.awt.event.FocusListener, java.awt.event.KeyListener, java.util.EventListener, Hardware, Peripheral
Direct Known Subclasses:
Keyboard

public class KeyboardMatrix
extends AbstractPeripheral
implements java.awt.event.FocusListener, java.awt.event.KeyListener

Keyboard matrix.

This swing peripheral can be connected to any AWT component and implements one matrix keyboard.

The matrix is organized in rows and columns. Normally the row are scanned one at once and if a key is pressed the relative columns bit is set to 0.

Since:
1.01
Version:
1.00
Author:
Mario Viara

Field Summary
protected  int[][] keysLoc
           
protected  int[] keyState
           
protected  int numRows
           
 
Fields inherited from class jmce.sim.AbstractPeripheral
cpu
 
Constructor Summary
KeyboardMatrix()
          Standard constructor
 
Method Summary
 void focusGained(java.awt.event.FocusEvent e)
           
 void focusLost(java.awt.event.FocusEvent e)
           
 int getRow(int r)
          Return the key state for the specified row.
protected  void keyEvent(int r, int c, boolean pressed)
          Can be redefined in subclass to detect keyboard event for example to fire a interrupt.
 void keyEvent(java.awt.event.KeyEvent e, boolean pressed)
           
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
protected  void resetKeyboard()
          Reset the state of the keyboard.
 void setComponent(java.awt.Component c)
           
 void setKey(int r, int c, int... keys)
           
 void setKeyLocation(int r, int c, int... keys)
          Set the location of specified key.
 void setNumCols(int c)
          Set the number of columns of the matrix.
 void setNumRows(int r)
          Set the number of row for the matrix
 java.lang.String toString()
           
 
Methods inherited from class jmce.sim.AbstractPeripheral
idle, registerCPU, setIdle, setLive
 
Methods inherited from class jmce.sim.AbstractHardware
addHardware, createFrame, destroy, getHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareForName, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jmce.sim.Hardware
addHardware, destroy, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName
 

Field Detail

numRows

protected int numRows

keyState

protected int[] keyState

keysLoc

protected int[][] keysLoc
Constructor Detail

KeyboardMatrix

public KeyboardMatrix()
Standard constructor

Method Detail

resetKeyboard

protected void resetKeyboard()
Reset the state of the keyboard.


setNumRows

public void setNumRows(int r)
Set the number of row for the matrix


setNumCols

public void setNumCols(int c)
Set the number of columns of the matrix.


setComponent

public void setComponent(java.awt.Component c)

getRow

public int getRow(int r)
Return the key state for the specified row.


setKeyLocation

public void setKeyLocation(int r,
                           int c,
                           int... keys)
Set the location of specified key.

The location is used when the same key appear more than one time on the keyboard and can generate more than one code. A typical example are the LEFT / RIGHT shift.


setKey

public void setKey(int r,
                   int c,
                   int... keys)

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Specified by:
focusLost in interface java.awt.event.FocusListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyEvent

public void keyEvent(java.awt.event.KeyEvent e,
                     boolean pressed)

keyEvent

protected void keyEvent(int r,
                        int c,
                        boolean pressed)
Can be redefined in subclass to detect keyboard event for example to fire a interrupt.


toString

public java.lang.String toString()
Overrides:
toString in class AbstractHardware

jmce - 1_02