//***************************************************************************** // 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.Panel; import java.awt.FlowLayout; import figue.*; import figue.box.*; import figue.path.*; import figue.resource.*; public final class Tutorial_23 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_23.java,v $ $revision$ $Date: 1998/11/02 15:55:54 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new BorderLayout()); _facade = new AWTFacade(getParameters()); add(BorderLayout.CENTER,_facade.getAwtComponent()); final Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); _buttonReplace = new Button("Replace \"Life\""); _buttonReplace.addActionListener(new ActionListener() { public final void actionPerformed(ActionEvent anEvent) { actionReplace(); } }); thePanel.add(_buttonReplace); _buttonAdd = new Button("Add \"!!\""); _buttonAdd.addActionListener(new ActionListener() { public final void actionPerformed(ActionEvent anEvent) { actionAdd(); } }); thePanel.add(_buttonAdd); _buttonRemove = new Button("Remove \"!!\""); _buttonRemove.addActionListener(new ActionListener() { public final void actionPerformed(ActionEvent anEvent) { actionRemove(); } }); thePanel.add(_buttonRemove); add(BorderLayout.NORTH,thePanel); validate(); setDefaultKeyListener(_facade); final GlyphInterface theBox = buildBox(); initResources(); PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theBox,0)); _facade.buildInit(thePath); _facade.buildComplete(); } private final void actionReplace() { final String theText; final GlyphInterface theGlyph; if ( _flagLife ) { theText = "Replace \"World\""; theGlyph = Atom.newAtom("World"); } else { theText = "Replace \"Life\""; theGlyph = Atom.newAtom("Life"); } PathInterface thePath = new Path(); PathInterface thePath0 = new Path(0); thePath.addChild(thePath0); PathInterface thePath0_0 = new Path(0); thePath0.addChild(thePath0_0); PathInterface thePath0_0_3 = new Path(3); thePath0_0.addChild(thePath0_0_3); thePath0_0_3.addOperation(new ReplaceGlyph(theGlyph)); _facade.updateAndRedisplay(thePath); _flagLife = ! _flagLife; _buttonReplace.setLabel(theText); _buttonReplace.invalidate(); validate(); } private final void actionAdd() { PathInterface thePath = new Path(); PathInterface thePath0 = new Path(0); thePath.addChild(thePath0); PathInterface thePath0_0 = new Path(0); thePath0.addChild(thePath0_0); thePath0_0.addOperation(new InsertGlyph(Atom.newAtom("!!","style hot"), _counter + 4)); _facade.updateAndRedisplay(thePath); if ( ++_counter > 0 ) { _buttonRemove.setEnabled(true); } } private final void actionRemove() { PathInterface thePath = new Path(); PathInterface thePath0 = new Path(0); thePath.addChild(thePath0); PathInterface thePath0_0 = new Path(0); thePath0.addChild(thePath0_0); thePath0_0.addOperation(new RemoveGlyph(_counter + 3)); _facade.updateAndRedisplay(thePath); if ( --_counter <= 0 ) { _buttonRemove.setEnabled(false); } } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; _buttonReplace = null; _buttonAdd = null; _buttonRemove = null; super.destroy(); } private final GlyphInterface buildBox() { final GlyphInterface theContext = new ChangeGraphicalContextAnonymous("italic","blue",null); final GlyphInterface theLine = new Paragraph(10,0,10); theContext.addChild(theLine); theLine.addChild(Atom.newAtom("It's")); theLine.addChild(Atom.newAtom('a')); theLine.addChild(Atom.newAtom("wonderful","style hot")); theLine.addChild(Atom.newAtom("life")); theLine.addChild(Atom.newAtom("!!","style hot")); return theContext; } private final void initResources() { try { _facade.doGetFont("italic",FontFamily.TIMES_ROMAN,FontStyle.BOLD_ITALIC,24,false); _facade.doGetFont("big font",FontFamily.COURIER,FontStyle.BOLD,46,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(550); setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private Button _buttonReplace; private Button _buttonAdd; private Button _buttonRemove; private boolean _flagLife = true; private int _counter = 1; }