//***************************************************************************** // 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.selection.*; import figue.resource.*; public final class Tutorial_13 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_13.java,v $ $revision$ $Date: 1998/11/02 15:55:49 $ Copyright 1998 INRIA."; protected final void initTutorial() { _counter = 0; setLayout(new BorderLayout()); Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); _button = new Button("Extend selection"); thePanel.add(_button); add(BorderLayout.NORTH,thePanel); _button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent anEvent) { extendSelection(); } }); _facade = new AWTFacade(); add(BorderLayout.CENTER,_facade.getAwtComponent()); setDefaultKeyListener(_facade); validate(); initResources(); buildBox(); try { _facade.doGetSelection("current selection", Priority.MEDIUM, null, "green"); } catch ( WrongSelectionException anException ) { ; } } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; _counter = -1; _button = null; super.destroy(); } private final void extendSelection() { if ( _counter < 3 ) { if ( _counter == 2 ) { _button.setEnabled(false); } try { final SelectionInterface theSelection = _facade.getSelection("current selection"); PathInterface thePath = new Path(); PathInterface theNextPath = new Path(0); thePath.addChild(theNextPath); PathInterface theFinalPath = new Path(_counter++ * 2); theNextPath.addChild(theFinalPath); theFinalPath.addOperation(new ExtendSelection(theSelection)); _facade.updateSelectionAndRedisplay(thePath); } catch ( WrongSelectionException anException ) { ; } } } private final void buildBox() { final GlyphInterface theBox = new Horizontal(10); theBox.addChild(Atom.newAtom("It's")); theBox.addChild(Atom.newAtom('a')); theBox.addChild(Atom.newAtom("wonderful","style hot")); theBox.addChild(Atom.newAtom("life")); theBox.addChild(Atom.newAtom("!!","style hot")); PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theBox,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); _facade.doGetFont("big font",FontFamily.COURIER,FontStyle.BOLD,20,false); _facade.doGetColor("yellow",BasicColor.YELLOW); _facade.doGetColor("red",BasicColor.RED); _facade.doGetColor("green",BasicColor.GREEN); _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(600); setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private Button _button; private int _counter; }