//***************************************************************************** // 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.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.FlowLayout; import figue.*; import figue.path.*; import figue.box.*; import figue.resource.*; public final class Tutorial_21 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_21.java,v $ $revision$ $Date: 1998/11/02 15:55:53 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new BorderLayout()); _modifyFlag = false; _dataFlag = true; _choiceHorizontal = new Choice(); _choiceHorizontal.add("Horizontal scroll always"); _choiceHorizontal.add("Horizontal scroll never"); _choiceHorizontal.add("Horizontal scroll as needed"); _choiceHorizontal.select(2); _choiceHorizontal.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if ( ! _modifyFlag ) { _modifyFlag = true; _buttonStart.setEnabled(true); } } }); _buttonStart = new Button("Apply parameters"); _buttonStart.setEnabled(false); _buttonStart.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { _modifyFlag = false; _buttonStart.setEnabled(false); applyParameters(false); } }); _choiceVertical = new Choice(); _choiceVertical.add("Vertical scroll always"); _choiceVertical.add("Vertical scroll never"); _choiceVertical.add("Vertical scroll as needed"); _choiceVertical.select(2); _choiceVertical.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if ( ! _modifyFlag ) { _modifyFlag = true; _buttonStart.setEnabled(true); } } }); Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); _buttonModify = new Button("Add datas"); _buttonModify.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if ( _dataFlag ) { _dataFlag = false; _buttonModify.setLabel("Remove datas"); _buttonModify.invalidate(); validate(); modifyDatas(true); } else { _dataFlag = true; _buttonModify.setLabel("Add datas"); _buttonModify.invalidate(); validate(); modifyDatas(false); } } }); thePanel.add(_buttonModify); add(BorderLayout.SOUTH,thePanel); thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); thePanel.add(_choiceHorizontal); thePanel.add(_choiceVertical); thePanel.add(_buttonStart); add(BorderLayout.NORTH,thePanel); validate(); applyParameters(true); } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; super.destroy(); } private final GlyphInterface buildBox() { final GlyphInterface theContext = new ChangeGraphicalContextAnonymous("italic","blue",null); theContext.addChild(makeLine()); return theContext; } private final GlyphInterface makeLine() { final GlyphInterface theLine = new Horizontal(10); theLine.addChild(Atom.newAtom("It's")); theLine.addChild(Atom.newAtom('a')); final GlyphInterface theContext = new ChangeGraphicalContextAnonymous("big font","red","yellow"); theLine.addChild(theContext); theContext.addChild(Atom.newAtom("wonderful")); theLine.addChild(Atom.newAtom("life")); theLine.addChild(Atom.newAtom("!!")); return theLine; } 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 modifyDatas(boolean anAddFlag) { final PathInterface thePath = new LinearPath(0); final PathInterface thePathBis = new LinearPath(0); thePath.addChild(thePathBis); final PathInterface thePathUnder = new LinearPath(4); thePathBis.addChild(thePathUnder); if ( ! anAddFlag ) { thePathUnder.addOperation(new RemoveGlyph(0)); } else { final GlyphInterface theNewGlyph = new Vertical(30,10); for (int i = 0; i < 5; i++ ) { theNewGlyph.addChild(makeLine()); } thePathUnder.addOperation(new InsertGlyph(theNewGlyph,0)); } _facade.updateAndRedisplay(thePath); } 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); } catch ( WrongResourceException anException ) { ; } initStandardResources(_facade); } private final FacadeInitializer getParameters(boolean aFirstTimeFlag) { FacadeInitializer theParameters = new FacadeInitializer(); if ( ! aFirstTimeFlag) { _dataFlag = true; _buttonModify.setLabel("Add Datas"); switch ( _choiceHorizontal.getSelectedIndex() ) { case 0: { theParameters.setHorizontalScrollbarPolicy(ScrollbarPolicy.ALWAYS); break; } case 1: { theParameters.setHorizontalScrollbarPolicy(ScrollbarPolicy.NEVER); break; } case 2: { theParameters.setHorizontalScrollbarPolicy(ScrollbarPolicy.AS_NEEDED); break; } default: { break; } } switch ( _choiceVertical.getSelectedIndex() ) { case 0: { theParameters.setVerticalScrollbarPolicy(ScrollbarPolicy.ALWAYS); break; } case 1: { theParameters.setVerticalScrollbarPolicy(ScrollbarPolicy.NEVER); break; } case 2: { theParameters.setVerticalScrollbarPolicy(ScrollbarPolicy.AS_NEEDED); break; } default: { break; } } } setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private boolean _modifyFlag; private boolean _dataFlag; private Choice _choiceHorizontal; private Choice _choiceVertical; private Button _buttonStart; private Button _buttonModify; private Component _component; }