//***************************************************************************** // 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.Button; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.GridLayout; import java.awt.Label; import figue.*; import figue.box.*; import figue.resource.*; import figue.path.*; import figue.selection.*; public final class Tutorial_25 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_25.java,v $ $revision$ $Date: 1998/11/02 15:55:54 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new BorderLayout()); _selectionFlag1 = false; _selectionFlag2 = false; _selectionFlag3 = false; _checkbox1 = new Checkbox("it's a",false); _checkbox1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent anEvent) { resetSelection(1,anEvent.getStateChange() == ItemEvent.SELECTED); } }); _checkbox2 = new Checkbox("wonderful",false); _checkbox2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent anEvent) { resetSelection(2,anEvent.getStateChange() == ItemEvent.SELECTED); } }); _checkbox3 = new Checkbox("life !!",false); _checkbox3.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent anEvent) { resetSelection(3,anEvent.getStateChange() == ItemEvent.SELECTED); } }); Panel thePanel = new Panel(); thePanel.setLayout(new GridLayout(6,1,10,5)); thePanel.add(_checkbox1); thePanel.add(_checkbox2); thePanel.add(_checkbox3); thePanel.add(new Label("")); _buttonStart = new Button("Scroll to"); _buttonStart.setEnabled(false); _buttonStart.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scrollTo(); } }); thePanel.add(_buttonStart); thePanel.add(new Label("")); add(BorderLayout.WEST,thePanel); _facade = new AWTFacade(getParameters()); add(BorderLayout.CENTER,_facade.getAwtComponent()); setDefaultKeyListener(_facade); initResources(); buildBox(); try { _selection =_facade.doGetSelection("selection", Priority.LOW, null, "pink"); } catch ( WrongSelectionException anException ) { ; } } private final void scrollTo() { if ( _selectionFlag1 || _selectionFlag2 || _selectionFlag3 ) { PathInterface thePath = new Path(); PathInterface theNextPath = new Path(0); thePath.addChild(theNextPath); if ( _selectionFlag1 ) { PathInterface theFinalPath = new Path(NOISE * 10); theNextPath.addChild(theFinalPath); theFinalPath.addOperation(MarkGlyph.INSTANCE); } if ( _selectionFlag2 ) { PathInterface theFinalPath = new Path((NOISE * 10) + (NOISE * 2) + 1); theNextPath.addChild(theFinalPath); theFinalPath.addOperation(MarkGlyph.INSTANCE); } if ( _selectionFlag3 ) { PathInterface theFinalPath = new Path((NOISE * 10) + (NOISE * 2) + 1 + (NOISE * 4) + 1); theNextPath.addChild(theFinalPath); theFinalPath.addOperation(MarkGlyph.INSTANCE); } _facade.insureVisible(thePath); } } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; _checkbox1 = null; _checkbox2 = null; _checkbox3 = null; _selection = null; super.destroy(); } private final void resetSelection(int aNumber, boolean aSelectFlag) { int theRank = -1; switch ( aNumber ) { case 1: { _selectionFlag1 = aSelectFlag; theRank = NOISE * 10; break; } case 2: { _selectionFlag2 = aSelectFlag; theRank = (NOISE * 10) + (NOISE * 2) + 1; break; } case 3: { _selectionFlag3 = aSelectFlag; theRank = (NOISE * 10) + (NOISE * 2) + 1 + (NOISE * 4) + 1; break; } } if ( theRank >= 0 ) { PathInterface thePath = new Path(); PathInterface theNextPath = new Path(0); thePath.addChild(theNextPath); PathInterface theFinalPath = new Path(theRank); theNextPath.addChild(theFinalPath); if ( aSelectFlag ) { theFinalPath.addOperation(new ExtendSelection(_selection)); } else { theFinalPath.addOperation(new ShrinkSelection(_selection)); } _facade.updateSelectionAndRedisplay(thePath); } _buttonStart.setEnabled(_selectionFlag1 || _selectionFlag2 || _selectionFlag3); } private final void buildBox() { final GlyphInterface theBox = new Paragraph(10,0,10); pushNoise(theBox,NOISE * 10); theBox.addChild(Atom.newAtom("It's a","style hot")); pushNoise(theBox,NOISE * 2); theBox.addChild(Atom.newAtom("wonderful","style hot")); pushNoise(theBox,NOISE * 4); theBox.addChild(Atom.newAtom("life !!","style hot")); pushNoise(theBox,NOISE * 10); PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theBox,0)); _facade.buildInit(thePath); _facade.buildComplete(); } private final void pushNoise(GlyphInterface aGlyph, int aNumber) { for ( int i = 0; i < aNumber; i++ ) { aGlyph.addChild(Atom.newAtom('.')); } } 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.setInsureVisiblePolicy(new InsureVisiblePolicy(20,0,0,0)); theParameters.setFormattingWidth(600); setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private Checkbox _checkbox1; private Checkbox _checkbox2; private Checkbox _checkbox3; private Button _buttonStart; private boolean _selectionFlag1; private boolean _selectionFlag2; private boolean _selectionFlag3; private SelectionInterface _selection; private final static int NOISE = 33; }