|
http://www.eteks.com | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.eteks.awt.PJAGraphicsManager
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.
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 |
protected PJAGraphicsManager()
PJAGraphicsManager
and loads fonts.
Method Detail |
public static PJAGraphicsManager getDefaultGraphicsManager()
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.
public boolean isClassAccessible(java.lang.String className)
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.
className
- the fully qualified class name.
true
if java.awt.Toolkit
class could be loaded.public boolean isFontInstantiable()
true
if it successes to load instantiate a java.awt.Font
.
true
if java.awt.Font
could be intantiated.public java.awt.peer.FontPeer getFontPeer(java.lang.String name, int style)
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.FontPeer
is returned.
name
- The font name.style
- The font style (Font.PLAIN
, Font.ITALIC
,
Font.BOLD
or Font.BOLD | Font.ITALIC
)
FontPeer
object. If the font name
isn't available the FontPeer
of the default font name
is returned.
java.awt.AWTError
- If no font is available.loadFonts()
public int getScreenWidth()
public int getScreenHeight()
public int getScreenResolution()
public java.awt.image.ColorModel getColorModel()
public int getClosestColorIndex(java.awt.image.IndexColorModel colorModel, int ARGB)
ARGB
in the indexed color model colorModel
.
colorModel
- an indexed color model.ARGB
- a color coded in the default color model.
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.public java.lang.String getFontsPath()
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.
public java.lang.String getFontsDirectory()
java.awt.fonts
system property, or the user.dir
directory
if that property is not set.
public void loadFonts()
getFontsPath()
. It's the main method called to load fonts in the graphics manager.
getFontsPath()
,
loadFont(java.io.InputStream)
public void loadFonts(java.lang.String dir)
dir
directory. May be
called more than once.
dir
- Directory where the font files are seeked.public void loadFont(java.io.InputStream fontStream) throws java.io.IOException
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.
fontStream
- A stream from which PJA fonts can be extracted.
java.io.IOException
public java.lang.String[] getFontList()
{"Dialog", "SansSerif", "Serif", "Monospaced", "DialogInput"}
is returned and the list of True Type fonts is obtained from
GraphicsEnvironment getAvailableFontFamilyNames() method.
public java.awt.FontMetrics getFontMetrics(java.awt.Font font)
public java.lang.String getDefaultFont()
public void sync()
public java.awt.Image getImage(java.lang.String filename)
filename
.
PJAToolkit.getImage(String)
public java.awt.Image getImage(java.net.URL url)
url
.
PJAToolkit.getImage(URL)
public java.awt.Image createImage(java.lang.String filename)
filename
.
PJAToolkit.createImage(String)
public java.awt.Image createImage(java.net.URL url)
url
.
PJAToolkit.createImage(URL)
public boolean prepareImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
PJAToolkit.prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
public int checkImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
PJAToolkit.checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
public java.awt.Image createImage(byte[] imagedata, int imageoffset, int imagelength)
imagedata
array.
PJAToolkit.createImage(byte[],int,int)
public java.awt.Image createImage(java.awt.image.ImageProducer producer)
producer
. This is the method that
finally creates an instance of PJAImage
.
java.awt.Image
(an instance of
either com.eteks.awt.PJAImage
or com.eteks.awt.PJABufferedImage
).PJAToolkit.createImage(ImageProducer)
public java.awt.Image createImage(int width, int height)
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).createImage (int, int)
of the class
PJAComponentPeer
(and thus of the class java.awt.Component
).
width
- Width in pixels of the new image.height
- Height in pixels of the new image.
java.awt.Image
(an instance of
either com.eteks.awt.PJAImage
or com.eteks.awt.PJABufferedImage
).PJAGraphicsEnvironment
public java.awt.GraphicsConfiguration getGraphicsConfiguration()
GraphicsConfiguration
instance required by the the method
getGraphicsConfiguration ()
of ComponentPeer
interface.
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |