Kaydet (Commit) 3e94e6f9 authored tarafından Kurt Zenker's avatar Kurt Zenker

INTEGRATION: CWS mav09 (1.10.2); FILE MERGED

2004/02/23 09:43:35 mav 1.10.2.5: #115011# improve object painting
2004/02/19 10:31:38 mav 1.10.2.4: #115011# embedded object representation
2004/01/30 08:43:57 mav 1.10.2.3: #115011# create bitmap
2004/01/28 08:58:05 mav 1.10.2.2: #115011# bitmap painting
2004/01/27 15:54:48 mav 1.10.2.1: #115011# VCL window for container
üst 9fdb743d
package embeddedobj.test;
import java.awt.*; import java.awt.*;
import java.applet.*; import java.applet.*;
import java.awt.event.*; import java.awt.event.*;
import java.net.*; import java.net.*;
import java.io.*; import java.io.*;
import java.util.Vector;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.Timer; import javax.swing.Timer;
...@@ -35,11 +38,46 @@ import com.sun.star.io.XInputStream; ...@@ -35,11 +38,46 @@ import com.sun.star.io.XInputStream;
import com.sun.star.io.XOutputStream; import com.sun.star.io.XOutputStream;
import com.sun.star.io.XTruncate; import com.sun.star.io.XTruncate;
import com.sun.star.awt.XWindow;
import com.sun.star.awt.XBitmap;
import com.sun.star.task.XJob; import com.sun.star.task.XJob;
import com.sun.star.embed.*; import com.sun.star.embed.*;
public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClient, ActionListener, XJob
class ActionObject
{
public byte m_nID;
public String m_sParam;
public ActionObject()
{
m_nID = 0;
m_sParam = null;
}
public ActionObject( byte nID )
{
m_nID = nID;
m_sParam = null;
}
public ActionObject( byte nID, String sParam )
{
m_nID = nID;
m_sParam = sParam;
}
public ActionObject( ActionObject aObject )
{
m_nID = aObject.m_nID;
m_sParam = aObject.m_sParam;
}
};
public class EmbedContApp extends Applet
implements MouseListener, XEmbeddedClient, ActionListener, XJob, XInplaceClient, XWindowSupplier
{ {
private XMultiServiceFactory m_xServiceFactory; private XMultiServiceFactory m_xServiceFactory;
...@@ -50,6 +88,10 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -50,6 +88,10 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
private XEmbeddedObject m_xEmbedObj; private XEmbeddedObject m_xEmbedObj;
private XStorage m_xStorage; private XStorage m_xStorage;
private float m_nXScaling;
private float m_nYScaling;
private float m_nXPixelSize;
private float m_nYPixelSize;
private Frame m_aFrame; private Frame m_aFrame;
private Menu m_aFileMenu; private Menu m_aFileMenu;
...@@ -65,8 +107,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -65,8 +107,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
private String m_aLinkURI; private String m_aLinkURI;
private Object m_oActionsNumberLock; private Object m_oActionsNumberLock;
private int m_nActionsNumber; private Vector m_aActionsList;
private byte[] m_pActionsList;
private Timer m_aTimer; private Timer m_aTimer;
private boolean m_bDestroyed = false; private boolean m_bDestroyed = false;
...@@ -76,9 +117,15 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -76,9 +117,15 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
private XURLTransformer m_xTransformer; private XURLTransformer m_xTransformer;
private NativeView m_aNativeView;
private XWindow m_xVCLWindow;
private XBitmap m_xBitmap;
private BitmapPainter m_aBitmapPainter;
// Constants // Constants
private final byte DESTROY = 1; private final byte DESTROY = 1;
private final byte MOUSE_CLICKED = 2; private final byte ACTIVATE_OUTPLACE = 2;
private final byte NEW_DOCUMENT = 3; private final byte NEW_DOCUMENT = 3;
private final byte SAVE_AS = 4; private final byte SAVE_AS = 4;
private final byte OPEN_FILE = 5; private final byte OPEN_FILE = 5;
...@@ -87,6 +134,8 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -87,6 +134,8 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
private final byte OBJECT_FROM_FILE = 8; private final byte OBJECT_FROM_FILE = 8;
private final byte LINK_FROM_FILE = 9; private final byte LINK_FROM_FILE = 9;
private final byte CONVERT_LINK_TO_OBJECT = 10; private final byte CONVERT_LINK_TO_OBJECT = 10;
private final byte ACTIVATE_INPLACE = 11;
private final byte DEACTIVATE = 12;
// Methods // Methods
public EmbedContApp( Frame aFrame, XMultiServiceFactory xServiceFactory ) public EmbedContApp( Frame aFrame, XMultiServiceFactory xServiceFactory )
...@@ -97,7 +146,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -97,7 +146,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void init() public void init()
{ {
resize( 640, 480 ); resize( 800, 600 );
setBackground( Color.gray ); setBackground( Color.gray );
m_aToolkit = Toolkit.getDefaultToolkit(); m_aToolkit = Toolkit.getDefaultToolkit();
...@@ -107,9 +156,8 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -107,9 +156,8 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
m_xTransformer = (XURLTransformer)UnoRuntime.queryInterface( XURLTransformer.class, oTransformer ); m_xTransformer = (XURLTransformer)UnoRuntime.queryInterface( XURLTransformer.class, oTransformer );
} catch( Exception e ) { System.exit( 0 ); } } catch( Exception e ) { System.exit( 0 ); }
m_pActionsList = new byte[200];
m_nActionsNumber = 0;
m_oActionsNumberLock = new Object(); m_oActionsNumberLock = new Object();
m_aActionsList = new Vector();
m_oInHandlerLock = new Object(); m_oInHandlerLock = new Object();
m_oImageLock = new Object(); m_oImageLock = new Object();
...@@ -125,6 +173,11 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -125,6 +173,11 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
System.exit( 0 ); System.exit( 0 );
} }
m_nXScaling = 1;
m_nYScaling = 1;
m_nXPixelSize = 1;
m_nYPixelSize = 1;
m_pValuesForExecutor = new NamedValue[1]; m_pValuesForExecutor = new NamedValue[1];
m_pValuesForExecutor[0] = new NamedValue( "JobToExecute", (Object)this ); m_pValuesForExecutor[0] = new NamedValue( "JobToExecute", (Object)this );
...@@ -173,9 +226,25 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -173,9 +226,25 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
aItem = new ConvertLinkToEmbedMenuItem(); aItem = new ConvertLinkToEmbedMenuItem();
m_aObjectMenu.add( aItem ); m_aObjectMenu.add( aItem );
// Activation menu
m_aObjectMenu = new Menu( "Activation", true );
aMenuBar.add( m_aObjectMenu );
aItem = new ActivateOutplaceMenuItem();
m_aObjectMenu.add( aItem );
aItem = new ActivateInplaceMenuItem();
m_aObjectMenu.add( aItem );
aItem = new DeactivateMenuItem();
m_aObjectMenu.add( aItem );
m_aNativeView = new NativeView();
m_aNativeView.resize( 800, 600 );
this.add( m_aNativeView );
// Handle mouse clicks in our window. // Handle mouse clicks in our window.
// addMouseListener( new MouseWatcher() ); // addMouseListener( this );
addMouseListener( this );
} }
public void actionPerformed( ActionEvent evt ) public void actionPerformed( ActionEvent evt )
...@@ -189,7 +258,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -189,7 +258,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
synchronized( m_oActionsNumberLock ) synchronized( m_oActionsNumberLock )
{ {
if ( m_nActionsNumber > 0 ) if ( m_aActionsList.size() > 0 )
{ {
try { try {
m_xMainThreadExecutor.execute( m_pValuesForExecutor ); m_xMainThreadExecutor.execute( m_pValuesForExecutor );
...@@ -209,19 +278,205 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -209,19 +278,205 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
} }
} }
// XWindowSupplier
public XWindow getWindow()
{
return m_xVCLWindow;
}
// XEmbeddedClient
public void saveObject()
throws com.sun.star.uno.Exception
{
if ( m_xEmbedObj != null )
{
try {
XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class, m_xEmbedObj );
if ( xPersist != null )
{
xPersist.storeOwn();
generateNewImage();
}
else
JOptionPane.showMessageDialog( m_aFrame, "No XEmbedPersist!", "Error:", JOptionPane.ERROR_MESSAGE );
}
catch( Exception e )
{
JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveObject:", JOptionPane.ERROR_MESSAGE );
}
}
generateNewImage();
repaint();
}
public void onShowWindow( boolean bVisible )
{
// for now nothing to do
}
// XInplaceClient
public boolean canInplaceActivate()
{
return true;
}
public void onInplaceActivate()
{
// TODO
// prepare for inplace activation
// REMOVE
// workaround for CLIPCHILDREN problem
if ( m_aBitmapPainter != null )
m_aBitmapPainter.stopPainting();
}
public void onUIActivate()
{
// TODO
// prepare for UI activate
}
public void onInplaceDeactivate()
{
// TODO
// inplace deactivation is done
// REMOVE
// workaround for CLIPCHILDREN problem
if ( m_aBitmapPainter != null )
m_aBitmapPainter.startPainting();
}
public void onUIDeactivate()
{
// TODO
// prepare for UI deactivate
}
public XIPMainContainerWindow getTopmostWindow()
{
// TODO
// return an implementation of XIPMainContainerWindow
// mainly required for ui activation
// dummy implementation is enough for inplace activation
return null;
}
public XInplaceUIWindow getDocumentWindow()
{
// TODO
// return implementation of XInplaceUIWindow
// mainly required for ui activation
// dummy implementation is enough for inplace activation
return null;
}
public com.sun.star.awt.Rectangle getPosRect()
{
// provide position rectangle to the object
try {
// here object bitmap and scaling factor hold the size
com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize();
com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size(
(int)( aBitmapSize.Width * m_nXScaling ),
(int)( aBitmapSize.Height * m_nYScaling ) );
return new com.sun.star.awt.Rectangle( 10, 10, aVisSize.Width, aVisSize.Height );
}
catch( Exception e )
{
System.out.println( "Position rectangle generation failed!" );
}
return new com.sun.star.awt.Rectangle( 10, 10, 110, 110 );
}
public com.sun.star.awt.Rectangle getClipRect()
{
// provide clip rectangle to the object
// in this application position and clip rectangles are the same
try {
// here object bitmap and scaling factor hold the size
com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize();
com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size(
(int)( aBitmapSize.Width * m_nXScaling ),
(int)( aBitmapSize.Height * m_nYScaling ) );
return new com.sun.star.awt.Rectangle( 10, 10, aVisSize.Width, aVisSize.Height );
}
catch( Exception e )
{
System.out.println( "Clip rectangle generation failed!" );
}
return new com.sun.star.awt.Rectangle( 10, 10, 110, 110 );
}
public void translateAccelerators( com.sun.star.awt.KeyEvent[] aKeys )
{
// TODO
// an accelerator table for object
// ui activation related
}
public void scrollObj( com.sun.star.awt.Size aOffset )
{
// TODO
// scrolls the object to a specified offset
// not mandatory for the testing application :)
}
public void onPosRectChange( com.sun.star.awt.Rectangle aPosRect )
{
// object asks to change the position
if ( m_xEmbedObj != null )
{
try {
int nState = m_xEmbedObj.getCurrentState();
// such a position change make sence only when object is
// either inplace or ui active
if ( nState == EmbedStates.EMBED_INPLACE_ACTIVE
|| nState == EmbedStates.EMBED_UI_ACTIVE )
{
XInplaceObject xInplObj = (XInplaceObject)UnoRuntime.queryInterface( XInplaceObject.class, m_xEmbedObj );
if ( xInplObj != null )
{
xInplObj.setObjectRects( aPosRect, aPosRect ); // show the whole object
if ( m_aBitmapPainter != null )
m_aBitmapPainter.setRect( aPosRect );
}
else
System.out.println( "Why object that does not support inplace activation behave like inplace object?!" );
}
else
System.out.println( "The object is not active but asks to change visual area!" );
} catch( Exception e )
{
System.out.println( "Exception is thrown in onPosRectChange: " + e );
}
}
else
System.out.println( "Who asks to change visual area?!!" );
}
// XJob
public Object execute( NamedValue[] pValues ) public Object execute( NamedValue[] pValues )
{ {
for( int nInd = 0; nInd < m_aActionsList.size(); nInd++ )
{ {
for( int nInd = 0; nInd < m_nActionsNumber; nInd++ ) ActionObject aAction = ( ActionObject ) m_aActionsList.get( nInd );
if ( aAction != null )
{ {
// TODO: execute m_pActionsList[ nInd ] operation if ( aAction.m_nID == DESTROY )
if ( m_pActionsList[ nInd ] == DESTROY )
{ {
// free all resources // free all resources
clearObjectAndStorage(); clearObjectAndStorage();
m_bDestroyed = true; m_bDestroyed = true;
} }
else if ( m_pActionsList[ nInd ] == MOUSE_CLICKED ) else if ( aAction.m_nID == ACTIVATE_OUTPLACE )
{ {
// activate object if exists and not active // activate object if exists and not active
if ( m_xEmbedObj != null ) if ( m_xEmbedObj != null )
...@@ -231,199 +486,110 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -231,199 +486,110 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
} }
catch( Exception ex ) catch( Exception ex )
{ {
JOptionPane.showMessageDialog( m_aFrame, ex, "Exception on mouse click", JOptionPane.ERROR_MESSAGE ); System.out.println( "Exception on mouse click" + ex );
} }
} }
} }
else if ( m_pActionsList[ nInd ] == NEW_DOCUMENT ) else if ( aAction.m_nID == NEW_DOCUMENT )
{ {
// clear everything // clear everything
clearObjectAndStorage(); clearObjectAndStorage();
repaint(); repaint();
} }
else if ( m_pActionsList[ nInd ] == SAVE_AS ) else if ( aAction.m_nID == SAVE_AS )
{ {
// open SaveAs dialog and store // open SaveAs dialog and store
if ( m_xStorage != null && m_xEmbedObj != null ) if ( m_xStorage != null && m_xEmbedObj != null )
{ {
FileDialog aFileDialog = new FileDialog( m_aFrame, "SaveAs", FileDialog.SAVE ); try {
aFileDialog.show(); /*
if ( aFileDialog.getFile() != null ) if ( m_bLinkObj )
storeLinkAsFileURI( aFileURI );
else
*/
saveObjectAsFileURI( aAction.m_sParam );
}
catch( Exception ex )
{ {
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); System.out.println( "Exception in SaveAsMenuItem: " + ex );
File aFile = new File( aFileName );
if ( aFile != null )
{
// create object from specified file
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
try {
/*
if ( m_bLinkObj )
storeLinkAsFileURI( aFileURI );
else
*/
saveObjectAsFileURI( aFileURI );
}
catch( Exception ex )
{
JOptionPane.showMessageDialog( m_aFrame,
ex,
"Exception in SaveAsMenuItem:",
JOptionPane.ERROR_MESSAGE );
}
}
} }
} }
else
JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE );
} }
else if ( m_pActionsList[ nInd ] == OPEN_FILE ) else if ( aAction.m_nID == OPEN_FILE )
{ {
// clear everything // clear everything
clearObjectAndStorage(); clearObjectAndStorage();
// open OpenFile dialog and load doc // load from specified file
FileDialog aFileDialog = new FileDialog( m_aFrame, "Open" ); loadFileURI( aAction.m_sParam );
aFileDialog.show();
if ( aFileDialog.getFile() != null ) if ( m_xEmbedObj != null )
{ {
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); try {
File aFile = new File( aFileName ); m_xEmbedObj.setClientSite( this );
if ( aFile != null ) }
catch( Exception ex )
{ {
// create object from specified file System.out.println( "Exception in OpenFileMenuItem: " + ex );
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
// load from specified file
loadFileURI( aFileURI );
if ( m_xEmbedObj != null )
{
try {
m_xEmbedObj.setClientSite( this );
}
catch( Exception ex )
{
JOptionPane.showMessageDialog( m_aFrame,
ex,
"Exception in OpenFileMenuItem:",
JOptionPane.ERROR_MESSAGE );
}
}
} }
} }
generateNewImage(); generateNewImage();
repaint(); repaint();
} }
else if ( m_pActionsList[ nInd ] == SAVE ) else if ( aAction.m_nID == SAVE )
{ {
// if has persistance store there
// if not open SaveAs dialog and store
if ( m_xStorage != null && m_xEmbedObj != null ) if ( m_xStorage != null && m_xEmbedObj != null )
{ {
// if has persistance store there
// if not it is and error, SaveAs had to be used
if ( m_bOwnFile ) if ( m_bOwnFile )
{ {
if ( m_xStorage == null ) if ( m_xStorage != null )
{ {
JOptionPane.showMessageDialog( m_aFrame, try {
"No storage for oned file!", saveObject();
"Error:",
JOptionPane.ERROR_MESSAGE ); if ( m_bLinkObj )
storeLinkToStorage();
synchronized( m_oInHandlerLock ) XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class,
m_xStorage );
if ( xTransact != null )
xTransact.commit();
}
catch( Exception ex )
{ {
m_bInHandler = false; System.out.println( "Exception during save operation in SaveMenuItem:" + ex );
} }
return Any.VOID;
} }
else
try {
saveObject();
if ( m_bLinkObj )
storeLinkToStorage();
XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class,
m_xStorage );
if ( xTransact != null )
xTransact.commit();
}
catch( Exception ex )
{ {
JOptionPane.showMessageDialog( m_aFrame, System.out.println( "No storage for owned file!" );
ex,
"Exception during save operation in SaveMenuItem:",
JOptionPane.ERROR_MESSAGE );
} }
} }
else else
{ {
FileDialog aFileDialog = new FileDialog( m_aFrame, "SaveAs", FileDialog.SAVE ); System.out.println( "No owned file!" );
aFileDialog.show();
if ( aFileDialog.getFile() != null )
{
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
File aFile = new File( aFileName );
if ( aFile != null )
{
// create object from specified file
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
try {
/*
if ( m_bLinkObj )
storeLinkAsFileURI( aFileURI );
else
*/
saveObjectAsFileURI( aFileURI );
}
catch( Exception ex )
{
JOptionPane.showMessageDialog( m_aFrame,
ex,
"Exception during 'save as' operation in SaveMenuItem:",
JOptionPane.ERROR_MESSAGE );
}
}
}
} }
} }
else
JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE );
} }
else if ( m_pActionsList[ nInd ] == NEW_OBJECT ) else if ( aAction.m_nID == NEW_OBJECT )
{ {
// remove current object an init a new one // remove current object an init a new one
clearObjectAndStorage(); clearObjectAndStorage();
Object[] possibleValues = { "com.sun.star.comp.Writer.TextDocument", if ( aAction.m_sParam != null )
"com.sun.star.comp.Writer.GlobalDocument",
"com.sun.star.comp.Writer.WebDocument",
"com.sun.star.comp.Calc.SpreadsheetDocument",
"com.sun.star.comp.Draw.PresentationDocument",
"com.sun.star.comp.Draw.DrawingDocument",
"com.sun.star.comp.Math.FormulaDocument",
"BitmapImage" };
String selectedValue = (String)JOptionPane.showInputDialog( null, "DocumentType", "Select",
JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues[0] );
if ( selectedValue != null )
{ {
m_xStorage = createTempStorage(); m_xStorage = createTempStorage();
if ( m_xStorage != null ) if ( m_xStorage != null )
m_xEmbedObj = createEmbedObject( selectedValue ); m_xEmbedObj = createEmbedObject( aAction.m_sParam );
else else
JOptionPane.showMessageDialog( m_aFrame, System.out.println( "Can't create temporary storage!" );
"Can't create temporary storage!",
"Error:",
JOptionPane.ERROR_MESSAGE );
if ( m_xEmbedObj != null ) if ( m_xEmbedObj != null )
{ {
...@@ -432,10 +598,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -432,10 +598,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
} }
catch( Exception ex ) catch( Exception ex )
{ {
JOptionPane.showMessageDialog( m_aFrame, System.out.println( "Exception in NewObjectMenuItem:" + ex );
ex,
"Exception in NewObjectMenuItem:",
JOptionPane.ERROR_MESSAGE );
} }
} }
} }
...@@ -443,100 +606,64 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -443,100 +606,64 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
generateNewImage(); generateNewImage();
repaint(); repaint();
} }
else if ( m_pActionsList[ nInd ] == OBJECT_FROM_FILE ) else if ( aAction.m_nID == OBJECT_FROM_FILE )
{ {
// first remove current object // first remove current object
clearObjectAndStorage(); clearObjectAndStorage();
// open OpenFile dialog and load doc // create object from specified file
FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" ); m_xStorage = createTempStorage();
aFileDialog.show();
if ( aFileDialog.getFile() != null )
{
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
File aFile = new File( aFileName );
if ( aFile != null )
{
// create object from specified file
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
m_xStorage = createTempStorage();
if ( m_xStorage != null ) if ( m_xStorage != null )
m_xEmbedObj = loadEmbedObject( aFileURI ); m_xEmbedObj = loadEmbedObject( aAction.m_sParam );
if ( m_xEmbedObj != null ) if ( m_xEmbedObj != null )
{ {
try { try {
m_xEmbedObj.setClientSite( this ); m_xEmbedObj.setClientSite( this );
} }
catch( Exception ex ) catch( Exception ex )
{ {
JOptionPane.showMessageDialog( m_aFrame, System.out.println( "Exception in LoadObjectMenuItem: " + ex );
ex,
"Exception in LoadObjectMenuItem:",
JOptionPane.ERROR_MESSAGE );
}
}
} }
} }
generateNewImage(); generateNewImage();
repaint(); repaint();
} }
else if ( m_pActionsList[ nInd ] == LINK_FROM_FILE ) else if ( aAction.m_nID == LINK_FROM_FILE )
{ {
// first remove current object // first remove current object
clearObjectAndStorage(); clearObjectAndStorage();
// open OpenFile dialog and load doc m_xStorage = createTempStorage();
FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" );
aFileDialog.show();
if ( aFileDialog.getFile() != null )
{
m_xStorage = createTempStorage();
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
File aFile = new File( aFileName );
if ( aFile != null )
{
// create object from specified file
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
m_xEmbedObj = createLinkObject( aFileURI ); // create object from specified file
m_xEmbedObj = createLinkObject( aAction.m_sParam );
if ( m_xEmbedObj != null ) if ( m_xEmbedObj != null )
{ {
m_aLinkURI = aFileURI; m_aLinkURI = aAction.m_sParam;
m_bLinkObj = true; m_bLinkObj = true;
try { try {
m_xEmbedObj.setClientSite( this ); m_xEmbedObj.setClientSite( this );
} }
catch( Exception ex ) catch( Exception ex )
{ {
JOptionPane.showMessageDialog( m_aFrame, System.out.println( "Exception in LinkObjectMenuItem:" + ex );
ex,
"Exception in LinkObjectMenuItem:",
JOptionPane.ERROR_MESSAGE );
}
}
} }
} }
generateNewImage(); generateNewImage();
repaint(); repaint();
} }
else if ( m_pActionsList[ nInd ] == CONVERT_LINK_TO_OBJECT ) else if ( aAction.m_nID == CONVERT_LINK_TO_OBJECT )
{ {
if ( !m_bLinkObj ) if ( !m_bLinkObj )
{ {
JOptionPane.showMessageDialog( m_aFrame, "The object is not a link!", "Error:", JOptionPane.ERROR_MESSAGE ); System.out.println( "The object is not a link!" );
synchronized( m_oInHandlerLock ) continue;
{
m_bInHandler = false;
}
return Any.VOID;
} }
if ( m_xEmbedObj != null ) if ( m_xEmbedObj != null )
...@@ -558,30 +685,69 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -558,30 +685,69 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
m_aLinkURI = null; m_aLinkURI = null;
} }
else else
JOptionPane.showMessageDialog( m_aFrame, System.out.println( "No XLinkageSupport in ConvertLink... !" );
"No XLinkageSupport in ConvertLink... !",
"Error:",
JOptionPane.ERROR_MESSAGE );
} }
catch( Exception e1 ) catch( Exception e1 )
{ {
JOptionPane.showMessageDialog( m_aFrame, System.out.println( "Exception in ConvertLinkToEmbed:try 1 :" + e1 );
e1, }
"Exception in ConvertLinkToEmbed:try 1 :", }
JOptionPane.ERROR_MESSAGE ); }
}
else if ( aAction.m_nID == ACTIVATE_INPLACE )
{
// activate object
if ( m_xEmbedObj != null )
{
// in general it is better to check acceptable states
try {
m_xEmbedObj.changeState( EmbedStates.EMBED_INPLACE_ACTIVE );
}
catch( Exception ex )
{
System.out.println( "Exception on inplace activation " + ex );
}
}
}
else if ( aAction.m_nID == DEACTIVATE )
{
// activate object
if ( m_xEmbedObj != null )
{
int nOldState = -1;
try {
nOldState = m_xEmbedObj.getCurrentState();
} catch( Exception e )
{}
if ( nOldState == EmbedStates.EMBED_ACTIVE
|| nOldState == EmbedStates.EMBED_INPLACE_ACTIVE
|| nOldState == EmbedStates.EMBED_UI_ACTIVE )
{
try {
m_xEmbedObj.changeState( EmbedStates.EMBED_RUNNING );
}
catch( Exception ex )
{
System.out.println( "Exception on inplace activation " + ex );
} }
} }
else
{
System.out.println( "Deactivation of nonactive object!" );
}
} }
} }
else else
{ {
System.out.println( "Unknoun action is requested: " + m_pActionsList[nInd] + "\n" ); System.out.println( "Unknoun action is requested: " + aAction.m_nID + "\n" );
} }
} }
m_nActionsNumber = 0;
} }
m_aActionsList.clear();
synchronized( m_oInHandlerLock ) synchronized( m_oInHandlerLock )
{ {
m_bInHandler = false; m_bInHandler = false;
...@@ -590,22 +756,52 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -590,22 +756,52 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
return Any.VOID; return Any.VOID;
} }
public void actionRegister( byte nActionID ) public void actionRegister( byte nActionID, String sParam )
{ {
synchronized( m_oActionsNumberLock ) synchronized( m_oActionsNumberLock )
{ {
if ( m_nActionsNumber < 199 int nSize = m_aActionsList.size();
&& ( m_nActionsNumber == 0 || m_pActionsList[ m_nActionsNumber - 1 ] != DESTROY ) ) if ( nSize < 199 )
{ {
m_pActionsList[ m_nActionsNumber++ ] = nActionID; if ( nSize == 0 )
m_aActionsList.add( new ActionObject( nActionID, sParam ) );
else
{
ActionObject aAction = ( ActionObject ) m_aActionsList.get( nSize - 1 );
if ( aAction != null && aAction.m_nID != DESTROY )
m_aActionsList.add( new ActionObject( nActionID, sParam ) );
}
} }
} }
} }
public void SaveAsOperation()
{
if ( m_xStorage != null && m_xEmbedObj != null )
{
FileDialog aFileDialog = new FileDialog( m_aFrame, "SaveAs", FileDialog.SAVE );
aFileDialog.show();
if ( aFileDialog.getFile() != null )
{
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
File aFile = new File( aFileName );
if ( aFile != null )
{
// create object from specified file
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
actionRegister( SAVE_AS, aFileURI );
}
}
}
else
JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE );
}
public void destroy() public void destroy()
{ {
// redirect the call through the timer and call super.destroy(); // redirect the call through the timer and call super.destroy();
actionRegister( DESTROY ); actionRegister( DESTROY, null );
for ( int i = 0; i < 3 && !m_bDestroyed; i++ ) for ( int i = 0; i < 3 && !m_bDestroyed; i++ )
{ {
...@@ -632,12 +828,45 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -632,12 +828,45 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
{ {
super.paint( g ); super.paint( g );
if ( m_xEmbedObj != null ) // m_aNativeView.paint( g );
createVclWindow();
}
public void createVclWindow()
{
synchronized( m_oImageLock )
{ {
synchronized( m_oImageLock ) if ( m_xVCLWindow == null && m_xServiceFactory != null && m_xEmbedObj != null && m_xBitmap != null )
{ {
if ( m_aImage != null ) java.awt.Rectangle aBounds = getBounds();
g.drawImage( m_aImage, 0, 0, this ); m_xVCLWindow = WindowHelper.createWindow( m_xServiceFactory, m_aNativeView, aBounds );
m_xVCLWindow.setVisible( true );
com.sun.star.awt.Size aBitmapSize = new com.sun.star.awt.Size( 200, 100 );
XVisualObject xVisObj = (XVisualObject)UnoRuntime.queryInterface( XVisualObject.class, m_xEmbedObj );
try {
com.sun.star.awt.Size aVisSize = xVisObj.getVisAreaSize( Aspects.MSASPECT_CONTENT );
m_nXPixelSize = aVisSize.Width / aBitmapSize.Width;
m_nYPixelSize = aVisSize.Height / aBitmapSize.Height;
}
catch( Exception e )
{
}
if ( m_xBitmap != null )
aBitmapSize = m_xBitmap.getSize();
System.out.println( "The visual area is Width = " + aBitmapSize.Width + "; Height = " + aBitmapSize.Height );
com.sun.star.awt.Rectangle aRect = new com.sun.star.awt.Rectangle(
10,
10,
Math.min( (int)aBounds.getWidth() - 20, aBitmapSize.Width ),
Math.min( (int)aBounds.getHeight() - 20, aBitmapSize.Height ) );
m_aBitmapPainter = new BitmapPainter( m_xMainThreadExecutor, m_xVCLWindow, m_xBitmap, aRect );
} }
} }
} }
...@@ -655,7 +884,8 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -655,7 +884,8 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
nState = EmbedStates.EMBED_RUNNING; nState = EmbedStates.EMBED_RUNNING;
} }
if ( nState == EmbedStates.EMBED_ACTIVE || nState == EmbedStates.EMBED_RUNNING ) if ( nState == EmbedStates.EMBED_UI_ACTIVE || nState == EmbedStates.EMBED_INPLACE_ACTIVE
|| nState == EmbedStates.EMBED_ACTIVE || nState == EmbedStates.EMBED_RUNNING )
{ {
XComponentSupplier xCompProv = (XComponentSupplier)UnoRuntime.queryInterface( XComponentSupplier xCompProv = (XComponentSupplier)UnoRuntime.queryInterface(
XComponentSupplier.class, XComponentSupplier.class,
...@@ -669,20 +899,33 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -669,20 +899,33 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
if ( xTransfer != null ) if ( xTransfer != null )
{ {
DataFlavor aFlavor = new DataFlavor(); DataFlavor aFlavor = new DataFlavor();
aFlavor.MimeType = "image/png"; aFlavor.MimeType = "application/x-openoffice;windows_formatname=\"Bitmap\"";
aFlavor.HumanPresentableName = "Portable Network Graphics"; aFlavor.HumanPresentableName = "Bitmap";
aFlavor.DataType = new Type( byte[].class ); aFlavor.DataType = new Type( byte[].class );
Object aAny = xTransfer.getTransferData( aFlavor ); Object aAny = xTransfer.getTransferData( aFlavor );
if ( aAny != null && AnyConverter.isArray( aAny ) ) if ( aAny != null && AnyConverter.isArray( aAny ) )
{ {
byte[] aPNGData = (byte[])AnyConverter.toArray( aAny ); synchronized( m_oImageLock )
if ( aPNGData != null && aPNGData.length != 0 )
{ {
synchronized( m_oImageLock ) m_xBitmap = WindowHelper.getVCLBitmapFromBytes( m_xServiceFactory, aAny );
if ( m_aBitmapPainter != null )
{ {
m_aImage = m_aToolkit.createImage( aPNGData ); m_aBitmapPainter.setBitmap( m_xBitmap );
// m_aImage = m_aToolkit.createImage( "file:///d:/test1.png" );
if ( m_xBitmap != null )
{
try {
com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize();
com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size(
(int)( aBitmapSize.Width * m_nXScaling ),
(int)( aBitmapSize.Height * m_nYScaling ) );
m_aBitmapPainter.setSize( aVisSize );
}
catch( Exception e )
{
}
}
} }
} }
} }
...@@ -706,7 +949,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -706,7 +949,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
{ {
if( e.getModifiers() == InputEvent.BUTTON1_MASK ) if( e.getModifiers() == InputEvent.BUTTON1_MASK )
{ {
actionRegister( MOUSE_CLICKED ); actionRegister( ACTIVATE_OUTPLACE, null );
} }
} }
...@@ -715,37 +958,6 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -715,37 +958,6 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void mouseExited( MouseEvent e ){}; public void mouseExited( MouseEvent e ){};
public void mouseReleased( MouseEvent e ){}; public void mouseReleased( MouseEvent e ){};
// XEmbeddedClient
public void saveObject()
throws com.sun.star.uno.Exception
{
if ( m_xEmbedObj != null )
{
try {
XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class, m_xEmbedObj );
if ( xPersist != null )
{
xPersist.storeOwn();
generateNewImage();
}
else
JOptionPane.showMessageDialog( m_aFrame, "No XEmbedPersist!", "Error:", JOptionPane.ERROR_MESSAGE );
}
catch( Exception e )
{
JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveObject:", JOptionPane.ERROR_MESSAGE );
}
}
generateNewImage();
repaint();
}
public void onShowWindow( boolean bVisible )
{
// for now nothing to do
}
// classes // classes
class NewMenuItem extends MenuItem implements ActionListener // Menu New class NewMenuItem extends MenuItem implements ActionListener // Menu New
{ {
...@@ -757,7 +969,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -757,7 +969,7 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
actionRegister( NEW_DOCUMENT ); actionRegister( NEW_DOCUMENT, null );
} }
} }
...@@ -771,7 +983,9 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -771,7 +983,9 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
actionRegister( SAVE_AS ); // open SaveAs dialog and store
SaveAsOperation();
} }
} }
...@@ -785,7 +999,20 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -785,7 +999,20 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
actionRegister( OPEN_FILE ); // open OpenFile dialog and load doc
FileDialog aFileDialog = new FileDialog( m_aFrame, "Open" );
aFileDialog.show();
if ( aFileDialog.getFile() != null )
{
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
File aFile = new File( aFileName );
if ( aFile != null )
{
// create object from specified file
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
actionRegister( OPEN_FILE, aFileURI );
}
}
} }
} }
...@@ -799,7 +1026,31 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -799,7 +1026,31 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
actionRegister( SAVE ); // if has persistance store there
// if not open SaveAs dialog and store
if ( m_xStorage != null && m_xEmbedObj != null )
{
if ( m_bOwnFile )
{
if ( m_xStorage == null )
{
JOptionPane.showMessageDialog( m_aFrame,
"No storage for oned file!",
"Error:",
JOptionPane.ERROR_MESSAGE );
return;
}
actionRegister( SAVE, null );
}
else
{
SaveAsOperation();
}
}
else
JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE );
} }
} }
...@@ -813,7 +1064,20 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -813,7 +1064,20 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
actionRegister( NEW_OBJECT ); Object[] possibleValues = { "com.sun.star.comp.Writer.TextDocument",
"com.sun.star.comp.Writer.GlobalDocument",
"com.sun.star.comp.Writer.WebDocument",
"com.sun.star.comp.Calc.SpreadsheetDocument",
"com.sun.star.comp.Draw.PresentationDocument",
"com.sun.star.comp.Draw.DrawingDocument",
"com.sun.star.comp.Math.FormulaDocument",
"BitmapImage" };
String selectedValue = (String)JOptionPane.showInputDialog( null, "DocumentType", "Select",
JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues[0] );
actionRegister( NEW_OBJECT, selectedValue );
} }
} }
...@@ -827,7 +1091,20 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -827,7 +1091,20 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
actionRegister( OBJECT_FROM_FILE ); // open OpenFile dialog and load doc
FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" );
aFileDialog.show();
if ( aFileDialog.getFile() != null )
{
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
File aFile = new File( aFileName );
if ( aFile != null )
{
// create object from specified file
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
actionRegister( OBJECT_FROM_FILE, aFileURI );
}
}
} }
} }
...@@ -841,7 +1118,20 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -841,7 +1118,20 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
actionRegister( LINK_FROM_FILE ); // open OpenFile dialog and load doc
FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" );
aFileDialog.show();
if ( aFileDialog.getFile() != null )
{
String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile();
File aFile = new File( aFileName );
if ( aFile != null )
{
// create object from specified file
String aFileURI = getValidURL( aFile.toURI().toASCIIString() );
actionRegister( LINK_FROM_FILE, aFileURI );
}
}
} }
} }
...@@ -855,7 +1145,49 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -855,7 +1145,49 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
actionRegister( CONVERT_LINK_TO_OBJECT ); actionRegister( CONVERT_LINK_TO_OBJECT, null );
}
}
class ActivateOutplaceMenuItem extends MenuItem implements ActionListener // Menu ActiveteOutplace
{
public ActivateOutplaceMenuItem()
{
super( "Activate outplace", new MenuShortcut( KeyEvent.VK_A ));
addActionListener( this );
}
public void actionPerformed( ActionEvent e )
{
actionRegister( ACTIVATE_OUTPLACE, null );
}
}
class ActivateInplaceMenuItem extends MenuItem implements ActionListener // Menu ActivateInplace
{
public ActivateInplaceMenuItem()
{
super( "Activate inplace", new MenuShortcut( KeyEvent.VK_I ));
addActionListener( this );
}
public void actionPerformed( ActionEvent e )
{
actionRegister( ACTIVATE_INPLACE, null );
}
}
class DeactivateMenuItem extends MenuItem implements ActionListener // Menu Deactivate
{
public DeactivateMenuItem()
{
super( "Deactivate", new MenuShortcut( KeyEvent.VK_D ));
addActionListener( this );
}
public void actionPerformed( ActionEvent e )
{
actionRegister( DEACTIVATE, null );
} }
} }
...@@ -1033,6 +1365,11 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -1033,6 +1365,11 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
m_aImage = null; m_aImage = null;
} }
m_nXScaling = 1;
m_nYScaling = 1;
m_nXPixelSize = 1;
m_nYPixelSize = 1;
m_bOwnFile = false; m_bOwnFile = false;
m_aLinkURI = null; m_aLinkURI = null;
...@@ -1330,5 +1667,21 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie ...@@ -1330,5 +1667,21 @@ public class EmbedContApp extends Applet implements MouseListener, XEmbeddedClie
return aURLs[0].Complete; return aURLs[0].Complete;
} }
public void disposeObject()
{
// TODO:
// usage of object, storage and bitmap painter should be locked
// but since possibility of rasecondition is very low
// it is not really required for testing application
clearObjectAndStorage();
if ( m_aBitmapPainter != null )
{
m_aBitmapPainter.disconnectListener();
m_aBitmapPainter = null;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment