|
http://www.eteks.com | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Toolkit com.eteks.awt.PJAToolkit
Pure Java AWT Toolkit implementation. This toolkit enables to draw in offscreen images
with all the Graphics
methods, even if no X11 or other device display is available.
Its main purpose is for servlets returning graphics and runing on servers with no display.
Java programs using AWT and compliant with any Java version,
will work directly on this toolkit with the following modification.
To enable automatic switch to this toolkit,
the system property awt.toolkit
must be changed to this class name
com.eteks.awt.PJAToolkit
, using either ways :
-Dawt.toolkit=com.eteks.awt.PJAToolkit
in your java command line.
awt.toolkit
system property :
This can be done more easily in Java 1.2 :Properties prop = System.getProperties (); prop.put ("awt.toolkit", "com.eteks.awt.PJAToolkit"); System.setProperties (prop);
System.setProperty ("awt.toolkit", "com.eteks.awt.PJAToolkit");
If JDK version if greater or equal to 1.2 and no Display is available the two next properties
must be also set, using one of the previous ways (see also PJAGraphicsEnvironment
) :
java.awt.graphicsenv
system property have to be set
to com.eteks.java2d.PJAGraphicsEnvironment
to allow the change
of java.awt.GraphicsEnvironment
default implementation.java.awt.fonts
system property must be set to the
path where True Type fonts files will be loaded from.Images can't be created using one of the three ways :
java.awt.Frame
instance to be able to call createImage ()
:
Frame frame = new Frame (); frame.addNotify (); Image image = frame.createImage (width, height);
come.eteks.awt.PJAImage
instance, created with :
This second way is usefull whenImage image = new com.eteks.awt.PJAImage (width, height);
Toolkit.getDefaultToolkit ()
fails because
the Java security manager forbids access to Java AWT Toolkit or because
it can't load the class set in awt.toolkit
system property
(pja.jar must be in bootclasspath).java.awt.image.BufferedImage
instance (supported only
with JDK version >= 1.2), created for example with :
Image image = new java.awt.image.BufferedImage (width, height, java.awt.image.PJABufferedImage.TYPE_INT_ARGB);
public Image createImage (int width, int height) throws Exception { try { // Dummy frame to create an image Frame frame = new Frame (); // addNotify () is required to create an image (this will call Toolkit.getDefaultToolkit ()) frame.addNotify (); return frame.createImage (width, height); } catch (AWTError e) { // Exception thrown because Toolkit class set in "awt.toolkit" couldn't be loaded or instantiate return createPJAImage (width, height, "Image can't be created : no AWT Toolkit available"); } catch (IllegalArgumentException e) { // Exception thrown because Class.forName () method in getDefaultToolkit () was called with "" return createPJAImage (width, height, "Image can't be created : no AWT Toolkit available"); } catch (SecurityException e) { // Exception thrown because getDefaultToolkit () didn't grant you access to AWT Toolkit return createPJAImage (width, height, "Image can't be created : access to AWT Toolkit refused"); } } public Image createPJAImage (int width, int height, String message) throws Exception { try { // Create an image with PJAToolkit directly (this one will be transparent) return new com.eteks.awt.PJAImage (width, height); } catch (LinkageError er) { // If you don't want to use this servlet with PJA library you'll get this error throw new Exception (this, message); } }
You can retrieve a Graphics
class instance calling getGraphics ()
on the image
instance, and use it to draw whatever you want.
When Toolkit.getDefaultToolkit ()
fails, java.awt.Font
can't be instantiated
because this class requires an instance of java.awt.Toolkit
in Java 1.1...
You can although use Graphics
methods to draw in the image, except
the methods setFont (Font font)
, getFontMetrics (Font font)
which needs a java.awt.Font
instance (getFont ()
will return null
).
Drawing text will be done with the default font name returned by PJAGraphicsManager.getDefaultFont()
,
plain, size 10 if available in that style and size.
With JDK 1.1 or if Java2D can't work, fonts are loaded from files with the ".pjaf" (Pure Java AWT Font) extension, either in the current directory, or in the directory kept in the System property "java.awt.fonts". For example, if you want to set this directory to be your servlet directory, you may use :
prop.put ("java.awt.fonts", getServletContext ().getRealPath ("/servlet"));
These optional fonts must be captured on a computer on which JDK AWT can work
(a PC, Mac or UNIX/X11 machine with an available DISPLAY), with the PJA Font capture utility
(main ()
method of the com.eteks.awt.PJAFontPeer
class).
If no fonts are available, all Graphics
drawing methods
that don't use Font
will work. Depending on the available fonts, default font
name is set to the following one, in that priority order :
PJAToolkit allows to get a Graphics
instance for an image initialized with a producer,
contrary to Java default Toolkit behavior which throws an IllegalAccessError
exception in that case.
This allows to create transparent images from scratch and sending transparent GIF from servlets.
To create an intially transparent image execute
Toolkit.getDefaultToolkit ().createImage (new java.awt.image.MemoryImageSource (width, height, new int [width * height], 0, width));
See the source of the main ()
method of the class ToolkitDemo
to have a test example
of all the Java 1.1 Graphics
methods. You may also try
com.eteks.servlet.TeksSurveyPie
servlet class.
From PJA version 1.1, the .pjaf font files loading methods and some other methods
were moved to the class PJAGraphicsManager
, to be able to use PJA even if no
Toolkit instance is available.
PJAToolkit and depending files are Java 1.0 compliant but needs Java 1.2 library or higher to compile (for Java 1.1 compilers, this can be done using any Java 2 rt.jar library instead of classes.zip in classpath at compile time).
ToolkitDemo
,
PJAFontPeer
,
PJAGraphics
,
PJAGraphicsManager
,
PJAServlet
Field Summary |
Fields inherited from class java.awt.Toolkit |
desktopProperties, desktopPropsSupport |
Constructor Summary | |
PJAToolkit()
|
Method Summary | |
void |
beep()
java.awt.Toolkit implementation.
|
int |
checkImage(java.awt.Image image,
int width,
int height,
java.awt.image.ImageObserver observer)
java.awt.Toolkit implementation. |
java.awt.peer.ButtonPeer |
createButton(java.awt.Button target)
java.awt.Toolkit implementation. |
java.awt.peer.CanvasPeer |
createCanvas(java.awt.Canvas target)
java.awt.Toolkit implementation. |
java.awt.peer.CheckboxPeer |
createCheckbox(java.awt.Checkbox target)
java.awt.Toolkit implementation. |
java.awt.peer.CheckboxMenuItemPeer |
createCheckboxMenuItem(java.awt.CheckboxMenuItem target)
java.awt.Toolkit implementation. |
java.awt.peer.ChoicePeer |
createChoice(java.awt.Choice target)
java.awt.Toolkit implementation. |
java.awt.peer.LightweightPeer |
createComponent(java.awt.Component target)
java.awt.Toolkit implementation. |
java.awt.peer.DialogPeer |
createDialog(java.awt.Dialog target)
java.awt.Toolkit implementation. |
java.awt.dnd.peer.DragSourceContextPeer |
createDragSourceContextPeer(java.awt.dnd.DragGestureEvent dge)
java.awt.Toolkit implementation.
|
java.awt.peer.FileDialogPeer |
createFileDialog(java.awt.FileDialog target)
java.awt.Toolkit implementation. |
java.awt.peer.FramePeer |
createFrame(java.awt.Frame target)
java.awt.Toolkit implementation. |
java.awt.Image |
createImage(byte[] imagedata,
int imageoffset,
int imagelength)
java.awt.Toolkit implementation. |
java.awt.Image |
createImage(java.awt.image.ImageProducer producer)
java.awt.Toolkit implementation. |
java.awt.Image |
createImage(java.lang.String filename)
java.awt.Toolkit implementation. |
java.awt.Image |
createImage(java.net.URL url)
java.awt.Toolkit implementation. |
java.awt.peer.LabelPeer |
createLabel(java.awt.Label target)
java.awt.Toolkit implementation. |
java.awt.peer.ListPeer |
createList(java.awt.List target)
java.awt.Toolkit implementation. |
java.awt.peer.MenuPeer |
createMenu(java.awt.Menu target)
java.awt.Toolkit implementation. |
java.awt.peer.MenuBarPeer |
createMenuBar(java.awt.MenuBar target)
java.awt.Toolkit implementation. |
java.awt.peer.MenuItemPeer |
createMenuItem(java.awt.MenuItem target)
java.awt.Toolkit implementation. |
java.awt.peer.PanelPeer |
createPanel(java.awt.Panel target)
java.awt.Toolkit implementation. |
java.awt.peer.PopupMenuPeer |
createPopupMenu(java.awt.PopupMenu target)
java.awt.Toolkit implementation. |
java.awt.peer.ScrollbarPeer |
createScrollbar(java.awt.Scrollbar target)
java.awt.Toolkit implementation. |
java.awt.peer.ScrollPanePeer |
createScrollPane(java.awt.ScrollPane target)
java.awt.Toolkit implementation. |
java.awt.peer.TextAreaPeer |
createTextArea(java.awt.TextArea target)
java.awt.Toolkit implementation. |
java.awt.peer.TextFieldPeer |
createTextField(java.awt.TextField target)
java.awt.Toolkit implementation. |
java.awt.peer.WindowPeer |
createWindow(java.awt.Window target)
java.awt.Toolkit implementation. |
java.awt.image.ColorModel |
getColorModel()
java.awt.Toolkit implementation. |
static java.lang.String |
getDefaultFont()
Deprecated. As of PJA version 1.1, replaced by PJAGraphicsManager.getDefaultFont (). |
java.lang.String[] |
getFontList()
java.awt.Toolkit implementation. |
java.awt.FontMetrics |
getFontMetrics(java.awt.Font font)
java.awt.Toolkit implementation. |
java.awt.peer.FontPeer |
getFontPeer(java.lang.String name,
int style)
Returns a FontPeer instance matching to font name
with style . |
static java.lang.String |
getFontsDirectory()
Deprecated. As of PJA version 1.1, replaced by PJAGraphicsManager.getFontsDirectory (). |
java.awt.Image |
getImage(java.lang.String filename)
java.awt.Toolkit implementation. |
java.awt.Image |
getImage(java.net.URL url)
java.awt.Toolkit implementation. |
java.awt.PrintJob |
getPrintJob(java.awt.Frame frame,
java.lang.String jobtitle,
java.util.Properties props)
java.awt.Toolkit implementation.
|
int |
getScreenResolution()
java.awt.Toolkit implementation. |
java.awt.Dimension |
getScreenSize()
java.awt.Toolkit implementation. |
java.awt.datatransfer.Clipboard |
getSystemClipboard()
java.awt.Toolkit implementation.
|
java.awt.EventQueue |
getSystemEventQueueImpl()
java.awt.Toolkit implementation.
|
static void |
loadFonts()
Deprecated. As of PJA version 1.1, replaced by PJAGraphicsManager.loadFonts (). |
static void |
loadFonts(java.lang.String dir)
Deprecated. As of PJA version 1.1, replaced by PJAGraphicsManager.loadFonts (String). |
void |
loadSystemColors(int[] systemColors)
java.awt.Toolkit implementation.
|
static void |
main(java.lang.String[] args)
Deprecated. As of PJA version 1.1, replaced by PJANativeToolkitComparison.main (args). |
java.util.Map |
mapInputMethodHighlight(java.awt.im.InputMethodHighlight highlight)
java.awt.Toolkit implementation.
|
boolean |
prepareImage(java.awt.Image image,
int width,
int height,
java.awt.image.ImageObserver observer)
java.awt.Toolkit implementation. |
void |
sync()
java.awt.Toolkit implementation.
|
Methods inherited from class java.awt.Toolkit |
addAWTEventListener, addPropertyChangeListener, createCustomCursor, createDragGestureRecognizer, createImage, getAWTEventListeners, getAWTEventListeners, getBestCursorSize, getDefaultToolkit, getDesktopProperty, getLockingKeyState, getMaximumCursorColors, getMenuShortcutKeyMask, getNativeContainer, getPrintJob, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getScreenInsets, getSystemEventQueue, getSystemSelection, initializeDesktopProperties, isDynamicLayoutActive, isDynamicLayoutSet, isFrameStateSupported, lazilyLoadDesktopProperty, removeAWTEventListener, removePropertyChangeListener, setDesktopProperty, setDynamicLayout, setLockingKeyState |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PJAToolkit()
Method Detail |
public java.awt.peer.ButtonPeer createButton(java.awt.Button target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.TextFieldPeer createTextField(java.awt.TextField target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.LabelPeer createLabel(java.awt.Label target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.ListPeer createList(java.awt.List target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.CheckboxPeer createCheckbox(java.awt.Checkbox target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.ScrollbarPeer createScrollbar(java.awt.Scrollbar target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.ScrollPanePeer createScrollPane(java.awt.ScrollPane target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.TextAreaPeer createTextArea(java.awt.TextArea target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.ChoicePeer createChoice(java.awt.Choice target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.FramePeer createFrame(java.awt.Frame target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.CanvasPeer createCanvas(java.awt.Canvas target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.PanelPeer createPanel(java.awt.Panel target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.WindowPeer createWindow(java.awt.Window target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.DialogPeer createDialog(java.awt.Dialog target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.MenuBarPeer createMenuBar(java.awt.MenuBar target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.MenuPeer createMenu(java.awt.Menu target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.PopupMenuPeer createPopupMenu(java.awt.PopupMenu target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.MenuItemPeer createMenuItem(java.awt.MenuItem target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.FileDialogPeer createFileDialog(java.awt.FileDialog target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.CheckboxMenuItemPeer createCheckboxMenuItem(java.awt.CheckboxMenuItem target)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.peer.LightweightPeer createComponent(java.awt.Component target)
java.awt.Toolkit
implementation.
Toolkit
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.
name
- The font name.style
- The font style (Font.PLAIN
, Font.ITALIC
,
Font.BOLD
or Font.BOLD | Font.ITALIC
)
null
if the font doesn't exist.loadFonts()
public void loadSystemColors(int[] systemColors)
java.awt.Toolkit
implementation.
Does nothing.
Toolkit
public java.awt.Dimension getScreenSize()
java.awt.Toolkit
implementation.
Toolkit
public int getScreenResolution()
java.awt.Toolkit
implementation.
Toolkit
public java.awt.image.ColorModel getColorModel()
java.awt.Toolkit
implementation.
Toolkit
public static java.lang.String getFontsDirectory()
public static void loadFonts()
getFontsDirectory ()
.
public static void loadFonts(java.lang.String dir)
dir
directory. May be
called more than once.
dir
- Directory where the font files are seeked.public java.lang.String[] getFontList()
java.awt.Toolkit
implementation.
Toolkit
public java.awt.FontMetrics getFontMetrics(java.awt.Font font)
java.awt.Toolkit
implementation.
Toolkit
public static java.lang.String getDefaultFont()
public void sync()
java.awt.Toolkit
implementation.
Does nothing.
Toolkit
public java.awt.Image getImage(java.lang.String filename)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.Image getImage(java.net.URL url)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.Image createImage(java.lang.String filename)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.Image createImage(java.net.URL url)
java.awt.Toolkit
implementation.
Toolkit
public boolean prepareImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
java.awt.Toolkit
implementation.
Toolkit
public int checkImage(java.awt.Image image, int width, int height, java.awt.image.ImageObserver observer)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.Image createImage(java.awt.image.ImageProducer producer)
java.awt.Toolkit
implementation.
Toolkit
public java.awt.Image createImage(byte[] imagedata, int imageoffset, int imagelength)
java.awt.Toolkit
implementation.
Toolkit
public void beep()
java.awt.Toolkit
implementation.
Does nothing.
Toolkit
public java.awt.PrintJob getPrintJob(java.awt.Frame frame, java.lang.String jobtitle, java.util.Properties props)
java.awt.Toolkit
implementation.
Returns null
.
Toolkit
public java.awt.datatransfer.Clipboard getSystemClipboard()
java.awt.Toolkit
implementation.
Returns null
.
Toolkit
public java.awt.EventQueue getSystemEventQueueImpl()
java.awt.Toolkit
implementation.
As of PJA version 2.2, returns a dummy EventQueue.
Toolkit
public java.awt.dnd.peer.DragSourceContextPeer createDragSourceContextPeer(java.awt.dnd.DragGestureEvent dge)
java.awt.Toolkit
implementation.
Returns null
.
Toolkit
public java.util.Map mapInputMethodHighlight(java.awt.im.InputMethodHighlight highlight)
java.awt.Toolkit
implementation.
Returns null
.
Toolkit
public static void main(java.lang.String[] args)
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |