//***************************************************************************** // 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_12 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_12.java,v $ $revision$ $Date: 1998/11/02 15:55:49 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new BorderLayout()); Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); _button = new Button("Show selection"); thePanel.add(_button); add(BorderLayout.NORTH,thePanel); _button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent anEvent) { resetSelection(); } }); _selectFlag = true; _facade = new AWTFacade(getParameters()); add(BorderLayout.CENTER,_facade.getAwtComponent()); setDefaultKeyListener(_facade); initResources(); buildBox(); try { _facade.doGetSelection("current selection", Priority.MEDIUM, null, "green"); } catch ( WrongSelectionException anException ) { ; } } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; _selectFlag = false; _button = null; super.destroy(); } private final void resetSelection() { try { final SelectionInterface theSelection = _facade.getSelection("current selection"); PathInterface thePath = new Path(); PathInterface theNextPath = new Path(0); thePath.addChild(theNextPath); PathInterface theFinalPath = new Path(2); theNextPath.addChild(theFinalPath); if ( _selectFlag ) { theFinalPath.addOperation(new ExtendSelection(theSelection)); _button.setLabel("Hide selection"); _button.invalidate(); validate(); _selectFlag = false; } else { theFinalPath.addOperation(new ShrinkSelection(theSelection)); _button.setLabel("Show selection"); _button.invalidate(); validate(); _selectFlag = true; } _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 boolean _selectFlag; private Button _button; }