home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 13.1 KB | 429 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.
-
-
- @(#)WeatherSection.java 0.00 26-Jan-96
-
- A SectionView for the Weather.
-
- Authors:
-
- jlee James Lee
- rphall Rick Hall
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/WeatherSection.java 11 3/22/96 11:13p Jlee $
-
- History:
-
- 0.00 26-Jan-96 jlee Initial Creation
- 13-Feb-96 rphall Defined WeatherColumn
- 14-Feb-96 jlee Added Map button functionality
- 21-Feb-96 jlee Changed(corrected) regional page's previous GridBagLayout to PjListLayout.
- 3-Mar-96 Ted S. Added weather icon.
- 3-Mar-96 Ted S. Removed countViews(), let parent class handle it.
- 26-Mar-96 jlee Changed "&Map" to "Map"
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.Column;
- import pj.awt.Notebook;
- import pj.awt.PjImages;
- import pj.awt.PjListLayout;
- import pj.awt.PjPageSpec;
- import pj.awt.PjFinals;
- import pj.awt.PjStr;
- import pj.awt.SectionView;
- import pj.awt.StoryFormatter;
- import pj.awt.WeatherView;
- import pj.io.MalformedPaperStoryException;
- import pj.io.Paper;
- import pj.io.PaperStory;
- import pj.net.RemoteImage;
-
- import collections.Assertable;
- import collections.ImplementationError;
- import java.awt.Button;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.GridBagLayout;
- import java.awt.GridBagConstraints;
- import java.awt.Insets;
- import java.awt.Label;
- import java.awt.Panel;
-
- /**
- * A SectionView for Weather.
- *
- * @see DividerView
- * @version 0.00 26-Jan-96
- * @author jlee
- */
- public class WeatherSection extends SectionView implements Assertable
- {
-
- // --- Instance variables
-
- private WeatherView hvWeather;
- private RemoteImage riWeather;
- private Paper paper;
-
- private PageView pvNortheast;
- private PageView pvSoutheast;
- private PageView pvMiddleUS;
- private PageView pvWest;
- private PageView pvCanada;
- private PageView pvSAmCarib;
- private PageView pvEurope;
- private PageView pvMideast;
- private PageView pvAfrica;
- private PageView pvAsiaAustrl;
-
-
- private final String pgWeather = "Weather";
-
- private final String pgNortheast = "U.S. Northeast";
- private final String pgSoutheast = "U.S. Southeast";
- private final String pgMiddleUS = "U.S. Middle";
- private final String pgWest = "U.S. West";
- private final String pgCanada = "Canada";
- private final String pgSAmCarib = "South America/Caribbean";
- private final String pgEurope = "Europe";
- private final String pgMideast = "Middle East";
- private final String pgAfrica = "Africa";
- private final String pgAsiaAustrl = "Asia/Australia";
-
- private final String strMap ="Map";
- // --- Public constructors
-
- /**
- * A general-purpose constructor that uses preassembled
- * components.
- * @param hv A WeatherView.
- * @param pagespec A specification for the page.
- * @param paper The paper being observed.
- */
- public WeatherSection( WeatherView hv, PjPageSpec pagespec, Paper p)
- {
- super(pagespec.tabspec);
-
- hvWeather = hv;
- paper = p;
-
- // Column pages creation
- InitColumns();
-
- initialLayout();
-
- } // WeatherSection constructor
-
- /**
- * A specialized constructor for a WeatherSection that uses
- * a page specification.
- * @param pagespec A page specification, either for the Weather.
- * @param pas A PjAdSpec object.
- * @param p The paper being observed.
- * @param riWeatherMap The Weather Map image.
- */
- public WeatherSection(PjPageSpec pagespec, PjAdSpec pas, Paper p, RemoteImage riWeatherMap)
- {
- super(pagespec.tabspec);
-
- paper = p;
-
- // Column pages creation
- InitColumns();
-
- // Weather viewer ceation
- hvWeather = new WeatherView(pagespec.strPageName, pas, riWeatherMap);
- hvWeather.setName(pgWeather);
-
- initialLayout();
-
- System.out.println("Debug-WeatherSection:constructed");
- } // WeatherSection constructor
-
-
-
-
-
- // --- Public operations
-
- /**
- * Handles events
- *
- * @param evt An Event object
- * @return true if the event's handled, false otherwise.
- */
- public boolean handleEvent(Event evt)
- {
- boolean bHandled = false;
-
- switch (evt.id)
- {
- default:
- bHandled = super.handleEvent(evt);
- break;
- } // switch
-
- return bHandled;
- } // handleEvent
-
- /**
- * Handles ACTION_EVENT. Specifically, when you click one of those regions in
- * the weather map, it'll generate this action event, which will be eventually handled here.
- *
- * @param e An Event object
- * @param arg An String object which is the name of the hot area which user cliked on.
- * @return true if further event handling's neccessary, false otherwise.
- */
- public boolean action(Event e, Object arg)
- {
- boolean bHandled = false;
-
- if ( pgNortheast.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgNortheast);
- }
- else if ( pgSoutheast.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgSoutheast);
- }
- else if ( pgMiddleUS.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgMiddleUS);
- }
- else if ( pgWest.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgWest);
- }
- else if ( pgCanada.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgCanada);
- }
- else if ( pgSAmCarib.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgSAmCarib);
- }
- else if ( pgEurope.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgEurope);
- }
- else if ( pgMideast.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgMideast);
- }
- else if ( pgAfrica.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgAfrica);
- }
- else if ( pgAsiaAustrl.equals( arg ) )
- {
- bHandled = true;
- stack.page(pgAsiaAustrl);
- }
- else if ( strMap.equals( arg ) )
- {
- bHandled = true;
- firstPage();
- }
-
- 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
-
-
- /**
- * Weather column pages init.
- */
- private void InitColumns()
- {
- pvNortheast = new WeatherColumn(pgNortheast, Paper.idWthUSNE, paper);
- pvSoutheast = new WeatherColumn(pgSoutheast, Paper.idWthUSSE, paper);
- pvMiddleUS = new WeatherColumn(pgMiddleUS, Paper.idWthUSMW, paper);
- pvWest = new WeatherColumn(pgWest, Paper.idWthUSWest,paper);
- pvCanada = new WeatherColumn(pgCanada, Paper.idWthCanada,paper);
- pvSAmCarib = new WeatherColumn(pgSAmCarib, Paper.idWthSouthA,paper);
- pvEurope = new WeatherColumn(pgEurope, Paper.idWthEurope,paper);
- pvMideast = new WeatherColumn(pgMideast, Paper.idWthMidE, paper);
- pvAfrica = new WeatherColumn(pgAfrica, Paper.idWthAfrica,paper);
- pvAsiaAustrl= new WeatherColumn(pgAsiaAustrl,Paper.idWthAsia, paper);
- }
-
- private void initialLayout()
- {
- assert( hvWeather != null );
- assert( pvNortheast != null );
- assert( pvSoutheast != null );
- assert( pvMiddleUS != null );
- assert( pvWest != null );
- assert( pvCanada != null );
- assert( pvSAmCarib != null );
- assert( pvEurope != null );
- assert( pvMideast != null );
- assert( pvAfrica != null );
- assert( pvAsiaAustrl != null );
- assert( paper != null );
-
-
-
- appendPage(hvWeather);
- appendPage(layoutPage( pvNortheast, pgNortheast ));
- appendPage(layoutPage( pvSoutheast, pgSoutheast ));
- appendPage(layoutPage( pvMiddleUS, pgMiddleUS ));
- appendPage(layoutPage( pvWest, pgWest ));
- appendPage(layoutPage( pvCanada, pgCanada ));
- appendPage(layoutPage( pvSAmCarib, pgSAmCarib ));
- appendPage(layoutPage( pvEurope, pgEurope ));
- appendPage(layoutPage( pvMideast, pgMideast ));
- appendPage(layoutPage( pvAfrica, pgAfrica ));
- appendPage(layoutPage( pvAsiaAustrl, pgAsiaAustrl ));
-
- }
-
-
- private Page layoutPage( PageView pv, String name )
- {
- //Create GridBagLayout
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
-
- //Create panels, label and button, pnlPage will contain pnlColumn
- Page pnlPage = new Page(name);
- Panel pnlColumn = new Panel();
- Label lblPageTitle = new Label(pgWeather);
- Label lblPageSubTitle = new Label(name);
- Button btnMap = new Button( strMap );
-
- //Set fonts
- lblPageTitle.setFont( PjFinals.fntSectionBigTitle );
- lblPageSubTitle.setFont( PjFinals.fntColumnLabel );
- btnMap.setFont( PjFinals.fntColumnLabel );
-
- //Set up pnlColumn
- pnlColumn.setLayout( new PjListLayout() );
- pnlColumn.add( lblPageSubTitle );
- pnlColumn.add( btnMap );
- pnlColumn.add( pv );
-
- //Layout lblPageTitle and pnlColumn
- pnlPage.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 ) );
-
- // Weather icon
- PjImages Imgs = new PjImages();
- // Add the little weather
- pnlHeader.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxWeather ].getImage() ) );
- // Add the title
- pnlHeader.add( lblPageTitle );
-
- // Add the header panel with its contents to the page.
- gbc.gridwidth=GridBagConstraints.REMAINDER;
- gbc.anchor=GridBagConstraints.WEST;
- gridbag.setConstraints(pnlHeader,gbc);
- pnlPage.add( pnlHeader );
-
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(pnlColumn, gbc);
- pnlPage.add( pnlColumn );
-
- return pnlPage;
-
- }
-
-
- } // WeatherSection
-
- /**
- * A special-purpose Column for Weather. A WeatherColumn uses
- * an ArrayFormatter by default, and fiddles with the first line
- * of the PaperStory that it observes.
- *
- * @see Column
- * @version 0.00 13-Feb-96
- * @author rphall
- */
- class WeatherColumn extends Column
- {
-
- // --- Public constructors
-
- /**
- * Construct a WeatherColumn as a standalone page.
- * @param pagename The name of the standalone page.
- * @param section The name of the observed section.
- * @param p The paper that contains the observed section.
- */
- public WeatherColumn(String pagename, String section, Paper p)
- {
- super(pagename, section, p);
- setStoryFormatter( new WeatherFormatter() );
- setFont( PjFinals.fntFormattedColumn );
- }
-
- } // WeatherColumn
-
- /**
- * A special-purpose StoryFormatter for Weather stories.
- *
- * @see StoryFormatter
- * @version 0.00 13-Feb-96
- * @author rphall
- */
- class WeatherFormatter implements StoryFormatter
- {
-
- // --- Public constructors
-
- public WeatherFormatter()
- {
- }
-
- // --- Public operations
-
- public String formatToString(PaperStory story)
- {
- return " " + story.getBody();
- }
-
- } // WeatherFormatter
-