public class IlvSwingControl
extends org.eclipse.swt.widgets.Composite
Portability: This class is supported on Windows, Unix, and MacOS X. This is in contrast to the Eclipse 3.1 SWT_AWT bridge, which on Unix has flickering problems 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.SWT.BORDER
is not supported, due to
Eclipse bug
91896.
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.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.
In particular, for portability to Linux/GTK platforms, it is recommended that
you call
IlvSwingUtil.
before instantiating the first Swing component, so as to avoid
Eclipse bug
126931.setDefaultAppropriateLookAndFeel
()
Constructor and Description |
---|
IlvSwingControl(org.eclipse.swt.widgets.Composite parent,
int style)
Creates an SWT control that can wrap a Swing
JComponent . |
IlvSwingControl(org.eclipse.swt.widgets.Composite parent,
int style,
boolean usingNativeBridge)
Creates an SWT control that can wrap a Swing
JComponent . |
IlvSwingControl(org.eclipse.swt.widgets.Composite parent,
int style,
JComponent swing)
Creates an SWT control that wraps a given Swing
JComponent . |
Modifier and Type | Method and Description |
---|---|
org.eclipse.swt.graphics.Point |
computeSize(int widthHint,
int heightHint,
boolean changed)
Overridden to take into account the minimum, maximum, and preferred size of
the embedded AWT component.
|
protected org.eclipse.swt.widgets.Composite |
getLayoutAncestor()
Returns the topmost ancestor control that needs to be notified and
relayouted if the preferred, minimum, or maximum sizes of the embedded AWT
component have changed.
|
static org.eclipse.swt.widgets.Menu |
getMenu(Component component,
boolean recursive)
Returns the registered menu for a given component.
|
org.eclipse.swt.widgets.Menu |
getMenu(Component component,
int x,
int y,
int xAbsolute,
int yAbsolute)
Returns the pop-up menu to be used on a given component.
|
JComponent |
getSwingComponent()
Returns the wrapped
JComponent , or null if none
has been set. |
void |
preferredSizeChanged(org.eclipse.swt.graphics.Point minSize,
org.eclipse.swt.graphics.Point prefSize,
org.eclipse.swt.graphics.Point maxSize)
This method gets called when the preferred, minimum, or maximum sizes of
the embedded AWT component have changed.
|
void |
setBackground(org.eclipse.swt.graphics.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(org.eclipse.swt.graphics.Rectangle rect)
Overridden to propagate the size change to the embedded AWT component.
|
static void |
setMenu(Component component,
boolean recursive,
org.eclipse.swt.widgets.Menu menu)
Registers a pop-up menu for a given component and, optionally, its
subcomponents.
|
void |
setSwingComponent(JComponent swing)
Sets the wrapped
JComponent . |
changed, checkSubclass, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setFocus, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setCapture, setCursor, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
public IlvSwingControl(org.eclipse.swt.widgets.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(org.eclipse.swt.widgets.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(org.eclipse.swt.widgets.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.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.protected org.eclipse.swt.widgets.Composite getLayoutAncestor()
null
if no such relayout
should happen (but then, this control may appear clipped).
You should usually implement this method. Often getParent()
or
getParent().getParent()
is the right choice. Sometimes you
have to follow the ancestor chain until you reach the first instance of
ScrolledComposite
.
preferredSizeChanged(Point, Point, Point)
public void preferredSizeChanged(org.eclipse.swt.graphics.Point minSize, org.eclipse.swt.graphics.Point prefSize, org.eclipse.swt.graphics.Point maxSize)
IlvSwingControl
object.
The default implementation is to request a layout of the control designated
by the method getLayoutAncestor()
.
public org.eclipse.swt.graphics.Point computeSize(int widthHint, int heightHint, boolean changed)
computeSize
in class org.eclipse.swt.widgets.Composite
public void setBounds(org.eclipse.swt.graphics.Rectangle rect)
setBounds
in class org.eclipse.swt.widgets.Control
public void setBounds(int x, int y, int width, int height)
setBounds
in class org.eclipse.swt.widgets.Control
public void setBackground(org.eclipse.swt.graphics.Color background)
setBackground
in class org.eclipse.swt.widgets.Control
public static org.eclipse.swt.widgets.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 pop-up menu.null
.public static void setMenu(Component component, boolean recursive, org.eclipse.swt.widgets.Menu menu)
Note: You can only specify one pop-up menu on a given component. You cannot specify a recursive and a non-recursive pop-up menu simultaneously on the same component.
component
- An AWT/Swing component.recursive
- Whether the menu also applies to subcomponents (unless another
pop-up menu is specified on the subcomponent or a component in
between in the hierarchy).menu
- A pop-up menu, or null
to clear the previously
specified pop-up menu.public org.eclipse.swt.widgets.Menu getMenu(Component component, int x, int y, int xAbsolute, int yAbsolute)
The default implementation walks up the component hierarchy, looking for
pop-up menus registered with setMenu(java.awt.Component, boolean, org.eclipse.swt.widgets.Menu)
and as fallback at the pop-up
menu registered on this Control
.
This method can be overridden, to achieve dynamic pop-up menus.
component
- The component on which a pop-up 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.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.