//***************************************************************************** // Copyright (c) 1998 INRIA. // http://www.inria.fr/croap/aioli/modules/figue/web/credits.html#COPYRIGHT //***************************************************************************** package figue.tutorial; import java.awt.Label; import java.awt.TextField; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Panel; import figue.*; import figue.box.*; import figue.resource.*; import figue.path.*; public final class Tutorial_7 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_7.java,v $ $revision$ $Date: 1998/11/02 15:56:00 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new BorderLayout()); final Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.LEFT,5,5)); thePanel.add(new Label("Right margin:", Label.RIGHT)); _field = new TextField(Integer.toString(INITIAL_SPACE),6); _field.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent anEvent) { resetRightMargin(); } }); thePanel.add(_field); add(BorderLayout.NORTH,thePanel); _margin = 99; _facade = new AWTFacade(getParameters()); add(BorderLayout.CENTER,_facade.getAwtComponent()); setDefaultKeyListener(_facade); validate(); initResources(); buildBox(); } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; _field = null; _margin = -1; super.destroy(); } private final void buildBox() { final GlyphInterface theParagraph = new Paragraph(5,50,5); for ( int theRank = 0; theRank < 33; theRank++ ) { theParagraph.addChild(Atom.newAtom("It's")); theParagraph.addChild(Atom.newAtom('a')); theParagraph.addChild(Atom.newAtom("wonderful")); theParagraph.addChild(Atom.newAtom("life")); theParagraph.addChild(Atom.newAtom("!!")); } PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theParagraph,0)); _facade.buildInit(thePath); _facade.buildComplete(); } private final void initResources() { try { _facade.doGetFont(Constants.DEFAULT_FONT,FontFamily.TIMES_ROMAN,FontStyle.PLAIN,15,false); _facade.doGetColor(Constants.DEFAULT_COLOR,BasicColor.BLUE); _facade.doGetColor(Constants.DEFAULT_BACKGROUND,BasicColor.WHITE); } catch ( WrongResourceException anException ) { ; } initStandardResources(_facade); } private final FacadeInitializer getParameters() { FacadeInitializer theParameters = new FacadeInitializer(); theParameters.setFormattingWidth(INITIAL_SPACE); setAppletParameters(theParameters); return theParameters; } private final void resetRightMargin() { try { String theInput = _field.getText(); _margin = Integer.parseInt(theInput); if ( _margin < 50 ) { _field.setText("50"); _margin = 50; } _facade.setFormattingWidth(_margin); } catch ( NumberFormatException anException ) { ; } } private AWTFacade _facade; private TextField _field; private int _margin; private final static int INITIAL_SPACE = 376; }