com.jniwrapper.win32.automation
Class OleContainer

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended bycom.jniwrapper.win32.automation.OleContainer
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
OfficeContainer

public class OleContainer
extends java.awt.Canvas

This class enables to embed OLE/ActiveX controls into a java application. An OLE/ActiveX control can be created in the container by class name: createObject(String oleClassName) or from file: createObject(File fileName) method.

Note: If you need a java menu to be displayed over an embedded ActiveX control, just add the following piece of code: JPopupMenu.setDefaultLightWeightPopupEnabled(false)

Since version 2.2 an ability is added to insert an IOleObject instance into the container using the insertObject(IOleObject oleObject) method.

See Also:
Serialized Form

Nested Class Summary
static class OleContainer.AutoActivateMode
          Represents enumeration of auto activation modes.
static class OleContainer.SizeMode
          Represents enumeration of available size modes.
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes 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
OleContainer()
           
OleContainer(java.lang.Class clientSiteImpl)
           
OleContainer(java.lang.Class clientSiteImpl, OleMessageLoop messageLoop)
           
OleContainer(OleMessageLoop messageLoop)
           
 
Method Summary
protected  void activate()
           
 void createObject(CLSID clsid)
          Creates an object in the container by CLSID.
 void createObject(java.io.File file)
          Creates an object in the container by association specified by the file name.
 void createObject(java.lang.String oleClassName)
          Creates an object in the container by class name.
 void destroyObject()
          Destroys the previously created OleObject.
protected  void disableFocusGainedIgnoreTimeout()
           
 void doVerb(int verb)
          Does the verb for OleObject.
protected  void draw()
          Default method for drawing an embedded component which is in inactive state using oleDraw OLE function.
protected  void drawBitmap(Bitmap bitmap)
          Draws bitmap object on the canvas of this container.
protected  void enableFocusGainedIgnoreTimeout()
           
protected  boolean gainedFocus()
           
protected  Wnd getActivatedWindow()
           
 int getActivationVerb()
          Returns the activation verb of this container.
 OleContainer.AutoActivateMode getAutoActivateMode()
           
 java.awt.Rectangle getContainerBounds()
          Returns the container bounds.
 Wnd getContainerWindow()
          Returns window of this container.
 CLSID getCurrentDocumentType()
          Returns identifier of embedded OLE object.
 FileOperationsHandler getFileOperationsHandler()
           
 Wnd getObjectWindow()
          Returns window of an embedded object.
 IOleClientSite getOleClientSite()
          Returns an instance of OleClientSite.
 OleMessageLoop getOleMessageLoop()
           
 IOleObjectImpl getOleObject()
          Returns an OleObject.
 Size getOleObjectViewSize()
          Returns the size of the embedded OLE object.
protected  java.awt.Container getParentContainer()
           
 PrintHandler getPrintDocumentHandler()
           
protected static Wnd getRootWindow(Wnd wnd, boolean ignoreWindowStyles)
           
protected  OleContainerSibling getSibling()
           
 OleContainer.SizeMode getSizeMode()
          Returns active size mode.
protected  boolean gotSameRoots(Wnd wnd1, Wnd wnd2)
           
 void inPlaceDeactivate()
          Performs in-place deactivation of the inserted OleObject.
 void insertObject(IOleObject oleObject)
          Inserts an externally created OLE object.
protected  boolean isComponentDisplayed()
           
 boolean isHandleUpdateAsSave()
           
protected  boolean isIgnoreTimeout()
           
 boolean isPrintPreview()
           
 void load(byte[] data)
          Loads an OLE object from the specified byte array.
 void load(java.io.InputStream stream)
          Loads an OLE object from the specified stream.
 void load(IStorage storage)
          Loads an OLE object from OLE storage.
protected  void makeContainerWindowFocused()
           
 void open(java.io.File file)
          Creates an OLE object from file.
 void paint(java.awt.Graphics g)
           
 void removeNotify()
           
protected  void resizeWindow()
           
 byte[] save()
          Saves an OLE object as byte array.
 HResult save(java.io.File file)
          Saves an OLE object to file.
 void save(java.io.OutputStream stream)
          Saves an OLE object to the specified stream.
protected  void setActivatedWindow(Wnd activatedWindow)
           
 void setActivationVerb(int activationVerb)
          Sets the default activation verb for the container.
 void setAutoActivateMode(OleContainer.AutoActivateMode value)
          Determines how the object in an OLE container is activated.
protected  void setComponentDisplayed(boolean componentDisplayed)
           
 void setFileOperationsHandler(FileOperationsHandler fileOperationsHandler)
           
 void setHandleUpdateAsSave(boolean handleUpdateAsSave)
          Set handle or not ole object update event.
 void setPrintDocumentHandler(PrintHandler printDocumentHandler)
           
 void setSizeMode(OleContainer.SizeMode value)
          Determines how the OLE object is sized in the OLE container.
protected  boolean shouldActivateWhenVisible()
           
 Bitmap takeScreenshot()
          Takes a screenshot of an embedded component.
 void uiActivate()
          Activates the OLE objects' UI.
 void uiDeactivate()
          Deactivates the OLE object's UI.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
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, 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, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, 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, isOpaque, 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, 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, setName, 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

OleContainer

public OleContainer()

OleContainer

public OleContainer(OleMessageLoop messageLoop)

OleContainer

public OleContainer(java.lang.Class clientSiteImpl)

OleContainer

public OleContainer(java.lang.Class clientSiteImpl,
                    OleMessageLoop messageLoop)
Method Detail

getOleMessageLoop

public OleMessageLoop getOleMessageLoop()

setSizeMode

public void setSizeMode(OleContainer.SizeMode value)
Determines how the OLE object is sized in the OLE container.

Parameters:
value - new size mode.

getSizeMode

public OleContainer.SizeMode getSizeMode()
Returns active size mode.

Returns:
active size mode.

isIgnoreTimeout

protected boolean isIgnoreTimeout()

gainedFocus

protected boolean gainedFocus()

setAutoActivateMode

public void setAutoActivateMode(OleContainer.AutoActivateMode value)
Determines how the object in an OLE container is activated.

Parameters:
value - new auto activation mode.

getAutoActivateMode

public OleContainer.AutoActivateMode getAutoActivateMode()
Returns:
auto activation mode

getRootWindow

protected static Wnd getRootWindow(Wnd wnd,
                                   boolean ignoreWindowStyles)

gotSameRoots

protected boolean gotSameRoots(Wnd wnd1,
                               Wnd wnd2)

draw

protected void draw()
Default method for drawing an embedded component which is in inactive state using oleDraw OLE function.


makeContainerWindowFocused

protected void makeContainerWindowFocused()

getCurrentDocumentType

public CLSID getCurrentDocumentType()
Returns identifier of embedded OLE object.

Returns:
identifier of embedded OLE object.

open

public void open(java.io.File file)
Creates an OLE object from file.

Parameters:
file - document file

save

public HResult save(java.io.File file)
Saves an OLE object to file.

Parameters:
file - for saving
Returns:
returns non-negative result of native method. Can be used to determine user choise in overwrite dialog.
See Also:
HResult.S_OK, HResult.S_FALSE

activate

protected void activate()

shouldActivateWhenVisible

protected boolean shouldActivateWhenVisible()

getSibling

protected OleContainerSibling getSibling()

removeNotify

public void removeNotify()

resizeWindow

protected void resizeWindow()

createObject

public void createObject(CLSID clsid)
                  throws ComException
Creates an object in the container by CLSID. A previously created object is destroyed automatically.

Parameters:
clsid - class ID of a component
Throws:
ComException - if any exception occurs

createObject

public void createObject(java.lang.String oleClassName)
                  throws ComException
Creates an object in the container by class name. A previously created object is destroyed automatically.

Parameters:
oleClassName - ProgID of a component
Throws:
ComException - if any exception occurs

createObject

public void createObject(java.io.File file)
                  throws ComException
Creates an object in the container by association specified by the file name. A previously created object is destroyed automatically.

Parameters:
file - document file
Throws:
ComException - if any exception occurs

insertObject

public void insertObject(IOleObject oleObject)
Inserts an externally created OLE object.

Important. The object should be created in OleMessageLoop:

 public void insertEmbeddedObject()
 {
     ...
     OleMessageLoop.invoke(this, "createEbmeddedObject");
     ...
 }
 

public void createEmbeddedObject() { _DPdf areader = Pdf.create(new ClsCtx(ClsCtx.CLSCTX_ALL)); IOleObject oleObject = new IOleObjectImpl(areader);

_container.insertObject(oleObject); }

Note. If you insert an OLE object provided by local COM server,
you should release all references to the inserted OLE object for unloading the COM server.

Parameters:
oleObject - is an OLE object inserted into container.

destroyObject

public void destroyObject()
Destroys the previously created OleObject.


getOleObject

public IOleObjectImpl getOleObject()
Returns an OleObject.

Returns:
the ole object

getOleClientSite

public IOleClientSite getOleClientSite()
Returns an instance of OleClientSite.

Returns:
an instance of OleClientSite.

doVerb

public void doVerb(int verb)
Does the verb for OleObject.

Parameters:
verb - is a verb listed in OleVerbs enumeration

uiDeactivate

public void uiDeactivate()
Deactivates the OLE object's UI.

Only OLE objects with active UI receive keyboard and mouse messages. The process have at most one UI active object.


uiActivate

public void uiActivate()
Activates the OLE objects' UI.

Only OLE objects with active UI receive keyboard and mouse messages. The process have at most one UI active object.

Invokes the doVerb(int) method with OleVerbs.UIACTIVATE parameter to activate the OLE object.


getContainerWindow

public Wnd getContainerWindow()
Returns window of this container.

Returns:
container handle

getObjectWindow

public Wnd getObjectWindow()
Returns window of an embedded object.

Returns:
object window

isPrintPreview

public boolean isPrintPreview()

inPlaceDeactivate

public void inPlaceDeactivate()
Performs in-place deactivation of the inserted OleObject.


getContainerBounds

public java.awt.Rectangle getContainerBounds()
Returns the container bounds.

Returns:
the container bounds.

getOleObjectViewSize

public Size getOleObjectViewSize()
Returns the size of the embedded OLE object.

Returns:
the size of the embedded OLE object.

load

public void load(IStorage storage)
          throws java.io.IOException
Loads an OLE object from OLE storage. If there's already an OLE object in the container, it is destroyed and any changes the user made to it are discarded.

Parameters:
storage - an OLE storage to load an object from.
Throws:
java.io.IOException - if any exception occurs

load

public void load(java.io.InputStream stream)
          throws java.io.IOException
Loads an OLE object from the specified stream. If there's already an OLE object in the container, it is destroyed and any changes the user made to it are discarded.

Parameters:
stream - a stream to load an object from.
Throws:
java.io.IOException - if any exception occurs

load

public void load(byte[] data)
Loads an OLE object from the specified byte array. If there's already an OLE object in the container, it is destroyed and any changes the user made to it are discarded.

Parameters:
data - the byte array to load an object from. This parameter cannot be null.

save

public void save(java.io.OutputStream stream)
          throws java.io.IOException
Saves an OLE object to the specified stream. An OLE object must already be loaded in the container before calling this method.

Parameters:
stream - a stream to save an object to.
Throws:
java.io.IOException - if any exception occurs

save

public byte[] save()
Saves an OLE object as byte array. An OLE object must already be loaded in the container before calling this method.

Returns:
byte array image of stored OLE object.

getPrintDocumentHandler

public PrintHandler getPrintDocumentHandler()

setPrintDocumentHandler

public void setPrintDocumentHandler(PrintHandler printDocumentHandler)

getFileOperationsHandler

public FileOperationsHandler getFileOperationsHandler()

setFileOperationsHandler

public void setFileOperationsHandler(FileOperationsHandler fileOperationsHandler)

setHandleUpdateAsSave

public void setHandleUpdateAsSave(boolean handleUpdateAsSave)
Set handle or not ole object update event. Enabling this option will treat IOleClientSite SaveObject event as file save. Default value for the Ms Excel 2007 is true, otherwise false.

Parameters:
handleUpdateAsSave - true to handle update event, otherwise false

isHandleUpdateAsSave

public boolean isHandleUpdateAsSave()

takeScreenshot

public Bitmap takeScreenshot()
Takes a screenshot of an embedded component. Caller must release the unused bitmap object.

Returns:
Bitmap object that contains a screenshot of an embedded component

getParentContainer

protected java.awt.Container getParentContainer()

drawBitmap

protected void drawBitmap(Bitmap bitmap)
Draws bitmap object on the canvas of this container.

Parameters:
bitmap - bitmap to draw

getActivationVerb

public int getActivationVerb()
Returns the activation verb of this container.

Returns:
activation verb

setActivationVerb

public void setActivationVerb(int activationVerb)
Sets the default activation verb for the container.

Parameters:
activationVerb - activation verb

paint

public void paint(java.awt.Graphics g)

isComponentDisplayed

protected boolean isComponentDisplayed()

setComponentDisplayed

protected void setComponentDisplayed(boolean componentDisplayed)

getActivatedWindow

protected Wnd getActivatedWindow()

setActivatedWindow

protected void setActivatedWindow(Wnd activatedWindow)

disableFocusGainedIgnoreTimeout

protected void disableFocusGainedIgnoreTimeout()

enableFocusGainedIgnoreTimeout

protected void enableFocusGainedIgnoreTimeout()