//***************************************************************************** // Copyright (c) 1998 INRIA. // http://www.inria.fr/croap/aioli/modules/figue/web/credits.html#COPYRIGHT //***************************************************************************** package figue.tutorial; import java.awt.GridLayout; import figue.*; import figue.box.*; import figue.path.*; import figue.event.*; import figue.resource.*; import figue.selection.*; public final class Tutorial_29 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_29.java,v $ $revision$ $Date: 1998/11/02 15:55:56 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new GridLayout(1,1)); _facade = new AWTFacade(getParameters()); add(_facade.getAwtComponent()); _facade.addPointingMotionListener(new PointingMotionListenerInterface() { public final void moving(PointingEvent anEvent) { } public final void startDragging(PointingEvent anEvent) { } public final void dragging(PointingEvent anEvent) { if ( anEvent.getPath() != null ) { hightlightBox(anEvent.getPath()); } } public final void stopDragging(PointingEvent anEvent) { } }); setDefaultKeyListener(_facade); initResources(); buildBox(); } private final void hightlightBox(PathInterface aPath) { if ( _previousPath != null ) { PathInterface theCurrentPath = _previousPath; while ( theCurrentPath.numberOfChildren() > 0 ) { theCurrentPath = theCurrentPath.getChild(0); } theCurrentPath.addOperation(new ShrinkSelection(_selection)); _facade.updateSelectionAndRedisplay(_previousPath); _previousPath = null; } PathInterface theCurrentPath = aPath; while ( theCurrentPath.numberOfChildren() > 0 ) { theCurrentPath = theCurrentPath.getChild(0); } theCurrentPath.addOperation(new ExtendSelection(_selection)); PathInterface theExtendedPath = new Path(); theExtendedPath.addChild(aPath); _facade.updateSelectionAndRedisplay(theExtendedPath); _previousPath = theExtendedPath; } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; _font = null; _yellow = null; _blue = null; _red = null; _selection = null; super.destroy(); } private final void initResources() { try { _font = _facade.doGetFont(null,FontFamily.HELVETICA ,FontStyle.BOLD,24,false); _red = _facade.doGetColor("red",BasicColor.RED); _yellow = _facade.doGetColor("yellow",BasicColor.YELLOW); _blue = _facade.doGetColor(null,0,0,255); _selection = _facade.doGetSelection("highlighted", Priority.MEDIUM, _facade.doGetColor(null,BasicColor.GREEN), null); } catch ( WrongResourceException anException ) { ; } catch ( WrongSelectionException anException ) { ; } initStandardResources(_facade); } private final void buildBox() { final GlyphInterface theContext = new ChangeGraphicalContextAnonymous(_font,_blue,null); final GlyphInterface theLine = new Paragraph(10,0,10); theContext.addChild(theLine); for( int i = 0; i < 25; i++ ) { pushWords(theLine); } PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theContext,0)); _facade.buildInit(thePath); _facade.buildComplete(); } private final void pushWords(GlyphInterface aGlyph) { aGlyph.addChild(Atom.newAtom("It's")); aGlyph.addChild(Atom.newAtom('a')); final GlyphInterface theContext = new ChangeGraphicalContextAnonymous(null,_red,_yellow); aGlyph.addChild(theContext); theContext.addChild(Atom.newAtom("wonderful")); aGlyph.addChild(Atom.newAtom("life")); aGlyph.addChild(Atom.newAtom("!!")); } private final FacadeInitializer getParameters() { FacadeInitializer theParameters = new FacadeInitializer(); theParameters.setFormattingWidth(475); setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private FontInterface _font; private ColorInterface _yellow; private ColorInterface _blue; private ColorInterface _red; private SelectionInterface _selection; private PathInterface _previousPath = null; }