home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 4.5 KB | 157 lines |
- /*---------------------------------------------------------------------------
-
- Written by the Personal Journal developers of Dow Jones & Company, Inc.
-
- Dow Jones makes no representations or warranties about
- the suitability of this software, either express or
- implied, including but not limited to the implied warranties
- of merchantability, fitness for a particular purpose,
- or non-infringement. Dow Jones will not be liable for
- any damages suffered by a user as a result of using,
- modifying or distributing this software or its derivatives.
-
-
- @(#)BullOrBear.java 0.00 01-Jan-96
-
- An image that observes the paper, and becomes a bull or
- a bear when the change DJIA arrives.
-
- Authors:
-
- Ted Skolnick
-
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/BullOrBear.java 3 2/11/96 4:39p Rphall $
-
- History:
-
- 0.00 18-Mar-96 Ted S. Initial Creation
-
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.GifCanvas;
- import pj.io.Paper;
- import pj.io.PaperSection;
- import pj.io.PaperStory;
- import pj.io.StoryContainerNotification;
- import pj.awt.PjImages;
-
-
- import java.util.Observable;
- import java.util.Observer;
- import java.util.Vector;
- import java.util.StringTokenizer;
- import java.lang.Float;
-
-
- /**
- * An image that observes the paper, and becomes a bull or
- * a bear when the change DJIA arrives.
- *
- * @version 0.00 18-Mar-96
- * @author Ted S.
- */
- public class BullOrBear extends GifCanvas implements Observer
- {
-
- // --- Public constructors
-
- /**
- * Construct a BullOrBear
- * @param p The paper that contains the observed section.
- */
- public BullOrBear( Paper p)
- {
- // PjImages holds all of Pj's images.
- PjImages Imgs = new PjImages();
-
- // Add the bull as a default
- setImage( Imgs.imagespecs()[ PjImages.idxBull ].getImage() );
-
- m_paper = p;
- m_paper.addObserver(this);
- }
-
- // --- Public operations
-
- /**
- * Update Bull or bear upon notification from a PaperSection.
- * @param src The object that sent or forwarded the notification.
- * @param arg The notification. An instance of StoryContainerNotification
- * is expected.
- */
- public synchronized void update(Observable src, Object arg)
- {
- if ( !(arg instanceof StoryContainerNotification) )
- return;
-
- StoryContainerNotification scn = (StoryContainerNotification) arg;
-
- if ( !(Paper.idMrkStkIdx.equals(scn.strSubsect)) )
- return;
-
- if (scn.newState != PaperSection.stateAdded)
- return;
-
- ChooseBullOrBear();
- } // update
-
-
-
- // Return the index of the icon in PjImages that has the Bull
- // or the Bear, depending on the change in the DJIA
- private void ChooseBullOrBear()
- {
- String szTemp = "";
- Float fPrev = new Float( 0 );
- Float fLast = new Float( 0 );
- String szStory;
- PjImages Imgs = new PjImages();
-
-
- //Get the 1st and 2nds token in the Stock indexes story
- // These are the last and the close values.
- //
- try
- {
- szStory = m_paper.section( Paper.idMrkStkIdx ).firstStory().getBody();
- StringTokenizer stEntries = new StringTokenizer( szStory, ",", false );
- szTemp = stEntries.nextToken();
- szTemp = stEntries.nextToken();
-
- // Convert Prev value token to a float
- try
- {
- fPrev = fPrev.valueOf( szTemp );
- }
- catch ( Exception e ){}
-
- // Convert last value token to a float
- szTemp = stEntries.nextToken();
- try
- {
- fLast = fLast.valueOf( szTemp );
- }
- catch ( Exception e ){}
- }
- catch ( Exception e ){}
-
- // If it starts with a "+" then the change is positive and the market
- // is charging like a bull.
- if ( (fLast.floatValue() >= fPrev.floatValue() ) )
- setImage( Imgs.imagespecs()[ PjImages.idxBull ].getImage() );
- else
- setImage( Imgs.imagespecs()[ PjImages.idxBear ].getImage() );
- }
-
-
-
- // --- Instance variables
- private Paper m_paper;
-
- } // BullOrBear
-