home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 7.6 KB | 278 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.
-
-
- @(#)StatusBar.java 0.00 08-Mar-96
-
- Continuos time update class.
-
- Authors:
-
- jlee James Lee
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/StatusBar.java 5 3/22/96 11:13p Jlee $
-
- History:
-
- 0.00 08-Mar-96 jlee Initial Creation
- 0.00 25-Mar-96 jlee Changed StatusBar's super class from Panel to Canvas
- for consistent use of Canvas component for drawing.
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.PjFinals;
- import pj.io.DownloadProgressNotification;
- import pj.io.Paper;
- import pj.io.PaperSection;
-
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.lang.Object;
- import java.lang.Runnable;
- import java.lang.String;
- import java.lang.Thread;
- import java.util.Observable;
- import java.util.Observer;
-
- /**
- * Displays status and messages.
- *
- * @version 0.00 08-Mar-96
- * @author James Lee
- */
- public class StatusBar extends Canvas implements Observer, Runnable
- {
- // --- Class variables
- public static int TEXT = 0;
- public static int PROGRESS = 1;
- public static int SLOTDRAW = 2;
-
- private static String m_strText = null;
- private static int m_nLeftOffset = 4;
- private static int m_nLineHeight = 0;
- private static int m_nFontAscent = 0;
- private static int m_nMessageType = TEXT;
- private static int m_nProgressPercent = 0;
-
- // --- Instance variables
- private int m_nTotalStoryCount = 75;
- private int m_nStoryCount = 0;
- private int m_nPrevSlotX = 0;
- private int m_nSlotX = 0;
- private Thread m_spThread = null;
-
- // --- Public constructors
-
- public StatusBar()
- {
- setFont( PjFinals.fntStatusBar );
- setForeground( Color.black );
-
- FontMetrics fmText = getFontMetrics(getFont());
- m_nLineHeight = fmText.getHeight();
- m_nFontAscent = fmText.getAscent();
- }
-
- public StatusBar( String strMessage )
- {
- this();
- m_strText = strMessage;
- m_nMessageType = TEXT;
- }
-
- public StatusBar( int nProgressPercent )
- {
- this();
- m_nProgressPercent = nProgressPercent;
- m_nMessageType = PROGRESS;
- }
-
- // --- Public operations
- public void setMessage( String str )
- {
- m_strText = str;
- m_nMessageType = TEXT;
- repaint();
- }
-
- public void eraseMessage()
- {
- m_strText = null;
- m_nMessageType = TEXT;
- repaint();
- }
-
- public void setProgressPercent( int nProgressPercent )
- {
- m_nProgressPercent = nProgressPercent;
- m_nMessageType = PROGRESS;
- repaint();
- }
-
- public void setType( int type )
- {
- m_nMessageType = type;
- }
-
- public void resetProgress()
- {
- m_nStoryCount = 0;
- m_nProgressPercent = 0;
- m_nMessageType = PROGRESS;
- repaint();
- }
-
- public void update(Observable o, Object arg)
- {
- if ( !(arg instanceof DownloadProgressNotification) )
- return;
-
- /*
- if ( null == m_spThread )
- {
- m_nSlotX = 0;
- m_nPrevSlotX = 0;
- m_spThread = new Thread( this );
- m_spThread.start();
- }
- */
-
- DownloadProgressNotification dpnProgress = (DownloadProgressNotification)arg;
-
-
- if ( dpnProgress.newState == PaperSection.stateAdding )
- setProgressPercent( 100 * ++m_nStoryCount / m_nTotalStoryCount );
-
-
- if ( dpnProgress.strSubsect.equals( Paper.idPcolEOT ) )
- resetProgress();
-
- /*
- if ( dpnProgress.strSubsect.equals(Paper.idPcolEOT) )
- {
- m_spThread.stop();
- m_spThread = null;
- super.repaint();
- }
- */
-
- } // update
-
- public void update( Graphics g )
- {
- if ( m_nMessageType != SLOTDRAW )
- super.update( g );
-
- paint( g );
- }
-
- public void run()
- {
- m_nMessageType = SLOTDRAW;
-
- while(true)
- {
- repaint();
-
- try
- {
- Thread.sleep(20);
- }
- catch (InterruptedException e)
- {
- }
- }
- } //run
-
- public synchronized void paint( Graphics g )
- {
- int nHeight = size().height - 4;
- int nLength;
- int nWidth;
- int nDir = 4;
- int nSlotSize;
-
- switch ( m_nMessageType )
- {
- case 0: //TEXT
- if ( m_strText != null )
- g.drawString( m_strText, m_nLeftOffset, (size().height - m_nLineHeight) / 2 + m_nFontAscent);
- else
- g.drawString( "", m_nLeftOffset, (size().height - m_nLineHeight) / 2 + m_nFontAscent);
- break;
-
- case 1: //PROGRESS
- nWidth = (size().width - m_nLeftOffset * 2) / 100;
- int nWidthRemainder = size().width - nWidth * 100;
- int nAccumulatedWidth = 0;
- int nAccumulatedRemainder = 0;
-
- g.setColor( Color.darkGray );
-
- for ( int i = 0; i < m_nProgressPercent; i++ )
- {
- nAccumulatedRemainder += nWidthRemainder;
-
- if ( nAccumulatedRemainder >= 100 )
- {
- nAccumulatedRemainder -= 100;
- nAccumulatedWidth++;
- }
-
- if ( i % 2 == 0 )
- g.fillRect( m_nLeftOffset + nAccumulatedWidth, 2, nWidth, nHeight );
-
- nAccumulatedWidth += nWidth;
- }
- break;
-
- case 2: //Draw One slot
- nLength = size().width;
- nWidth = nLength / 100;
- nSlotSize = 20 * nWidth;
-
- if ( m_nSlotX < 0 )
- {
- m_nSlotX = 0;
- nDir = 4;
- }
- else
- if ( m_nPrevSlotX % (nLength - nSlotSize) > m_nSlotX % (nLength - nSlotSize) )
- {
- nDir = -4;
- m_nSlotX += nDir;
- }
-
- g.setColor( Color.lightGray );
- g.fillRect( m_nPrevSlotX, 2, nSlotSize, nHeight );
-
- g.setColor( Color.black );
- g.fillRect( m_nSlotX, 2, nSlotSize, nHeight );
-
- m_nPrevSlotX = m_nSlotX;
- m_nSlotX += nDir;
- break;
-
- default:
- break;
- }
- }
- } //StatusBar
-
-
-