//***************************************************************************** // Copyright (c) 1998 INRIA. // http://www.inria.fr/croap/aioli/modules/figue/web/credits.html#COPYRIGHT //***************************************************************************** package figue.tutorial; import java.awt.GridLayout; import java.awt.event.KeyEvent; import figue.*; import figue.box.*; import figue.path.*; import figue.event.*; import figue.resource.*; public final class Tutorial_30 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_30.java,v $ $revision$ $Date: 1998/11/02 15:55:56 $ Copyright 1998 INRIA."; protected final void initTutorial() { setLayout(new GridLayout(1,1)); _facade = new AWTFacade(getParameters()); add(_facade.getAwtComponent()); _facade.addKeyListener (new KeyListenerInterface() { public final void keyTyped(KeyEvent anEvent) { } public final void keyPressed(KeyEvent anEvent) { switch ( anEvent.getKeyCode() ) { case KeyEvent.VK_A: case KeyEvent.VK_B: case KeyEvent.VK_C: case KeyEvent.VK_D: case KeyEvent.VK_E: case KeyEvent.VK_F: case KeyEvent.VK_G: case KeyEvent.VK_H: case KeyEvent.VK_I: case KeyEvent.VK_J: case KeyEvent.VK_K: case KeyEvent.VK_L: case KeyEvent.VK_M: case KeyEvent.VK_N: case KeyEvent.VK_O: case KeyEvent.VK_P: case KeyEvent.VK_Q: case KeyEvent.VK_R: case KeyEvent.VK_S: case KeyEvent.VK_T: case KeyEvent.VK_U: case KeyEvent.VK_V: case KeyEvent.VK_W: case KeyEvent.VK_X: case KeyEvent.VK_Y: { insertChar(anEvent.getKeyChar(),"letter"); break; } default: { } } } public final void keyReleased(KeyEvent anEvent) { } }); final class NumberListener extends DefaultKeyListener { public NumberListener(InteractiveFacade aFacade) { super(aFacade); } public final void keyPressed(KeyEvent anEvent) { switch ( anEvent.getKeyCode() ) { case KeyEvent.VK_0: case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: case KeyEvent.VK_4: case KeyEvent.VK_5: case KeyEvent.VK_6: case KeyEvent.VK_7: case KeyEvent.VK_8: case KeyEvent.VK_9: case KeyEvent.VK_NUMPAD0: case KeyEvent.VK_NUMPAD1: case KeyEvent.VK_NUMPAD2: case KeyEvent.VK_NUMPAD3: case KeyEvent.VK_NUMPAD4: case KeyEvent.VK_NUMPAD5: case KeyEvent.VK_NUMPAD6: case KeyEvent.VK_NUMPAD7: case KeyEvent.VK_NUMPAD8: case KeyEvent.VK_NUMPAD9: { insertChar(anEvent.getKeyChar(),"number"); break; } default: { super.keyPressed(anEvent); } } } } _facade.addKeyListener(new NumberListener(_facade)); _facade.addPointingListener(new PointingListenerInterface() { public final void mouseEntered(PointingEvent anEvent) { _facade.requestFocus(); } public final void mouseExited(PointingEvent anEvent) { } public final void mousePressed(PointingEvent anEvent) { } public final void mouseReleased(PointingEvent anEvent) { } public final void mouseClicked(PointingEvent anEvent) { } }); initResources(); buildBox(); } private final void insertChar(char aChar,String aStyle) { PathInterface thePath = new Path(); PathInterface thePath1 = new Path(); thePath.addChild(thePath1); PathInterface thePath2 = new Path(); thePath1.addChild(thePath2); thePath2.addOperation(new InsertGlyph(Atom.newAtom("<"+aChar+">",aStyle),_insertRank++)); _facade.updateAndRedisplay(thePath); } public final void destroy() { _facade.disposeWhenInactive(); _facade = null; _font = null; _yellow = null; _blue = null; _red = null; super.destroy(); } private final void initResources() { try { _font = _facade.doGetFont(null,FontFamily.HELVETICA,FontStyle.BOLD,24,false); _yellow = _facade.doGetColor("yellow",BasicColor.YELLOW); _blue = _facade.doGetColor(null,0,0,255); _red = _facade.doGetColor("red",BasicColor.RED); _facade.doGetStyle("letter",null,_facade.doGetColor("green",BasicColor.GREEN),null); _facade.doGetStyle("number",null,null,_yellow); } catch ( WrongResourceException anException ) { ; } initStandardResources(_facade); } private final void buildBox() { final GlyphInterface theContext = new ChangeGraphicalContextAnonymous(_font,_blue,null); final GlyphInterface theLine = new Paragraph(10,0,10); theContext.addChild(theLine); for( int i = 0; i < 5; i++ ) { pushWords(theLine); } PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theContext,0)); _facade.buildInit(thePath); _facade.buildComplete(); } private final void pushWords(GlyphInterface aGlyph) { aGlyph.addChild(Atom.newAtom("It's")); aGlyph.addChild(Atom.newAtom('a')); final GlyphInterface theContext = new ChangeGraphicalContextAnonymous(null,_red,_yellow); aGlyph.addChild(theContext); theContext.addChild(Atom.newAtom("wonderful")); aGlyph.addChild(Atom.newAtom("life")); aGlyph.addChild(Atom.newAtom("!!")); } private final FacadeInitializer getParameters() { FacadeInitializer theParameters = new FacadeInitializer(); theParameters.setFormattingWidth(475); setAppletParameters(theParameters); return theParameters; } private AWTFacade _facade; private FontInterface _font; private ColorInterface _yellow; private ColorInterface _blue; private ColorInterface _red; private int _insertRank = 20; }