1113d1ee9SAndrew Rist /************************************************************** 2113d1ee9SAndrew Rist * 3113d1ee9SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4113d1ee9SAndrew Rist * or more contributor license agreements. See the NOTICE file 5113d1ee9SAndrew Rist * distributed with this work for additional information 6113d1ee9SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7113d1ee9SAndrew Rist * to you under the Apache License, Version 2.0 (the 8113d1ee9SAndrew Rist * "License"); you may not use this file except in compliance 9113d1ee9SAndrew Rist * with the License. You may obtain a copy of the License at 10113d1ee9SAndrew Rist * 11113d1ee9SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12113d1ee9SAndrew Rist * 13113d1ee9SAndrew Rist * Unless required by applicable law or agreed to in writing, 14113d1ee9SAndrew Rist * software distributed under the License is distributed on an 15113d1ee9SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16113d1ee9SAndrew Rist * KIND, either express or implied. See the License for the 17113d1ee9SAndrew Rist * specific language governing permissions and limitations 18113d1ee9SAndrew Rist * under the License. 19113d1ee9SAndrew Rist * 20113d1ee9SAndrew Rist *************************************************************/ 21113d1ee9SAndrew Rist 22*95e2fe77Smseidel 23*95e2fe77Smseidel 24cdf0e10cSrcweir package embeddedobj.test; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.awt.*; 27cdf0e10cSrcweir import java.applet.*; 28cdf0e10cSrcweir import java.awt.event.*; 29cdf0e10cSrcweir import java.net.*; 30cdf0e10cSrcweir import java.io.*; 31cdf0e10cSrcweir import java.util.Vector; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import javax.swing.JOptionPane; 34cdf0e10cSrcweir import javax.swing.Timer; 35cdf0e10cSrcweir 36cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 37cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 38cdf0e10cSrcweir 39cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 40cdf0e10cSrcweir import com.sun.star.uno.XInterface; 41cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 42cdf0e10cSrcweir import com.sun.star.uno.Type; 43cdf0e10cSrcweir import com.sun.star.uno.Any; 44cdf0e10cSrcweir 45cdf0e10cSrcweir import com.sun.star.lang.XComponent; 46cdf0e10cSrcweir 47cdf0e10cSrcweir import com.sun.star.util.XCloseable; 48cdf0e10cSrcweir import com.sun.star.util.XURLTransformer; 49cdf0e10cSrcweir import com.sun.star.util.URL; 50cdf0e10cSrcweir 51cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 52cdf0e10cSrcweir import com.sun.star.beans.NamedValue; 53cdf0e10cSrcweir 54cdf0e10cSrcweir import com.sun.star.datatransfer.DataFlavor; 55cdf0e10cSrcweir import com.sun.star.datatransfer.XTransferable; 56cdf0e10cSrcweir 57cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 58cdf0e10cSrcweir 59cdf0e10cSrcweir import com.sun.star.io.XStream; 60cdf0e10cSrcweir import com.sun.star.io.XInputStream; 61cdf0e10cSrcweir import com.sun.star.io.XOutputStream; 62cdf0e10cSrcweir import com.sun.star.io.XTruncate; 63cdf0e10cSrcweir 64cdf0e10cSrcweir import com.sun.star.awt.XWindow; 65cdf0e10cSrcweir import com.sun.star.awt.XBitmap; 66cdf0e10cSrcweir 67cdf0e10cSrcweir import com.sun.star.task.XJob; 68cdf0e10cSrcweir 69cdf0e10cSrcweir import com.sun.star.embed.*; 70cdf0e10cSrcweir 71cdf0e10cSrcweir 72cdf0e10cSrcweir class ActionObject 73cdf0e10cSrcweir { 74cdf0e10cSrcweir public byte m_nID; 75cdf0e10cSrcweir public String m_sParam; 76cdf0e10cSrcweir ActionObject()77cdf0e10cSrcweir public ActionObject() 78cdf0e10cSrcweir { 79cdf0e10cSrcweir m_nID = 0; 80cdf0e10cSrcweir m_sParam = null; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir ActionObject( byte nID )83cdf0e10cSrcweir public ActionObject( byte nID ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir m_nID = nID; 86cdf0e10cSrcweir m_sParam = null; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir ActionObject( byte nID, String sParam )89cdf0e10cSrcweir public ActionObject( byte nID, String sParam ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir m_nID = nID; 92cdf0e10cSrcweir m_sParam = sParam; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir ActionObject( ActionObject aObject )95cdf0e10cSrcweir public ActionObject( ActionObject aObject ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir m_nID = aObject.m_nID; 98cdf0e10cSrcweir m_sParam = aObject.m_sParam; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir }; 101cdf0e10cSrcweir 102cdf0e10cSrcweir public class EmbedContApp extends Applet 103cdf0e10cSrcweir implements MouseListener, XEmbeddedClient, ActionListener, XJob, XInplaceClient, XWindowSupplier 104cdf0e10cSrcweir { 105cdf0e10cSrcweir private XMultiServiceFactory m_xServiceFactory; 106cdf0e10cSrcweir 107cdf0e10cSrcweir private final boolean m_bStoreVisRepl = false; 108cdf0e10cSrcweir 109cdf0e10cSrcweir private XJob m_xMainThreadExecutor; 110cdf0e10cSrcweir private NamedValue[] m_pValuesForExecutor; 111cdf0e10cSrcweir 112cdf0e10cSrcweir private XEmbeddedObject m_xEmbedObj; 113cdf0e10cSrcweir private XStorage m_xStorage; 114cdf0e10cSrcweir private float m_nXScaling; 115cdf0e10cSrcweir private float m_nYScaling; 116cdf0e10cSrcweir private float m_nXPixelSize; 117cdf0e10cSrcweir private float m_nYPixelSize; 118cdf0e10cSrcweir 119cdf0e10cSrcweir private Frame m_aFrame; 120cdf0e10cSrcweir private Menu m_aFileMenu; 121cdf0e10cSrcweir private Menu m_aObjectMenu; 122cdf0e10cSrcweir private Toolkit m_aToolkit; 123cdf0e10cSrcweir 124cdf0e10cSrcweir private Image m_aImage; 125cdf0e10cSrcweir private Object m_oImageLock; 126cdf0e10cSrcweir 127cdf0e10cSrcweir private boolean m_bOwnFile = false; 128cdf0e10cSrcweir 129cdf0e10cSrcweir private boolean m_bLinkObj = false; 130cdf0e10cSrcweir private String m_aLinkURI; 131cdf0e10cSrcweir 132cdf0e10cSrcweir private Object m_oActionsNumberLock; 133cdf0e10cSrcweir private Vector m_aActionsList; 134cdf0e10cSrcweir 135cdf0e10cSrcweir private Timer m_aTimer; 136cdf0e10cSrcweir private boolean m_bDestroyed = false; 137cdf0e10cSrcweir 138cdf0e10cSrcweir private Object m_oInHandlerLock; 139cdf0e10cSrcweir private boolean m_bInHandler = false; 140cdf0e10cSrcweir 141cdf0e10cSrcweir private XURLTransformer m_xTransformer; 142cdf0e10cSrcweir 143cdf0e10cSrcweir private NativeView m_aNativeView; 144cdf0e10cSrcweir private XWindow m_xVCLWindow; 145cdf0e10cSrcweir 146cdf0e10cSrcweir private XBitmap m_xBitmap; 147cdf0e10cSrcweir private BitmapPainter m_aBitmapPainter; 148cdf0e10cSrcweir 149cdf0e10cSrcweir // Constants 150cdf0e10cSrcweir private final byte DESTROY = 1; 151cdf0e10cSrcweir private final byte ACTIVATE_OUTPLACE = 2; 152cdf0e10cSrcweir private final byte NEW_DOCUMENT = 3; 153cdf0e10cSrcweir private final byte SAVE_AS = 4; 154cdf0e10cSrcweir private final byte OPEN_FILE = 5; 155cdf0e10cSrcweir private final byte SAVE = 6; 156cdf0e10cSrcweir private final byte NEW_OBJECT = 7; 157cdf0e10cSrcweir private final byte OBJECT_FROM_FILE = 8; 158cdf0e10cSrcweir private final byte LINK_FROM_FILE = 9; 159cdf0e10cSrcweir private final byte CONVERT_LINK_TO_OBJECT = 10; 160cdf0e10cSrcweir private final byte ACTIVATE_INPLACE = 11; 161cdf0e10cSrcweir private final byte DEACTIVATE = 12; 162cdf0e10cSrcweir 163cdf0e10cSrcweir // Methods EmbedContApp( Frame aFrame, XMultiServiceFactory xServiceFactory )164cdf0e10cSrcweir public EmbedContApp( Frame aFrame, XMultiServiceFactory xServiceFactory ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir m_aFrame = aFrame; 167cdf0e10cSrcweir m_xServiceFactory = xServiceFactory; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir init()170cdf0e10cSrcweir public void init() 171cdf0e10cSrcweir { 172cdf0e10cSrcweir resize( 800, 600 ); 173cdf0e10cSrcweir setBackground( Color.gray ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir m_aToolkit = Toolkit.getDefaultToolkit(); 176cdf0e10cSrcweir 177cdf0e10cSrcweir try { 178cdf0e10cSrcweir Object oTransformer = m_xServiceFactory.createInstance( "com.sun.star.util.URLTransformer" ); 179cdf0e10cSrcweir m_xTransformer = (XURLTransformer)UnoRuntime.queryInterface( XURLTransformer.class, oTransformer ); 180cdf0e10cSrcweir } catch( Exception e ) { System.exit( 0 ); } 181cdf0e10cSrcweir 182cdf0e10cSrcweir m_oActionsNumberLock = new Object(); 183cdf0e10cSrcweir m_aActionsList = new Vector(); 184cdf0e10cSrcweir 185cdf0e10cSrcweir m_oInHandlerLock = new Object(); 186cdf0e10cSrcweir m_oImageLock = new Object(); 187cdf0e10cSrcweir 188cdf0e10cSrcweir try { 189cdf0e10cSrcweir Object oJob = m_xServiceFactory.createInstance( "com.sun.star.comp.thread.MainThreadExecutor" ); 190cdf0e10cSrcweir m_xMainThreadExecutor = (XJob)UnoRuntime.queryInterface( XJob.class, oJob ); 191cdf0e10cSrcweir } catch( Exception e ) {} 192cdf0e10cSrcweir 193cdf0e10cSrcweir if ( m_xMainThreadExecutor == null ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir System.out.println( "Can't create MainThreadExecutor! The application is unusable!" ); 196cdf0e10cSrcweir System.exit( 0 ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir m_nXScaling = 1; 200cdf0e10cSrcweir m_nYScaling = 1; 201cdf0e10cSrcweir m_nXPixelSize = 1; 202cdf0e10cSrcweir m_nYPixelSize = 1; 203cdf0e10cSrcweir 204cdf0e10cSrcweir m_pValuesForExecutor = new NamedValue[1]; 205cdf0e10cSrcweir m_pValuesForExecutor[0] = new NamedValue( "JobToExecute", (Object)this ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir m_aTimer = new Timer( 100, this ); 208cdf0e10cSrcweir m_aTimer.start(); 209cdf0e10cSrcweir 210cdf0e10cSrcweir // Get a menu bar. 211cdf0e10cSrcweir MenuBar aMenuBar = m_aFrame.getMenuBar(); 212cdf0e10cSrcweir if( aMenuBar == null ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir aMenuBar = new MenuBar(); 215cdf0e10cSrcweir m_aFrame.setMenuBar( aMenuBar ); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir // Create menus for the menu bar. 219cdf0e10cSrcweir 220cdf0e10cSrcweir // File menu 221cdf0e10cSrcweir m_aFileMenu = new Menu( "File", true ); 222cdf0e10cSrcweir aMenuBar.add( m_aFileMenu ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir MenuItem aItem = new NewMenuItem(); 225cdf0e10cSrcweir m_aFileMenu.add( aItem ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir aItem = new OpenFileMenuItem(); 228cdf0e10cSrcweir m_aFileMenu.add( aItem ); 229cdf0e10cSrcweir 230cdf0e10cSrcweir aItem = new SaveMenuItem(); 231cdf0e10cSrcweir m_aFileMenu.add( aItem ); 232cdf0e10cSrcweir 233cdf0e10cSrcweir aItem = new SaveAsMenuItem(); 234cdf0e10cSrcweir m_aFileMenu.add( aItem ); 235cdf0e10cSrcweir 236cdf0e10cSrcweir // Object menu 237cdf0e10cSrcweir m_aObjectMenu = new Menu( "Object", true ); 238cdf0e10cSrcweir aMenuBar.add( m_aObjectMenu ); 239cdf0e10cSrcweir 240cdf0e10cSrcweir aItem = new NewObjectMenuItem(); 241cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 242cdf0e10cSrcweir 243cdf0e10cSrcweir aItem = new LoadObjectMenuItem(); 244cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 245cdf0e10cSrcweir 246cdf0e10cSrcweir aItem = new LinkObjectMenuItem(); 247cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 248cdf0e10cSrcweir 249cdf0e10cSrcweir aItem = new ConvertLinkToEmbedMenuItem(); 250cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 251cdf0e10cSrcweir 252cdf0e10cSrcweir // Activation menu 253cdf0e10cSrcweir m_aObjectMenu = new Menu( "Activation", true ); 254cdf0e10cSrcweir aMenuBar.add( m_aObjectMenu ); 255cdf0e10cSrcweir 256cdf0e10cSrcweir aItem = new ActivateOutplaceMenuItem(); 257cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 258cdf0e10cSrcweir 259cdf0e10cSrcweir aItem = new ActivateInplaceMenuItem(); 260cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 261cdf0e10cSrcweir 262cdf0e10cSrcweir aItem = new DeactivateMenuItem(); 263cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 264cdf0e10cSrcweir 265cdf0e10cSrcweir m_aNativeView = new NativeView(); 266cdf0e10cSrcweir m_aNativeView.resize( 800, 600 ); 267cdf0e10cSrcweir this.add( m_aNativeView ); 268cdf0e10cSrcweir 269cdf0e10cSrcweir // Handle mouse clicks in our window. 270cdf0e10cSrcweir // addMouseListener( this ); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir actionPerformed( ActionEvent evt )273cdf0e10cSrcweir public void actionPerformed( ActionEvent evt ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir synchronized( m_oInHandlerLock ) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir if ( m_bInHandler ) 278cdf0e10cSrcweir return; 279cdf0e10cSrcweir m_bInHandler = true; 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir synchronized( m_oActionsNumberLock ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir if ( m_aActionsList.size() > 0 ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir try { 287cdf0e10cSrcweir m_xMainThreadExecutor.execute( m_pValuesForExecutor ); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir catch( Exception e ) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir System.out.println( "Exception in actionPerformed() : " + e ); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir } 294cdf0e10cSrcweir else 295cdf0e10cSrcweir { 296cdf0e10cSrcweir synchronized( m_oInHandlerLock ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir m_bInHandler = false; 299cdf0e10cSrcweir } 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir // XWindowSupplier getWindow()305cdf0e10cSrcweir public XWindow getWindow() 306cdf0e10cSrcweir { 307cdf0e10cSrcweir return m_xVCLWindow; 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir // XEmbeddedClient saveObject()311cdf0e10cSrcweir public void saveObject() 312cdf0e10cSrcweir throws com.sun.star.uno.Exception 313cdf0e10cSrcweir { 314cdf0e10cSrcweir if ( m_xEmbedObj != null ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir try { 317cdf0e10cSrcweir XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class, m_xEmbedObj ); 318cdf0e10cSrcweir if ( xPersist != null ) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir xPersist.storeOwn(); 321cdf0e10cSrcweir generateNewImage(); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir else 324cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No XEmbedPersist!", "Error:", JOptionPane.ERROR_MESSAGE ); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir catch( Exception e ) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveObject:", JOptionPane.ERROR_MESSAGE ); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir generateNewImage(); 333cdf0e10cSrcweir repaint(); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir onShowWindow( boolean bVisible )336cdf0e10cSrcweir public void onShowWindow( boolean bVisible ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir // for now nothing to do 339cdf0e10cSrcweir } 340cdf0e10cSrcweir 341cdf0e10cSrcweir // XInplaceClient canInplaceActivate()342cdf0e10cSrcweir public boolean canInplaceActivate() 343cdf0e10cSrcweir { 344cdf0e10cSrcweir return true; 345cdf0e10cSrcweir } 346cdf0e10cSrcweir onInplaceActivate()347cdf0e10cSrcweir public void onInplaceActivate() 348cdf0e10cSrcweir { 349cdf0e10cSrcweir // TODO 350cdf0e10cSrcweir // prepare for inplace activation 351cdf0e10cSrcweir 352cdf0e10cSrcweir // REMOVE 353cdf0e10cSrcweir // workaround for CLIPCHILDREN problem 354cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 355cdf0e10cSrcweir m_aBitmapPainter.stopPainting(); 356cdf0e10cSrcweir } 357cdf0e10cSrcweir onUIActivate()358cdf0e10cSrcweir public void onUIActivate() 359cdf0e10cSrcweir { 360cdf0e10cSrcweir // TODO 361cdf0e10cSrcweir // prepare for UI activate 362cdf0e10cSrcweir } 363cdf0e10cSrcweir onInplaceDeactivate()364cdf0e10cSrcweir public void onInplaceDeactivate() 365cdf0e10cSrcweir { 366cdf0e10cSrcweir // TODO 367cdf0e10cSrcweir // inplace deactivation is done 368cdf0e10cSrcweir 369cdf0e10cSrcweir // REMOVE 370cdf0e10cSrcweir // workaround for CLIPCHILDREN problem 371cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 372cdf0e10cSrcweir m_aBitmapPainter.startPainting(); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir onUIDeactivate()375cdf0e10cSrcweir public void onUIDeactivate() 376cdf0e10cSrcweir { 377cdf0e10cSrcweir // TODO 378cdf0e10cSrcweir // prepare for UI deactivate 379cdf0e10cSrcweir } 380cdf0e10cSrcweir getTopmostWindow()381cdf0e10cSrcweir public XIPMainContainerWindow getTopmostWindow() 382cdf0e10cSrcweir { 383cdf0e10cSrcweir // TODO 384cdf0e10cSrcweir // return an implementation of XIPMainContainerWindow 385cdf0e10cSrcweir // mainly required for ui activation 386cdf0e10cSrcweir // dummy implementation is enough for inplace activation 387cdf0e10cSrcweir 388cdf0e10cSrcweir return null; 389cdf0e10cSrcweir } 390cdf0e10cSrcweir getDocumentWindow()391cdf0e10cSrcweir public XInplaceUIWindow getDocumentWindow() 392cdf0e10cSrcweir { 393cdf0e10cSrcweir // TODO 394cdf0e10cSrcweir // return implementation of XInplaceUIWindow 395cdf0e10cSrcweir // mainly required for ui activation 396cdf0e10cSrcweir // dummy implementation is enough for inplace activation 397cdf0e10cSrcweir 398cdf0e10cSrcweir return null; 399cdf0e10cSrcweir } 400cdf0e10cSrcweir getPosRect()401cdf0e10cSrcweir public com.sun.star.awt.Rectangle getPosRect() 402cdf0e10cSrcweir { 403cdf0e10cSrcweir // provide position rectangle to the object 404cdf0e10cSrcweir try { 405cdf0e10cSrcweir // here object bitmap and scaling factor hold the size 406cdf0e10cSrcweir com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize(); 407cdf0e10cSrcweir com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size( 408cdf0e10cSrcweir (int)( aBitmapSize.Width * m_nXScaling ), 409cdf0e10cSrcweir (int)( aBitmapSize.Height * m_nYScaling ) ); 410cdf0e10cSrcweir return new com.sun.star.awt.Rectangle( 10, 10, aVisSize.Width, aVisSize.Height ); 411cdf0e10cSrcweir } 412cdf0e10cSrcweir catch( Exception e ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir System.out.println( "Position rectangle generation failed!" ); 415cdf0e10cSrcweir } 416cdf0e10cSrcweir 417cdf0e10cSrcweir return new com.sun.star.awt.Rectangle( 10, 10, 110, 110 ); 418cdf0e10cSrcweir } 419cdf0e10cSrcweir getClipRect()420cdf0e10cSrcweir public com.sun.star.awt.Rectangle getClipRect() 421cdf0e10cSrcweir { 422cdf0e10cSrcweir // provide clip rectangle to the object 423cdf0e10cSrcweir // in this application position and clip rectangles are the same 424cdf0e10cSrcweir 425cdf0e10cSrcweir try { 426cdf0e10cSrcweir // here object bitmap and scaling factor hold the size 427cdf0e10cSrcweir com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize(); 428cdf0e10cSrcweir com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size( 429cdf0e10cSrcweir (int)( aBitmapSize.Width * m_nXScaling ), 430cdf0e10cSrcweir (int)( aBitmapSize.Height * m_nYScaling ) ); 431cdf0e10cSrcweir return new com.sun.star.awt.Rectangle( 10, 10, aVisSize.Width, aVisSize.Height ); 432cdf0e10cSrcweir } 433cdf0e10cSrcweir catch( Exception e ) 434cdf0e10cSrcweir { 435cdf0e10cSrcweir System.out.println( "Clip rectangle generation failed!" ); 436cdf0e10cSrcweir } 437cdf0e10cSrcweir 438cdf0e10cSrcweir return new com.sun.star.awt.Rectangle( 10, 10, 110, 110 ); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir translateAccelerators( com.sun.star.awt.KeyEvent[] aKeys )441cdf0e10cSrcweir public void translateAccelerators( com.sun.star.awt.KeyEvent[] aKeys ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir // TODO 444cdf0e10cSrcweir // an accelerator table for object 445cdf0e10cSrcweir // ui activation related 446cdf0e10cSrcweir } 447cdf0e10cSrcweir scrollObj( com.sun.star.awt.Size aOffset )448cdf0e10cSrcweir public void scrollObj( com.sun.star.awt.Size aOffset ) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir // TODO 451cdf0e10cSrcweir // scrolls the object to a specified offset 452cdf0e10cSrcweir // not mandatory for the testing application :) 453cdf0e10cSrcweir } 454cdf0e10cSrcweir onPosRectChange( com.sun.star.awt.Rectangle aPosRect )455cdf0e10cSrcweir public void onPosRectChange( com.sun.star.awt.Rectangle aPosRect ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir // object asks to change the position 458cdf0e10cSrcweir if ( m_xEmbedObj != null ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir try { 461cdf0e10cSrcweir int nState = m_xEmbedObj.getCurrentState(); 46230acf5e8Spfg // such a position change make sense only when object is 463cdf0e10cSrcweir // either inplace or ui active 464cdf0e10cSrcweir if ( nState == EmbedStates.EMBED_INPLACE_ACTIVE 465cdf0e10cSrcweir || nState == EmbedStates.EMBED_UI_ACTIVE ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir XInplaceObject xInplObj = (XInplaceObject)UnoRuntime.queryInterface( XInplaceObject.class, m_xEmbedObj ); 468cdf0e10cSrcweir if ( xInplObj != null ) 469cdf0e10cSrcweir { 470cdf0e10cSrcweir xInplObj.setObjectRects( aPosRect, aPosRect ); // show the whole object 471cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 472cdf0e10cSrcweir m_aBitmapPainter.setRect( aPosRect ); 473cdf0e10cSrcweir } 474cdf0e10cSrcweir else 475cdf0e10cSrcweir System.out.println( "Why object that does not support inplace activation behave like inplace object?!" ); 476cdf0e10cSrcweir } 477cdf0e10cSrcweir else 478cdf0e10cSrcweir System.out.println( "The object is not active but asks to change visual area!" ); 479cdf0e10cSrcweir } catch( Exception e ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir System.out.println( "Exception is thrown in onPosRectChange: " + e ); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir } 484cdf0e10cSrcweir else 485cdf0e10cSrcweir System.out.println( "Who asks to change visual area?!!" ); 486cdf0e10cSrcweir } 487cdf0e10cSrcweir 488cdf0e10cSrcweir // XJob execute( NamedValue[] pValues )489cdf0e10cSrcweir public Object execute( NamedValue[] pValues ) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir for( int nInd = 0; nInd < m_aActionsList.size(); nInd++ ) 492cdf0e10cSrcweir { 493cdf0e10cSrcweir ActionObject aAction = ( ActionObject ) m_aActionsList.get( nInd ); 494cdf0e10cSrcweir if ( aAction != null ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir if ( aAction.m_nID == DESTROY ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir // free all resources 499cdf0e10cSrcweir clearObjectAndStorage(); 500cdf0e10cSrcweir m_bDestroyed = true; 501cdf0e10cSrcweir } 502cdf0e10cSrcweir else if ( aAction.m_nID == ACTIVATE_OUTPLACE ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir // activate object if exists and not active 505cdf0e10cSrcweir if ( m_xEmbedObj != null ) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir try { 508cdf0e10cSrcweir m_xEmbedObj.changeState( EmbedStates.EMBED_ACTIVE ); 509cdf0e10cSrcweir } 510cdf0e10cSrcweir catch( Exception ex ) 511cdf0e10cSrcweir { 512cdf0e10cSrcweir System.out.println( "Exception on mouse click" + ex ); 513cdf0e10cSrcweir } 514cdf0e10cSrcweir } 515cdf0e10cSrcweir } 516cdf0e10cSrcweir else if ( aAction.m_nID == NEW_DOCUMENT ) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir // clear everything 519cdf0e10cSrcweir clearObjectAndStorage(); 520cdf0e10cSrcweir 521cdf0e10cSrcweir repaint(); 522cdf0e10cSrcweir } 523cdf0e10cSrcweir else if ( aAction.m_nID == SAVE_AS ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir // open SaveAs dialog and store 526cdf0e10cSrcweir 527cdf0e10cSrcweir if ( m_xStorage != null && m_xEmbedObj != null ) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir try { 530cdf0e10cSrcweir /* 531cdf0e10cSrcweir if ( m_bLinkObj ) 532cdf0e10cSrcweir storeLinkAsFileURI( aFileURI ); 533cdf0e10cSrcweir else 534cdf0e10cSrcweir */ 535cdf0e10cSrcweir saveObjectAsFileURI( aAction.m_sParam ); 536cdf0e10cSrcweir } 537cdf0e10cSrcweir catch( Exception ex ) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir System.out.println( "Exception in SaveAsMenuItem: " + ex ); 540cdf0e10cSrcweir } 541cdf0e10cSrcweir } 542cdf0e10cSrcweir } 543cdf0e10cSrcweir else if ( aAction.m_nID == OPEN_FILE ) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir // clear everything 546cdf0e10cSrcweir clearObjectAndStorage(); 547cdf0e10cSrcweir 548cdf0e10cSrcweir // load from specified file 549cdf0e10cSrcweir loadFileURI( aAction.m_sParam ); 550cdf0e10cSrcweir 551cdf0e10cSrcweir if ( m_xEmbedObj != null ) 552cdf0e10cSrcweir { 553cdf0e10cSrcweir try { 554cdf0e10cSrcweir m_xEmbedObj.setClientSite( this ); 555cdf0e10cSrcweir } 556cdf0e10cSrcweir catch( Exception ex ) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir System.out.println( "Exception in OpenFileMenuItem: " + ex ); 559cdf0e10cSrcweir } 560cdf0e10cSrcweir } 561cdf0e10cSrcweir 562cdf0e10cSrcweir generateNewImage(); 563cdf0e10cSrcweir repaint(); 564cdf0e10cSrcweir } 565cdf0e10cSrcweir else if ( aAction.m_nID == SAVE ) 566cdf0e10cSrcweir { 567cdf0e10cSrcweir if ( m_xStorage != null && m_xEmbedObj != null ) 568cdf0e10cSrcweir { 56907a3d7f1SPedro Giffuni // if has persistence store there 570cdf0e10cSrcweir // if not it is and error, SaveAs had to be used 571cdf0e10cSrcweir 572cdf0e10cSrcweir if ( m_bOwnFile ) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir if ( m_xStorage != null ) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir try { 577cdf0e10cSrcweir saveObject(); 578cdf0e10cSrcweir 579cdf0e10cSrcweir if ( m_bLinkObj ) 580cdf0e10cSrcweir storeLinkToStorage(); 581cdf0e10cSrcweir 582cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class, 583cdf0e10cSrcweir m_xStorage ); 584cdf0e10cSrcweir if ( xTransact != null ) 585cdf0e10cSrcweir xTransact.commit(); 586cdf0e10cSrcweir } 587cdf0e10cSrcweir catch( Exception ex ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir System.out.println( "Exception during save operation in SaveMenuItem:" + ex ); 590cdf0e10cSrcweir } 591cdf0e10cSrcweir } 592cdf0e10cSrcweir else 593cdf0e10cSrcweir { 594cdf0e10cSrcweir System.out.println( "No storage for owned file!" ); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir } 597cdf0e10cSrcweir else 598cdf0e10cSrcweir { 599cdf0e10cSrcweir System.out.println( "No owned file!" ); 600cdf0e10cSrcweir } 601cdf0e10cSrcweir } 602cdf0e10cSrcweir } 603cdf0e10cSrcweir else if ( aAction.m_nID == NEW_OBJECT ) 604cdf0e10cSrcweir { 605*95e2fe77Smseidel // remove current object and init a new one 606cdf0e10cSrcweir clearObjectAndStorage(); 607cdf0e10cSrcweir 608cdf0e10cSrcweir if ( aAction.m_sParam != null ) 609cdf0e10cSrcweir { 610cdf0e10cSrcweir m_xStorage = createTempStorage(); 611cdf0e10cSrcweir 612cdf0e10cSrcweir if ( m_xStorage != null ) 613cdf0e10cSrcweir m_xEmbedObj = createEmbedObject( aAction.m_sParam ); 614cdf0e10cSrcweir else 615cdf0e10cSrcweir System.out.println( "Can't create temporary storage!" ); 616cdf0e10cSrcweir 617cdf0e10cSrcweir if ( m_xEmbedObj != null ) 618cdf0e10cSrcweir { 619cdf0e10cSrcweir try { 620cdf0e10cSrcweir m_xEmbedObj.setClientSite( this ); 621cdf0e10cSrcweir } 622cdf0e10cSrcweir catch( Exception ex ) 623cdf0e10cSrcweir { 624cdf0e10cSrcweir System.out.println( "Exception in NewObjectMenuItem:" + ex ); 625cdf0e10cSrcweir } 626cdf0e10cSrcweir } 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir generateNewImage(); 630cdf0e10cSrcweir repaint(); 631cdf0e10cSrcweir } 632cdf0e10cSrcweir else if ( aAction.m_nID == OBJECT_FROM_FILE ) 633cdf0e10cSrcweir { 634cdf0e10cSrcweir // first remove current object 635cdf0e10cSrcweir clearObjectAndStorage(); 636cdf0e10cSrcweir 637cdf0e10cSrcweir // create object from specified file 638cdf0e10cSrcweir m_xStorage = createTempStorage(); 639cdf0e10cSrcweir 640cdf0e10cSrcweir if ( m_xStorage != null ) 641cdf0e10cSrcweir m_xEmbedObj = loadEmbedObject( aAction.m_sParam ); 642cdf0e10cSrcweir 643cdf0e10cSrcweir if ( m_xEmbedObj != null ) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir try { 646cdf0e10cSrcweir m_xEmbedObj.setClientSite( this ); 647cdf0e10cSrcweir } 648cdf0e10cSrcweir catch( Exception ex ) 649cdf0e10cSrcweir { 650cdf0e10cSrcweir System.out.println( "Exception in LoadObjectMenuItem: " + ex ); 651cdf0e10cSrcweir } 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir generateNewImage(); 655cdf0e10cSrcweir repaint(); 656cdf0e10cSrcweir } 657cdf0e10cSrcweir else if ( aAction.m_nID == LINK_FROM_FILE ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir // first remove current object 660cdf0e10cSrcweir clearObjectAndStorage(); 661cdf0e10cSrcweir 662cdf0e10cSrcweir m_xStorage = createTempStorage(); 663cdf0e10cSrcweir 664cdf0e10cSrcweir // create object from specified file 665cdf0e10cSrcweir m_xEmbedObj = createLinkObject( aAction.m_sParam ); 666cdf0e10cSrcweir 667cdf0e10cSrcweir if ( m_xEmbedObj != null ) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir m_aLinkURI = aAction.m_sParam; 670cdf0e10cSrcweir m_bLinkObj = true; 671cdf0e10cSrcweir 672cdf0e10cSrcweir try { 673cdf0e10cSrcweir m_xEmbedObj.setClientSite( this ); 674cdf0e10cSrcweir } 675cdf0e10cSrcweir catch( Exception ex ) 676cdf0e10cSrcweir { 677cdf0e10cSrcweir System.out.println( "Exception in LinkObjectMenuItem:" + ex ); 678cdf0e10cSrcweir } 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir generateNewImage(); 682cdf0e10cSrcweir repaint(); 683cdf0e10cSrcweir } 684cdf0e10cSrcweir else if ( aAction.m_nID == CONVERT_LINK_TO_OBJECT ) 685cdf0e10cSrcweir { 686cdf0e10cSrcweir if ( !m_bLinkObj ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir System.out.println( "The object is not a link!" ); 689cdf0e10cSrcweir continue; 690cdf0e10cSrcweir } 691cdf0e10cSrcweir 692cdf0e10cSrcweir if ( m_xEmbedObj != null ) 693cdf0e10cSrcweir { 694cdf0e10cSrcweir if ( m_xStorage != null ) 695cdf0e10cSrcweir { 696cdf0e10cSrcweir try { 697cdf0e10cSrcweir XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, 698cdf0e10cSrcweir m_xStorage ); 699cdf0e10cSrcweir if ( xNameAccess != null && xNameAccess.hasByName( "LinkName" ) ) 700cdf0e10cSrcweir m_xStorage.removeElement( "LinkName" ); 701cdf0e10cSrcweir 702cdf0e10cSrcweir XLinkageSupport xLinkage = (XLinkageSupport)UnoRuntime.queryInterface( XLinkageSupport.class, 703cdf0e10cSrcweir m_xEmbedObj ); 704cdf0e10cSrcweir if ( xLinkage != null ) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir xLinkage.breakLink( m_xStorage, "EmbedSub" ); 707cdf0e10cSrcweir m_bLinkObj = false; 708cdf0e10cSrcweir m_aLinkURI = null; 709cdf0e10cSrcweir } 710cdf0e10cSrcweir else 711cdf0e10cSrcweir System.out.println( "No XLinkageSupport in ConvertLink... !" ); 712cdf0e10cSrcweir } 713cdf0e10cSrcweir catch( Exception e1 ) 714cdf0e10cSrcweir { 715cdf0e10cSrcweir System.out.println( "Exception in ConvertLinkToEmbed:try 1 :" + e1 ); 716cdf0e10cSrcweir } 717cdf0e10cSrcweir } 718cdf0e10cSrcweir } 719cdf0e10cSrcweir } 720cdf0e10cSrcweir else if ( aAction.m_nID == ACTIVATE_INPLACE ) 721cdf0e10cSrcweir { 722cdf0e10cSrcweir // activate object 723cdf0e10cSrcweir if ( m_xEmbedObj != null ) 724cdf0e10cSrcweir { 725cdf0e10cSrcweir // in general it is better to check acceptable states 726cdf0e10cSrcweir try { 727cdf0e10cSrcweir m_xEmbedObj.changeState( EmbedStates.EMBED_INPLACE_ACTIVE ); 728cdf0e10cSrcweir } 729cdf0e10cSrcweir catch( Exception ex ) 730cdf0e10cSrcweir { 731cdf0e10cSrcweir System.out.println( "Exception on inplace activation " + ex ); 732cdf0e10cSrcweir } 733cdf0e10cSrcweir } 734cdf0e10cSrcweir } 735cdf0e10cSrcweir else if ( aAction.m_nID == DEACTIVATE ) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir // activate object 738cdf0e10cSrcweir 739cdf0e10cSrcweir if ( m_xEmbedObj != null ) 740cdf0e10cSrcweir { 741cdf0e10cSrcweir int nOldState = -1; 742cdf0e10cSrcweir try { 743cdf0e10cSrcweir nOldState = m_xEmbedObj.getCurrentState(); 744cdf0e10cSrcweir } catch( Exception e ) 745cdf0e10cSrcweir {} 746cdf0e10cSrcweir 747cdf0e10cSrcweir if ( nOldState == EmbedStates.EMBED_ACTIVE 748cdf0e10cSrcweir || nOldState == EmbedStates.EMBED_INPLACE_ACTIVE 749cdf0e10cSrcweir || nOldState == EmbedStates.EMBED_UI_ACTIVE ) 750cdf0e10cSrcweir { 751cdf0e10cSrcweir try { 752cdf0e10cSrcweir m_xEmbedObj.changeState( EmbedStates.EMBED_RUNNING ); 753cdf0e10cSrcweir } 754cdf0e10cSrcweir catch( Exception ex ) 755cdf0e10cSrcweir { 756cdf0e10cSrcweir System.out.println( "Exception on inplace activation " + ex ); 757cdf0e10cSrcweir } 758cdf0e10cSrcweir } 759cdf0e10cSrcweir else 760cdf0e10cSrcweir { 761cdf0e10cSrcweir System.out.println( "Deactivation of nonactive object!" ); 762cdf0e10cSrcweir } 763cdf0e10cSrcweir } 764cdf0e10cSrcweir } 765cdf0e10cSrcweir else 766cdf0e10cSrcweir { 767*95e2fe77Smseidel System.out.println( "Unknown action is requested: " + aAction.m_nID + "\n" ); 768cdf0e10cSrcweir } 769cdf0e10cSrcweir } 770cdf0e10cSrcweir } 771cdf0e10cSrcweir 772cdf0e10cSrcweir m_aActionsList.clear(); 773cdf0e10cSrcweir 774cdf0e10cSrcweir synchronized( m_oInHandlerLock ) 775cdf0e10cSrcweir { 776cdf0e10cSrcweir m_bInHandler = false; 777cdf0e10cSrcweir } 778cdf0e10cSrcweir 779cdf0e10cSrcweir return Any.VOID; 780cdf0e10cSrcweir } 781cdf0e10cSrcweir actionRegister( byte nActionID, String sParam )782cdf0e10cSrcweir public void actionRegister( byte nActionID, String sParam ) 783cdf0e10cSrcweir { 784cdf0e10cSrcweir synchronized( m_oActionsNumberLock ) 785cdf0e10cSrcweir { 786cdf0e10cSrcweir int nSize = m_aActionsList.size(); 787cdf0e10cSrcweir if ( nSize < 199 ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir if ( nSize == 0 ) 790cdf0e10cSrcweir m_aActionsList.add( new ActionObject( nActionID, sParam ) ); 791cdf0e10cSrcweir else 792cdf0e10cSrcweir { 793cdf0e10cSrcweir ActionObject aAction = ( ActionObject ) m_aActionsList.get( nSize - 1 ); 794cdf0e10cSrcweir if ( aAction != null && aAction.m_nID != DESTROY ) 795cdf0e10cSrcweir m_aActionsList.add( new ActionObject( nActionID, sParam ) ); 796cdf0e10cSrcweir } 797cdf0e10cSrcweir } 798cdf0e10cSrcweir } 799cdf0e10cSrcweir } 800cdf0e10cSrcweir SaveAsOperation()801cdf0e10cSrcweir public void SaveAsOperation() 802cdf0e10cSrcweir { 803cdf0e10cSrcweir if ( m_xStorage != null && m_xEmbedObj != null ) 804cdf0e10cSrcweir { 805cdf0e10cSrcweir FileDialog aFileDialog = new FileDialog( m_aFrame, "SaveAs", FileDialog.SAVE ); 806cdf0e10cSrcweir aFileDialog.show(); 807cdf0e10cSrcweir if ( aFileDialog.getFile() != null ) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); 810cdf0e10cSrcweir File aFile = new File( aFileName ); 811cdf0e10cSrcweir if ( aFile != null ) 812cdf0e10cSrcweir { 813cdf0e10cSrcweir // create object from specified file 814cdf0e10cSrcweir String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); 815cdf0e10cSrcweir actionRegister( SAVE_AS, aFileURI ); 816cdf0e10cSrcweir } 817cdf0e10cSrcweir } 818cdf0e10cSrcweir } 819cdf0e10cSrcweir else 820cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE ); 821cdf0e10cSrcweir 822cdf0e10cSrcweir } 823cdf0e10cSrcweir destroy()824cdf0e10cSrcweir public void destroy() 825cdf0e10cSrcweir { 826cdf0e10cSrcweir // redirect the call through the timer and call super.destroy(); 827cdf0e10cSrcweir actionRegister( DESTROY, null ); 828cdf0e10cSrcweir 829cdf0e10cSrcweir for ( int i = 0; i < 3 && !m_bDestroyed; i++ ) 830cdf0e10cSrcweir { 831cdf0e10cSrcweir try { 832cdf0e10cSrcweir Thread.sleep( 200 ); 833cdf0e10cSrcweir } catch ( Exception e ) 834cdf0e10cSrcweir {} 835cdf0e10cSrcweir } 836cdf0e10cSrcweir 837cdf0e10cSrcweir if ( !m_bDestroyed ) 838cdf0e10cSrcweir System.out.println( "The object application can not exit correctly!" ); 839cdf0e10cSrcweir 840cdf0e10cSrcweir m_aTimer.stop(); 841cdf0e10cSrcweir 842cdf0e10cSrcweir super.destroy(); 843cdf0e10cSrcweir } 844cdf0e10cSrcweir update( Graphics g )845cdf0e10cSrcweir public void update( Graphics g ) 846cdf0e10cSrcweir { 847cdf0e10cSrcweir paint( g ); 848cdf0e10cSrcweir } 849cdf0e10cSrcweir paint( Graphics g )850cdf0e10cSrcweir public void paint( Graphics g ) 851cdf0e10cSrcweir { 852cdf0e10cSrcweir super.paint( g ); 853cdf0e10cSrcweir 854cdf0e10cSrcweir // m_aNativeView.paint( g ); 855cdf0e10cSrcweir 856cdf0e10cSrcweir createVclWindow(); 857cdf0e10cSrcweir } 858cdf0e10cSrcweir createVclWindow()859cdf0e10cSrcweir public void createVclWindow() 860cdf0e10cSrcweir { 861cdf0e10cSrcweir synchronized( m_oImageLock ) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir if ( m_xVCLWindow == null && m_xServiceFactory != null && m_xEmbedObj != null && m_xBitmap != null ) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir java.awt.Rectangle aBounds = getBounds(); 866cdf0e10cSrcweir m_xVCLWindow = WindowHelper.createWindow( m_xServiceFactory, m_aNativeView, aBounds ); 867cdf0e10cSrcweir m_xVCLWindow.setVisible( true ); 868cdf0e10cSrcweir 869cdf0e10cSrcweir com.sun.star.awt.Size aBitmapSize = new com.sun.star.awt.Size( 200, 100 ); 870cdf0e10cSrcweir 871cdf0e10cSrcweir XVisualObject xVisObj = (XVisualObject)UnoRuntime.queryInterface( XVisualObject.class, m_xEmbedObj ); 872cdf0e10cSrcweir try { 873cdf0e10cSrcweir com.sun.star.awt.Size aVisSize = xVisObj.getVisAreaSize( Aspects.MSASPECT_CONTENT ); 874cdf0e10cSrcweir m_nXPixelSize = aVisSize.Width / aBitmapSize.Width; 875cdf0e10cSrcweir m_nYPixelSize = aVisSize.Height / aBitmapSize.Height; 876cdf0e10cSrcweir } 877cdf0e10cSrcweir catch( Exception e ) 878cdf0e10cSrcweir { 879cdf0e10cSrcweir } 880cdf0e10cSrcweir 881cdf0e10cSrcweir if ( m_xBitmap != null ) 882cdf0e10cSrcweir aBitmapSize = m_xBitmap.getSize(); 883cdf0e10cSrcweir 884cdf0e10cSrcweir System.out.println( "The visual area is Width = " + aBitmapSize.Width + "; Height = " + aBitmapSize.Height ); 885cdf0e10cSrcweir 886cdf0e10cSrcweir com.sun.star.awt.Rectangle aRect = new com.sun.star.awt.Rectangle( 887cdf0e10cSrcweir 10, 888cdf0e10cSrcweir 10, 889cdf0e10cSrcweir Math.min( (int)aBounds.getWidth() - 20, aBitmapSize.Width ), 890cdf0e10cSrcweir Math.min( (int)aBounds.getHeight() - 20, aBitmapSize.Height ) ); 891cdf0e10cSrcweir 892cdf0e10cSrcweir m_aBitmapPainter = new BitmapPainter( m_xMainThreadExecutor, m_xVCLWindow, m_xBitmap, aRect ); 893cdf0e10cSrcweir } 894cdf0e10cSrcweir } 895cdf0e10cSrcweir } 896cdf0e10cSrcweir generateNewImage()897cdf0e10cSrcweir public void generateNewImage() 898cdf0e10cSrcweir { 899cdf0e10cSrcweir if ( m_xEmbedObj != null ) 900cdf0e10cSrcweir { 901cdf0e10cSrcweir try { 902cdf0e10cSrcweir int nOldState = m_xEmbedObj.getCurrentState(); 903cdf0e10cSrcweir int nState = nOldState; 904cdf0e10cSrcweir if ( nOldState == EmbedStates.EMBED_LOADED ) 905cdf0e10cSrcweir { 906cdf0e10cSrcweir m_xEmbedObj.changeState( EmbedStates.EMBED_RUNNING ); 907cdf0e10cSrcweir nState = EmbedStates.EMBED_RUNNING; 908cdf0e10cSrcweir } 909cdf0e10cSrcweir 910cdf0e10cSrcweir if ( nState == EmbedStates.EMBED_UI_ACTIVE || nState == EmbedStates.EMBED_INPLACE_ACTIVE 911cdf0e10cSrcweir || nState == EmbedStates.EMBED_ACTIVE || nState == EmbedStates.EMBED_RUNNING ) 912cdf0e10cSrcweir { 913cdf0e10cSrcweir XComponentSupplier xCompProv = (XComponentSupplier)UnoRuntime.queryInterface( 914cdf0e10cSrcweir XComponentSupplier.class, 915cdf0e10cSrcweir m_xEmbedObj ); 916cdf0e10cSrcweir if ( xCompProv != null ) 917cdf0e10cSrcweir { 918cdf0e10cSrcweir XCloseable xCloseable = xCompProv.getComponent(); 919cdf0e10cSrcweir XTransferable xTransfer = (XTransferable)UnoRuntime.queryInterface( 920cdf0e10cSrcweir XTransferable.class, 921cdf0e10cSrcweir xCloseable ); 922cdf0e10cSrcweir if ( xTransfer != null ) 923cdf0e10cSrcweir { 924cdf0e10cSrcweir DataFlavor aFlavor = new DataFlavor(); 925cdf0e10cSrcweir aFlavor.MimeType = "application/x-openoffice;windows_formatname=\"Bitmap\""; 926cdf0e10cSrcweir aFlavor.HumanPresentableName = "Bitmap"; 927cdf0e10cSrcweir aFlavor.DataType = new Type( byte[].class ); 928cdf0e10cSrcweir 929cdf0e10cSrcweir Object aAny = xTransfer.getTransferData( aFlavor ); 930cdf0e10cSrcweir if ( aAny != null && AnyConverter.isArray( aAny ) ) 931cdf0e10cSrcweir { 932cdf0e10cSrcweir synchronized( m_oImageLock ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir m_xBitmap = WindowHelper.getVCLBitmapFromBytes( m_xServiceFactory, aAny ); 935cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir m_aBitmapPainter.setBitmap( m_xBitmap ); 938cdf0e10cSrcweir 939cdf0e10cSrcweir if ( m_xBitmap != null ) 940cdf0e10cSrcweir { 941cdf0e10cSrcweir try { 942cdf0e10cSrcweir com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize(); 943cdf0e10cSrcweir com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size( 944cdf0e10cSrcweir (int)( aBitmapSize.Width * m_nXScaling ), 945cdf0e10cSrcweir (int)( aBitmapSize.Height * m_nYScaling ) ); 946cdf0e10cSrcweir m_aBitmapPainter.setSize( aVisSize ); 947cdf0e10cSrcweir } 948cdf0e10cSrcweir catch( Exception e ) 949cdf0e10cSrcweir { 950cdf0e10cSrcweir } 951cdf0e10cSrcweir } 952cdf0e10cSrcweir } 953cdf0e10cSrcweir } 954cdf0e10cSrcweir } 955cdf0e10cSrcweir } 956cdf0e10cSrcweir else 957cdf0e10cSrcweir System.out.println( "paint() : can not get XTransferable for the component!\n" ); 958cdf0e10cSrcweir } 959cdf0e10cSrcweir else 960cdf0e10cSrcweir System.out.println( "paint() : XComponentSupplier is not implemented!\n" ); 961cdf0e10cSrcweir } 962cdf0e10cSrcweir } 963cdf0e10cSrcweir catch( com.sun.star.uno.Exception e ) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir // dialogs should not be used in paint() 966cdf0e10cSrcweir System.out.println( "Exception in paint(): " + e ); 967cdf0e10cSrcweir } 968cdf0e10cSrcweir } 969cdf0e10cSrcweir } 970cdf0e10cSrcweir mouseClicked( MouseEvent e )971cdf0e10cSrcweir public void mouseClicked( MouseEvent e ) 972cdf0e10cSrcweir { 973cdf0e10cSrcweir if( e.getModifiers() == InputEvent.BUTTON1_MASK ) 974cdf0e10cSrcweir { 975cdf0e10cSrcweir actionRegister( ACTIVATE_OUTPLACE, null ); 976cdf0e10cSrcweir } 977cdf0e10cSrcweir } 978cdf0e10cSrcweir mousePressed( MouseEvent e )979cdf0e10cSrcweir public void mousePressed( MouseEvent e ){}; mouseEntered( MouseEvent e )980cdf0e10cSrcweir public void mouseEntered( MouseEvent e ){}; mouseExited( MouseEvent e )981cdf0e10cSrcweir public void mouseExited( MouseEvent e ){}; mouseReleased( MouseEvent e )982cdf0e10cSrcweir public void mouseReleased( MouseEvent e ){}; 983cdf0e10cSrcweir 984cdf0e10cSrcweir // classes 985cdf0e10cSrcweir class NewMenuItem extends MenuItem implements ActionListener // Menu New 986cdf0e10cSrcweir { NewMenuItem()987cdf0e10cSrcweir public NewMenuItem() 988cdf0e10cSrcweir { 989cdf0e10cSrcweir super( "New", new MenuShortcut( KeyEvent.VK_A )); 990cdf0e10cSrcweir addActionListener( this ); 991cdf0e10cSrcweir } 992cdf0e10cSrcweir actionPerformed( ActionEvent e )993cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 994cdf0e10cSrcweir { 995cdf0e10cSrcweir actionRegister( NEW_DOCUMENT, null ); 996cdf0e10cSrcweir } 997cdf0e10cSrcweir } 998cdf0e10cSrcweir 999cdf0e10cSrcweir class SaveAsMenuItem extends MenuItem implements ActionListener // Menu SaveAs... 1000cdf0e10cSrcweir { SaveAsMenuItem()1001cdf0e10cSrcweir public SaveAsMenuItem() 1002cdf0e10cSrcweir { 1003cdf0e10cSrcweir super( "SaveAs..." ); 1004cdf0e10cSrcweir addActionListener( this ); 1005cdf0e10cSrcweir } 1006cdf0e10cSrcweir actionPerformed( ActionEvent e )1007cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1008cdf0e10cSrcweir { 1009cdf0e10cSrcweir // open SaveAs dialog and store 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir SaveAsOperation(); 1012cdf0e10cSrcweir } 1013cdf0e10cSrcweir } 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir class OpenFileMenuItem extends MenuItem implements ActionListener // Menu Open 1016cdf0e10cSrcweir { OpenFileMenuItem()1017cdf0e10cSrcweir public OpenFileMenuItem() 1018cdf0e10cSrcweir { 1019cdf0e10cSrcweir super( "Open", new MenuShortcut( KeyEvent.VK_C )); 1020cdf0e10cSrcweir addActionListener( this ); 1021cdf0e10cSrcweir } 1022cdf0e10cSrcweir actionPerformed( ActionEvent e )1023cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1024cdf0e10cSrcweir { 1025cdf0e10cSrcweir // open OpenFile dialog and load doc 1026cdf0e10cSrcweir FileDialog aFileDialog = new FileDialog( m_aFrame, "Open" ); 1027cdf0e10cSrcweir aFileDialog.show(); 1028cdf0e10cSrcweir if ( aFileDialog.getFile() != null ) 1029cdf0e10cSrcweir { 1030cdf0e10cSrcweir String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); 1031cdf0e10cSrcweir File aFile = new File( aFileName ); 1032cdf0e10cSrcweir if ( aFile != null ) 1033cdf0e10cSrcweir { 1034cdf0e10cSrcweir // create object from specified file 1035cdf0e10cSrcweir String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); 1036cdf0e10cSrcweir actionRegister( OPEN_FILE, aFileURI ); 1037cdf0e10cSrcweir } 1038cdf0e10cSrcweir } 1039cdf0e10cSrcweir } 1040cdf0e10cSrcweir } 1041cdf0e10cSrcweir 1042cdf0e10cSrcweir class SaveMenuItem extends MenuItem implements ActionListener // Menu Save 1043cdf0e10cSrcweir { SaveMenuItem()1044cdf0e10cSrcweir public SaveMenuItem() 1045cdf0e10cSrcweir { 1046cdf0e10cSrcweir super( "Save", new MenuShortcut( KeyEvent.VK_D )); 1047cdf0e10cSrcweir addActionListener( this ); 1048cdf0e10cSrcweir } 1049cdf0e10cSrcweir actionPerformed( ActionEvent e )1050cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1051cdf0e10cSrcweir { 105207a3d7f1SPedro Giffuni // if has persistence store there 1053cdf0e10cSrcweir // if not open SaveAs dialog and store 1054cdf0e10cSrcweir if ( m_xStorage != null && m_xEmbedObj != null ) 1055cdf0e10cSrcweir { 1056cdf0e10cSrcweir if ( m_bOwnFile ) 1057cdf0e10cSrcweir { 1058cdf0e10cSrcweir if ( m_xStorage == null ) 1059cdf0e10cSrcweir { 1060cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1061cdf0e10cSrcweir "No storage for oned file!", 1062cdf0e10cSrcweir "Error:", 1063cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1064cdf0e10cSrcweir 1065cdf0e10cSrcweir return; 1066cdf0e10cSrcweir } 1067cdf0e10cSrcweir 1068cdf0e10cSrcweir actionRegister( SAVE, null ); 1069cdf0e10cSrcweir } 1070cdf0e10cSrcweir else 1071cdf0e10cSrcweir { 1072cdf0e10cSrcweir SaveAsOperation(); 1073cdf0e10cSrcweir } 1074cdf0e10cSrcweir } 1075cdf0e10cSrcweir else 1076cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE ); 1077cdf0e10cSrcweir } 1078cdf0e10cSrcweir } 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir class NewObjectMenuItem extends MenuItem implements ActionListener // Menu NewObject 1081cdf0e10cSrcweir { NewObjectMenuItem()1082cdf0e10cSrcweir public NewObjectMenuItem() 1083cdf0e10cSrcweir { 1084cdf0e10cSrcweir super( "Create", new MenuShortcut( KeyEvent.VK_N )); 1085cdf0e10cSrcweir addActionListener( this ); 1086cdf0e10cSrcweir } 1087cdf0e10cSrcweir actionPerformed( ActionEvent e )1088cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1089cdf0e10cSrcweir { 1090cdf0e10cSrcweir Object[] possibleValues = { "com.sun.star.comp.Writer.TextDocument", 1091cdf0e10cSrcweir "com.sun.star.comp.Writer.GlobalDocument", 1092cdf0e10cSrcweir "com.sun.star.comp.Writer.WebDocument", 1093cdf0e10cSrcweir "com.sun.star.comp.Calc.SpreadsheetDocument", 1094cdf0e10cSrcweir "com.sun.star.comp.Draw.PresentationDocument", 1095cdf0e10cSrcweir "com.sun.star.comp.Draw.DrawingDocument", 1096cdf0e10cSrcweir "com.sun.star.comp.Math.FormulaDocument", 1097cdf0e10cSrcweir "BitmapImage" }; 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir String selectedValue = (String)JOptionPane.showInputDialog( null, "DocumentType", "Select", 1100cdf0e10cSrcweir JOptionPane.INFORMATION_MESSAGE, null, 1101cdf0e10cSrcweir possibleValues, possibleValues[0] ); 1102cdf0e10cSrcweir 1103cdf0e10cSrcweir actionRegister( NEW_OBJECT, selectedValue ); 1104cdf0e10cSrcweir } 1105cdf0e10cSrcweir } 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir class LoadObjectMenuItem extends MenuItem implements ActionListener // Menu LoadObject 1108cdf0e10cSrcweir { LoadObjectMenuItem()1109cdf0e10cSrcweir public LoadObjectMenuItem() 1110cdf0e10cSrcweir { 1111cdf0e10cSrcweir super( "Load from file", new MenuShortcut( KeyEvent.VK_L )); 1112cdf0e10cSrcweir addActionListener( this ); 1113cdf0e10cSrcweir } 1114cdf0e10cSrcweir actionPerformed( ActionEvent e )1115cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1116cdf0e10cSrcweir { 1117cdf0e10cSrcweir // open OpenFile dialog and load doc 1118cdf0e10cSrcweir FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" ); 1119cdf0e10cSrcweir aFileDialog.show(); 1120cdf0e10cSrcweir if ( aFileDialog.getFile() != null ) 1121cdf0e10cSrcweir { 1122cdf0e10cSrcweir String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); 1123cdf0e10cSrcweir File aFile = new File( aFileName ); 1124cdf0e10cSrcweir if ( aFile != null ) 1125cdf0e10cSrcweir { 1126cdf0e10cSrcweir // create object from specified file 1127cdf0e10cSrcweir String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); 1128cdf0e10cSrcweir actionRegister( OBJECT_FROM_FILE, aFileURI ); 1129cdf0e10cSrcweir } 1130cdf0e10cSrcweir } 1131cdf0e10cSrcweir } 1132cdf0e10cSrcweir } 1133cdf0e10cSrcweir 1134cdf0e10cSrcweir class LinkObjectMenuItem extends MenuItem implements ActionListener // Menu LinkObject 1135cdf0e10cSrcweir { LinkObjectMenuItem()1136cdf0e10cSrcweir public LinkObjectMenuItem() 1137cdf0e10cSrcweir { 1138cdf0e10cSrcweir super( "Create link", new MenuShortcut( KeyEvent.VK_M )); 1139cdf0e10cSrcweir addActionListener( this ); 1140cdf0e10cSrcweir } 1141cdf0e10cSrcweir actionPerformed( ActionEvent e )1142cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1143cdf0e10cSrcweir { 1144cdf0e10cSrcweir // open OpenFile dialog and load doc 1145cdf0e10cSrcweir FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" ); 1146cdf0e10cSrcweir aFileDialog.show(); 1147cdf0e10cSrcweir if ( aFileDialog.getFile() != null ) 1148cdf0e10cSrcweir { 1149cdf0e10cSrcweir String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); 1150cdf0e10cSrcweir File aFile = new File( aFileName ); 1151cdf0e10cSrcweir if ( aFile != null ) 1152cdf0e10cSrcweir { 1153cdf0e10cSrcweir // create object from specified file 1154cdf0e10cSrcweir String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); 1155cdf0e10cSrcweir actionRegister( LINK_FROM_FILE, aFileURI ); 1156cdf0e10cSrcweir } 1157cdf0e10cSrcweir } 1158cdf0e10cSrcweir } 1159cdf0e10cSrcweir } 1160cdf0e10cSrcweir 1161cdf0e10cSrcweir class ConvertLinkToEmbedMenuItem extends MenuItem implements ActionListener // Menu LinkObject 1162cdf0e10cSrcweir { ConvertLinkToEmbedMenuItem()1163cdf0e10cSrcweir public ConvertLinkToEmbedMenuItem() 1164cdf0e10cSrcweir { 1165cdf0e10cSrcweir super( "Convert link to embed", new MenuShortcut( KeyEvent.VK_M )); 1166cdf0e10cSrcweir addActionListener( this ); 1167cdf0e10cSrcweir } 1168cdf0e10cSrcweir actionPerformed( ActionEvent e )1169cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1170cdf0e10cSrcweir { 1171cdf0e10cSrcweir actionRegister( CONVERT_LINK_TO_OBJECT, null ); 1172cdf0e10cSrcweir } 1173cdf0e10cSrcweir } 1174cdf0e10cSrcweir 1175cdf0e10cSrcweir class ActivateOutplaceMenuItem extends MenuItem implements ActionListener // Menu ActiveteOutplace 1176cdf0e10cSrcweir { ActivateOutplaceMenuItem()1177cdf0e10cSrcweir public ActivateOutplaceMenuItem() 1178cdf0e10cSrcweir { 1179cdf0e10cSrcweir super( "Activate outplace", new MenuShortcut( KeyEvent.VK_A )); 1180cdf0e10cSrcweir addActionListener( this ); 1181cdf0e10cSrcweir } 1182cdf0e10cSrcweir actionPerformed( ActionEvent e )1183cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1184cdf0e10cSrcweir { 1185cdf0e10cSrcweir actionRegister( ACTIVATE_OUTPLACE, null ); 1186cdf0e10cSrcweir } 1187cdf0e10cSrcweir } 1188cdf0e10cSrcweir 1189cdf0e10cSrcweir class ActivateInplaceMenuItem extends MenuItem implements ActionListener // Menu ActivateInplace 1190cdf0e10cSrcweir { ActivateInplaceMenuItem()1191cdf0e10cSrcweir public ActivateInplaceMenuItem() 1192cdf0e10cSrcweir { 1193cdf0e10cSrcweir super( "Activate inplace", new MenuShortcut( KeyEvent.VK_I )); 1194cdf0e10cSrcweir addActionListener( this ); 1195cdf0e10cSrcweir } 1196cdf0e10cSrcweir actionPerformed( ActionEvent e )1197cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1198cdf0e10cSrcweir { 1199cdf0e10cSrcweir actionRegister( ACTIVATE_INPLACE, null ); 1200cdf0e10cSrcweir } 1201cdf0e10cSrcweir } 1202cdf0e10cSrcweir 1203cdf0e10cSrcweir class DeactivateMenuItem extends MenuItem implements ActionListener // Menu Deactivate 1204cdf0e10cSrcweir { DeactivateMenuItem()1205cdf0e10cSrcweir public DeactivateMenuItem() 1206cdf0e10cSrcweir { 1207cdf0e10cSrcweir super( "Deactivate", new MenuShortcut( KeyEvent.VK_D )); 1208cdf0e10cSrcweir addActionListener( this ); 1209cdf0e10cSrcweir } 1210cdf0e10cSrcweir actionPerformed( ActionEvent e )1211cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1212cdf0e10cSrcweir { 1213cdf0e10cSrcweir actionRegister( DEACTIVATE, null ); 1214cdf0e10cSrcweir } 1215cdf0e10cSrcweir } 1216cdf0e10cSrcweir 1217cdf0e10cSrcweir // Helper methods createEmbedObject( String aServiceName )1218cdf0e10cSrcweir public XEmbeddedObject createEmbedObject( String aServiceName ) 1219cdf0e10cSrcweir { 1220cdf0e10cSrcweir XEmbeddedObject xEmbObj = null; 1221cdf0e10cSrcweir byte[] pClassID = new byte[16]; 1222cdf0e10cSrcweir 1223cdf0e10cSrcweir if ( aServiceName.equals( "com.sun.star.comp.Writer.TextDocument" ) ) 1224cdf0e10cSrcweir { 1225cdf0e10cSrcweir int[] pTempClassID = { 0x8B, 0xC6, 0xB1, 0x65, 0xB1, 0xB2, 0x4E, 0xDD, 1226cdf0e10cSrcweir 0xAA, 0x47, 0xDA, 0xE2, 0xEE, 0x68, 0x9D, 0xD6 }; 1227cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1228cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1229cdf0e10cSrcweir } 1230cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Writer.GlobalDocument" ) ) 1231cdf0e10cSrcweir { 1232cdf0e10cSrcweir int[] pTempClassID = { 0xB2, 0x1A, 0x0A, 0x7C, 0xE4, 0x03, 0x41, 0xFE, 1233cdf0e10cSrcweir 0x95, 0x62, 0xBD, 0x13, 0xEA, 0x6F, 0x15, 0xA0 }; 1234cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1235cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1236cdf0e10cSrcweir } 1237cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Writer.WebDocument" ) ) 1238cdf0e10cSrcweir { 1239cdf0e10cSrcweir int[] pTempClassID = { 0xA8, 0xBB, 0xA6, 0x0C, 0x7C, 0x60, 0x45, 0x50, 1240cdf0e10cSrcweir 0x91, 0xCE, 0x39, 0xC3, 0x90, 0x3F, 0xAC, 0x5E }; 1241cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1242cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1243cdf0e10cSrcweir } 1244cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Calc.SpreadsheetDocument" ) ) 1245cdf0e10cSrcweir { 1246cdf0e10cSrcweir int[] pTempClassID = { 0x47, 0xBB, 0xB4, 0xCB, 0xCE, 0x4C, 0x4E, 0x80, 1247cdf0e10cSrcweir 0xA5, 0x91, 0x42, 0xD9, 0xAE, 0x74, 0x95, 0x0F }; 1248cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1249cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1250cdf0e10cSrcweir } 1251cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Draw.PresentationDocument" ) ) 1252cdf0e10cSrcweir { 1253cdf0e10cSrcweir int[] pTempClassID = { 0x91, 0x76, 0xE4, 0x8A, 0x63, 0x7A, 0x4D, 0x1F, 1254cdf0e10cSrcweir 0x80, 0x3B, 0x99, 0xD9, 0xBF, 0xAC, 0x10, 0x47 }; 1255cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1256cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1257cdf0e10cSrcweir } 1258cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Draw.DrawingDocument" ) ) 1259cdf0e10cSrcweir { 1260cdf0e10cSrcweir int[] pTempClassID = { 0x4B, 0xAB, 0x89, 0x70, 0x8A, 0x3B, 0x45, 0xB3, 1261cdf0e10cSrcweir 0x99, 0x1C, 0xCB, 0xEE, 0xAC, 0x6B, 0xD5, 0xE3 }; 1262cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1263cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1264cdf0e10cSrcweir } 1265cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Math.FormulaDocument" ) ) 1266cdf0e10cSrcweir { 1267cdf0e10cSrcweir int[] pTempClassID = { 0x07, 0x8B, 0x7A, 0xBA, 0x54, 0xFC, 0x45, 0x7F, 1268cdf0e10cSrcweir 0x85, 0x51, 0x61, 0x47, 0xE7, 0x76, 0xA9, 0x97 }; 1269cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1270cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1271cdf0e10cSrcweir } 1272cdf0e10cSrcweir else if ( aServiceName.equals( "BitmapImage" ) ) 1273cdf0e10cSrcweir { 1274cdf0e10cSrcweir int[] pTempClassID = { 0xD3, 0xE3, 0x4B, 0x21, 0x9D, 0x75, 0x10, 0x1A, 1275cdf0e10cSrcweir 0x8C, 0x3D, 0x00, 0xAA, 0x00, 0x1A, 0x16, 0x52 }; 1276cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1277cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1278cdf0e10cSrcweir } 1279cdf0e10cSrcweir 1280cdf0e10cSrcweir if ( pClassID != null ) 1281cdf0e10cSrcweir { 1282cdf0e10cSrcweir // create embedded object based on the class ID 1283cdf0e10cSrcweir try { 1284cdf0e10cSrcweir Object oEmbedCreator = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" ); 1285cdf0e10cSrcweir XEmbedObjectCreator xEmbedCreator = (XEmbedObjectCreator)UnoRuntime.queryInterface( 1286cdf0e10cSrcweir XEmbedObjectCreator.class, 1287cdf0e10cSrcweir oEmbedCreator ); 1288cdf0e10cSrcweir if ( xEmbedCreator != null ) 1289cdf0e10cSrcweir { 1290cdf0e10cSrcweir Object oEmbObj = xEmbedCreator.createInstanceInitNew( pClassID, 1291cdf0e10cSrcweir "Dummy name", 1292cdf0e10cSrcweir m_xStorage, 1293cdf0e10cSrcweir "EmbedSub", 1294cdf0e10cSrcweir new PropertyValue[0] ); 1295cdf0e10cSrcweir xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 1296cdf0e10cSrcweir } 1297cdf0e10cSrcweir else 1298cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1299cdf0e10cSrcweir "Can't create EmbedCreator!", 1300cdf0e10cSrcweir "Error:", 1301cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1302cdf0e10cSrcweir } 1303cdf0e10cSrcweir catch( Exception e ) 1304cdf0e10cSrcweir { 1305cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createInstanceInitNew():", JOptionPane.ERROR_MESSAGE ); 1306cdf0e10cSrcweir } 1307cdf0e10cSrcweir } 1308cdf0e10cSrcweir else 1309cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "Can't retrieve class ID!", "Error:", JOptionPane.ERROR_MESSAGE ); 1310cdf0e10cSrcweir 1311cdf0e10cSrcweir return xEmbObj; 1312cdf0e10cSrcweir } 1313cdf0e10cSrcweir createLinkObject( String aLinkURL )1314cdf0e10cSrcweir public XEmbeddedObject createLinkObject( String aLinkURL ) 1315cdf0e10cSrcweir { 1316cdf0e10cSrcweir XEmbeddedObject xEmbObj = null; 1317cdf0e10cSrcweir 1318cdf0e10cSrcweir try { 1319cdf0e10cSrcweir Object oLinkCreator = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" ); 1320cdf0e10cSrcweir XLinkCreator xLinkCreator = (XLinkCreator)UnoRuntime.queryInterface( 1321cdf0e10cSrcweir XLinkCreator.class, 1322cdf0e10cSrcweir oLinkCreator ); 1323cdf0e10cSrcweir if ( xLinkCreator != null ) 1324cdf0e10cSrcweir { 1325cdf0e10cSrcweir PropertyValue[] aMedDescr = { new PropertyValue(), new PropertyValue() }; 1326cdf0e10cSrcweir aMedDescr[0].Name = "URL"; 1327cdf0e10cSrcweir aMedDescr[0].Value = (Object) aLinkURL; 1328cdf0e10cSrcweir aMedDescr[1].Name = "ReadOnly"; 1329cdf0e10cSrcweir aMedDescr[1].Value = (Object) new Boolean( false ); 1330cdf0e10cSrcweir Object oEmbObj = xLinkCreator.createInstanceLink( m_xStorage, "EmbedSub", aMedDescr, new PropertyValue[0] ); 1331cdf0e10cSrcweir xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 1332cdf0e10cSrcweir } 1333cdf0e10cSrcweir else 1334cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1335cdf0e10cSrcweir "Can't create LinkCreator!", 1336cdf0e10cSrcweir "Error:", 1337cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1338cdf0e10cSrcweir } 1339cdf0e10cSrcweir catch( Exception e ) 1340cdf0e10cSrcweir { 1341cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createLinkObject():", JOptionPane.ERROR_MESSAGE ); 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir 1345cdf0e10cSrcweir return xEmbObj; 1346cdf0e10cSrcweir } 1347cdf0e10cSrcweir 1348cdf0e10cSrcweir loadEmbedObject( String aFileURI )1349cdf0e10cSrcweir public XEmbeddedObject loadEmbedObject( String aFileURI ) 1350cdf0e10cSrcweir { 1351cdf0e10cSrcweir XEmbeddedObject xEmbObj = null; 1352cdf0e10cSrcweir try { 1353cdf0e10cSrcweir Object oEmbedCreator = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" ); 1354cdf0e10cSrcweir XEmbedObjectCreator xEmbedCreator = (XEmbedObjectCreator)UnoRuntime.queryInterface( 1355cdf0e10cSrcweir XEmbedObjectCreator.class, 1356cdf0e10cSrcweir oEmbedCreator ); 1357cdf0e10cSrcweir if ( xEmbedCreator != null ) 1358cdf0e10cSrcweir { 1359cdf0e10cSrcweir PropertyValue[] aMedDescr = { new PropertyValue(), new PropertyValue() }; 1360cdf0e10cSrcweir aMedDescr[0].Name = "URL"; 1361cdf0e10cSrcweir aMedDescr[0].Value = (Object) aFileURI; 1362cdf0e10cSrcweir aMedDescr[1].Name = "ReadOnly"; 1363cdf0e10cSrcweir aMedDescr[1].Value = (Object) new Boolean( false ); 1364cdf0e10cSrcweir Object oEmbObj = xEmbedCreator.createInstanceInitFromMediaDescriptor( m_xStorage, 1365cdf0e10cSrcweir "EmbedSub", 1366cdf0e10cSrcweir aMedDescr, 1367cdf0e10cSrcweir new PropertyValue[0] ); 1368cdf0e10cSrcweir xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 1369cdf0e10cSrcweir } 1370cdf0e10cSrcweir else 1371cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1372cdf0e10cSrcweir "Can't create EmbedFactory!", 1373cdf0e10cSrcweir "Error:", 1374cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1375cdf0e10cSrcweir } 1376cdf0e10cSrcweir catch( Exception e ) 1377cdf0e10cSrcweir { 1378cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in loadEmbedObject():", JOptionPane.ERROR_MESSAGE ); 1379cdf0e10cSrcweir } 1380cdf0e10cSrcweir 1381cdf0e10cSrcweir return xEmbObj; 1382cdf0e10cSrcweir } 1383cdf0e10cSrcweir clearObjectAndStorage()1384cdf0e10cSrcweir public void clearObjectAndStorage() 1385cdf0e10cSrcweir { 1386cdf0e10cSrcweir synchronized( m_oImageLock ) 1387cdf0e10cSrcweir { 1388cdf0e10cSrcweir m_aImage = null; 1389cdf0e10cSrcweir } 1390cdf0e10cSrcweir 1391cdf0e10cSrcweir m_nXScaling = 1; 1392cdf0e10cSrcweir m_nYScaling = 1; 1393cdf0e10cSrcweir m_nXPixelSize = 1; 1394cdf0e10cSrcweir m_nYPixelSize = 1; 1395cdf0e10cSrcweir 1396cdf0e10cSrcweir m_bOwnFile = false; 1397cdf0e10cSrcweir 1398cdf0e10cSrcweir m_aLinkURI = null; 1399cdf0e10cSrcweir m_bLinkObj = false; 1400cdf0e10cSrcweir 1401cdf0e10cSrcweir if ( m_xEmbedObj != null ) 1402cdf0e10cSrcweir { 1403cdf0e10cSrcweir try { 1404cdf0e10cSrcweir XCloseable xClose = (XCloseable)UnoRuntime.queryInterface( XCloseable.class, m_xEmbedObj ); 1405cdf0e10cSrcweir if ( xClose != null ) 1406cdf0e10cSrcweir xClose.close( true ); 1407cdf0e10cSrcweir } 1408cdf0e10cSrcweir catch ( Exception ex ) 1409cdf0e10cSrcweir {} 1410cdf0e10cSrcweir m_xEmbedObj = null; 1411cdf0e10cSrcweir } 1412cdf0e10cSrcweir 1413cdf0e10cSrcweir if ( m_xStorage != null ) 1414cdf0e10cSrcweir { 1415cdf0e10cSrcweir try { 1416cdf0e10cSrcweir XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); 1417cdf0e10cSrcweir if ( xComponent != null ) 1418cdf0e10cSrcweir xComponent.dispose(); 1419cdf0e10cSrcweir } 1420cdf0e10cSrcweir catch ( Exception ex ) 1421cdf0e10cSrcweir {} 1422cdf0e10cSrcweir m_xStorage = null; 1423cdf0e10cSrcweir } 1424cdf0e10cSrcweir } 1425cdf0e10cSrcweir createTempStorage()1426cdf0e10cSrcweir public XStorage createTempStorage() 1427cdf0e10cSrcweir { 1428cdf0e10cSrcweir XStorage xTempStorage = null; 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir try { 1431cdf0e10cSrcweir Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); 1432cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 1433cdf0e10cSrcweir XSingleServiceFactory.class, 1434cdf0e10cSrcweir oStorageFactory ); 1435cdf0e10cSrcweir if ( xStorageFactory != null ) 1436cdf0e10cSrcweir { 1437cdf0e10cSrcweir Object oStorage = xStorageFactory.createInstance(); 1438cdf0e10cSrcweir xTempStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); 1439cdf0e10cSrcweir } 1440cdf0e10cSrcweir else 1441cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1442cdf0e10cSrcweir "Can't create StorageFactory!", 1443cdf0e10cSrcweir "Error:", 1444cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1445cdf0e10cSrcweir } 1446cdf0e10cSrcweir catch( Exception e ) 1447cdf0e10cSrcweir { 1448cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createTempStorage():", JOptionPane.ERROR_MESSAGE ); 1449cdf0e10cSrcweir } 1450cdf0e10cSrcweir 1451cdf0e10cSrcweir return xTempStorage; 1452cdf0e10cSrcweir } 1453cdf0e10cSrcweir saveObjectAsFileURI( String aFileURI )1454cdf0e10cSrcweir public void saveObjectAsFileURI( String aFileURI ) 1455cdf0e10cSrcweir { 1456cdf0e10cSrcweir try { 1457cdf0e10cSrcweir Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); 1458cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 1459cdf0e10cSrcweir XSingleServiceFactory.class, 1460cdf0e10cSrcweir oStorageFactory ); 1461cdf0e10cSrcweir if ( xStorageFactory != null ) 1462cdf0e10cSrcweir { 1463cdf0e10cSrcweir XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class, m_xEmbedObj ); 1464cdf0e10cSrcweir if ( xPersist != null ) 1465cdf0e10cSrcweir { 1466cdf0e10cSrcweir Object aArgs[] = new Object[2]; 1467cdf0e10cSrcweir aArgs[0] = aFileURI; 1468cdf0e10cSrcweir aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); 1469cdf0e10cSrcweir 1470cdf0e10cSrcweir Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); 1471cdf0e10cSrcweir XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); 1472cdf0e10cSrcweir 1473cdf0e10cSrcweir PropertyValue aProps[] = { new PropertyValue() }; 1474cdf0e10cSrcweir aProps[0].Name = "StoreVisualReplacement"; 1475cdf0e10cSrcweir aProps[0].Value = new Boolean( m_bStoreVisRepl ); 1476cdf0e10cSrcweir 1477cdf0e10cSrcweir xPersist.storeAsEntry( xTargetStorage, "EmbedSub", new PropertyValue[0], aProps ); 1478cdf0e10cSrcweir xPersist.saveCompleted( true ); 1479cdf0e10cSrcweir 1480cdf0e10cSrcweir // the object must be already based on new storage 1481cdf0e10cSrcweir XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); 1482cdf0e10cSrcweir xComponent.dispose(); 1483cdf0e10cSrcweir 1484cdf0e10cSrcweir m_xStorage = xTargetStorage; 1485cdf0e10cSrcweir m_bOwnFile = true; 1486cdf0e10cSrcweir 1487cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class, 1488cdf0e10cSrcweir m_xStorage ); 1489cdf0e10cSrcweir if ( xTransact != null ) 1490cdf0e10cSrcweir xTransact.commit(); 1491cdf0e10cSrcweir } 1492cdf0e10cSrcweir else 1493cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No XEmbedPersist!", "Error:", JOptionPane.ERROR_MESSAGE ); 1494cdf0e10cSrcweir } 1495cdf0e10cSrcweir else 1496cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1497cdf0e10cSrcweir "Can't create StorageFactory!", 1498cdf0e10cSrcweir "Error:", 1499cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1500cdf0e10cSrcweir } 1501cdf0e10cSrcweir catch( Exception e ) 1502cdf0e10cSrcweir { 1503cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveStorageToFileURI():", JOptionPane.ERROR_MESSAGE ); 1504cdf0e10cSrcweir } 1505cdf0e10cSrcweir 1506cdf0e10cSrcweir } 1507cdf0e10cSrcweir loadFileURI( String aFileURI )1508cdf0e10cSrcweir public void loadFileURI( String aFileURI ) 1509cdf0e10cSrcweir { 1510cdf0e10cSrcweir try 1511cdf0e10cSrcweir { 1512cdf0e10cSrcweir Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); 1513cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 1514cdf0e10cSrcweir XSingleServiceFactory.class, 1515cdf0e10cSrcweir oStorageFactory ); 1516cdf0e10cSrcweir Object aArgs[] = new Object[2]; 1517cdf0e10cSrcweir aArgs[0] = aFileURI; 1518cdf0e10cSrcweir aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); 1519cdf0e10cSrcweir 1520cdf0e10cSrcweir Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); 1521cdf0e10cSrcweir XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); 1522cdf0e10cSrcweir 1523cdf0e10cSrcweir Object oEmbedCreator = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" ); 1524cdf0e10cSrcweir XEmbedObjectCreator xEmbedCreator = (XEmbedObjectCreator)UnoRuntime.queryInterface( 1525cdf0e10cSrcweir XEmbedObjectCreator.class, 1526cdf0e10cSrcweir oEmbedCreator ); 1527cdf0e10cSrcweir 1528cdf0e10cSrcweir XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, 1529cdf0e10cSrcweir xTargetStorage ); 1530cdf0e10cSrcweir if ( xNameAccess == null ) 1531cdf0e10cSrcweir { 1532cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No XNameAccess!", "Error:", JOptionPane.ERROR_MESSAGE ); 1533cdf0e10cSrcweir return; 1534cdf0e10cSrcweir } 1535cdf0e10cSrcweir 1536cdf0e10cSrcweir Object oEmbObj = null; 1537cdf0e10cSrcweir if ( xNameAccess.hasByName( "LinkName" ) && xTargetStorage.isStreamElement( "LinkName" ) ) 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir /* 1540*95e2fe77Smseidel // AOO links will not be tested until they have correct persistence 1541cdf0e10cSrcweir XStream xLinkStream = xTargetStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_READ ); 1542cdf0e10cSrcweir if ( xLinkStream != null ) 1543cdf0e10cSrcweir { 1544cdf0e10cSrcweir XInputStream xInStream = xLinkStream.getInputStream(); 1545cdf0e10cSrcweir if ( xInStream != null ) 1546cdf0e10cSrcweir { 1547cdf0e10cSrcweir byte[][] pBuff = new byte[1][0]; 1548cdf0e10cSrcweir int nRead = xInStream.readBytes( pBuff, 1000 ); 1549cdf0e10cSrcweir m_aLinkURI = new String( pBuff[0] ); 1550cdf0e10cSrcweir xInStream.closeInput(); 1551cdf0e10cSrcweir oEmbObj = xEmbedCreator.createInstanceLink( m_aLinkURI ); 1552cdf0e10cSrcweir m_bLinkObj = true; 1553cdf0e10cSrcweir } 1554cdf0e10cSrcweir } 1555cdf0e10cSrcweir */ 1556cdf0e10cSrcweir } 1557cdf0e10cSrcweir else 1558cdf0e10cSrcweir oEmbObj = xEmbedCreator.createInstanceInitFromEntry( xTargetStorage, 1559cdf0e10cSrcweir "EmbedSub", 1560cdf0e10cSrcweir false, 1561cdf0e10cSrcweir new PropertyValue[0] ); 1562cdf0e10cSrcweir 1563cdf0e10cSrcweir m_xEmbedObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 1564cdf0e10cSrcweir 1565cdf0e10cSrcweir if ( m_xEmbedObj != null ) 1566cdf0e10cSrcweir { 1567cdf0e10cSrcweir m_xStorage = xTargetStorage; 1568cdf0e10cSrcweir m_bOwnFile = true; 1569cdf0e10cSrcweir } 1570cdf0e10cSrcweir else 1571cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1572cdf0e10cSrcweir "Can't create EmbedObject from storage!", 1573cdf0e10cSrcweir "Error:", 1574cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1575cdf0e10cSrcweir } 1576cdf0e10cSrcweir catch( Exception e ) 1577cdf0e10cSrcweir { 1578cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in loadFileURI():", JOptionPane.ERROR_MESSAGE ); 1579cdf0e10cSrcweir } 1580cdf0e10cSrcweir } 1581cdf0e10cSrcweir storeLinkToStorage()1582cdf0e10cSrcweir public void storeLinkToStorage() 1583cdf0e10cSrcweir { 1584cdf0e10cSrcweir if ( m_xStorage != null && m_bLinkObj ) 1585cdf0e10cSrcweir { 1586cdf0e10cSrcweir try { 1587cdf0e10cSrcweir XStream xLinkStream = m_xStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_WRITE ); 1588cdf0e10cSrcweir 1589cdf0e10cSrcweir if ( xLinkStream != null ) 1590cdf0e10cSrcweir { 1591cdf0e10cSrcweir XOutputStream xLinkOutStream = xLinkStream.getOutputStream(); 1592cdf0e10cSrcweir XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, 1593cdf0e10cSrcweir xLinkOutStream ); 1594cdf0e10cSrcweir if ( xLinkOutStream != null && xTruncate != null ) 1595cdf0e10cSrcweir { 1596cdf0e10cSrcweir xTruncate.truncate(); 1597cdf0e10cSrcweir 1598cdf0e10cSrcweir char[] aLinkChar = m_aLinkURI.toCharArray(); 1599cdf0e10cSrcweir byte[] aLinkBytes = new byte[ aLinkChar.length ]; 1600cdf0e10cSrcweir for ( int ind = 0; ind < aLinkChar.length; ind++ ) 1601cdf0e10cSrcweir aLinkBytes[ind] = (byte)aLinkChar[ind]; 1602cdf0e10cSrcweir 1603cdf0e10cSrcweir xLinkOutStream.writeBytes( aLinkBytes ); 1604cdf0e10cSrcweir xLinkOutStream.closeOutput(); 1605cdf0e10cSrcweir 1606cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, 1607cdf0e10cSrcweir xLinkStream ); 1608cdf0e10cSrcweir if ( xComponent != null ) 1609cdf0e10cSrcweir xComponent.dispose(); 1610cdf0e10cSrcweir } 1611cdf0e10cSrcweir else 1612cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1613cdf0e10cSrcweir "The substream can not be truncated or written!", 1614cdf0e10cSrcweir "Error:", 1615cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1616cdf0e10cSrcweir 1617cdf0e10cSrcweir } 1618cdf0e10cSrcweir else 1619cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1620cdf0e10cSrcweir "Can't create/open substream!", 1621cdf0e10cSrcweir "Error:", 1622cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1623cdf0e10cSrcweir } 1624cdf0e10cSrcweir catch( Exception e ) 1625cdf0e10cSrcweir { 1626cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1627cdf0e10cSrcweir e, 1628cdf0e10cSrcweir "Exception in storeLinkToStorage:", 1629cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1630cdf0e10cSrcweir 1631cdf0e10cSrcweir } 1632cdf0e10cSrcweir } 1633cdf0e10cSrcweir } 1634cdf0e10cSrcweir storeLinkAsFileURI( String aFileURI )1635cdf0e10cSrcweir public void storeLinkAsFileURI( String aFileURI ) 1636cdf0e10cSrcweir { 1637cdf0e10cSrcweir try { 1638cdf0e10cSrcweir Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); 1639cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 1640cdf0e10cSrcweir XSingleServiceFactory.class, 1641cdf0e10cSrcweir oStorageFactory ); 1642cdf0e10cSrcweir if ( xStorageFactory != null ) 1643cdf0e10cSrcweir { 1644cdf0e10cSrcweir Object aArgs[] = new Object[2]; 1645cdf0e10cSrcweir aArgs[0] = aFileURI; 1646cdf0e10cSrcweir aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); 1647cdf0e10cSrcweir 1648cdf0e10cSrcweir Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); 1649cdf0e10cSrcweir XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); 1650cdf0e10cSrcweir 1651cdf0e10cSrcweir XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); 1652cdf0e10cSrcweir xComponent.dispose(); 1653cdf0e10cSrcweir 1654cdf0e10cSrcweir m_xStorage = xTargetStorage; 1655cdf0e10cSrcweir m_bOwnFile = true; 1656cdf0e10cSrcweir 1657cdf0e10cSrcweir storeLinkToStorage(); 1658cdf0e10cSrcweir 1659cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class, 1660cdf0e10cSrcweir m_xStorage ); 1661cdf0e10cSrcweir if ( xTransact != null ) 1662cdf0e10cSrcweir xTransact.commit(); 1663cdf0e10cSrcweir } 1664cdf0e10cSrcweir else 1665cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1666cdf0e10cSrcweir "Can't create StorageFactory!", 1667cdf0e10cSrcweir "Error:", 1668cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1669cdf0e10cSrcweir } 1670cdf0e10cSrcweir catch( Exception e ) 1671cdf0e10cSrcweir { 1672cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveStorageToFileURI():", JOptionPane.ERROR_MESSAGE ); 1673cdf0e10cSrcweir } 1674cdf0e10cSrcweir } 1675cdf0e10cSrcweir getValidURL( String sFileURL )1676cdf0e10cSrcweir public String getValidURL( String sFileURL ) 1677cdf0e10cSrcweir { 1678cdf0e10cSrcweir // m_xTransformer must be set! 1679cdf0e10cSrcweir URL[] aURLs = { new URL() }; 1680cdf0e10cSrcweir aURLs[0].Complete = sFileURL; 1681cdf0e10cSrcweir 1682cdf0e10cSrcweir try { 1683cdf0e10cSrcweir if ( !m_xTransformer.parseSmart( aURLs, "" ) ) 1684cdf0e10cSrcweir throw new Exception(); 1685cdf0e10cSrcweir } 1686cdf0e10cSrcweir catch( Exception e ) 1687cdf0e10cSrcweir { 1688cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in getValidURL():", JOptionPane.ERROR_MESSAGE ); 1689cdf0e10cSrcweir } 1690cdf0e10cSrcweir 1691cdf0e10cSrcweir return aURLs[0].Complete; 1692cdf0e10cSrcweir } 1693cdf0e10cSrcweir disposeObject()1694cdf0e10cSrcweir public void disposeObject() 1695cdf0e10cSrcweir { 1696cdf0e10cSrcweir // TODO: 1697cdf0e10cSrcweir // usage of object, storage and bitmap painter should be locked 1698cdf0e10cSrcweir // but since possibility of rasecondition is very low 1699cdf0e10cSrcweir // it is not really required for testing application 1700cdf0e10cSrcweir 1701cdf0e10cSrcweir clearObjectAndStorage(); 1702cdf0e10cSrcweir 1703cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 1704cdf0e10cSrcweir { 1705cdf0e10cSrcweir m_aBitmapPainter.disconnectListener(); 1706cdf0e10cSrcweir m_aBitmapPainter = null; 1707cdf0e10cSrcweir } 1708cdf0e10cSrcweir } 1709cdf0e10cSrcweir } 1710