Class TransactionTicker

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--TransactionTicker

public class TransactionTicker
extends java.applet.Applet
implements java.lang.Runnable

source
class diagram

This class displays transaction ticker data. If the market is open, it displays market transaction data. If the market is closed, it displays the closing prices for all of the listed NYSE stocks in alphabetical order. Data is retrieved using Quotes.getStatus(...) and Quotes.getTransactionTickerData(...).

This applet is displayed on home.html and marketinfo/marketinfo.html.

This class does not extend Portfolio directly, however it follows its basic design algorithym. Multiple buffer images are threads are used to smooth ticker data scrolling. Multiple buffer images are used to allow for the time it make take to retrieve additional ticker data and update the ticker images without visually impacting the ticker.

The stock transaction data is display by drawing them onta a series of fixed width images chained together and redrawn as necessary to form a continuous image representing the continuously updated ticker data.









This class uses four threads to implement the ticker functionallity, they are: slider, painter, appRepainter and statusChecker. Slider slides the quote data images; painter draws ticker data on the images retrieving additional transaction data as necessary; appRepainter draws the ticker images in all TransactionTicker applet windows for the current browser session; and statusChecker monitors market status for closing to open or open to closing changes and retrieves the data that reflects the new market status when the change occurs reseting the ticker images to reflect the status changes ASAP.

Redefines init(), start(), run() and the keyDown(...) event handler.

To initialize data and for creating or reading background images, createImages(), getSourceImages(), and initData() are used and are primarily used during applet startup or thread startup.

To redraw transaction data as needed, updateQuotesData(...), update(...), paint(...), paintTicker(...), paintBackground(...), and paintWindow(...) are used continuously throughout the applet's lifetime.

Adds startThreads(...), stopThreads(...), runSlider(), runPainter(), runAppRepainter(), and runStatusChecker() for thread control.

stop(), destroy() are primarily used during applet shutdown.

Version:
1.0 08/14/99
Author:
David Mannies
See Also:
Serialized Form

Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
(package private) static java.awt.Rectangle APPLET_TICKER
          applet bounds
(package private) static java.util.Vector applets
          list of applets running
(package private) static java.lang.Thread appRepainter
          applet repaint thread
(package private) static java.awt.Image background
          background image for applet; bkg.gif
(package private) static java.awt.Color BACKGROUND
          applet background color until background image retrieved
(package private) static java.awt.Image buffer
          double buffer for applet
(package private) static int CHAR_PER_IMAGE
          characters per ticker image
(package private) static java.awt.Rectangle CHAR_SIZE
          individual character size
(package private) static int[] characterPositions
          character positions in tickerSrc.gif
(package private) static java.lang.String characters
          character sequence in tickerSrc.gif
(package private) static int currentImage
          current images sliding; this index and currentImage-1 index are only images being shown
(package private) static java.lang.String ERROR_MSG_STRING
          error message shown when data not available
(package private) static java.awt.Graphics g_buffer
          graphics port into
(package private) static java.awt.Graphics g_tickerCharacter
          graphics port into
(package private) static java.awt.Graphics[] g_tickers
          graphics port into
(package private) static java.util.Vector graphics
          graphics ports into
(package private) static long nextQuotesDataReadTime
          minumum time before next data read attempt
(package private) static long nextStatusReadTime
          minumum time before next status read attempt
(package private) static java.lang.Thread painter
          ticker painter thread
(package private) static Quotes quotes
          quote data access
(package private) static java.lang.String quotesData
          last quote data retrieved
(package private) static java.lang.String quotesDisplay
          string data to draw on ticker
(package private) static int quotesDisplayIndex
          next character index to draw on ticker
(package private) static java.lang.Thread slider
          slider thread
(package private) static int SLIDER_MAX_SPEED
          max slider speed
(package private) static int SLIDER_MIN_SPEED
          min slider speed
(package private) static int slider_position
          image slider position
(package private) static int SLIDER_SLEEP_DELAY
          slider sleep delay
(package private) static int slider_speed
          image slider speed
(package private) static int SLIDER_SPEED_OFFSET
          speed fudge factor
(package private) static java.lang.Thread statusChecker
          status checker thread
(package private) static int TICKER_IMAGES
          count ticker images, should be at least 2(current and previous) + 1; more if data retrieval is slow
(package private) static java.lang.String TICKER_INTERVAL
          spaces between individual symbol quote data
(package private) static java.awt.Image tickerCharacter
          image buffer to crop individual characters
(package private) static java.awt.Image[] tickers
          ticker images
(package private) static java.awt.Image tickerSrc
          character images
(package private) static int updateImage
          next image to update
(package private) static int widths
          images width
 
Fields inherited from class java.applet.Applet
serialVersionUID, stub
 
Fields inherited from class java.awt.Panel
base, nameCounter, serialVersionUID
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dispatcher, layoutMgr, maxSize, ncomponents, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, assert, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
TransactionTicker()
           
 
Method Summary
(package private)  void createImages()
          Create images and graphic ports for tickers and window buffer.
 void destroy()
          Applet.destroy() defined for this applet.
(package private)  void getSourceImages()
          Gets source images for background and letters.
 void init()
          Applet.init() defined for this applet.
(package private)  void initData()
          Initializes data.
 boolean keyDown(java.awt.Event e, int key)
          Key event handler for this applet.
 void paint(java.awt.Graphics g)
          Applet.paint() defined for this applet.
 void paintBackground(java.awt.Graphics g)
          Paints background of applet on given graphics context.
 void paintTicker(java.awt.Graphics g, int x, int y)
          Paints quote data on ticker images at given x and y.
 void paintTicker(int index)
          Paints quote data on given ticker images index.
 void paintWindow(java.awt.Graphics g)
          Paints ticker images on given graphics context adjusted by slider position.
 void run()
          Runnable.run() defined for this runnable class.
 void runAppRepainter()
          Runnable.run() for appRepainter thread.
 void runPainter()
          Runnable.run() for painter thread.
 void runSlider()
          Runnable.run() for Slider thread.
 void runStatusChecker()
          Runnable.run() for appRepainter thread.
 void start()
          Applet.start() defined for this applet.
(package private) static void startThreads(TransactionTicker app)
          Starts threads if needed and adds applet and its graphic port to list for appRepainter.
 void stop()
          Applet.stop() defined for this applet.
(package private) static void stopThreads(TransactionTicker app)
          Removes applet from appRepainter lists and stops threads of last applet.
 void update(java.awt.Graphics g)
          Applet.update() defined for this applet.
 void updateQuotesData()
          Update quotes data.
 void updateQuotesData(java.lang.String newData)
          Updates quotes data to display to given string setting quotesData, quotesDisplay, and quotesDisplayIndex as required.
 
Methods inherited from class java.applet.Applet
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
, addNotify, constructComponentName
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyOrientation, countComponents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPrint, list, list, locate, minimumSize, nextFocus, paintComponents, paramString, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, print, printComponents, printOneComponent, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, readObject, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusOwner, setFont, setLayout, transferFocus, validate, validateTree, writeObject
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

BACKGROUND

static final java.awt.Color BACKGROUND
applet background color until background image retrieved

CHAR_PER_IMAGE

static final int CHAR_PER_IMAGE
characters per ticker image

TICKER_IMAGES

static final int TICKER_IMAGES
count ticker images, should be at least 2(current and previous) + 1; more if data retrieval is slow

SLIDER_SLEEP_DELAY

static final int SLIDER_SLEEP_DELAY
slider sleep delay

SLIDER_SPEED_OFFSET

static final int SLIDER_SPEED_OFFSET
speed fudge factor

SLIDER_MAX_SPEED

static final int SLIDER_MAX_SPEED
max slider speed

SLIDER_MIN_SPEED

static final int SLIDER_MIN_SPEED
min slider speed

CHAR_SIZE

static final java.awt.Rectangle CHAR_SIZE
individual character size

APPLET_TICKER

static final java.awt.Rectangle APPLET_TICKER
applet bounds

TICKER_INTERVAL

static final java.lang.String TICKER_INTERVAL
spaces between individual symbol quote data

ERROR_MSG_STRING

static final java.lang.String ERROR_MSG_STRING
error message shown when data not available

characters

static final java.lang.String characters
character sequence in tickerSrc.gif

characterPositions

static int[] characterPositions
character positions in tickerSrc.gif

background

static java.awt.Image background
background image for applet; bkg.gif

tickerSrc

static java.awt.Image tickerSrc
character images

buffer

static java.awt.Image buffer
double buffer for applet

g_buffer

static java.awt.Graphics g_buffer
graphics port into

tickerCharacter

static java.awt.Image tickerCharacter
image buffer to crop individual characters

g_tickerCharacter

static java.awt.Graphics g_tickerCharacter
graphics port into

tickers

static java.awt.Image[] tickers
ticker images

g_tickers

static java.awt.Graphics[] g_tickers
graphics port into

widths

static int widths
images width

currentImage

static int currentImage
current images sliding; this index and currentImage-1 index are only images being shown

updateImage

static int updateImage
next image to update

quotesDisplay

static java.lang.String quotesDisplay
string data to draw on ticker

quotesDisplayIndex

static int quotesDisplayIndex
next character index to draw on ticker

quotesData

static java.lang.String quotesData
last quote data retrieved

slider_position

static int slider_position
image slider position

slider_speed

static int slider_speed
image slider speed

quotes

static Quotes quotes
quote data access

applets

static java.util.Vector applets
list of applets running

graphics

static java.util.Vector graphics
graphics ports into

slider

static java.lang.Thread slider
slider thread

painter

static java.lang.Thread painter
ticker painter thread

appRepainter

static java.lang.Thread appRepainter
applet repaint thread

statusChecker

static java.lang.Thread statusChecker
status checker thread

nextQuotesDataReadTime

static long nextQuotesDataReadTime
minumum time before next data read attempt

nextStatusReadTime

static long nextStatusReadTime
minumum time before next status read attempt
Constructor Detail

TransactionTicker

public TransactionTicker()
Method Detail

init

public void init()
Applet.init() defined for this applet. Nothing for this class. Main init stuff is in initData() and executed from slider thread to speed up initial html page view.
Overrides:
init in class java.applet.Applet

start

public void start()
Applet.start() defined for this applet. Starts threads via startThreads().
Overrides:
start in class java.applet.Applet

stop

public void stop()
Applet.stop() defined for this applet. Stops threads via stopThreads().
Overrides:
stop in class java.applet.Applet

destroy

public void destroy()
Applet.destroy() defined for this applet. Nothing for this class.
Overrides:
destroy in class java.applet.Applet

update

public void update(java.awt.Graphics g)
Applet.update() defined for this applet. Just jumps to paint(g).
Parameters:
g - graphics context to draw on
Overrides:
update in class java.awt.Container

paint

public void paint(java.awt.Graphics g)
Applet.paint() defined for this applet. Draws buffer or background if buffer not defined yet.
Parameters:
g - graphics context to draw on
Overrides:
paint in class java.awt.Container

keyDown

public boolean keyDown(java.awt.Event e,
                       int key)
Key event handler for this applet. Increases speed for cursor up and cursor left. Decreases speed for cursor down and cursor right. Resets to default for spacebar.
Parameters:
e - key down event
key - pressed
Returns:
true
Overrides:
keyDown in class java.awt.Component

run

public void run()
Runnable.run() defined for this runnable class. Just jumps to runSlider(), runPainter(), or runAppRepainter() for each particular thread.
Specified by:
run in interface java.lang.Runnable

initData

void initData()
Initializes data. Initializes 'characterPositions' to x position in graphic for each ascii letter; creates Quotes used to get quote data and configuration; gets source images; creates images and image buffers; and paints initial ticker images.

startThreads

static void startThreads(TransactionTicker app)
Starts threads if needed and adds applet and its graphic port to list for appRepainter.
Parameters:
app - Applet starting

stopThreads

static void stopThreads(TransactionTicker app)
Removes applet from appRepainter lists and stops threads of last applet.
Parameters:
app - Applet stoping

runSlider

public void runSlider()
Runnable.run() for Slider thread. Initializes data using initData() and slides images and notifies appRepainter thread to repaint applets and notifies painter thread when ticker image can be updated.

runPainter

public void runPainter()
Runnable.run() for painter thread. Updates tickers images until all images that can be updated are updated. May result in data retrieval when updating ticker image. Waits until notified by slider thread.

runAppRepainter

public void runAppRepainter()
Runnable.run() for appRepainter thread. Paints buffer onto applets. Waits until notified by slider thread.

runStatusChecker

public void runStatusChecker()
Runnable.run() for appRepainter thread. Paints buffer onto applets. Waits until notified by slider thread.

updateQuotesData

public void updateQuotesData(java.lang.String newData)
Updates quotes data to display to given string setting quotesData, quotesDisplay, and quotesDisplayIndex as required.
Parameters:
newData - data to display

updateQuotesData

public void updateQuotesData()
Update quotes data. Sets quotesData, quotesDisplay, and quotesDisplayIndex.

paintTicker

public void paintTicker(java.awt.Graphics g,
                        int x,
                        int y)
Paints quote data on ticker images at given x and y.
Parameters:
g - graphics context to draw on
x - position to paint quote data
y - position to paint quote data

paintTicker

public void paintTicker(int index)
Paints quote data on given ticker images index.
Parameters:
index - of ticker images to paint

paintBackground

public void paintBackground(java.awt.Graphics g)
Paints background of applet on given graphics context.
Parameters:
g - graphics context to draw on

paintWindow

public void paintWindow(java.awt.Graphics g)
Paints ticker images on given graphics context adjusted by slider position. Assumes clip region already set.
Parameters:
g - graphics context to draw on

createImages

void createImages()
Create images and graphic ports for tickers and window buffer. Also sets clip rectangle for window buffer.

getSourceImages

void getSourceImages()
Gets source images for background and letters. Uses media tracker to 'block' while loading images since tickerSrc.gif required to display data. Images are: img/bkg.gif and img/tickerSrc.gif.