home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 18.0 KB | 662 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.
-
-
- @(#)MarketSection.java 0.00 22-Jan-96
-
- A SectionView for the Market pages.
-
- Authors:
-
- rphall Rick Hall
- jlee James Lee
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/MarketSection.java 14 3/22/96 11:53p Jlee $
-
- History:
-
- 0.00 22-Jan-96 rphall Initial Creation
- 0.01 08-Feb-96 jlee Adopted custom layout managers: PjListLayout and PjButtonLayout.
- 0.02 23-Feb-96 Ted S. Adjustments for PaperView changes. Also changes for icons.
- 0.03 22-Mar-96 jlee Fixed market News's column's font using PjFinals' font variable.
- 0.04 27-Mar-96 Ted S. Made use of BullOrBear.
-
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.ArrayFormatter;
- import pj.awt.Chart;
- import pj.awt.Column;
- import pj.awt.DJChart;
- import pj.awt.PageView;
- import pj.awt.PjImages;
- import pj.awt.PjButtonLayout;
- import pj.awt.PjListLayout;
- import pj.awt.PjPageSpec;
- import pj.awt.PjFinals;
- import pj.awt.PjStr;
- import pj.awt.SectionView;
- import pj.awt.BullOrBear;
- import pj.io.Paper;
-
-
- import collections.Assertable;
- import collections.ImplementationError;
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.Label;
- import java.awt.Panel;
- import java.awt.Dimension ;
- import java.awt.Rectangle;
-
-
-
- /**
- * A SectionView for the Market pages.
- *
- * @see SectionView
- * @version 0.00 22-Jan-96
- * @author rphall
- */
- public class MarketSection extends SectionView implements Assertable
- {
-
-
-
-
- // --- Class variables
-
- /**
- * Labels for the Markets buttons
- * and page names for the Market views
- */
- static final String strStkIdx = "Stock Indexes";
- static final String strMarkets = "Markets";
- static final String strWrap = "Market News";
- static final String strExTrs = "Currencies and Bonds";
- static final String strDjia = "Dow Jones Industrial Average";
- static final String strExRates = "Exchange Rates (Per U.S. Dollar)";
- static final String strUSTrs = "U.S. Treasurys (Updated Daily)";
-
-
- // --- Instance variables
-
- private PageView pvStkIdx; // Stock Indexes
- private PageView pvExTrs; // Currencies & Bonds
- private PageView pvWrap; // Wrapup
- private Paper paper;
-
- // --- Public constructors
-
- /**
- * A general-purpose constructor that uses preassembled
- * components.
- * @param stkidx A view of Stocks Indexes.
- * @param extrs A view of Currencies and Bonds.
- * @param wrap A view of the Market Wrapup.
- * @param pagespec A specification for the page.
- * @param paper The paper being observed.
- */
- public MarketSection( PageView stkidx, PageView extrs,
- PageView wrap, PjPageSpec pagespec, Paper p)
- {
- super(pagespec.tabspec);
-
- pvStkIdx = stkidx;
- pvExTrs = extrs;
- pvWrap = wrap;
- paper = p;
-
- initialLayout();
-
- } // MarketSection constructor
-
- /**
- * A specialized constructor for a MarketSection that uses
- * a page specification.
- * @param pagespec A page specification, either for the
- * Front Page headlines or the ThisJustIn headlines.
- * @param p The paper being observed.
- */
- public MarketSection(PjPageSpec pagespec, Paper p)
- {
- super(pagespec.tabspec);
- paper = p;
-
- if ( pagespec.strPageName.equals( PjStr.pageMrk) )
- {
- pvStkIdx = new MrkViewStkIdx(paper);
- pvExTrs = new MrkViewExTrs(paper);
- pvWrap = new MrkViewWrap(paper);
- }
-
- else
- {
- // Bad page specification
- assert(false);
- }
-
- initialLayout();
- System.out.println("Debug-MarketSection:constructed");
- } // MarketSection constructor
-
-
-
-
- // --- Public operations
-
- /**
- * @return The number (one) of views in a MarketSection.
- */
- public int countViews()
- {
- int num = 0;
- num += pvStkIdx.countViews();
- num += pvExTrs.countViews();
- num += pvWrap.countViews();
- return num;
- }
-
- public boolean action(Event e, Object arg)
- {
- boolean bHandled = false;
-
- // FIXME: a weak check for a hit
- if ( arg instanceof String )
- {
- bHandled = true;
- stack.page((String)arg);
- }
-
- // Let super handle action
- else
- {
- bHandled = super.action(e,arg);
- }
-
- return bHandled;
- } // action
-
- /**
- * Raise an exception if predicate is false.
- * @see collections.Assertable
- */
- public void assert(boolean predicate) throws ImplementationError
- {
- ImplementationError.assert(this, predicate);
- }
-
- // --- Private operations
-
- private void initialLayout()
- {
- assert( pvStkIdx!= null );
- assert( pvExTrs != null );
- assert( pvWrap != null );
-
- appendPage(pvStkIdx);
- appendPage(pvExTrs);
- appendPage(pvWrap);
- }
-
-
- } // MarketSection
-
-
-
- /**
- * A helper class that creates a view of the DJIA and Stock Indexes
- */
- class MrkViewStkIdx extends PageView
- {
-
- // --- Public constructors
-
- public MrkViewStkIdx(Paper paper)
- {
- super(MarketSection.strStkIdx);
-
- Label lblDjia = new Label(MarketSection.strDjia);
- lblDjia.setFont( PjFinals.fntColumnLabel );
-
- Chart chartDjia = new Chart("DOW", "Dow Jones", paper.idMrkDjia,paper);
- Panel pnlDjia = new Panel();
-
- pnlDjia.setLayout( new PjListLayout() );
-
- pnlDjia.add( lblDjia );
- pnlDjia.add( chartDjia);
-
- PageView pvStocks = new Column(Paper.idMrkStkIdx,paper);
- ((Column)pvStocks).setStoryFormatter( new ArrayFormatter(Paper.idMrkStkIdx) );
- ((Column)pvStocks).setFont( PjFinals.fntFormattedColumn );
-
- Button btnWrap = new Button(MarketSection.strWrap);
- Button btnExTrs = new Button(MarketSection.strExTrs);
- ViewAndButtons vabs = new ViewAndButtons( pvStocks, btnWrap, btnExTrs, MarketSection.strStkIdx, paper);
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- setLayout(gridbag);
-
- // Create a panel to hold the icon and the text for page title.
- Panel pnlHeader = new Panel();
- pnlHeader.setLayout( new FlowLayout( FlowLayout.LEFT ) );
-
-
- // Add the bull or bear icon.
- // fixme: determine bull or bear.
- pnlHeader.add( new BullOrBear( paper ) );
-
- // Add the title
- Label lblTitle = new Label(MarketSection.strMarkets);
- lblTitle.setFont( PjFinals.fntSectionBigTitle );
- pnlHeader.add( lblTitle );
-
- // Add the header panel with its contents to the page.
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gbc.anchor=GridBagConstraints.WEST;
- gridbag.setConstraints(pnlHeader,gbc);
- add( pnlHeader );
-
-
- // Djia
- // gbc.weightx = 1.0;
- gbc.weighty = 1.0;
-
-
-
- gbc.fill=GridBagConstraints.BOTH;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlDjia,gbc);
- add(pnlDjia);
-
- // Indexes ViewAndButtons
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(vabs,gbc);
- add(vabs);
-
- } // constructor
-
- // --- Public operations
-
- public int countViews()
- {
- return 1;
- }
-
- } // MrkViewStkIdx
-
-
-
- /**
- * A helper class that creates a view of Currencies and Bonds
- */
- class MrkViewExTrs extends PageView
- {
-
- // --- Public constructors
-
- public MrkViewExTrs(Paper paper)
- {
- super(MarketSection.strExTrs);
-
- Label lblEx = new Label(MarketSection.strExRates);
- lblEx.setFont( PjFinals.fntColumnLabel );
-
- PageView pvEx = new Column(Paper.idMrkExch,paper);
- ((Column)pvEx).setStoryFormatter(
- new ArrayFormatter(Paper.idMrkExch) );
-
- ((Column)pvEx).setFont( PjFinals.fntFormattedColumn );
- Panel pnlEx = new Panel();
-
- pnlEx.setLayout( new PjListLayout() );
- pnlEx.add( lblEx );
- pnlEx.add( pvEx );
-
- PageView pvTrs = new Column(Paper.idMrkTreas,paper);
- ((Column)pvTrs).setStoryFormatter(
- new ArrayFormatter(Paper.idMrkTreas) );
-
- ((Column)pvTrs).setFont( PjFinals.fntFormattedColumn );
-
- Button btnStkIdx = new Button(MarketSection.strStkIdx);
- Button btnWrap = new Button(MarketSection.strWrap);
-
- ViewAndButtons vabs = new ViewAndButtons(pvTrs, btnStkIdx, btnWrap, MarketSection.strUSTrs, paper);
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- setLayout(gridbag);
-
-
- // Create a panel to hold the icon and the text for page title.
- Panel pnlHeader = new Panel();
- pnlHeader.setLayout( new FlowLayout( FlowLayout.LEFT ) );
-
-
- // Add the bull or bear icon.
- pnlHeader.add( new BullOrBear( paper ) );
-
- // Add the title
- Label lblTitle = new Label(MarketSection.strExTrs);
- lblTitle.setFont( PjFinals.fntSectionBigTitle );
- pnlHeader.add( lblTitle );
-
- // Add the header panel with its contents to the page.
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gbc.anchor=GridBagConstraints.WEST;
- gridbag.setConstraints(pnlHeader,gbc);
- add( pnlHeader );
-
- // Exchange rates
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
-
- gbc.fill=GridBagConstraints.BOTH;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlEx,gbc);
- add(pnlEx);
-
- // Treasuries ViewAndButtons
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(vabs,gbc);
- add(vabs);
-
- } // constructor
-
- // --- Public operations
-
- public int countViews()
- {
- return 1;
- }
-
- } // MrkViewExTrs
-
-
-
- /**
- * A helper class that creates a view of the DJIA and Stock Indexes
- */
- class MrkViewWrap extends ViewAndButtons
- {
-
- // --- Public constructors
-
- public MrkViewWrap(Paper paper)
- {
- super
- (
- new Column(Paper.idMrkWrap,paper), // view
- new Button(MarketSection.strExTrs), // left button
- new Button(MarketSection.strStkIdx), // right button
- MarketSection.strWrap, // (local) page name
- paper
- );
-
- } // constructor
-
- // --- Public operations
-
- public int countViews()
- {
- return 1;
- }
-
- } // MrkViewWrap
-
-
-
- /**
- * A PageView containing three components: a view and two buttons
- * laid out beneath the subpanel. This is a helper class for Market
- * views.
- * <P>
- * The layout of ViewAndButtons is:
- * <pre>
- * -------------------
- * | |
- * | view |
- * | |
- * -------------------
- * | left | right |
- * -------------------
- * </pre>
- *
- * @version 0.00 01-Jan-96
- * @author rphall
- */
- class ViewAndButtons extends PageView
- {
-
- // --- Instance variables
-
- PageView pageview;
- Button btnLeft;
- Button btnRight;
-
-
- // --- Public constructors
-
- /**
- * Construct a ViewAndButtons as a standalone page.
- * @param pv Some page view, already constructed.
- * @param l Left button.
- * @param r Right button.
- * @param pagename The name of the standalone page.
- */
- public ViewAndButtons(PageView pv, Button l, Button r, String pagename, Paper paper )
- {
-
- super(pagename);
-
- pageview = pv;
- btnLeft = l;
- btnRight = r;
-
- btnLeft.setFont( PjFinals.fntColumnLabel );
- btnRight.setFont( PjFinals.fntColumnLabel );
-
- Label lblPageView = new Label(pagename, Label.LEFT);
- lblPageView.setFont( PjFinals.fntColumnLabel );
- Panel pnlPageView = new Panel();
-
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- Panel pnlButtons = new Panel();
-
-
- if ( pagename.equals( MarketSection.strWrap ) )
- {
- // Set the font
- pageview.setFont( PjFinals.fntUnfColumnPlain );
-
- //GridBagLayout for column and button panels.
- setLayout(gridbag);
-
- //Button panel. false: un-constrained width.
- pnlButtons.setLayout( new PjButtonLayout(false) );
- pnlButtons.add( btnLeft );
- pnlButtons.add( btnRight );
-
- // Create a panel to hold the icon and the text for page title.
- Panel pnlHeader = new Panel();
- pnlHeader.setLayout( new FlowLayout( FlowLayout.LEFT ) );
-
- // Add the bull or bear icon.
- if ( null != paper )
- pnlHeader.add( new BullOrBear( paper ) );
-
- // Add the title
- //Culumn title
- lblPageView.setFont( PjFinals.fntSectionBigTitle );
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(lblPageView, gbc);
- pnlHeader.add(lblPageView);
-
- // Add the header panel with its contents to the page.
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gbc.anchor=GridBagConstraints.WEST;
- gridbag.setConstraints(pnlHeader,gbc);
- add( pnlHeader );
-
- //Column panel
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
-
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pageview, gbc);
- add(pageview);
-
- // Button panel
- gbc.weighty = 0;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlButtons,gbc);
- add(pnlButtons);
- }
- else
- {
- //GridBagLayout for column and button panels.
- setLayout(gridbag);
-
- //Column panel
- pnlPageView.setLayout( new PjListLayout() );
- pnlPageView.add( lblPageView );
- pnlPageView.add( pageview );
-
- //Button panel. true: constrained width.
- pnlButtons.setLayout( new PjButtonLayout(true) );
- pnlButtons.add( btnLeft );
- pnlButtons.add( btnRight );
-
- // Column panel
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
-
- gbc.fill=GridBagConstraints.BOTH;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlPageView,gbc);
- add(pnlPageView);
-
- // Button panel
- gbc.weighty = 0;
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlButtons,gbc);
- add(pnlButtons);
- }
-
- } // gen'l constructor
-
- /**
- * Construct a ViewAndButtons as a page component.
- * @param pv Some page view, already constructed.
- * @param left Left button.
- * @param right Right button.
- */
- public ViewAndButtons(PageView pv, Button left, Button right)
- {
- this(pv,left,right,(String)null, (Paper)null);
- }
-
-
- // --- Public operations
-
- /**
- * @return The number of stories in the observed section.
- */
- public int countViews()
- {
- return pageview.countViews();
- }
-
- /**
- * Make the first story of the observed section the current view.
- */
- public void firstView()
- {
- pageview.firstView();
- }
-
- /**
- * Make the next story (after the current story) the current view.
- */
- public boolean nextView()
- {
- return pageview.nextView();
- }
-
- /**
- * Make the last story of the observed section the current view.
- */
- public void lastView()
- {
- pageview.lastView();
- }
-
- /**
- * Make the previous story (before the current story) the current view.
- */
- public boolean previousView()
- {
- return pageview.previousView();
- }
-
-
-
- /**
- * Make a specific story the current view.
- * @param idx The index of the view to display.
- */
- public void view(int idx)
- {
- pageview.view(idx);
- }
-
- /*
- public Dimension minimumSize()
- {
- return wwh.minimumSize();
- }
-
- public Dimension preferredSize()
- {
- return wwh.preferredSize();
- }
- */
-
- // --- Private operations
-
- private void postEventToParent(Event evt)
- {
- Container c = getParent();
- if ( c != null ) c.postEvent(evt);
- }
-
-
-
- } // ViewAndButtons
-