//***************************************************************************** // Copyright (c) 1998 INRIA. // http://www.inria.fr/croap/aioli/modules/figue/web/credits.html#COPYRIGHT //***************************************************************************** package figue.tutorial; import java.awt.GridLayout; import java.awt.TextArea; import java.io.StringWriter; import figue.*; import figue.box.*; import figue.path.*; import figue.resource.*; public final class Tutorial_11 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_11.java,v $ $revision$ $Date: 1998/11/02 15:55:48 $ Copyright 1998 INRIA."; protected final void initTutorial() { internalInit(); FacadeInitializer theParameters = getParameters(); theParameters.setFormattingWidth(50); _facade = new ASCIIFacade(theParameters); initResources(_facade); buildBox(_facade); final StringWriter theOutputStream = new StringWriter(); _facade.executeWhenInactive(new CommandInterface() { public final boolean execute() { _facade.update(theOutputStream); _textArea.append(theOutputStream.toString()); return true; } public final String getName() { return "Done"; } }); } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; super.destroy(); } private final void buildBox(FacadeInterface aFacade) { final GlyphInterface theColumn = new Vertical(0,0); final GlyphInterface theLine = new Horizontal(10); theColumn.addChild(theLine); pushWords(theLine); final GlyphInterface theOtherColumn = new Vertical(0,0); theLine.addChild(theOtherColumn); pushWords(theOtherColumn); final GlyphInterface theOtherLine = new Horizontal(10); theLine.addChild(theOtherLine); pushWords(theOtherLine); final GlyphInterface theParagraph = new Paragraph(10,50,5); theColumn.addChild(theParagraph); for ( int theRank = 0; theRank < 100; theRank++ ) { pushWords(theParagraph); } PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theColumn,0)); aFacade.buildInit(thePath); aFacade.buildComplete(); } private final void pushWords(GlyphInterface aGlyph) { aGlyph.addChild(Atom.newAtom("It's")); aGlyph.addChild(Atom.newAtom("a")); aGlyph.addChild(Atom.newAtom("wonderful","style hot")); aGlyph.addChild(Atom.newAtom("life")); aGlyph.addChild(Atom.newAtom("!!","style hot")); } private final void initResources(FacadeInterface aFacade) { try { aFacade.doGetFont(Constants.DEFAULT_FONT,FontFamily.TIMES_ROMAN,FontStyle.PLAIN,15,false); aFacade.doGetColor(Constants.DEFAULT_COLOR,BasicColor.BLUE); aFacade.doGetColor(Constants.DEFAULT_BACKGROUND,BasicColor.WHITE); aFacade.doGetFont("big font",FontFamily.COURIER,FontStyle.BOLD,20,false); aFacade.doGetColor("yellow",BasicColor.YELLOW); aFacade.doGetColor("red",BasicColor.RED); aFacade.doGetStyle("style hot", aFacade.getFont("big font"), aFacade.getColor("red"), aFacade.getColor("yellow")); } catch ( WrongResourceException anException ) { ; } initStandardResources(aFacade); } private final FacadeInitializer getParameters() { FacadeInitializer theParameters = new FacadeInitializer(); setAppletParameters(theParameters); return theParameters; } private ASCIIFacade _facade; private final void internalInit() { setLayout(new GridLayout(2,1)); _internalFacade = new AWTFacade(getParameters()); add(_internalFacade.getAwtComponent()); setDefaultKeyListener(_internalFacade); _textArea = new TextArea("",13,51,TextArea.SCROLLBARS_BOTH); _textArea.setFont(new java.awt.Font("Monospaced",java.awt.Font.PLAIN,13)); _textArea.setBackground(java.awt.Color.white); _textArea.setColumns(55); _textArea.setEditable(false); add(_textArea); validate(); initResources(_internalFacade); buildBox(_internalFacade); } private AWTFacade _internalFacade; private TextArea _textArea; }