home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / awt / pjticker.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  4.6 KB  |  183 lines

  1. /*---------------------------------------------------------------------------
  2.     Written by the Personal Journal developers of Dow Jones & Company, Inc.
  3.  
  4.     Dow Jones makes no representations or warranties about 
  5.     the suitability of this software, either express or 
  6.     implied, including but not limited to the implied warranties 
  7.     of merchantability, fitness for a particular purpose, 
  8.     or non-infringement.  Dow Jones will not be liable for 
  9.     any damages suffered by a user as a result of using, 
  10.     modifying or distributing this software or its derivatives.
  11.  
  12.  
  13.     @(#)PjTicker.java  0.00 Feb 17 1996
  14.  
  15.         Slider control.
  16.  
  17.     Authors:
  18.       Lindee Ning                                                
  19.  
  20.     Version Ident:
  21.  
  22.         $Header:$
  23.  
  24.     History:
  25.  
  26.       Feb.17, 1996     Initial Creation                          
  27. ---------------------------------------------------------------------------*/
  28.  
  29. package pj.awt;
  30.  
  31. import pj.awt.Ticker;
  32. import pj.io.Paper;
  33. import pj.io.PaperSection;
  34. import pj.io.PaperStory;
  35. import pj.io.StoryContainerNotification;
  36.  
  37. import java.awt.*;
  38. import java.lang.*;
  39. import java.util.*;
  40.  
  41. /**
  42.  * Extends the Ticker to display the download status and portfolio
  43.  *
  44.  * @version 0.00 17-Feb-96
  45.  * @author Lindee Ning
  46. */
  47. public class PjTicker extends Ticker implements Observer
  48.     {
  49.  
  50.     // --- Public constructors
  51.  
  52.     /**
  53.     * Construct a Ticker as a page component.
  54.     * @param section   The name of the observed section.
  55.     * @param paper     The paper that contains the observed section.
  56.     */
  57.     public PjTicker(String section, Paper paper)
  58.         {
  59.         m_PaperSection = section;
  60.         m_Paper = paper;
  61.         m_Paper.addObserver(this);
  62.         System.out.println("Debug-PjTicker:constructed");
  63.         } // PjTicker
  64.  
  65.     // --- Public operations
  66.  
  67.     public synchronized void update(Observable src, Object arg)
  68.         {
  69.         if ( !(arg instanceof StoryContainerNotification) )
  70.             return;
  71.  
  72.         StoryContainerNotification scn = (StoryContainerNotification) arg;
  73.  
  74.         // Reactivate the ticker
  75.         if ( scn.strSubsect.equals( Paper.idPcolEOT ) )
  76.             {
  77.             //m_Thread.setPriority( Thread.NORM_PRIORITY );
  78.             SetSpeed();
  79.             m_Thread.resume();
  80.             }
  81.  
  82.         if ( !(m_PaperSection.equals(scn.strSubsect)) )
  83.             return;
  84.  
  85.         getQuotes();
  86.         } // update
  87.  
  88.     /**
  89.     * Start the Ticker
  90.     */
  91.  
  92.     public void startTicker()
  93.         {
  94.         if (!m_Active)
  95.             {
  96.             m_Thread = new Thread(this);
  97.             m_Active = true;
  98.             m_Thread.setPriority( Thread.MIN_PRIORITY );
  99.             SetSpeed(0);
  100.             SetStartPosition(2);
  101.             m_Thread.start();
  102.             m_Thread.suspend();
  103.             }
  104.         } // startTicker
  105.  
  106.     /**
  107.     * Stop the Ticker
  108.     */
  109.  
  110.     public void stopTicker()
  111.         {
  112.         m_Active = false;
  113.         m_Thread = null;
  114.         } // stopTicker
  115.  
  116.  
  117.     // --- Protected operations
  118.  
  119.     protected PaperSection getSection()
  120.         {
  121.         return m_Paper.section(m_PaperSection);
  122.         } //getSection
  123.  
  124.  
  125.     /**
  126.     * Get Quotes from portfolio section
  127.     *
  128.     */
  129.     protected void getQuotes()
  130.         {
  131.         // convert paper section to string
  132.         if (getSection().numStories() < 1)
  133.             return;
  134.  
  135.         String tempStr;
  136.  
  137.         try
  138.             {
  139.             tempStr = getSection().currentStory().getBody();
  140.             }
  141.         catch(NoSuchElementException e)
  142.             {
  143.             return;
  144.             }
  145.  
  146.         // create the tokenizer
  147.         StringTokenizer strData = new StringTokenizer(tempStr,  "\n\r");
  148.         String strOut = new String();
  149.         TokenLoop:
  150.         while(strData.hasMoreTokens())
  151.             {
  152.             try
  153.                 {
  154.                 strOut = strOut + "   " + strData.nextToken();
  155.                 }
  156.             catch (NoSuchElementException e)
  157.                 {
  158.                 break TokenLoop;
  159.                 }
  160.             } // while
  161.         SetMessage(strOut);
  162.  
  163.         } // getQuotes
  164.  
  165.  
  166.     // --- Private operations
  167.  
  168.  
  169.     // --- Private attributes
  170.  
  171.     private Paper           m_Paper;
  172.     private String          m_PaperSection;
  173.     private StringTokenizer m_strData;
  174.     private int             m_NumQuotes;
  175.     private String[]            m_Symbols;
  176.     private String[]        m_Prev;
  177.     private String[]        m_Last;
  178.     private boolean         m_Active = false;
  179.     private Thread          m_Thread = null;
  180.  
  181.     } // PjTicker
  182.  
  183.