//***************************************************************************** // Copyright (c) 1998 INRIA. // http://www.inria.fr/croap/aioli/modules/figue/web/credits.html#COPYRIGHT //***************************************************************************** package figue.tutorial; import java.awt.Font; import java.awt.Component; import java.awt.Graphics; import java.awt.FontMetrics; import java.awt.event.MouseEvent; import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Button; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Label; import java.util.Hashtable; import java.net.URL; import java.net.MalformedURLException; import java.awt.Panel; import java.awt.FlowLayout; import figue.*; import figue.box.*; import figue.path.*; import figue.resource.*; import figue.event.*; public final class Tutorial_17 extends TutorialApplet { /** * For code identification with unix what command. * @level internal */ public final static String VERSION_ID = "@(#) $Source: /net/croap/CVSROOT/figue/java/tutorial/Tutorial_17.java,v $ $revision$ $Date: 1998/11/02 15:55:51 $ Copyright 1998 INRIA."; protected final void initTutorial() { _history = new HyperlinkHistoryInterface() { public final void clear() { _followedLinks.clear(); } public final boolean isVisited(Hyperlink aLink) { return _followedLinks.containsKey((String)(aLink.getInfo())); } public final void setVisited(Hyperlink aLink) { _followedLinks.put((String)(aLink.getInfo()),this); } private Hashtable _followedLinks = new Hashtable(); }; setLayout(new BorderLayout()); final Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.LEFT,10,5)); Button theButton = new Button("Clear history"); thePanel.add(theButton); _statusLine = new Label(STATUS); thePanel.add(_statusLine); add(BorderLayout.SOUTH,thePanel); theButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent anEvent) { _history.clear(); _facade.refresh(); } }); _facade = new AWTFacade(getParameters()); _facade.addHyperlinkListener(new HyperlinkListenerInterface() { public void linkEntered(HyperlinkEvent anEvent) { _statusLine.setText(STATUS + (String)(anEvent.getHyperlink().getInfo())); _statusLine.invalidate(); validate(); } public final void linkClicked(HyperlinkEvent anEvent) { try { final String theString = (String)(anEvent.getHyperlink().getInfo()); final URL theUrl; if ( theString.equals(POSTER) ) { theUrl = new URL("http://us.imdb.com/Posters?It%27s+a+Wonderful+Life+(1946)"); } else { if ( theString.equals(URL) ) { theUrl = new URL("http://us.imdb.com/Title?It%27s+a+Wonderful+Life+(1946)"); } else { theUrl = null; } } if ( theUrl!= null ) { anEvent.getHyperlink().setVisited(); getAppletContext().showDocument(theUrl); } } catch ( MalformedURLException anException ) { ; } } public final void linkExited(HyperlinkEvent anEvent) { _statusLine.setText(STATUS); _statusLine.invalidate(); validate(); } }); add(BorderLayout.CENTER,_facade.getAwtComponent()); setDefaultKeyListener(_facade); validate(); initResources(); buildBox(); } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; super.destroy(); } private final void buildBox() { GlyphInterface theParagraph = new Paragraph(); GlyphInterface theLink; for ( int theCounter = 0; theCounter < 10; theCounter++ ) { theParagraph.addChild(Atom.newAtom("Click")); theParagraph.addChild(Atom.newAtom("on")); theParagraph.addChild(Atom.newAtom("the")); theParagraph.addChild(Atom.newAtom("following")); theParagraph.addChild(Atom.newAtom("link:")); if ( ( theCounter % 2 ) == 0 ) { theLink = new Hyperlink(POSTER,_history); } else { theLink = new Hyperlink(URL,_history); } theLink.addChild(Atom.newAtom("its")); theLink.addChild(Atom.newAtom('a')); theLink.addChild(Atom.newAtom("wonderful")); theLink.addChild(Atom.newAtom("life")); if ( ( theCounter % 2 ) == 0 ) { theLink.addChild(Atom.newAtom("(poster).")); } else { theLink.addChild(Atom.newAtom("(url).")); } theParagraph.addChild(theLink); } PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theParagraph,0)); _facade.buildInit(thePath); _facade.buildComplete(); } private final void initResources() { try { _facade.doGetColor(Constants.DEFAULT_COLOR,BasicColor.BLACK); _facade.doGetColor(Constants.DEFAULT_BACKGROUND,BasicColor.WHITE); _facade.doGetFont(Constants.DEFAULT_FONT,FontFamily.TIMES_ROMAN,FontStyle.PLAIN,15,false); _facade.doGetColor(Constants.ACTIVE_LINK_COLOR,BasicColor.BLUE); _facade.doGetColor(Constants.VISITED_LINK_COLOR,BasicColor.MAGENTA); _facade.doGetColor(Constants.SELECTED_LINK_COLOR,BasicColor.RED); _facade.doGetFont(Constants.ACTIVE_LINK_FONT,FontFamily.TIMES_ROMAN,FontStyle.ITALIC,15,true); } catch ( WrongResourceException anException ) { ; } initStandardResources(_facade); } private final FacadeInitializer getParameters() { FacadeInitializer theParameters = new FacadeInitializer(); theParameters.setFormattingWidth(475); theParameters.setHorizontalScrollbarPolicy(ScrollbarPolicy.ALWAYS); setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private HyperlinkHistoryInterface _history; private Label _statusLine; private final static String STATUS = "Status: "; private final static String URL = "URL"; private final static String POSTER = "POSTER"; }