//***************************************************************************** // Copyright (c) 1998 INRIA. // http://www.inria.fr/croap/aioli/modules/figue/web/credits.html#COPYRIGHT //***************************************************************************** package figue.tutorial; import java.awt.Frame; import java.awt.Toolkit; import java.awt.BorderLayout; import java.awt.Button; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Frame; import java.awt.FlowLayout; import java.awt.Panel; import java.awt.Label; import java.awt.FlowLayout; import figue.*; import figue.box.*; import figue.resource.*; import figue.path.*; import figue.event.*; import figue.error.Error; public final class Tutorial_10 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_10.java,v $ $revision$ $Date: 1998/11/02 15:55:48 $ Copyright 1998 INRIA."; protected final void initTutorial() { _dummyFrame = null; internalInit(); Panel thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,5)); _button = new Button("Print"); thePanel.add(_button); add(BorderLayout.NORTH,thePanel); _button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent anEvent) { try { _button.setEnabled(false); print(); } catch ( SecurityException anError ) { printFailure(); } catch ( Error anError ) { printFailure(); } if ( _dummyFrame != null ) { _dummyFrame.setVisible(false); _dummyFrame.dispose(); } } }); _status = new Label("STATUS : inactive"); thePanel = new Panel(); thePanel.setLayout(new FlowLayout(FlowLayout.LEFT,10,5)); thePanel.add(_status); add(BorderLayout.SOUTH,thePanel); validate(); } private final void printFailure() { showAlertVersion("a Java print enabled browser",java.awt.Color.lightGray,getFont(),"SECURITY"); } private final void print() { _dummyFrame = new Frame(); _dummyFrame.addNotify(); _facade = new PSFacade(Toolkit.getDefaultToolkit().getPrintJob(_dummyFrame,"",null)); _facade.addPrintListener(new PrintListenerInterface() { public void printInitiate(PrintEvent anEvent) { showPrintStatus("start printing"); } public void printAdvance(PrintEvent anEvent) { showPrintStatus("printing page " + anEvent.getPageNumber() + " " + anEvent.getPercentDone() + "%"); } public void printDone(PrintEvent anEvent) { showPrintStatus("printing done"); } }); initResources(_facade); buildBox(_facade); _facade.print(); _facade.disposeWhenInactive(); if ( _dummyFrame != null ) { _dummyFrame.setVisible(false); _dummyFrame.dispose(); } } private final void showPrintStatus(String aMessage) { _status.setText("STATUS : " + aMessage); _status.invalidate(); validate(); } public final void destroy() { if ( _facade != null ) { _facade.disposeWhenInactive(); _facade = null; } setAlertBox(null); super.destroy(); } private final void buildBox(FacadeInterface aFacade) { final GlyphInterface theParagraph = new Paragraph(10,50,5); for ( int theRank = 0; theRank < 100; theRank++ ) { theParagraph.addChild(Atom.newAtom("It's")); theParagraph.addChild(Atom.newAtom('a')); theParagraph.addChild(Atom.newAtom("wonderful","style hot")); theParagraph.addChild(Atom.newAtom("life")); theParagraph.addChild(Atom.newAtom("!!","style hot")); } PathInterface thePath = new Path(); thePath.addOperation(new InsertGlyph(theParagraph,0)); aFacade.buildInit(thePath); aFacade.buildComplete(); } private final void initResources(FacadeInterface aFacade) { try { aFacade.doGetFont(Constants.DEFAULT_FONT,FontFamily.TIMES_ROMAN,FontStyle.PLAIN,15,false); aFacade.doGetColor(Constants.DEFAULT_COLOR,BasicColor.BLUE); aFacade.doGetColor(Constants.DEFAULT_BACKGROUND,BasicColor.WHITE); aFacade.doGetFont("big font",FontFamily.COURIER,FontStyle.BOLD,20,false); aFacade.doGetColor("yellow",BasicColor.YELLOW); aFacade.doGetColor("red",BasicColor.RED); aFacade.doGetStyle("style hot", aFacade.getFont("big font"), aFacade.getColor("red"), aFacade.getColor("yellow")); } catch ( WrongResourceException anException ) { ; } initStandardResources(aFacade); } private final FacadeInitializer getParameters() { FacadeInitializer theParameters = new FacadeInitializer(); setAppletParameters(theParameters); return theParameters; } private PSFacade _facade; private final void internalInit() { setLayout(new BorderLayout()); _internalFacade = new AWTFacade(getParameters()); add(BorderLayout.CENTER,_internalFacade.getAwtComponent()); setDefaultKeyListener(_internalFacade); initResources(_internalFacade); buildBox(_internalFacade); } private AWTFacade _internalFacade; private Button _button; private Frame _dummyFrame; private Label _status; }