ilog.views.util.swt
Class IlvSwingControl

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by ilog.views.util.swt.IlvSwingControl
All Implemented Interfaces:
Drawable

public class IlvSwingControl
extends Composite

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:

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.

Since:
JViews 8.1

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.Control
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
 
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

IlvSwingControl

public IlvSwingControl(Composite parent,
                       int style)
Creates an SWT control that can wrap a Swing 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.

Parameters:
parent - The parent SWT control to which this one shall be added.
style - The SWT flags for this control.

IlvSwingControl

public IlvSwingControl(Composite parent,
                       int style,
                       boolean usingNativeBridge)
Creates an SWT control that can wrap a Swing 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.

Parameters:
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.

IlvSwingControl

public IlvSwingControl(Composite parent,
                       int style,
                       JComponent swing)
Creates an SWT control that wraps a given Swing JComponent.

Parameters:
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

getSwingComponent

public JComponent getSwingComponent()
Returns the wrapped JComponent, or null if none has been set.


setSwingComponent

public void setSwingComponent(JComponent swing)
Sets the wrapped JComponent.

Parameters:
swing - A Swing component, or null for none.

computeSize

public Point computeSize(int widthHint,
                         int heightHint,
                         boolean changed)
Overridden to take into account the minimum, maximum, and preferred size of the embedded AWT component.

Overrides:
computeSize in class Composite

setBounds

public void setBounds(Rectangle rect)
Overridden to propagate the size change to the embedded AWT component.

Overrides:
setBounds in class Control

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Overridden to propagate the size change to the embedded AWT component.

Overrides:
setBounds in class Control

setBackground

public void setBackground(Color background)
Overridden to propagate the background color change to the embedded AWT component.

Overrides:
setBackground in class Control

getMenu

public static Menu getMenu(Component component,
                           boolean recursive)
Returns the registered menu for a given component.

Parameters:
component - An AWT/Swing component.
recursive - Whether to look for a recursive or for a non-recursive specification of a popup menu.
Returns:
A popup menu, or null.

setMenu

public static void setMenu(Component component,
                           boolean recursive,
                           Menu menu)
Registers a popup menu for a given component and, optionally, its subcomponents.

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.

Parameters:
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.

getMenu

public Menu getMenu(Component component,
                    int x,
                    int y,
                    int xAbsolute,
                    int yAbsolute)
Returns the popup menu to be used on a given component.

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.

Parameters:
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.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.