home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 7.3 KB | 269 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.
-
-
- @(#)StoryList.java 0.00 01-Jan-96
-
- A PageView that lists the titles of stories in one PaperSection.
-
- Authors:
-
- rphall Rick Hall
- jlee James Lee
-
- Version Ident:
-
- $Header: /PjJavaClient/src/pj/awt/StoryList.java 2 1/23/96 2:56p Rphall $
-
- History:
-
- 0.00 01-Jan-96 rphall Initial Creation
- 0.01 1-Mar-96 Ted S. Conform to new PaperView interface.
- 0.02 1-Mar-96 jlee Added a private function CleanTitle to replace CRLF with null char.
- 12-Mar-96 jlee Used a custom made TitleList in place of List.
-
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import pj.awt.PageView;
- import pj.awt.TitleList;
- import pj.io.Paper;
- import pj.io.PaperSection;
- import pj.io.PaperStory;
- import pj.io.StoryContainerNotification;
-
- import java.awt.Color;
- import java.awt.Event;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.lang.String;
- import java.util.Observable;
- import java.util.Observer;
-
-
- /**
- * A PageView that lists the titles of stories in one PaperSection.
- * StoryLists may be used inside other pages or as standalone pages.
- * StoryLists may not be used as dividers.
- *
- * @version 0.00 01-Jan-96
- * @author rphall
- */
- public class StoryList extends PageView implements Observer
- {
-
- // --- Class variables
-
- static int debugCount = 0;
-
- // --- Instance variables
-
- private final String CR = "\r";
- private final String LF = "\n";
- private final String CRLF = CR + LF;
-
- private boolean bSelectionEnabled;
- private Paper paper;
- private String strPaperSection;
- private TitleList list;
-
- // --- Public constructors
-
- /**
- * Construct a StoryList as a standalone page.
- * @param pagename The name of the standalone page.
- * @param section The name of the observed section.
- * @param paper The paper that contains the observed section.
- */
- public StoryList(String pagename, String section, Paper p)
- {
- super(pagename);
- bSelectionEnabled = false;
- strPaperSection = section;
-
- list = new TitleList();
-
- GridBagLayout gridbag = new GridBagLayout();
- setLayout(gridbag);
- GridBagConstraints gbc = new GridBagConstraints();
-
- gbc.weightx = 1.0;
- gbc.weighty = 1.0;
-
- gbc.fill = GridBagConstraints.BOTH;
- gbc.gridwidth = GridBagConstraints.REMAINDER;
- gbc.gridheight= GridBagConstraints.REMAINDER;
-
- gridbag.setConstraints(list, gbc);
- add(list);
-
- paper = p;
- paper.addObserver(this);
- }
-
- /**
- * Construct a StoryList as a page component.
- * @param section The name of the observed section.
- * @param paper The paper that contains the observed section.
- */
- public StoryList(String section, Paper paper)
- {
- this(null,section,paper);
- }
-
- // --- Public operations
-
- /**
- * @return A story list displays one view.
- */
- public int countViews()
- {
- return 1;
- }
-
- /**
- * Make the first story of the observed section the current view.
- */
- public void firstView()
- {
- }
-
- /**
- * Make the next story (after the current story) the current view.
- */
- public boolean nextView()
- {
- return false;
- }
-
- /**
- * Make the last story of the observed section the current view.
- */
- public void lastView()
- {
- }
-
- /**
- * Make the previous story (before the current story) the current view.
- */
- public boolean previousView()
- {
- return false;
- }
-
-
-
- /**
- * Make a specific story the current view.
- * @param idx The index of the view to display.
- */
- public void view(int idx)
- {
- }
-
- /**
- * Update view upon notification from a PaperSection. When a section
- * notifies of a transisition to the Added state, a story list clears
- * its list and then iterates over the stories in the section, adding
- * each story title to its list.
- * @param src The object that sent or forwarded the notification.
- * @param arg The notification. An instance of StoryContainerNotification
- * is expected.
- */
- public void update(Observable src, Object arg)
- {
- if ( !(arg instanceof StoryContainerNotification) )
- return;
-
- StoryContainerNotification scn = (StoryContainerNotification) arg;
-
- if ( !(strPaperSection.equals(scn.strSubsect)) )
- return;
-
- if (scn.newState != PaperSection.stateAdded)
- return;
-
- view();
-
- } // update
-
- /**
- * Handle event:
- * If the event is LIST_SELECT, but list selection is disenabled,
- * immediately deselect this selection, otherwise let super handle it.
- * In either case, return false so that LIST_SELECT events propagate
- * up the window chain.
- */
- public boolean handleEvent(Event evt)
- {
- switch (evt.id)
- {
- case Event.MOUSE_DOWN:
- if ( evt.clickCount > 0 )
- super.handleEvent(evt);
- return false;
-
- default:
- return super.handleEvent(evt);
- } // switch
- } // handleEvent
-
-
- // --- Protected operations
-
-
- protected void view()
- {
- list.clear();
- PaperSection sec = getSection();
-
- for (int i=0; i < sec.numStories(); i++)
- list.addItem( cleanTitleString( sec.story(i).getTitle() ), false );
-
- if ( sec.numStories() > 0 )
- list.addItem( "", true );//neccessary to mark the end of adding
-
- } // view
-
- protected PaperSection getSection()
- {
- return paper.section(strPaperSection);
- }
-
- // Private operations
- private String cleanTitleString( String strTitle )
- {
- // Replace CRLF with null
- String text = strTitle;
- int nextCRLF = text.indexOf(CRLF);
- int nextSubstr = 0;
-
- while ( nextCRLF != -1 )
- {
- nextSubstr = text.length() - CRLF.length();
-
- if ( nextSubstr == 0 )
- text = text.substring(0, nextCRLF);
- else
- text = text.substring(0, nextCRLF) + text.substring(nextCRLF + CRLF.length());
-
- nextCRLF = text.indexOf(CRLF);
- } // while CRLF
-
- return text;
- }
-
-
-
- } // StoryList
-