FileDocCategorySizeDatePackage
MarketDataModel.javaAPI DocExample1815Mon Nov 09 12:45:50 GMT 1998None

MarketDataModel

public class MarketDataModel extends AbstractTableModel implements Runnable

Fields Summary
Thread
runner
MYOSM
market
int
delay
Stock[]
stocks
int[]
stockIndices
String[]
headers
Constructors Summary
public MarketDataModel(int initialDelay)

    market = new MYOSM();
    delay = initialDelay * 1000;
    Thread runner = new Thread(this);
    runner.start();
  
Methods Summary
public intgetColumnCount()

 return headers.length; 
public java.lang.StringgetColumnName(int c)

 return headers[c]; 
public intgetRowCount()


      return stocks.length; 
public java.lang.ObjectgetValueAt(int r, int c)

    switch(c) {
    case 0:
      return stocks[r].symbol;
    case 1:
      return new Double(stocks[r].price);
    case 2:
      return new Double(stocks[r].delta);
    case 3:
      return stocks[r].lastUpdate;
    }
    throw new IllegalArgumentException("Bad cell (" + r + ", " + c +")");
  
public voidrun()

    while(true) {
      // blind update . . . we could check for real deltas if necessary
      updateStocks();

      // Now, we know there are no new columns, so don't fire a data change, only
      // fire a row update . . . this keeps the table from flashing
      fireTableRowsUpdated(0, stocks.length - 1);
      try { Thread.sleep(delay); }
      catch(InterruptedException ie) {}
    }
  
public voidsetDelay(int seconds)

 delay = seconds * 1000; 
public voidsetStocks(int[] indices)

    stockIndices = indices;
    updateStocks();
    fireTableDataChanged();
  
public voidupdateStocks()

    stocks = new Stock[stockIndices.length];
    for (int i = 0; i < stocks.length; i++) {
      stocks[i] = market.getQuote(stockIndices[i]);
    }