|
Apple Java Extensions | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Canvas com.apple.eawt.CocoaComponent
public abstract class CocoaComponent
Allows custom widgets based on Cocoa's NSView class to be hosted in the AWT component hierarchy. Using this class, in conjunction with JNI libraries, you can embed Cocoa components inside of native Java applications. Use CocoaComponent to pass AWT events and messages through to the embedded Cocoa component.
When using CocoaComponent, it is important to understand that there are two threading models involved. Whenever a graphical Java application is run, it is hosted inside of a Cocoa NSApplication. Normally any interactions between the native environment and the Java environment are handled for you and you need not be concerned with their threading or event models. When implementing this class though, you must take a few precautions to ensure harmony between the two environments:
The embedded Cocoa component, included all of its methods, is fully available from Java. It can can be told to draw onto the canvas, receive events, change its bounds, or perform any other behavior provided by the native API. It does not understand Java-specific things not defined in its own API. For example, you are not able to set the font, background color, mouse cursor, or related characteristics of the NSView from Java, since AWT does not know how to pass these messages to the underlying NSView.
If the underlying NSView consumes NSEvents it may not be possible for AWT to generate AWT events for the CocoaComponent.
WARNING: Given the nature of the interrelationship between the AppKit and AWT, it is important to adhere to the guidelines presented here. Failure to do so may result in your Java application deadlocking or crashing, possibly also resulting in data loss.
NOTE: In Mac OS X v10.4, the threading model of the AWT native implementation has been revised.
To provide compatibility between the improved threading model and older implementations of
CocoaComponent, a special mode has been introduced. This compatibility mode activates
the first time a CocoaComponent is used in an application and defaults to true. A developer can turn
this mode off by setting a System Property:
com.apple.eawt.CocoaComponent.CompatibilityMode=falseWhile the compatibility mode is active, the AWT will not deadlock longer than 0.5 seconds. However, this also means that any AWT peer request that takes longer 0.5 seconds will return asynchronously (with possibly incorrect results for a "get"). The intent is for older applications to work better on Mac OS X v10.4. However, it's strongly suggested that newer applications fix their threading model and disable this compatibility mode. By default, applets always have the compatibility mode enabled, though not active. The first applet to use CocoaComponent will activate the compatibility mode. Once all applets have been closed, the compatibility mode is disabled. At this time there is no supported way to exclude specific applets from the compatibility mode.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Canvas |
---|
java.awt.Canvas.AccessibleAWTCanvas |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary |
---|
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
CocoaComponent()
|
Method Summary | |
---|---|
abstract int |
createNSView()
Deprecated. As of Mac OS X 10.4 (Tiger), programs should pass native pointers to java as a long; replaced by long createNSViewLong() . |
long |
createNSViewLong()
This is the same as createNSView. |
abstract java.awt.Dimension |
getMaximumSize()
Used by AWT layout managers to get the maximum allowable size for the embedded component. |
abstract java.awt.Dimension |
getMinimumSize()
Used by AWT layout managers to get the minimum allowable size for the embedded component. |
abstract java.awt.Dimension |
getPreferredSize()
Used by AWT layout managers to get the preferred size for the embedded component. |
void |
paint(java.awt.Graphics g)
|
void |
sendMessage(int messageID,
java.lang.Object message)
Sends a message to the embedded NSView. |
void |
update(java.awt.Graphics g)
|
Methods inherited from class java.awt.Canvas |
---|
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CocoaComponent()
Method Detail |
---|
public abstract int createNSView()
long createNSViewLong()
.
createCanvas
returns the NSView to AppKit's main thread.
It is then added to the main superview of the containing NSApplication. The embedded NSView will not be usable until
it receives the viewDidMoveToSuperview
message.
public void update(java.awt.Graphics g)
update
in class java.awt.Canvas
public void paint(java.awt.Graphics g)
paint
in class java.awt.Canvas
public long createNSViewLong()
public final void sendMessage(int messageID, java.lang.Object message)
createNSView
. That NSView must have a selector of type
-(void)awtMessage:(jint)messageID message:(jobject)message env:(JNIEnv *)env
(or implement
the AWTCocoaComponent
protocol found in JavaVM/AWTCocoaComponent.h
) to receive the
message. The method is sent asynchronously, so the method does not wait for the message to return.
Note that this method is provided as a convenience API.
public abstract java.awt.Dimension getMaximumSize()
new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)
.
getMaximumSize
in class java.awt.Component
public abstract java.awt.Dimension getMinimumSize()
new Dimension(0,0)
, Cocoa may not actually add the
component to its superview as expected. If you do not have a default minimum size and would normally return a Dimension
with 0
as both the height and the width, instead return new Dimension(2,2)
.
getMinimumSize
in class java.awt.Component
public abstract java.awt.Dimension getPreferredSize()
getMinimumSize
.
Do not just return Dimension(0,0)
, because Cocoa may not add the component to its superview as expected.
getPreferredSize
in class java.awt.Component
|
Apple Java Extensions | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |