http://www.eteks.com

com.eteks.awt
Class PJAGraphicsManager

java.lang.Object
  extended bycom.eteks.awt.PJAGraphicsManager
Direct Known Subclasses:
PJAGraphicsManager2D

public abstract class PJAGraphicsManager
extends java.lang.Object

Pure Java AWT Manager. This manager implements most of the methods required in an AWT Toolkit and manages .pjaf fonts loading.
From version 1.1, com.eteks.tools.fontcapture.PJAFontCapture is used to capture the fonts. PJA 1.0 .pjaf font files are not compatible with PJA 1.1, please use font capture utility to produce PJA 1.1 font files. This class is abstract ; an instance can be obtained calling the method getDefaultGraphicsManager (). You may change the default behavior of PJAGraphicsManager by creating a new class extending this one, and setting the com.eteks.awt.graphicsmanager system property with the new class name.
The main purpose of the existence of this class is to give access to other classes to Toolkit services, without having an instance of java.awt.Toolkit class at disposal. Actually, com.eteks.awt.PJAToolkit extends java.awt.Toolkit. When com.eteks.awt.PJAToolkit is instantiated, both classes are loaded by class loader and their static initializers are executed : at this moment java.awt.Toolkit needs awt system library to call initIDs native method. If the privilege to laod awt library is denied, the classes java.awt.Toolkit and also com.eteks.awt.PJAToolkit won't be loaded and it will be impossible to instantiate them.
As the class com.eteks.awt.PJAGraphics needs font resources for drawString () method, it will able to use them thanks to an instance of PJAGraphicsManager and without any Toolkit instance, thus enabling to draw in a com.eteks.awt.PJAImage instance even in case security control is very restrictive.
Anyway, a lot of AWT classes (in particular, java.awt.Color, java.awt.Rectangle, java.awt.Font, java.awt.FontMetrics, java.awt.image.ColorModel) need also the class java.awt.Toolkit or with JDK 1.2 have an initIDs native method that needs the library awt. This could prevent from using some methods of the class java.awt.Graphics. PJAGraphics implements com.eteks.awt.PJAGraphicsExtension methods that you can use to perform graphics operation if java.awt.Toolkit or awt library can't be accessed.

Since:
PJA1.1
Version:
2.5
Author:
Emmanuel Puybaret
See Also:
PJAToolkit, PJAGraphics, PJAFontPeer, isClassAccessible(java.lang.String)

Constructor Summary
protected PJAGraphicsManager()
          Creates a default instance of PJAGraphicsManager and loads fonts.
 
Method Summary
 int checkImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
          Checks the status of an image laoding.
 java.awt.Image createImage(byte[] imagedata, int imageoffset, int imagelength)
          Creates an image from the imagedata array.
 java.awt.Image createImage(java.awt.image.ImageProducer producer)
          Creates an image from the producer.
 java.awt.Image createImage(int width, int height)
          Creates an image of width x height pixels.
 java.awt.Image createImage(java.lang.String filename)
          Returns an image from the file filename.
 java.awt.Image createImage(java.net.URL url)
          Returns an image from the URL url.
 int getClosestColorIndex(java.awt.image.IndexColorModel colorModel, int ARGB)
          Returns the index of the closest color of ARGB in the indexed color model colorModel.
 java.awt.image.ColorModel getColorModel()
          Returns the default color model used by images for this manager (RGB default color model).
 java.lang.String getDefaultFont()
          Returns the default font name.
static PJAGraphicsManager getDefaultGraphicsManager()
          Returns a default PJAGraphicsManager.
 java.lang.String[] getFontList()
          Returns an array of all the font names.
 java.awt.FontMetrics getFontMetrics(java.awt.Font font)
          Returns the font metrics of a font.
 java.awt.peer.FontPeer getFontPeer(java.lang.String name, int style)
          Returns a FontPeer instance matching to font name with style.
 java.lang.String getFontsDirectory()
          Returns a font directory.
 java.lang.String getFontsPath()
          Returns the current font path.
 java.awt.GraphicsConfiguration getGraphicsConfiguration()
          Returns a GraphicsConfiguration instance required by the the method getGraphicsConfiguration () of ComponentPeer interface.
 java.awt.Image getImage(java.lang.String filename)
          Returns an image from the file filename.
 java.awt.Image getImage(java.net.URL url)
          Returns an image from the URL url.
 int getScreenHeight()
          Returns a default screen height for this manager (768 pixels).
 int getScreenResolution()
          Returns a default screen resolution for this manager (75 dpi which is the resolution of a 15' screen displaying 1024 x 768 pixels).
 int getScreenWidth()
          Returns a default screen width for this manager (1024pixels).
 boolean isClassAccessible(java.lang.String className)
          Returns true if it successes to load the class className.
 boolean isFontInstantiable()
          Returns true if it successes to load instantiate a java.awt.Font.
 void loadFont(java.io.InputStream fontStream)
          Loads the PJA 1.1 fonts from the stream fontStream and add them to graphics manager for PJAGraphics disposal.
 void loadFonts()
          Loads all font files (with extension .pjaf) contained in the path returned by getFontsPath().
 void loadFonts(java.lang.String dir)
          Loads all font files (with extension .pjaf) in the dir directory.
 boolean prepareImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
          Starts the loading of an image.
 void sync()
          Does nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PJAGraphicsManager

protected PJAGraphicsManager()
Creates a default instance of PJAGraphicsManager and loads fonts.

Method Detail

getDefaultGraphicsManager

public static PJAGraphicsManager getDefaultGraphicsManager()
Returns a default PJAGraphicsManager. This method is programmed in the same style as java.awt.Toolkit : it tries to instantiate either the class set in the com.eteks.awt.graphicsmanager system property or the class com.eteks.awt.PJAGraphicsManager if the property is not set. This allows PJA users to change the way fonts and other stuff used by this class are managed.


isClassAccessible

public boolean isClassAccessible(java.lang.String className)
Returns true if it successes to load the class className. If security manager is too restictive, it is possible that the classes java.awt.Color, java.awt.Rectangle, java.awt.Font, java.awt.FontMetrics and java.awt.image.ColorModel (and also java.awt.Dimension and other classes not required by PJA classes) can't be loaded because they need either the class java.awt.Toolkit or the library awt to be accessible to call their initIDs () native method.

Parameters:
className - the fully qualified class name.
Returns:
true if java.awt.Toolkit class could be loaded.

isFontInstantiable

public boolean isFontInstantiable()
Returns true if it successes to load instantiate a java.awt.Font.

Returns:
true if java.awt.Font could be intantiated.

getFontPeer

public java.awt.peer.FontPeer getFontPeer(java.lang.String name,
                                          int style)
Returns a FontPeer instance matching to font name with style. If font directory changed, any font available in the new directory will be loaded first. This enables to share a JVM with different users and different font directories.
If Java2D is used, a dummy FontPeer is returned.

Parameters:
name - The font name.
style - The font style (Font.PLAIN, Font.ITALIC, Font.BOLD or Font.BOLD | Font.ITALIC)
Returns:
Always return a FontPeer object. If the font name isn't available the FontPeer of the default font name is returned.
Throws:
java.awt.AWTError - If no font is available.
See Also:
loadFonts()

getScreenWidth

public int getScreenWidth()
Returns a default screen width for this manager (1024pixels).


getScreenHeight

public int getScreenHeight()
Returns a default screen height for this manager (768 pixels).


getScreenResolution

public int getScreenResolution()
Returns a default screen resolution for this manager (75 dpi which is the resolution of a 15' screen displaying 1024 x 768 pixels).


getColorModel

public java.awt.image.ColorModel getColorModel()
Returns the default color model used by images for this manager (RGB default color model).


getClosestColorIndex

public int getClosestColorIndex(java.awt.image.IndexColorModel colorModel,
                                int ARGB)
Returns the index of the closest color of ARGB in the indexed color model colorModel.

Parameters:
colorModel - an indexed color model.
ARGB - a color coded in the default color model.
Returns:
if alpha chanel == 0, returns the index returned by getTransparentPixel () on colorModel. If this index is -1, 0 is returned. The returned color index is the index of the color with the smallest distance between the given ARGB color and the colors of the color model.
Since:
PJA2.3

getFontsPath

public java.lang.String getFontsPath()
Returns the current font path. It is the path recorded in the java.awt.fonts system property if it exists followed by the user.dir directory. The returned path may be a set of directories separated by File.pathSeparator characters.


getFontsDirectory

public java.lang.String getFontsDirectory()
Returns a font directory. It is either the first directory of the path recorded in the java.awt.fonts system property, or the user.dir directory if that property is not set.


loadFonts

public void loadFonts()
Loads all font files (with extension .pjaf) contained in the path returned by getFontsPath(). It's the main method called to load fonts in the graphics manager.
Override it if you want to get files from somewhere else than the file system.

See Also:
getFontsPath(), loadFont(java.io.InputStream)

loadFonts

public void loadFonts(java.lang.String dir)
Loads all font files (with extension .pjaf) in the dir directory. May be called more than once.

Parameters:
dir - Directory where the font files are seeked.

loadFont

public void loadFont(java.io.InputStream fontStream)
              throws java.io.IOException
Loads the PJA 1.1 fonts from the stream fontStream and add them to graphics manager for PJAGraphics disposal. If the stream doesn't start with PJAFontData.PJAF1_1_FILE_HEADER header, this method simply returns without throwing an exception.

Parameters:
fontStream - A stream from which PJA fonts can be extracted.
Throws:
java.io.IOException

getFontList

public java.lang.String[] getFontList()
Returns an array of all the font names. If Java2D is used, the array {"Dialog", "SansSerif", "Serif", "Monospaced", "DialogInput"} is returned and the list of True Type fonts is obtained from GraphicsEnvironment getAvailableFontFamilyNames() method.


getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font font)
Returns the font metrics of a font.


getDefaultFont

public java.lang.String getDefaultFont()
Returns the default font name. You may override this method to have a different font.


sync

public void sync()
Does nothing. Should sync image loading.


getImage

public java.awt.Image getImage(java.lang.String filename)
Returns an image from the file filename.

See Also:
PJAToolkit.getImage(String)

getImage

public java.awt.Image getImage(java.net.URL url)
Returns an image from the URL url.

See Also:
PJAToolkit.getImage(URL)

createImage

public java.awt.Image createImage(java.lang.String filename)
Returns an image from the file filename.

See Also:
PJAToolkit.createImage(String)

createImage

public java.awt.Image createImage(java.net.URL url)
Returns an image from the URL url.

See Also:
PJAToolkit.createImage(URL)

prepareImage

public boolean prepareImage(java.awt.Image image,
                            int width,
                            int height,
                            java.awt.image.ImageObserver observer)
Starts the loading of an image.

See Also:
PJAToolkit.prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)

checkImage

public int checkImage(java.awt.Image image,
                      int width,
                      int height,
                      java.awt.image.ImageObserver observer)
Checks the status of an image laoding.

See Also:
PJAToolkit.checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)

createImage

public java.awt.Image createImage(byte[] imagedata,
                                  int imageoffset,
                                  int imagelength)
Creates an image from the imagedata array.

See Also:
PJAToolkit.createImage(byte[],int,int)

createImage

public java.awt.Image createImage(java.awt.image.ImageProducer producer)
Creates an image from the producer. This is the method that finally creates an instance of PJAImage.

Returns:
An instance of the class java.awt.Image (an instance of either com.eteks.awt.PJAImage or com.eteks.awt.PJABufferedImage).
See Also:
PJAToolkit.createImage(ImageProducer)

createImage

public java.awt.Image createImage(int width,
                                  int height)
Creates an image of width x height pixels. This method returns an instance of com.eteks.awt.PJAImage if Java2D can't work (JDK < 1.2 or because GraphicsEnvironment.getLocalGraphicsEnvironment () failed). This ensures to always get an Image but may require you to verify if Image getGraphics () method returns an instance of Graphics or code>Graphics2D (com.eteks.awt.PJAImage don't have Java2D and Graphics2D capabilities).
This method is called by createImage (int, int) of the class PJAComponentPeer (and thus of the class java.awt.Component).

Parameters:
width - Width in pixels of the new image.
height - Height in pixels of the new image.
Returns:
An instance of the class java.awt.Image (an instance of either com.eteks.awt.PJAImage or com.eteks.awt.PJABufferedImage).
See Also:
PJAGraphicsEnvironment

getGraphicsConfiguration

public java.awt.GraphicsConfiguration getGraphicsConfiguration()
Returns a GraphicsConfiguration instance required by the the method getGraphicsConfiguration () of ComponentPeer interface.

Since:
PJA2.0

© 1997-2003 eTeks - All rights reserved