//***************************************************************************** // 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.Panel; import java.awt.Choice; import java.awt.GridLayout; import java.awt.Button; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import java.awt.Component; import java.awt.Panel; import java.awt.FlowLayout; import figue.*; import figue.box.*; import figue.path.*; import figue.resource.*; public final class Tutorial_24 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_24.java,v $ $revision$ $Date: 1998/11/02 15:55:54 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new BorderLayout()); _modifyFlag = false; Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); _choice = new Choice(); _choice.add("On"); _choice.add("Off"); _choice.select(0); _choice.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if ( ! _modifyFlag ) { _modifyFlag = true; _buttonStart.setEnabled(true); } } }); thePanel.add(_choice); _choiceMargin = new Choice(); _choiceMargin.add("Margin 15"); _choiceMargin.add("Margin 30"); _choiceMargin.add("Margin 45"); _choiceMargin.select(1); _choiceMargin.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if ( ! _modifyFlag ) { _modifyFlag = true; _buttonStart.setEnabled(true); } } }); thePanel.add(_choiceMargin); _choiceRate = new Choice(); _choiceRate.add("Fast"); _choiceRate.add("Medium"); _choiceRate.add("Slow"); _choiceRate.select(0); _choiceRate.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if ( ! _modifyFlag ) { _modifyFlag = true; _buttonStart.setEnabled(true); } } }); thePanel.add(_choiceRate); _choiceDelay = new Choice(); _choiceDelay.add("Delay 0 s"); _choiceDelay.add("Delay 0.5 s"); _choiceDelay.add("Delay 1 s"); _choiceDelay.add("Delay 1.5 s"); _choiceDelay.select(3); _choiceDelay.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if ( ! _modifyFlag ) { _modifyFlag = true; _buttonStart.setEnabled(true); } } }); thePanel.add(_choiceDelay); _buttonStart = new Button("Apply parameters"); _buttonStart.setEnabled(false); _buttonStart.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { _modifyFlag = false; _buttonStart.setEnabled(false); applyParameters(false); } }); Panel theOtherPanel = new Panel(); theOtherPanel.setLayout(new GridLayout(2,1)); theOtherPanel.add(thePanel); thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); thePanel.add(_buttonStart); theOtherPanel.add(thePanel); add(BorderLayout.NORTH,theOtherPanel); validate(); applyParameters(true); } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; super.destroy(); } private final GlyphInterface buildBox() { final GlyphInterface theFirstContext = new ChangeGraphicalContextAnonymous("italic","blue",null); final GlyphInterface theColumn = new Vertical(); theFirstContext.addChild(theColumn); for ( int theRank = 0; theRank < 25; theRank++ ) { final GlyphInterface theLine = new Horizontal(10); theLine.addChild(Atom.newAtom("It's")); theLine.addChild(Atom.newAtom('a')); theLine.addChild(Atom.newAtom("wonderful","style hot")); theLine.addChild(Atom.newAtom("life")); theLine.addChild(Atom.newAtom("!!")); theLine.addChild(Atom.newAtom("It's")); theLine.addChild(Atom.newAtom('a')); theLine.addChild(Atom.newAtom("wonderful","style hot")); theLine.addChild(Atom.newAtom("life","style hot")); theLine.addChild(Atom.newAtom("!!")); theColumn.addChild(theLine); } return theFirstContext; } private final void applyParameters(boolean aFirstTimeFlag) { if ( ! aFirstTimeFlag ) { _facade.disposeWhenInactive(); remove(_component); } _facade = new AWTFacade(getParameters(aFirstTimeFlag)); _component = _facade.getAwtComponent(); setDefaultKeyListener(_facade); add(BorderLayout.CENTER,_component); validate(); final GlyphInterface theBox = buildBox(); initResources(); PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theBox,0)); _facade.buildInit(thePath); _facade.buildComplete(); } private final void initResources() { try { _facade.doGetFont("italic",FontFamily.TIMES_ROMAN,FontStyle.BOLD_ITALIC,24,false); _facade.doGetFont("big font",FontFamily.COURIER,FontStyle.BOLD,46,false); _facade.doGetColor("red",BasicColor.RED); _facade.doGetColor("yellow",BasicColor.YELLOW); _facade.doGetColor("blue",BasicColor.BLUE); _facade.doGetStyle("style hot", _facade.getFont("big font"), _facade.getColor("red"), _facade.getColor("yellow")); } catch ( WrongResourceException anException ) { ; } initStandardResources(_facade); } private final FacadeInitializer getParameters(boolean aFirstTimeFlag) { FacadeInitializer theParameters = new FacadeInitializer(); if ( ! aFirstTimeFlag) { switch ( _choice.getSelectedIndex() ) { case 0: { theParameters.setAutoScrollPolicy(AutoScrollPolicy.WITHIN_FRAME); switch ( _choiceMargin.getSelectedIndex() ) { case 0: { theParameters.setAutoScrollMargin(15); break; } case 1: { theParameters.setAutoScrollMargin(30); break; } case 2: { theParameters.setAutoScrollMargin(45); break; } default: { break; } } switch ( _choiceRate.getSelectedIndex() ) { case 0: { theParameters.setAutoScrollRate(50); break; } case 1: { theParameters.setAutoScrollRate(100); break; } case 2: { theParameters.setAutoScrollRate(150); break; } default: { break; } } switch ( _choiceDelay.getSelectedIndex() ) { case 0: { theParameters.setAutoScrollDelay(0); break; } case 1: { theParameters.setAutoScrollDelay(500); break; } case 2: { theParameters.setAutoScrollDelay(1000); break; } case 3: { theParameters.setAutoScrollDelay(1500); break; } default: { break; } } break; } case 1: { theParameters.setAutoScrollPolicy(AutoScrollPolicy.NONE); break; } default: { break; } } } theParameters.setFormattingWidth(1575); setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private boolean _modifyFlag; private Choice _choice; private Choice _choiceMargin; private Choice _choiceRate; private Choice _choiceDelay; private Button _buttonStart; private Component _component; }