home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 4.6 KB | 183 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.
-
-
- @(#)PjTicker.java 0.00 Feb 17 1996
-
- Slider control.
-
- Authors:
- Lindee Ning
-
- Version Ident:
-
- $Header:$
-
- History:
-
- Feb.17, 1996 Initial Creation
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.Ticker;
- import pj.io.Paper;
- import pj.io.PaperSection;
- import pj.io.PaperStory;
- import pj.io.StoryContainerNotification;
-
- import java.awt.*;
- import java.lang.*;
- import java.util.*;
-
- /**
- * Extends the Ticker to display the download status and portfolio
- *
- * @version 0.00 17-Feb-96
- * @author Lindee Ning
- */
- public class PjTicker extends Ticker implements Observer
- {
-
- // --- Public constructors
-
- /**
- * Construct a Ticker as a page component.
- * @param section The name of the observed section.
- * @param paper The paper that contains the observed section.
- */
- public PjTicker(String section, Paper paper)
- {
- m_PaperSection = section;
- m_Paper = paper;
- m_Paper.addObserver(this);
- System.out.println("Debug-PjTicker:constructed");
- } // PjTicker
-
- // --- Public operations
-
- public synchronized void update(Observable src, Object arg)
- {
- if ( !(arg instanceof StoryContainerNotification) )
- return;
-
- StoryContainerNotification scn = (StoryContainerNotification) arg;
-
- // Reactivate the ticker
- if ( scn.strSubsect.equals( Paper.idPcolEOT ) )
- {
- //m_Thread.setPriority( Thread.NORM_PRIORITY );
- SetSpeed();
- m_Thread.resume();
- }
-
- if ( !(m_PaperSection.equals(scn.strSubsect)) )
- return;
-
- getQuotes();
- } // update
-
- /**
- * Start the Ticker
- */
-
- public void startTicker()
- {
- if (!m_Active)
- {
- m_Thread = new Thread(this);
- m_Active = true;
- m_Thread.setPriority( Thread.MIN_PRIORITY );
- SetSpeed(0);
- SetStartPosition(2);
- m_Thread.start();
- m_Thread.suspend();
- }
- } // startTicker
-
- /**
- * Stop the Ticker
- */
-
- public void stopTicker()
- {
- m_Active = false;
- m_Thread = null;
- } // stopTicker
-
-
- // --- Protected operations
-
- protected PaperSection getSection()
- {
- return m_Paper.section(m_PaperSection);
- } //getSection
-
-
- /**
- * Get Quotes from portfolio section
- *
- */
- protected void getQuotes()
- {
- // convert paper section to string
- if (getSection().numStories() < 1)
- return;
-
- String tempStr;
-
- try
- {
- tempStr = getSection().currentStory().getBody();
- }
- catch(NoSuchElementException e)
- {
- return;
- }
-
- // create the tokenizer
- StringTokenizer strData = new StringTokenizer(tempStr, "\n\r");
- String strOut = new String();
- TokenLoop:
- while(strData.hasMoreTokens())
- {
- try
- {
- strOut = strOut + " " + strData.nextToken();
- }
- catch (NoSuchElementException e)
- {
- break TokenLoop;
- }
- } // while
- SetMessage(strOut);
-
- } // getQuotes
-
-
- // --- Private operations
-
-
- // --- Private attributes
-
- private Paper m_Paper;
- private String m_PaperSection;
- private StringTokenizer m_strData;
- private int m_NumQuotes;
- private String[] m_Symbols;
- private String[] m_Prev;
- private String[] m_Last;
- private boolean m_Active = false;
- private Thread m_Thread = null;
-
- } // PjTicker
-
-