//***************************************************************************** // Copyright (c) 1998 INRIA. // http://www.inria.fr/croap/aioli/modules/figue/web/credits.html#COPYRIGHT //***************************************************************************** package figue.tutorial; import java.awt.BorderLayout; import java.awt.Button; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Component; import java.awt.FlowLayout; import java.awt.Panel; import figue.*; import figue.box.*; import figue.resource.*; import figue.path.*; public final class Tutorial_31 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_31.java,v $ $revision$ $Date: 1998/11/02 15:55:57 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new BorderLayout()); _counter = 0; _buildingThread = null; Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); add(BorderLayout.NORTH,thePanel); _buttonStart = new Button("Start"); thePanel.add(_buttonStart); _buttonStart.setEnabled(true); _buttonStart.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if ( _buildingThread == null ) { _buttonStart.setEnabled(false); _buildingThread = new BuildingThread(); final GlyphInterface theBox = buildBox(); PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theBox,0)); _facade.buildInit(thePath); _buildingThread.start(); } } }); add(BorderLayout.NORTH,thePanel); _facade = new AWTFacade(getParameters()); _component = _facade.getAwtComponent(); validate(); setDefaultKeyListener(_facade); add(BorderLayout.CENTER,_component); initResources(); } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; super.destroy(); } private final GlyphInterface buildBox() { final GlyphInterface theGlyph = new Vertical(0,100); theGlyph.addChild(buildNewBox(-1)); return theGlyph; } private final GlyphInterface buildNewBox(int aMaxRank) { final GlyphInterface theContext = new ChangeGraphicalContextAnonymous("italic","blue",null); if ( ( _counter < aMaxRank ) || ( aMaxRank < 0 ) ) { theContext.setUnstable(); } final GlyphInterface theLine = new Paragraph(10,0,10); theContext.addChild(theLine); for ( int i = 0; i < 50; i++ ) { theLine.addChild(Atom.newAtom("<" + _counter + "|" + i + ">")); theLine.addChild(Atom.newAtom("It's")); theLine.addChild(Atom.newAtom('a')); theLine.addChild(Atom.newAtom("wonderful","style hot")); theLine.addChild(Atom.newAtom("life","style hot")); theLine.addChild(Atom.newAtom("!!")); if ( i == 25 ) { java.lang.Thread.yield(); } } return theContext; } private final void initResources() { try { _facade.doGetFont("italic",FontFamily.TIMES_ROMAN,FontStyle.BOLD_ITALIC,12,false); _facade.doGetFont("big font",FontFamily.COURIER,FontStyle.BOLD,20,false); _facade.doGetColor("red",BasicColor.RED); _facade.doGetColor("yellow",BasicColor.YELLOW); _facade.doGetColor("blue",BasicColor.BLUE); _facade.doGetStyle("style hot", _facade.getFont("big font"), _facade.getColor("red"), _facade.getColor("yellow")); } catch ( WrongResourceException anException ) { ; } initStandardResources(_facade); } private final FacadeInitializer getParameters() { FacadeInitializer theParameters = new FacadeInitializer(); theParameters.setFormattingWidth(450); setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private Component _component; private Button _buttonStart; private int _counter; private java.lang.Thread _buildingThread; final class BuildingThread extends java.lang.Thread { public final void run() { final int theMax = 100; while ( _counter < theMax ) { java.lang.Thread.yield(); final PathInterface thePath = new Path(); final PathInterface thePathUnder = new Path(0); thePath.addChild(thePathUnder); final PathInterface thePathToPreviousUnstable = new Path(_counter++); thePathToPreviousUnstable.addOperation(MarkStable.INSTANCE); final PathInterface thePathToNewBox = new Path(_counter); thePathToNewBox.addOperation(new InsertGlyph(buildNewBox(theMax),_counter)); thePath.addChild(thePathToNewBox); thePathUnder.addChild(thePathToPreviousUnstable); _facade.build(thePath); java.lang.Thread.yield(); } _facade.buildComplete(); _buildingThread.stop(); } } }