Class Portfolio

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--Portfolio
Direct Known Subclasses:
simpleQuote, TablePortfolio, TickerPortfolio

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

source
class diagram

Common base class for quote data displaying applets. Provides functionallity to read stock portfolio from applet parameters, defines stub methods to be generalized by subclasses as needed, and provides thread to refresh data and repaint applet periodically.

The primary algorithym used by this class is:
1. read in portfolio stocks from applet parameter tags in init()
2. start refresher thread in start()
3. initialize data including creating/reading in images in run() startup
4. within run() continuously loop refreshing quotes data, repainting
applet and sleeping a refresh interval
5. stop the refresher thread in stop()

Inner class PortfolioInfo is used to maintain portfolio stock data read from applet parameters. For each stock in portfolio, a PortfolioInfo is created and stored in the portfolio Vector and Hashtable.

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

Stock data is edited using portfolio/edit.html.

To initialize portfolio stock list and create buffer or read background images, init(), start(), initData(), createImages(), getSourceImages(), getStockParameters(), getStockSymbolData(...), getStockSymbolsIndices(...) are used and are primarily used during applet startup or thread startup.

To redraw quote data as needed, update(...), paint(...), paintBackground(...), paintWindow(...), getQuotesData(), drawText(...), loadTickerInBrowser(...) are used continuously throughout the applets lifetime.

run() defines refresher thread.

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

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

Inner Class Summary
(package private)  class Portfolio.PortfolioInfo
          
Class used to maintain portfolio stock data parsed from applet parameters.
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
(package private) static java.awt.Color BACKGROUND
          background color
(package private) static java.awt.Color COLOR_DATA
          color for stock quote values
(package private) static java.awt.Color COLOR_DATA_RED
          color for stock quote values that are negative
(package private) static java.awt.Color COLOR_INFO
          color for As of time stamp
(package private) static java.awt.Color COLOR_TICKER
          color for ticker symbol
(package private) static int DEFAULT_REFRESH_INTERVAL
          default refresh interval
(package private) static int FIELDS_PER_TICKER
          maximum number of fields per stock ticker
(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.Font FONT_TIME_DATE
          font for time stamp
(package private) static java.awt.Color FOREGROUND
          foreground color
(package private) static int MAX_INDICES
          maximum number of indices
(package private) static int MAX_SINGLE_TICKER_FIELDS
          maximum number of fields in stock ticker field
(package private) static int MAX_TICKERS
          maximum number of stock tickers
(package private)  java.util.Vector portfolio
          list of portfolio stocks from applet parameters
(package private)  java.util.Hashtable portfolioKeys
          list of porfolio stocks keyed by quote symbol
(package private)  Quotes quotesData
          configuration and stock quote data
(package private)  java.lang.Thread refresher
          thread to refresh quotes and applet window
(package private)  int refreshInterval
          refresh interval to update quotes and applet window
(package private)  java.lang.String stockSymbols
          stock symbols delimited list to query cgi with
static boolean TRACE
          print trace data to System.out
 
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
Portfolio()
           
 
Method Summary
(package private)  void createImages()
          Create images and graphic ports.
 void destroy()
          Applet.destroy() defined for this applet.
 void drawText(java.awt.Graphics g, java.lang.String[] v, int x, int y, java.awt.Font fw, java.awt.Font ff, java.awt.Color c, boolean rightJustify)
          Draw given array of text strings representing a whole and fraction number on given graphics context at given x, y position using given fonts for whole and fraction value and color with right justification if wanted.
 void drawText(java.awt.Graphics g, java.lang.String v, int x, int y, java.awt.Font f, java.awt.Color c)
          Draw given text string on given graphics context at given x, y position using given font and color.
 void drawText(java.awt.Graphics g, java.lang.String v, int x, int y, java.awt.Font f, java.awt.Color c, boolean rightJustify)
          Draw given text string on given graphics context at given x, y position using given font and color with right justification if wanted.
(package private)  void getQuotesData()
          Gets quotes data.
(package private)  void getSourceImages()
          Gets source images.
(package private)  java.util.Vector getStockSymbolData(java.lang.String dataIn, java.util.Hashtable keys)
          Get portfolio stock data from applet parameters.
(package private)  java.util.Vector getStockSymbolData(java.lang.String dataIn, java.util.Hashtable keys, boolean noDuplicates)
          Get portfolio stock symbol data from applet parameters.
 void getStockSymbolParameters()
          Get stock symols from applet parameters.
(package private)  java.util.Vector getStockSymbolsIndices(java.lang.String dataIn, java.util.Vector ret)
          Get indices data from applet parameters.
 void init()
          Applet.init() defined for this applet.
 void initData()
          Initializes data.
 void loadTickerInBrowser(Portfolio.PortfolioInfo p)
          Loads browser window named by "browserWindowName" with URL defined by "tickerLoad" configuration values for given stock symbol.
 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 paintWindow(java.awt.Graphics g)
          Paints quote data on given graphics context.
 void run()
          Runnable.run() defined for this runnable class.
 void start()
          Applet.start() defined for this applet.
 void stop()
          Applet.stop() defined for this applet.
 void update(java.awt.Graphics g)
          Applet.update() defined for this applet.
 
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, keyDown, 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

TRACE

public static boolean TRACE
print trace data to System.out

DEFAULT_REFRESH_INTERVAL

static final int DEFAULT_REFRESH_INTERVAL
default refresh interval

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

FONT_TIME_DATE

static final java.awt.Font FONT_TIME_DATE
font for time stamp

COLOR_TICKER

static final java.awt.Color COLOR_TICKER
color for ticker symbol

COLOR_DATA

static final java.awt.Color COLOR_DATA
color for stock quote values

COLOR_DATA_RED

static final java.awt.Color COLOR_DATA_RED
color for stock quote values that are negative

COLOR_INFO

static final java.awt.Color COLOR_INFO
color for As of time stamp

BACKGROUND

static final java.awt.Color BACKGROUND
background color

FOREGROUND

static final java.awt.Color FOREGROUND
foreground color

MAX_TICKERS

static final int MAX_TICKERS
maximum number of stock tickers

FIELDS_PER_TICKER

static final int FIELDS_PER_TICKER
maximum number of fields per stock ticker

MAX_SINGLE_TICKER_FIELDS

static final int MAX_SINGLE_TICKER_FIELDS
maximum number of fields in stock ticker field

MAX_INDICES

static final int MAX_INDICES
maximum number of indices

refresher

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

quotesData

Quotes quotesData
configuration and stock quote data

refreshInterval

int refreshInterval
refresh interval to update quotes and applet window

stockSymbols

java.lang.String stockSymbols
stock symbols delimited list to query cgi with

portfolio

java.util.Vector portfolio
list of portfolio stocks from applet parameters

portfolioKeys

java.util.Hashtable portfolioKeys
list of porfolio stocks keyed by quote symbol
Constructor Detail

Portfolio

public Portfolio()
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.
Overrides:
start in class java.applet.Applet

stop

public void stop()
Applet.stop() defined for this applet. Stops threads.
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. Just jumps to paintWindow(g).
Parameters:
g - graphics context to draw on
Overrides:
paint in class java.awt.Container

run

public void run()
Runnable.run() defined for this runnable class. Initializes data using initData() then refreshes quoteData, repaints applet and then sleeps refreshInterval.
Specified by:
run in interface java.lang.Runnable

initData

public void initData()
Initializes data. Gets source images and creates images and image buffers.

paintBackground

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

paintWindow

public void paintWindow(java.awt.Graphics g)
Paints quote data on given graphics context. Just calls paintBackground(g) for this class.
Parameters:
g - graphics context to draw on

getQuotesData

void getQuotesData()
Gets quotes data.

drawText

public void drawText(java.awt.Graphics g,
                     java.lang.String v,
                     int x,
                     int y,
                     java.awt.Font f,
                     java.awt.Color c)
Draw given text string on given graphics context at given x, y position using given font and color.
Parameters:
g - graphics context to draw on
v - string to draw
x - position to draw at
y - position to draw at
f - font to use
c - color to use

drawText

public void drawText(java.awt.Graphics g,
                     java.lang.String v,
                     int x,
                     int y,
                     java.awt.Font f,
                     java.awt.Color c,
                     boolean rightJustify)
Draw given text string on given graphics context at given x, y position using given font and color with right justification if wanted. If right justification is wanted, text is drawn to left of x, y position.
Parameters:
g - graphics context to draw on
v - string to draw
x - position to draw at
y - position to draw at
f - font to use
c - color to use
rightJustify - true if text should be drawn right justified

drawText

public void drawText(java.awt.Graphics g,
                     java.lang.String[] v,
                     int x,
                     int y,
                     java.awt.Font fw,
                     java.awt.Font ff,
                     java.awt.Color c,
                     boolean rightJustify)
Draw given array of text strings representing a whole and fraction number on given graphics context at given x, y position using given fonts for whole and fraction value and color with right justification if wanted. If right justification is wanted, text is drawn to left of x, y position. In array of strings index o is whole part; index 1 is numerator and index 2 is denominator.
Parameters:
g - graphics context to draw on
v - string array to draw as whole + fraction number
x - position to draw at
y - position to draw at
fw - font to use for whole part
ff - font to use for fractions part
c - color to use
rightJustify - true if text should be drawn right justified

loadTickerInBrowser

public void loadTickerInBrowser(Portfolio.PortfolioInfo p)
Loads browser window named by "browserWindowName" with URL defined by "tickerLoad" configuration values for given stock symbol. If a specific URL was defined in ticker symbol string, then that URL is used.
Parameters:
p - portfolio ticker symbol info to load

createImages

void createImages()
Create images and graphic ports. Nothing for this class.

getSourceImages

void getSourceImages()
Gets source images. Nothing for this class.

getStockSymbolParameters

public void getStockSymbolParameters()
Get stock symols from applet parameters. Gets portfolio, ticker, and indices applet parameters and sets applet data fields.

getStockSymbolData

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

getStockSymbolData

java.util.Vector getStockSymbolData(java.lang.String dataIn,
                                    java.util.Hashtable keys,
                                    boolean noDuplicates)
Get portfolio stock symbol data from applet parameters. Adds stocks data to given list and stockSymbols.
Parameters:
dataIn - applet parameter
keys - list of stock tickers
noDuplicates - ignore duplicate keys
Returns:
list of portfolio stock data

getStockSymbolsIndices

java.util.Vector getStockSymbolsIndices(java.lang.String dataIn,
                                        java.util.Vector ret)
Get indices data from applet parameters. Add indices to given list and stockSymbols.
Parameters:
dataIn - applet parameter
ret - list of stock tickers to add to
Returns:
list of portfolio stock data