Class TickerPortfolio

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

public class TickerPortfolio
extends Portfolio
implements java.awt.image.ImageObserver

source
class diagram

This class displays a stock portfolio passed in via the applet parameter tags, as read by Portfolio, as a periodically updated ticker tape. Each stock is displayed in sequence with its stock symbol ticker image, its current price and its current change in price for the day. Only NYSE listed companies can have a stock symbol ticker image.

This applet is displayed using portfolio/ticker.html.

Portfolio data consists of a Portfolio configurable number of individual stocks and indices. Indices are displayed using descriptive text.

The quotes results for each portfolio stock and portfolio indice are displayed by drawing them onta a series of fixed width images chained together to form a continuous image.








The total number of images is adjusted upward as necessary to contain the variable length quotes data. The slider thread scrolls the continuous image. The chained images are drawn as necessary relative to the slider position for the continuous image.

The image is ticker tape scrolled in either horizontal direction with a speed that can be incrementally selected using the left, right, and stop buffons.

This class uses two threads to implement the ticker functionallity, they are alider and refresher. slider slides the quotes data images across the applet window and repaints the images when they are hidden or the slider speed is 0. refresher retrieves updated quote information and requests that the quotes data images be repainted.

Note that quotes image updating only occurs when the complete quotes data image is hidden or if the ticker has been stopped.

This class adds to Portfolio keyDown(...), mouseDown(...), and imageUpade(...) event handlers along with specific implementations for painting applet window, creating buffer images and reading the applet background image.

Adds keyDown(...), mouseDown(...) and imageUpdate(...) event handlers.

Redefines init(), start(), stop(), paint(...), paintBackground(...), paintWindow(...), getSourceImages(), createImages(), initData() and getStockSymbolData(...).

Adds repaintPortfolio(), paintQuoteImage() and paintQuoteImage(...) for painting applet window.

Adds startThreads(...), stopThreads(...), runSlider() and runRefresher() for thread control.

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

Inner classes inherited from class Portfolio
Portfolio.PortfolioInfo
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
(package private) static java.awt.Rectangle APPLET_FORWARD
          forward button position on applet
(package private) static java.awt.Rectangle APPLET_QUOTES
          quotes position on applet
(package private) static java.awt.Rectangle APPLET_REVERSE
          reverse button position on applet
(package private) static java.awt.Rectangle APPLET_STOP
          stop button position on applet
(package private) static java.awt.Rectangle BACKGROUND_POS
          background image position offset adjusted for applet
(package private)  java.awt.Image buffer
          double buffer for applet
(package private)  boolean doRepaintPortfolio
          flag set to request repainting of quotes data when quote data is hidden
(package private) static java.awt.Font FONT_DATA
          font for stock quote values
(package private) static java.awt.Font FONT_DATA_FRACTION
          font for fraction part stock quote values
(package private) static java.awt.Font FONT_TICKER
          font for ticker symbol
(package private) static java.awt.Rectangle FORWARD
          forward button position on background image
(package private)  java.awt.Graphics g_buffer
          graphics port into
(package private)  java.awt.Graphics[] g_portfolioImages
          graphics ports into
(package private)  java.awt.Graphics g_this
          graphic port into this applet
(package private) static java.lang.String imagesLoc
          location of ticker images
(package private)  java.awt.Image[] portfolioImages
          images used to diplay quotes data
(package private)  int portfolioImageWidth
          total image width of images need to display quotes data
(package private)  int[] positions
          positions with quotes display images for quotes; used by mouseDown(...) to determine which quote selected
(package private) static java.awt.Rectangle QUOTE_SIZE
          quote size; width is ignored
(package private) static int QUOTES_IMAGE_WIDTH
          width of each image
(package private) static int QUOTES_IMAGES_MAX
          maximum number of images to create for quotes data
(package private)  java.lang.Thread refresher
          thread to refresh quotes and applet window
(package private) static java.awt.Rectangle REVERSE
          reverse button position on background image
(package private)  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.awt.Rectangle STOP
          stop button position on background image
(package private) static java.awt.Image ticker
          background image for applet
(package private) static java.awt.Rectangle TICKER_IMAGE
          expected ticker images size; not always followed
(package private)  java.awt.Image[] tickerImages
          ticker images for stock portfolio
(package private)  boolean[] tickerImagesLoaded
          flag for image found/loaded for each stock in portfolio
 
Fields inherited from class Portfolio
BACKGROUND, COLOR_DATA, COLOR_DATA_RED, COLOR_INFO, COLOR_TICKER, DEFAULT_REFRESH_INTERVAL, FIELDS_PER_TICKER, FONT_DATA, FONT_DATA_FRACTION, FONT_TICKER, FONT_TIME_DATE, FOREGROUND, MAX_INDICES, MAX_SINGLE_TICKER_FIELDS, MAX_TICKERS, portfolio, portfolioKeys, quotesData, refresher, refreshInterval, stockSymbols, TRACE
 
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
TickerPortfolio()
           
 
Method Summary
(package private)  void createImages()
          Create images and graphic ports for tickers and window buffer.
(package private)  void getSourceImages()
          Gets source image for background.
(package private)  java.util.Vector getStockSymbolData(java.lang.String dataIn, java.util.Hashtable keys)
          Get stock symbol data from applet parameters.
 boolean imageUpdate(java.awt.Image image, int infoflags, int x, int y, int w, int h)
          Image update event handler for this applet.
 void init()
          Applet.init() defined for this applet.
 void initData()
          Initializes data, gets "imagesListed" configuration setting, and paints initial quote image.
 boolean keyDown(java.awt.Event e, int key)
          Key event handler for this applet.
 boolean mouseDown(java.awt.Event e, int x, int y)
          Mouse 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.
 int paintQuoteImage()
          Paints quotes image.
 int paintQuoteImage(int imageIndex)
          Paints quotes images starting with indexed image buffer.
 void paintWindow(java.awt.Graphics g)
          Paints quote data on given graphics context.
(package private)  void repaintPortfolio()
          Sets deferrable repaint quotes image flag.
 void run()
          Runnable.run() defined for this runnable class.
 void runRefresher()
          Runnable.run() for refresher thread.
 void runSlider()
          Runnable.run() for Slider thread.
 void start()
          Applet.start() defined for this applet.
(package private) static void startThreads(TickerPortfolio 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(TickerPortfolio app)
          Removes applet from appRepainter lists and stops threads of last applet.
 
Methods inherited from class Portfolio
destroy, drawText, drawText, drawText, getQuotesData, getStockSymbolData, getStockSymbolParameters, getStockSymbolsIndices, loadTickerInBrowser, update
 
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, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyUp, list, list, list, location, lostFocus, 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

SLIDER_SLEEP_DELAY

static final int SLIDER_SLEEP_DELAY
slider sleep delay

SLIDER_SPEED_OFFSET

static final int SLIDER_SPEED_OFFSET
speed fudge factor

QUOTES_IMAGES_MAX

static final int QUOTES_IMAGES_MAX
maximum number of images to create for quotes data

QUOTES_IMAGE_WIDTH

static final int QUOTES_IMAGE_WIDTH
width of each image

SLIDER_MAX_SPEED

static final int SLIDER_MAX_SPEED
max slider speed

SLIDER_MIN_SPEED

static final int SLIDER_MIN_SPEED
min slider speed

FONT_TICKER

static final java.awt.Font FONT_TICKER
font for ticker symbol

FONT_DATA

static final java.awt.Font FONT_DATA
font for stock quote values

FONT_DATA_FRACTION

static final java.awt.Font FONT_DATA_FRACTION
font for fraction part stock quote values

QUOTE_SIZE

static java.awt.Rectangle QUOTE_SIZE
quote size; width is ignored

TICKER_IMAGE

static final java.awt.Rectangle TICKER_IMAGE
expected ticker images size; not always followed

REVERSE

static final java.awt.Rectangle REVERSE
reverse button position on background image

STOP

static final java.awt.Rectangle STOP
stop button position on background image

FORWARD

static final java.awt.Rectangle FORWARD
forward button position on background image

BACKGROUND_POS

static final java.awt.Rectangle BACKGROUND_POS
background image position offset adjusted for applet

APPLET_REVERSE

static final java.awt.Rectangle APPLET_REVERSE
reverse button position on applet

APPLET_STOP

static final java.awt.Rectangle APPLET_STOP
stop button position on applet

APPLET_FORWARD

static final java.awt.Rectangle APPLET_FORWARD
forward button position on applet

APPLET_QUOTES

static final java.awt.Rectangle APPLET_QUOTES
quotes position on applet

ticker

static java.awt.Image ticker
background image for applet

portfolioImages

java.awt.Image[] portfolioImages
images used to diplay quotes data

g_portfolioImages

java.awt.Graphics[] g_portfolioImages
graphics ports into

portfolioImageWidth

int portfolioImageWidth
total image width of images need to display quotes data

tickerImages

java.awt.Image[] tickerImages
ticker images for stock portfolio

tickerImagesLoaded

boolean[] tickerImagesLoaded
flag for image found/loaded for each stock in portfolio

positions

int[] positions
positions with quotes display images for quotes; used by mouseDown(...) to determine which quote selected

doRepaintPortfolio

boolean doRepaintPortfolio
flag set to request repainting of quotes data when quote data is hidden

imagesLoc

static java.lang.String imagesLoc
location of ticker images

g_this

java.awt.Graphics g_this
graphic port into this applet

buffer

java.awt.Image buffer
double buffer for applet

g_buffer

java.awt.Graphics g_buffer
graphics port into

slider_position

static int slider_position
image slider position

slider_speed

static int slider_speed
image slider speed

slider

java.lang.Thread slider
slider thread

refresher

java.lang.Thread refresher
thread to refresh quotes and applet window
Constructor Detail

TickerPortfolio

public TickerPortfolio()
Method Detail

init

public void init()
Applet.init() defined for this applet. Just insures applet is not stopped when applet started.
Overrides:
init in class Portfolio

start

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

stop

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

paint

public void paint(java.awt.Graphics g)
Applet.paint() defined for this applet. Draws buffer or fills background to BACKGROUND color.
Parameters:
g - graphics context to draw on
Overrides:
paint in class Portfolio

mouseDown

public boolean mouseDown(java.awt.Event e,
                         int x,
                         int y)
Mouse event handler for this applet. Button bar on left hits translated into keydown events. Hits on quotes loads browser window.
Parameters:
e - mouse event
x - cursor position of mouse event
y - cursor position of mouse event
Returns:
true
Overrides:
mouseDown in class java.awt.Component

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

imageUpdate

public boolean imageUpdate(java.awt.Image image,
                           int infoflags,
                           int x,
                           int y,
                           int w,
                           int h)
Image update event handler for this applet.
Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Parameters:
image - updating
x - ignored
y - ignored
w - ignored
h - ignored
Returns:
true
Overrides:
imageUpdate in class java.awt.Component

run

public void run()
Runnable.run() defined for this runnable class. Just jumps to runSlider(), runRefresher(), or runAppRepainter() for each particular thread.
Overrides:
run in class Portfolio

paintBackground

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

paintWindow

public void paintWindow(java.awt.Graphics g)
Paints quote data on given graphics context.
Parameters:
g - graphics context to draw on
Overrides:
paintWindow in class Portfolio

initData

public void initData()
Initializes data, gets "imagesListed" configuration setting, and paints initial quote image. Gets source images and creates images and image buffers.
Overrides:
initData in class Portfolio

getStockSymbolData

java.util.Vector getStockSymbolData(java.lang.String dataIn,
                                    java.util.Hashtable keys)
Get stock symbol data from applet parameters. Adds stocks data to given list and stockSymbols.
Parameters:
dataIn - applet parameter
keys - list of stock tickers
Overrides:
getStockSymbolData in class Portfolio

createImages

void createImages()
Create images and graphic ports for tickers and window buffer. Also sets clip rectangle for window buffer.
Overrides:
createImages in class Portfolio

getSourceImages

void getSourceImages()
Gets source image for background. Uses media tracker to 'block' while loading images. Images are: img/bkg.gif and img/tickerSrc.gif.
Overrides:
getSourceImages in class Portfolio

startThreads

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

stopThreads

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

runSlider

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

runRefresher

public void runRefresher()
Runnable.run() for refresher thread. Initializes data using initData() then refreshes quoteData and repaints applet and then sleeps refreshInterval.

repaintPortfolio

void repaintPortfolio()
Sets deferrable repaint quotes image flag. Will also paint immediately if slider is stopped.

paintQuoteImage

public int paintQuoteImage()
Paints quotes image.
Returns:
total image width

paintQuoteImage

public int paintQuoteImage(int imageIndex)
Paints quotes images starting with indexed image buffer. Each quote is painted in turn, with new image buffers added as needed.
Parameters:
imageIndex - index of image list to begin with
Returns:
total image width