Class TablePortfolio

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

public class TablePortfolio
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 table. Each row of the table consists of the stock ticker, its current prices, total value for its number of shares and its change in value for its number of shares. Values max out at 10 million and any value over it is displayed as ">10 million". Up to QUOTES_PAGES can be shown with QUOTES_PER_PAGE quotes per page. Quotes are displayed by pages only, not as a scrollable list. If data is not entered for numbers of shares or its amount paid, current stock value and change will be displayed as "N/A" as defined by NONE_PAID and NO_SHARES.

This applet is displayed using portfolio/list.html.

Portfolio data consists of a Portfolio configurable number of individual stocks and indices. Indices are displayed using their stock symbol.

The quote results for each portfolio stock and portfolio indice are displayed by drawing them onto a single buffer image large to enough to contain the complete portfolio list of stocks and indices.

This image is displayed by offseting its drawn location when drawing it on the applet buffer by amount relative to the desired quotes page. Pages are selected by using the Previous and Next buttons. A seperate buffer image is used to display portfolio total values and Previous and Next buttons.

These images are then combined onto the applet buffer.

This class extends the default Portfolio algorithym to:
1. read in background image and crop elements from it to use as qoutes data background, up and down arrows to indicate gain or loss, and Previous and Next buttons to use to select page to display
2. displaying quote data by first drawing quote and non quote data using buffer images created and then drawing the buffer images onto the applet buffer image

This class uses Portfolio's default refresher thread to updates its quote data periodically.

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 paintBackground(...), paintWindow(...), getSourceImages(). getSourceImages() also creates images using myCreateImages() which is different than the default implementation provided by Portfolio.

Adds paintQuotes(...), paintNonQuotes(...), and paintOverPreviousNext(...) for painting applet window.

newTop(...) processes keyDown events to select index for top of quotes page to display.

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_NEXT
          next button area with applet
(package private) static java.awt.Rectangle APPLET_PREVIOUS
          previous button area within applet
(package private) static java.awt.Rectangle APPLET_QUOTES
          quotes area within applet
(package private) static java.awt.Rectangle ARROW_DOWN
          down arrow position of background image
(package private) static java.awt.Rectangle ARROW_UP
          up arrow position of background image
(package private) static java.awt.Image arrowDown
          cropped image of down arrow
(package private) static java.awt.Image arrowUp
          cropped image of up arrow
(package private) static java.awt.Rectangle BACKGROUND
          applet background area offset of background image
(package private)  java.awt.Image buffer
          double buffer for applet
(package private) static java.awt.Rectangle EMPTY_NEXT_PREVIOUS
          empty previous and next button area of background image
(package private)  java.awt.Graphics g_buffer
          graphics port into
(package private)  java.awt.Graphics g_nonQuotes
          graphics port into
(package private)  java.awt.Graphics g_quotes
          graphics port into
(package private) static java.awt.Image next
          cropped image of next button
(package private) static java.awt.Rectangle NEXT
          next button position of background image
(package private) static java.lang.String NO_SHARES
          string to display if number shares not entered
(package private) static java.awt.Rectangle NON_QUOTES
          non quotes area of background image
(package private) static java.lang.String NONE_PAID
          string to display if amount paid not entered
(package private)  java.awt.Image nonQuotes
          buffer for non quotes area of applet
(package private)  Portfolio.PortfolioInfo[] portfolioAtIndex
          table pointer to PortfolioInfo displayed on quotes data indexed position
(package private) static java.awt.Image previous
          cropped image of previous button
(package private) static java.awt.Rectangle PREVIOUS
          previous button position of background image
(package private) static java.awt.Image previousNext
          cropped image of previous and next buttons
(package private)  java.awt.Image quotes
          buffer for quotes area of applet
(package private) static java.awt.Rectangle QUOTES
          quotes area of background image
(package private) static int QUOTES_PAGES
          quotes pages
(package private) static int QUOTES_PER_PAGE
          quotes per page
(package private) static int QUOTES_ROW_WIDTH
          width of single quote within quotes area
(package private) static java.awt.Image quotesBackground
          cropped image of quotes background
(package private)  int quotesTop
          index of quote at top of page
(package private) static java.awt.Image table
          applet background image
(package private)  float totalChange
          total change in value of stock portfolio
(package private)  float totalValue
          total value of stock 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
TablePortfolio()
           
 
Method Summary
(package private)  void getSourceImages()
          Gets source images and creates images.
 boolean imageUpdate(java.awt.Image image, int infoflags, int x, int y, int w, int h)
          Image update event handler for this applet.
 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.
(package private)  void myCreateImages()
          Create images and graphic ports.
(package private)  int newTop(int current, int size, int key)
          Returns index of top of next quote page selected from key event.
 void paintBackground(java.awt.Graphics g)
          Paints background of applet on given graphics context.
 void paintNonQuotes(java.awt.Graphics g)
          Paints non quote data on given graphics context.
 void paintOverPreviousNext(java.awt.Graphics g, int offsetX, int offsetY)
          Paints Previous and Next buttons on given graphics context.
 void paintQuotes(java.awt.Graphics g)
          Paints quote data on given graphics context.
 void paintWindow(java.awt.Graphics g)
          Paints quote data on given graphics context.
 
Methods inherited from class Portfolio
createImages, destroy, drawText, drawText, drawText, getQuotesData, getStockSymbolData, getStockSymbolData, getStockSymbolParameters, getStockSymbolsIndices, init, initData, loadTickerInBrowser, paint, run, start, stop, 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

QUOTES_PER_PAGE

static final int QUOTES_PER_PAGE
quotes per page

QUOTES_PAGES

static final int QUOTES_PAGES
quotes pages

NONE_PAID

static final java.lang.String NONE_PAID
string to display if amount paid not entered

NO_SHARES

static final java.lang.String NO_SHARES
string to display if number shares not entered

BACKGROUND

static final java.awt.Rectangle BACKGROUND
applet background area offset of background image

QUOTES

static final java.awt.Rectangle QUOTES
quotes area of background image

NON_QUOTES

static final java.awt.Rectangle NON_QUOTES
non quotes area of background image

PREVIOUS

static final java.awt.Rectangle PREVIOUS
previous button position of background image

NEXT

static final java.awt.Rectangle NEXT
next button position of background image

EMPTY_NEXT_PREVIOUS

static final java.awt.Rectangle EMPTY_NEXT_PREVIOUS
empty previous and next button area of background image

ARROW_UP

static final java.awt.Rectangle ARROW_UP
up arrow position of background image

ARROW_DOWN

static final java.awt.Rectangle ARROW_DOWN
down arrow position of background image

APPLET_QUOTES

static final java.awt.Rectangle APPLET_QUOTES
quotes area within applet

APPLET_PREVIOUS

static final java.awt.Rectangle APPLET_PREVIOUS
previous button area within applet

APPLET_NEXT

static final java.awt.Rectangle APPLET_NEXT
next button area with applet

QUOTES_ROW_WIDTH

static final int QUOTES_ROW_WIDTH
width of single quote within quotes area

table

static java.awt.Image table
applet background image

quotesBackground

static java.awt.Image quotesBackground
cropped image of quotes background

arrowUp

static java.awt.Image arrowUp
cropped image of up arrow

arrowDown

static java.awt.Image arrowDown
cropped image of down arrow

next

static java.awt.Image next
cropped image of next button

previousNext

static java.awt.Image previousNext
cropped image of previous and next buttons

previous

static java.awt.Image previous
cropped image of previous button

nonQuotes

java.awt.Image nonQuotes
buffer for non quotes area of applet

g_nonQuotes

java.awt.Graphics g_nonQuotes
graphics port into

quotes

java.awt.Image quotes
buffer for quotes area of applet

g_quotes

java.awt.Graphics g_quotes
graphics port into

buffer

java.awt.Image buffer
double buffer for applet

g_buffer

java.awt.Graphics g_buffer
graphics port into

quotesTop

int quotesTop
index of quote at top of page

totalValue

float totalValue
total value of stock portfolio

totalChange

float totalChange
total change in value of stock portfolio

portfolioAtIndex

Portfolio.PortfolioInfo[] portfolioAtIndex
table pointer to PortfolioInfo displayed on quotes data indexed position
Constructor Detail

TablePortfolio

public TablePortfolio()
Method Detail

mouseDown

public boolean mouseDown(java.awt.Event e,
                         int x,
                         int y)
Mouse event handler for this applet. Next nad Previous button hits translated into keydown events. Hits on quotes loads browser window with marketinfo and quick quote.
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. Selects page to display using newTop(...).
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. Crops quotes background and arrow images when complete background image has been loaded.
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

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

myCreateImages

void myCreateImages()
Create images and graphic ports.

getSourceImages

void getSourceImages()
Gets source images and creates images.
Overrides:
getSourceImages in class Portfolio

newTop

int newTop(int current,
           int size,
           int key)
Returns index of top of next quote page selected from key event. cursor home selects first page cursor end selects last page cursor page down selects next page cursor page up selects previous page
Parameters:
current - index of top of current page
size - of portfolio
key - pressed
Returns:
index of top of page

paintQuotes

public void paintQuotes(java.awt.Graphics g)
Paints quote data on given graphics context. Also computes quote totals.
Parameters:
g - graphics context to draw on

paintNonQuotes

public void paintNonQuotes(java.awt.Graphics g)
Paints non quote data on given graphics context.
Parameters:
g - graphics context to draw on

paintOverPreviousNext

public void paintOverPreviousNext(java.awt.Graphics g,
                                  int offsetX,
                                  int offsetY)
Paints Previous and Next buttons on given graphics context.
Parameters:
g - graphics context to draw on
offsetX - x offset in given context to draw with
offsetY - y offset in given context to draw with