//***************************************************************************** // 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.Checkbox; import java.awt.Panel; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import java.awt.GridLayout; import figue.*; import figue.box.*; import figue.path.*; import figue.selection.*; import figue.resource.*; public final class Tutorial_32 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_32.java,v $ $revision$ $Date: 1998/11/02 15:55:57 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new BorderLayout()); _checkbox1 = new Checkbox("High priority",false); _checkbox1.setForeground(java.awt.Color.green); _checkbox1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent anEvent) { resetSelection(1,anEvent.getStateChange() == ItemEvent.SELECTED); } }); _checkbox2 = new Checkbox("Medium priority",false); _checkbox2.setForeground(java.awt.Color.cyan); _checkbox2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent anEvent) { resetSelection(2,anEvent.getStateChange() == ItemEvent.SELECTED); } }); _checkbox3 = new Checkbox("Low priority",false); _checkbox3.setForeground(java.awt.Color.pink); _checkbox3.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent anEvent) { resetSelection(3,anEvent.getStateChange() == ItemEvent.SELECTED); } }); Panel thePanel = new Panel(); thePanel.setLayout(new GridLayout(3,1)); thePanel.add(_checkbox1); thePanel.add(_checkbox2); thePanel.add(_checkbox3); add(BorderLayout.WEST,thePanel); _facade = new AWTFacade(getParameters()); add(BorderLayout.CENTER,_facade.getAwtComponent()); setDefaultKeyListener(_facade); initResources(); buildBox(); try { _facade.doGetSelection("selection 1", Priority.HIGH, null, "green"); _facade.doGetSelection("selection 2", Priority.MEDIUM, null, "cyan").setHighlighter(BarHighlighter.INSTANCE); _facade.doGetSelection("selection 3", Priority.LOW, null, "pink").setHighlighter(CornerHighlighter.INSTANCE); } catch ( WrongSelectionException anException ) { ; } } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; _checkbox1 = null; _checkbox2 = null; _checkbox3 = null; super.destroy(); } private final void resetSelection(int aNumber, boolean aSelectFlag) { try { final SelectionInterface theSelection = _facade.getSelection("selection " + aNumber); PathInterface thePath = new Path(); PathInterface theNextPath = new Path(0); thePath.addChild(theNextPath); for ( int theRank = 0; theRank < aNumber; theRank++ ) { PathInterface theFinalPath = new Path(theRank * 2); theNextPath.addChild(theFinalPath); if ( aSelectFlag ) { theFinalPath.addOperation(new ExtendSelection(theSelection)); } else { theFinalPath.addOperation(new ShrinkSelection(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.doGetColor("pink",BasicColor.PINK); _facade.doGetColor("cyan",BasicColor.CYAN); _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 Checkbox _checkbox1; private Checkbox _checkbox2; private Checkbox _checkbox3; }