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

  1. /*---------------------------------------------------------------------------
  2.  
  3.     Written by the Personal Journal developers of Dow Jones & Company, Inc.
  4.  
  5.     Dow Jones makes no representations or warranties about 
  6.     the suitability of this software, either express or 
  7.     implied, including but not limited to the implied warranties 
  8.     of merchantability, fitness for a particular purpose, 
  9.     or non-infringement.  Dow Jones will not be liable for 
  10.     any damages suffered by a user as a result of using, 
  11.     modifying or distributing this software or its derivatives.
  12.  
  13.  
  14.     @(#)WeatherView.java  0.00 01-Jan-96
  15.  
  16.         A WeatherView for the Weather section.
  17.  
  18.     Authors:
  19.  
  20.         jlee     James Lee
  21.  
  22.     Version Ident:
  23.  
  24.         $Header: /PjJavaClient/src/pj/awt/WeatherView.java 7     3/22/96 11:13p Jlee $
  25.  
  26.     History:
  27.  
  28.         0.00 24-Jan-96  jlee        Initial Creation
  29.         0.01 1-Mar-96   Ted S.      Added weather icon.
  30.         0.02 27-Mar-96  Ted S.      Added copyright and some instructional text.
  31. ---------------------------------------------------------------------------*/
  32.  
  33. package pj.awt;
  34.  
  35.  
  36. import pj.awt.PageView;
  37. import pj.awt.PjAdSpec;
  38. import pj.awt.PjAdView;
  39. import pj.awt.PjImages;
  40. import pj.awt.WeatherImageMap;
  41. import pj.io.Paper;
  42. import pj.net.RemoteImage;
  43.  
  44.  
  45. import collections.Assertable;
  46. import collections.ImplementationError;
  47. import java.awt.BorderLayout;
  48. import java.awt.Component;
  49. import java.awt.FlowLayout;
  50. import java.awt.Font;
  51. import java.awt.GridBagConstraints;
  52. import java.awt.GridBagLayout;
  53. import java.awt.Color;
  54. import java.awt.Label;
  55. import java.awt.Panel;
  56.  
  57. /**
  58.  * A PageView for the Weather section.
  59.  *
  60.  * @see PageView
  61.  * @version 0.00 24-Jan-96
  62.  * @author  jlee
  63. */
  64. public class WeatherView extends PageView implements Assertable
  65.     {
  66.  
  67.     // --- Instance variables
  68.  
  69.     private Component       cPageTitle;
  70.     private PjAdView        pjav;
  71.     private WeatherImageMap WeatherImageMap;
  72.  
  73.     // --- Public constructors
  74.  
  75.     /**
  76.      * A general-purpose constructor that uses preassembled
  77.      * components.
  78.      * @param t A title component.
  79.      * @param pas A specification for the Portfolio ad.
  80.      * @param ri  The Weather GIF remote image.
  81.     */
  82.     public WeatherView( Component t, PjAdSpec pas, RemoteImage riWeatherMap)
  83.         {
  84.         cPageTitle = t;
  85.         WeatherImageMap WeatherImageMap = new WeatherImageMap( riWeatherMap.getImage() );
  86.         pjav = new PjAdView(pas);
  87.  
  88.         initialLayout();
  89.  
  90.         } // WeatherView constructor
  91.  
  92.     /**
  93.      * A specialized constructor for a PortView that uses
  94.      * a page specification.
  95.          *
  96.          * @param pas A specification for the Portfolio ad.
  97.          * @param ri  The Weather GIF remote image.
  98.          */
  99.     public WeatherView(String pagename, PjAdSpec pas, RemoteImage riWeatherMap)
  100.         {
  101.         super(pagename);
  102.  
  103.         WeatherImageMap = new WeatherImageMap( riWeatherMap.getImage() );
  104.  
  105.         // Create weather section title
  106.         cPageTitle = new Label("Weather");
  107.         cPageTitle.setFont( PjFinals.fntSectionBigTitle );
  108.  
  109.         pjav = new PjAdView(pas);
  110.  
  111.         initialLayout();
  112.  
  113.         System.out.println("Debug-WeatherView:constructed");
  114.         } // WeatherView constructor
  115.  
  116.     // --- Public operations
  117.  
  118.     /**
  119.      * @return The number (one) of views in a WeatherView.
  120.     */
  121.     public int countViews()
  122.         {
  123.         return 1;
  124.         }
  125.  
  126.     /**
  127.      * Raise an exception if predicate is false.
  128.      * @see collections.Assertable
  129.     */
  130.     public void assert(boolean predicate) throws ImplementationError
  131.         {
  132.         ImplementationError.assert(this, predicate);
  133.         }
  134.  
  135.     // --- Private operations
  136.  
  137.     private void initialLayout()
  138.         {
  139.         Panel pnlTop = new Panel();//default FlowLayout
  140.         layoutTopPanel(pnlTop);
  141.  
  142.         Panel pnlWthMap = new Panel();//default FlowLayout
  143.         layoutWthMapPanel(pnlWthMap);
  144.  
  145.         Panel pnlAd = new Panel();
  146.                 pnlAd.setLayout( new BorderLayout() );
  147.         layoutAdPanel(pnlAd, pjav);
  148.  
  149.         layoutPanels(pnlTop,pnlWthMap,pnlAd);
  150.  
  151.         } // initialLayout
  152.  
  153.     private void layoutTopPanel(Panel pnl)
  154.         {
  155.         PjImages Imgs;
  156.         Imgs = new PjImages();
  157.  
  158.         // allign evrything to the left like in VB PJ.
  159.         pnl.setLayout( new FlowLayout( FlowLayout.LEFT ) );
  160.  
  161.         // Add the little umbrella icon
  162.         pnl.add( new GifCanvas(Imgs.imagespecs()[ PjImages.idxWeather ].getImage() ));
  163.  
  164.         // add the page title "Weather"
  165.         pnl.add(cPageTitle);
  166.         }
  167.  
  168.     private void layoutWthMapPanel(Panel pnl)
  169.         {
  170.         // Create the labels to add to the panel
  171.         Label lblCopyRight = new Label( "(c) 1996 Accu-Weather Inc. All Rights Reserved.", Label.CENTER);
  172.         lblCopyRight.setForeground( Color.darkGray );
  173.         Label lblInstructions = new Label( "Select the region for which you wish to view weather.", Label.CENTER);
  174.  
  175.         // Place all items vertically, and centered, one on top of the other.
  176.         GridBagLayout gridbag = new GridBagLayout();
  177.         GridBagConstraints gbc = new GridBagConstraints();
  178.         pnl.setLayout(gridbag);
  179.  
  180.         // Add each item, from top to bottom
  181.         gbc = new GridBagConstraints();
  182.         gbc.fill = GridBagConstraints.VERTICAL;
  183.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  184.         gridbag.setConstraints(lblCopyRight, gbc);
  185.         pnl.add( lblCopyRight);
  186.  
  187.         gbc = new GridBagConstraints();
  188.         gbc.fill = GridBagConstraints.VERTICAL;
  189.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  190.         gridbag.setConstraints(lblInstructions, gbc);
  191.         pnl.add( lblInstructions );
  192.  
  193.         gbc = new GridBagConstraints();
  194.         gbc.fill = GridBagConstraints.VERTICAL;
  195.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  196.         gridbag.setConstraints(WeatherImageMap, gbc);
  197.         pnl.add(WeatherImageMap);
  198.         }
  199.  
  200.     private void layoutAdPanel(Panel pnl, PjAdView pjav)
  201.         {
  202.         pnl.add("Center", pjav );
  203.         }
  204.  
  205.     private void layoutPanels( Panel pnlTop, Panel pnlWthMap, Panel pnlAd)
  206.         {
  207.         GridBagLayout gridbag = new GridBagLayout();
  208.         setLayout(gridbag);
  209.  
  210.         // Top panel
  211.         GridBagConstraints gbc = new GridBagConstraints();
  212.  
  213.         gbc.fill = GridBagConstraints.HORIZONTAL;
  214.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  215.  
  216.         gridbag.setConstraints(pnlTop, gbc);
  217.         add(pnlTop);
  218.  
  219.         // Top panel of Weather Image Map
  220.         gbc = new GridBagConstraints();
  221.         //gbc.weightx = 1.0;
  222.  
  223.         gbc.fill = GridBagConstraints.NONE;
  224.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  225.  
  226.         gridbag.setConstraints(pnlWthMap, gbc);
  227.         add(pnlWthMap);
  228.  
  229.         // Empty panel to fill the gap between Weather panel and Ad panel.
  230.         Panel pnlGap = new Panel();
  231.         gbc = new GridBagConstraints();
  232.         gbc.weighty = 1.0;
  233.  
  234.         gbc.fill = GridBagConstraints.BOTH;
  235.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  236.  
  237.         gridbag.setConstraints(pnlGap, gbc);
  238.         add(pnlGap);
  239.  
  240.         // Ad panel
  241.         gbc = new GridBagConstraints();
  242.         gbc.weightx = 0.0;
  243.         gbc.weighty = 0.0;
  244.  
  245.         gbc.fill = GridBagConstraints.NONE;
  246.         gbc.gridwidth = GridBagConstraints.REMAINDER;
  247.  
  248.         gridbag.setConstraints(pnlAd, gbc);
  249.         add(pnlAd);
  250.  
  251.         } // layoutPanels
  252.  
  253.  
  254.     } // WeatherView
  255.  
  256.