FileDocCategorySizeDatePackage
Seeder.javaAPI DocExample1932Mon Feb 23 16:11:26 GMT 1998oreilly.jonathan.util

Seeder

public class Seeder extends Object implements KeyListener

Fields Summary
protected byte[]
mSeed
protected int
mBitIndex
protected boolean
mDone
protected char
mLastKeyChar
protected ActionListener
mListenerChain
protected Counter
mCounter
Constructors Summary
public Seeder(int seedBytes)

 reset(seedBytes); 
Methods Summary
public voidaddActionListener(java.awt.event.ActionListener al)

    mListenerChain = AWTEventMulticaster.add(mListenerChain, al);
  
public intgetBitLength()

 return mSeed.length * 8; 
public intgetCurrentBitIndex()

    return mSeed.length * 8 - 1 - mBitIndex;
  
public byte[]getSeed()

 return mSeed; 
protected voidgrabTimeBit()

    if (mDone) return;
    int t = mCounter.getCount();
    int bit = t & 0x0001;

    if (bit != 0) {
      int seedIndex = mBitIndex / 8;
      int shiftIndex = mBitIndex % 8;
      mSeed[seedIndex] |= (bit << shiftIndex);
    }

    mBitIndex--;

    if (mBitIndex < 0) {
      mCounter.stop();
      mBitIndex = 0; // Reset this so getCurrentBitIndex() works.
      mDone = true;

      if (mListenerChain != null) {
        mListenerChain.actionPerformed(
            new ActionEvent(this, 0, "Your seed is ready."));
      }
    }
  
public voidkeyPressed(java.awt.event.KeyEvent ke)

public voidkeyReleased(java.awt.event.KeyEvent ke)

public voidkeyTyped(java.awt.event.KeyEvent ke)

    char keyChar = ke.getKeyChar();
    if (keyChar != mLastKeyChar)
      grabTimeBit();
    mLastKeyChar = keyChar;
  
public voidremoveActionListener(java.awt.event.ActionListener al)

    mListenerChain = AWTEventMulticaster.remove(mListenerChain, al);
  
public voidreset(int seedBytes)

    mSeed = new byte[seedBytes];
    mBitIndex = seedBytes * 8 - 1;
    mDone = false;
    mLastKeyChar = '\0";
    mListenerChain = null;
    mCounter = new Counter();