|
||||||||||
| PREV CLASS Documentation homepage. NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
ilog.views.util.swt.IlvSwingControl
public class IlvSwingControl
Embeds a Swing JComponent in an SWT Control with double-buffered drawing.
Portability: This class is supported on Windows, Unix, and MacOS X 10.4 or newer. JDK 1.5 or newer is required on MacOS X. This is in contrast to the Eclipse 3.1 SWT_AWT bridge, which on Unix does not work with JRE 1.4 and has flickering problems with JRE 1.5, and does not work at all on MacOS X.
Limitations:
paintImmediately() must not
be called.getLocationOnScreen() must not be
called; use
IlvSwingUtil.getLocationOnScreen(java.awt.Component)
instead. The SwingUtilities methods convertPoint,
convertRectangle and
convertPointToScreen must not be called; use
IlvSwingUtil.convertPoint(java.awt.Component, java.awt.Point, java.awt.Component),
IlvSwingUtil.convertRectangle(java.awt.Component, java.awt.Rectangle, java.awt.Component) and
IlvSwingUtil.convertPointToScreen(java.awt.Point, java.awt.Component)
instead.autoscrolls cannot be set to
true; it is forced to false automatically.IlvEventThreadUtil.enableAWTThreadRedirect()), code running in
the AWT/Swing event thread must not use Display.syncExec,
otherwise deadlocks can happen. Display.asyncExec is
still possible, of course.Note: Accesses to the SWT API of this control must be done in the SWT
thread. Use Display.syncExec() or
Display.asyncExec() if needed. On the other hand, accesses to
the Swing API of the embedded JComponents must be done in the AWT-EventQueue
thread. Use EventQueue.invokeAndWait() or
EventQueue.invokeLater if needed.
The following is a good reference to SWT_AWT Eclipse Corner article. It explains many problems and workarounds about SWT_AWT. Some of them also apply to this class.
| Field Summary |
|---|
| Fields inherited from class org.eclipse.swt.widgets.Control |
|---|
handle |
| Constructor Summary | |
|---|---|
IlvSwingControl(Composite parent,
int style)
Creates an SWT control that can wrap a Swing JComponent. |
|
IlvSwingControl(Composite parent,
int style,
boolean usingNativeBridge)
Creates an SWT control that can wrap a Swing JComponent. |
|
IlvSwingControl(Composite parent,
int style,
JComponent swing)
Creates an SWT control that wraps a given Swing JComponent. |
|
| Method Summary | |
|---|---|
Point |
computeSize(int widthHint,
int heightHint,
boolean changed)
Overridden to take into account the minimum, maximum, and preferred size of the embedded AWT component. |
static Menu |
getMenu(Component component,
boolean recursive)
Returns the registered menu for a given component. |
Menu |
getMenu(Component component,
int x,
int y,
int xAbsolute,
int yAbsolute)
Returns the popup menu to be used on a given component. |
JComponent |
getSwingComponent()
Returns the wrapped JComponent, or null if none
has been set. |
void |
setBackground(Color background)
Overridden to propagate the background color change to the embedded AWT component. |
void |
setBounds(int x,
int y,
int width,
int height)
Overridden to propagate the size change to the embedded AWT component. |
void |
setBounds(Rectangle rect)
Overridden to propagate the size change to the embedded AWT component. |
static void |
setMenu(Component component,
boolean recursive,
Menu menu)
Registers a popup menu for a given component and, optionally, its subcomponents. |
void |
setSwingComponent(JComponent swing)
Sets the wrapped JComponent. |
| Methods inherited from class org.eclipse.swt.widgets.Composite |
|---|
changed, checkSubclass, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setFocus, setLayout, setLayoutDeferred, setTabList |
| Methods inherited from class org.eclipse.swt.widgets.Scrollable |
|---|
computeTrim, getClientArea, getHorizontalBar, getVerticalBar |
| Methods inherited from class org.eclipse.swt.widgets.Widget |
|---|
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public IlvSwingControl(Composite parent,
int style)
JComponent.
The JComponent can then be added through
setSwingComponent(javax.swing.JComponent).
With this constructor, the decision whether to use the native SWT_AWT
bridge or a more portable bridge is done according to the platform. A
setting of the system property ilog.views.swt.useNativeBridge
can override this choice: A JVM argument
"-Dilog.views.swt.useNativeBridge=true" will force the use of the SWT_AWT
bridge. A JVM argument
"-Dilog.views.swt.useNativeBridge=false" will force the use of the more
portable bridge.
In the latter case, the bridge exists in a variant that uses native AWT
peers and one that doesn't. Again, the default choice depends on the
platform. A setting of the system property
ilog.views.swt.peerless to false or
true enforces one or the other choice.
parent - The parent SWT control to which this one shall be added.style - The SWT flags for this control.
public IlvSwingControl(Composite parent,
int style,
boolean usingNativeBridge)
JComponent.
The JComponent can then be added through
setSwingComponent(javax.swing.JComponent).
With this constructor, the decision whether to use the native SWT_AWT bridge or a more portable bridge is entirely under the programmer's control.
parent - The parent SWT control to which this one shall be added.style - The SWT flags for this control.usingNativeBridge - If true, the native SWT_AWT bridge
will be used. Otherwise a portable emulation
will be used.
public IlvSwingControl(Composite parent,
int style,
JComponent swing)
JComponent.
parent - The parent SWT control to which this one shall be added.style - The SWT flags for this control.swing - A Swing component, or null for none.| Method Detail |
|---|
public JComponent getSwingComponent()
JComponent, or null if none
has been set.
public void setSwingComponent(JComponent swing)
JComponent.
swing - A Swing component, or null for none.
public Point computeSize(int widthHint,
int heightHint,
boolean changed)
computeSize in class Compositepublic void setBounds(Rectangle rect)
setBounds in class Control
public void setBounds(int x,
int y,
int width,
int height)
setBounds in class Controlpublic void setBackground(Color background)
setBackground in class Control
public static Menu getMenu(Component component,
boolean recursive)
component - An AWT/Swing component.recursive - Whether to look for a recursive or for a non-recursive
specification of a popup menu.
null.
public static void setMenu(Component component,
boolean recursive,
Menu menu)
Note: You can only specify one popup menu on a given component. You cannot specify a recursive and a non-recursive popup menu simultaneously on the same component.
component - An AWT/Swing component.recursive - Whether the menu also applies to subcomponents (unless
another popup menu is specified on the subcomponent or
a component in between in the hierarchy).menu - A popup menu, or null to clear the previously
specified popup menu.
public Menu getMenu(Component component,
int x,
int y,
int xAbsolute,
int yAbsolute)
The default implementation walks up the component hierarchy, looking
for popup menus registered with setMenu(java.awt.Component, boolean, org.eclipse.swt.widgets.Menu) and as fallback at
the popup menu registered on this Control.
This method can be overridden, to achieve dynamic popup menus.
component - The component on which a popup event was received.x - The x coordinate, relative to the component's top left corner,
of the mouse cursor when the event occurred.y - The y coordinate, relative to the component's top left corner,
of the mouse cursor when the event occurred.xAbsolute - The x coordinate, relative to this control's top left
corner, of the mouse cursor when the event occurred.yAbsolute - The y coordinate, relative to this control's top left
corner, of the mouse cursor when the event occurred.
|
||||||||||
| PREV CLASS Documentation homepage. NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||