2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package embeddedobj
.test
;
23 import java
.awt
.event
.*;
26 import java
.util
.Vector
;
28 import javax
.swing
.JOptionPane
;
29 import javax
.swing
.Timer
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.lang
.XSingleServiceFactory
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.Any
;
40 import com
.sun
.star
.lang
.XComponent
;
42 import com
.sun
.star
.util
.XCloseable
;
43 import com
.sun
.star
.util
.XURLTransformer
;
44 import com
.sun
.star
.util
.URL
;
46 import com
.sun
.star
.beans
.PropertyValue
;
47 import com
.sun
.star
.beans
.NamedValue
;
49 import com
.sun
.star
.datatransfer
.DataFlavor
;
50 import com
.sun
.star
.datatransfer
.XTransferable
;
52 import com
.sun
.star
.container
.XNameAccess
;
54 import com
.sun
.star
.io
.XStream
;
55 import com
.sun
.star
.io
.XInputStream
;
56 import com
.sun
.star
.io
.XOutputStream
;
57 import com
.sun
.star
.io
.XTruncate
;
59 import com
.sun
.star
.awt
.XWindow
;
60 import com
.sun
.star
.awt
.XBitmap
;
62 import com
.sun
.star
.task
.XJob
;
64 import com
.sun
.star
.embed
.*;
70 public String m_sParam
;
78 public ActionObject( byte nID
)
84 public ActionObject( byte nID
, String sParam
)
90 public ActionObject( ActionObject aObject
)
92 m_nID
= aObject
.m_nID
;
93 m_sParam
= aObject
.m_sParam
;
97 public class EmbedContApp
extends Applet
98 implements MouseListener
, XEmbeddedClient
, ActionListener
, XJob
, XInplaceClient
, XWindowSupplier
100 private XMultiServiceFactory m_xServiceFactory
;
102 private final boolean m_bStoreVisRepl
= false;
104 private XJob m_xMainThreadExecutor
;
105 private NamedValue
[] m_pValuesForExecutor
;
107 private XEmbeddedObject m_xEmbedObj
;
108 private XStorage m_xStorage
;
109 private float m_nXScaling
;
110 private float m_nYScaling
;
111 private float m_nXPixelSize
;
112 private float m_nYPixelSize
;
114 private Frame m_aFrame
;
115 private Menu m_aFileMenu
;
116 private Menu m_aObjectMenu
;
117 private Toolkit m_aToolkit
;
119 private Image m_aImage
;
120 private Object m_oImageLock
;
122 private boolean m_bOwnFile
= false;
124 private boolean m_bLinkObj
= false;
125 private String m_aLinkURI
;
127 private Object m_oActionsNumberLock
;
129 private Timer m_aTimer
;
130 private boolean m_bDestroyed
= false;
132 private Object m_oInHandlerLock
;
133 private boolean m_bInHandler
= false;
135 private XURLTransformer m_xTransformer
;
137 private NativeView m_aNativeView
;
138 private XWindow m_xVCLWindow
;
140 private XBitmap m_xBitmap
;
141 private BitmapPainter m_aBitmapPainter
;
144 private final byte DESTROY
= 1;
145 private final byte ACTIVATE_OUTPLACE
= 2;
146 private final byte NEW_DOCUMENT
= 3;
147 private final byte SAVE_AS
= 4;
148 private final byte OPEN_FILE
= 5;
149 private final byte SAVE
= 6;
150 private final byte NEW_OBJECT
= 7;
151 private final byte OBJECT_FROM_FILE
= 8;
152 private final byte LINK_FROM_FILE
= 9;
153 private final byte CONVERT_LINK_TO_OBJECT
= 10;
154 private final byte ACTIVATE_INPLACE
= 11;
155 private final byte DEACTIVATE
= 12;
158 public EmbedContApp( Frame aFrame
, XMultiServiceFactory xServiceFactory
)
161 m_xServiceFactory
= xServiceFactory
;
167 setBackground( Color
.gray
);
169 m_aToolkit
= Toolkit
.getDefaultToolkit();
172 Object oTransformer
= m_xServiceFactory
.createInstance( "com.sun.star.util.URLTransformer" );
173 m_xTransformer
= (XURLTransformer
)UnoRuntime
.queryInterface( XURLTransformer
.class, oTransformer
);
174 } catch( Exception e
) { System
.exit( 0 ); }
176 m_oActionsNumberLock
= new Object();
177 m_aActionsList
= new ArrayList();
179 m_oInHandlerLock
= new Object();
180 m_oImageLock
= new Object();
183 Object oJob
= m_xServiceFactory
.createInstance( "com.sun.star.comp.thread.MainThreadExecutor" );
184 m_xMainThreadExecutor
= (XJob
)UnoRuntime
.queryInterface( XJob
.class, oJob
);
185 } catch( Exception e
) {}
187 if ( m_xMainThreadExecutor
== null )
189 System
.out
.println( "Can't create MainThreadExecutor! The application is unusable!" );
198 m_pValuesForExecutor
= new NamedValue
[1];
199 m_pValuesForExecutor
[0] = new NamedValue( "JobToExecute", (Object
)this );
201 m_aTimer
= new Timer( 100, this );
205 MenuBar aMenuBar
= m_aFrame
.getMenuBar();
206 if( aMenuBar
== null )
208 aMenuBar
= new MenuBar();
209 m_aFrame
.setMenuBar( aMenuBar
);
212 // Create menus for the menu bar.
215 m_aFileMenu
= new Menu( "File", true );
216 aMenuBar
.add( m_aFileMenu
);
218 MenuItem aItem
= new NewMenuItem();
219 m_aFileMenu
.add( aItem
);
221 aItem
= new OpenFileMenuItem();
222 m_aFileMenu
.add( aItem
);
224 aItem
= new SaveMenuItem();
225 m_aFileMenu
.add( aItem
);
227 aItem
= new SaveAsMenuItem();
228 m_aFileMenu
.add( aItem
);
231 m_aObjectMenu
= new Menu( "Object", true );
232 aMenuBar
.add( m_aObjectMenu
);
234 aItem
= new NewObjectMenuItem();
235 m_aObjectMenu
.add( aItem
);
237 aItem
= new LoadObjectMenuItem();
238 m_aObjectMenu
.add( aItem
);
240 aItem
= new LinkObjectMenuItem();
241 m_aObjectMenu
.add( aItem
);
243 aItem
= new ConvertLinkToEmbedMenuItem();
244 m_aObjectMenu
.add( aItem
);
247 m_aObjectMenu
= new Menu( "Activation", true );
248 aMenuBar
.add( m_aObjectMenu
);
250 aItem
= new ActivateOutplaceMenuItem();
251 m_aObjectMenu
.add( aItem
);
253 aItem
= new ActivateInplaceMenuItem();
254 m_aObjectMenu
.add( aItem
);
256 aItem
= new DeactivateMenuItem();
257 m_aObjectMenu
.add( aItem
);
259 m_aNativeView
= new NativeView();
260 m_aNativeView
.resize( 800, 600 );
261 this.add( m_aNativeView
);
263 // Handle mouse clicks in our window.
264 // addMouseListener( this );
267 public void actionPerformed( ActionEvent evt
)
269 synchronized( m_oInHandlerLock
)
276 synchronized( m_oActionsNumberLock
)
278 if ( m_aActionsList
.size() > 0 )
281 m_xMainThreadExecutor
.execute( m_pValuesForExecutor
);
285 System
.out
.println( "Exception in actionPerformed() : " + e
);
290 synchronized( m_oInHandlerLock
)
292 m_bInHandler
= false;
299 public XWindow
getWindow()
305 public void saveObject()
306 throws com
.sun
.star
.uno
.Exception
308 if ( m_xEmbedObj
!= null )
311 XEmbedPersist xPersist
= (XEmbedPersist
)UnoRuntime
.queryInterface( XEmbedPersist
.class, m_xEmbedObj
);
312 if ( xPersist
!= null )
318 JOptionPane
.showMessageDialog( m_aFrame
, "No XEmbedPersist!", "Error:", JOptionPane
.ERROR_MESSAGE
);
322 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in saveObject:", JOptionPane
.ERROR_MESSAGE
);
330 public void onShowWindow( boolean bVisible
)
332 // for now nothing to do
336 public boolean canInplaceActivate()
341 public void onInplaceActivate()
344 // prepare for inplace activation
347 // workaround for CLIPCHILDREN problem
348 if ( m_aBitmapPainter
!= null )
349 m_aBitmapPainter
.stopPainting();
352 public void onUIActivate()
355 // prepare for UI activate
358 public void onInplaceDeactivate()
361 // inplace deactivation is done
364 // workaround for CLIPCHILDREN problem
365 if ( m_aBitmapPainter
!= null )
366 m_aBitmapPainter
.startPainting();
369 public void onUIDeactivate()
372 // prepare for UI deactivate
375 public XIPMainContainerWindow
getTopmostWindow()
378 // return an implementation of XIPMainContainerWindow
379 // mainly required for ui activation
380 // dummy implementation is enough for inplace activation
385 public XInplaceUIWindow
getDocumentWindow()
388 // return implementation of XInplaceUIWindow
389 // mainly required for ui activation
390 // dummy implementation is enough for inplace activation
395 public com
.sun
.star
.awt
.Rectangle
getPosRect()
397 // provide position rectangle to the object
399 // here object bitmap and scaling factor hold the size
400 com
.sun
.star
.awt
.Size aBitmapSize
= m_xBitmap
.getSize();
401 com
.sun
.star
.awt
.Size aVisSize
= new com
.sun
.star
.awt
.Size(
402 (int)( aBitmapSize
.Width
* m_nXScaling
),
403 (int)( aBitmapSize
.Height
* m_nYScaling
) );
404 return new com
.sun
.star
.awt
.Rectangle( 10, 10, aVisSize
.Width
, aVisSize
.Height
);
408 System
.out
.println( "Position rectangle generation failed!" );
411 return new com
.sun
.star
.awt
.Rectangle( 10, 10, 110, 110 );
414 public com
.sun
.star
.awt
.Rectangle
getClipRect()
416 // provide clip rectangle to the object
417 // in this application position and clip rectangles are the same
420 // here object bitmap and scaling factor hold the size
421 com
.sun
.star
.awt
.Size aBitmapSize
= m_xBitmap
.getSize();
422 com
.sun
.star
.awt
.Size aVisSize
= new com
.sun
.star
.awt
.Size(
423 (int)( aBitmapSize
.Width
* m_nXScaling
),
424 (int)( aBitmapSize
.Height
* m_nYScaling
) );
425 return new com
.sun
.star
.awt
.Rectangle( 10, 10, aVisSize
.Width
, aVisSize
.Height
);
429 System
.out
.println( "Clip rectangle generation failed!" );
432 return new com
.sun
.star
.awt
.Rectangle( 10, 10, 110, 110 );
435 public void translateAccelerators( com
.sun
.star
.awt
.KeyEvent
[] aKeys
)
438 // an accelerator table for object
439 // ui activation related
442 public void scrollObj( com
.sun
.star
.awt
.Size aOffset
)
445 // scrolls the object to a specified offset
446 // not mandatory for the testing application :)
449 public void onPosRectChange( com
.sun
.star
.awt
.Rectangle aPosRect
)
451 // object asks to change the position
452 if ( m_xEmbedObj
!= null )
455 int nState
= m_xEmbedObj
.getCurrentState();
456 // such a position change make sence only when object is
457 // either inplace or ui active
458 if ( nState
== EmbedStates
.EMBED_INPLACE_ACTIVE
459 || nState
== EmbedStates
.EMBED_UI_ACTIVE
)
461 XInplaceObject xInplObj
= (XInplaceObject
)UnoRuntime
.queryInterface( XInplaceObject
.class, m_xEmbedObj
);
462 if ( xInplObj
!= null )
464 xInplObj
.setObjectRects( aPosRect
, aPosRect
); // show the whole object
465 if ( m_aBitmapPainter
!= null )
466 m_aBitmapPainter
.setRect( aPosRect
);
469 System
.out
.println( "Why object that does not support inplace activation behave like inplace object?!" );
472 System
.out
.println( "The object is not active but asks to change visual area!" );
473 } catch( Exception e
)
475 System
.out
.println( "Exception is thrown in onPosRectChange: " + e
);
479 System
.out
.println( "Who asks to change visual area?!!" );
483 public Object
execute( NamedValue
[] pValues
)
485 for( int nInd
= 0; nInd
< m_aActionsList
.size(); nInd
++ )
487 ActionObject aAction
= m_aActionsList
.get( nInd
);
488 if ( aAction
!= null )
490 if ( aAction
.m_nID
== DESTROY
)
492 // free all resources
493 clearObjectAndStorage();
496 else if ( aAction
.m_nID
== ACTIVATE_OUTPLACE
)
498 // activate object if exists and not active
499 if ( m_xEmbedObj
!= null )
502 m_xEmbedObj
.changeState( EmbedStates
.EMBED_ACTIVE
);
504 catch( Exception ex
)
506 System
.out
.println( "Exception on mouse click" + ex
);
510 else if ( aAction
.m_nID
== NEW_DOCUMENT
)
513 clearObjectAndStorage();
517 else if ( aAction
.m_nID
== SAVE_AS
)
519 // open SaveAs dialog and store
521 if ( m_xStorage
!= null && m_xEmbedObj
!= null )
526 storeLinkAsFileURI( aFileURI );
529 saveObjectAsFileURI( aAction
.m_sParam
);
531 catch( Exception ex
)
533 System
.out
.println( "Exception in SaveAsMenuItem: " + ex
);
537 else if ( aAction
.m_nID
== OPEN_FILE
)
540 clearObjectAndStorage();
542 // load from specified file
543 loadFileURI( aAction
.m_sParam
);
545 if ( m_xEmbedObj
!= null )
548 m_xEmbedObj
.setClientSite( this );
550 catch( Exception ex
)
552 System
.out
.println( "Exception in OpenFileMenuItem: " + ex
);
559 else if ( aAction
.m_nID
== SAVE
)
561 if ( m_xStorage
!= null && m_xEmbedObj
!= null )
563 // if has persistance store there
564 // if not it is and error, SaveAs had to be used
568 if ( m_xStorage
!= null )
574 storeLinkToStorage();
576 XTransactedObject xTransact
= (XTransactedObject
)UnoRuntime
.queryInterface( XTransactedObject
.class,
578 if ( xTransact
!= null )
581 catch( Exception ex
)
583 System
.out
.println( "Exception during save operation in SaveMenuItem:" + ex
);
588 System
.out
.println( "No storage for owned file!" );
593 System
.out
.println( "No owned file!" );
597 else if ( aAction
.m_nID
== NEW_OBJECT
)
599 // remove current object an init a new one
600 clearObjectAndStorage();
602 if ( aAction
.m_sParam
!= null )
604 m_xStorage
= createTempStorage();
606 if ( m_xStorage
!= null )
607 m_xEmbedObj
= createEmbedObject( aAction
.m_sParam
);
609 System
.out
.println( "Can't create temporary storage!" );
611 if ( m_xEmbedObj
!= null )
614 m_xEmbedObj
.setClientSite( this );
616 catch( Exception ex
)
618 System
.out
.println( "Exception in NewObjectMenuItem:" + ex
);
626 else if ( aAction
.m_nID
== OBJECT_FROM_FILE
)
628 // first remove current object
629 clearObjectAndStorage();
631 // create object from specified file
632 m_xStorage
= createTempStorage();
634 if ( m_xStorage
!= null )
635 m_xEmbedObj
= loadEmbedObject( aAction
.m_sParam
);
637 if ( m_xEmbedObj
!= null )
640 m_xEmbedObj
.setClientSite( this );
642 catch( Exception ex
)
644 System
.out
.println( "Exception in LoadObjectMenuItem: " + ex
);
651 else if ( aAction
.m_nID
== LINK_FROM_FILE
)
653 // first remove current object
654 clearObjectAndStorage();
656 m_xStorage
= createTempStorage();
658 // create object from specified file
659 m_xEmbedObj
= createLinkObject( aAction
.m_sParam
);
661 if ( m_xEmbedObj
!= null )
663 m_aLinkURI
= aAction
.m_sParam
;
667 m_xEmbedObj
.setClientSite( this );
669 catch( Exception ex
)
671 System
.out
.println( "Exception in LinkObjectMenuItem:" + ex
);
678 else if ( aAction
.m_nID
== CONVERT_LINK_TO_OBJECT
)
682 System
.out
.println( "The object is not a link!" );
686 if ( m_xEmbedObj
!= null )
688 if ( m_xStorage
!= null )
691 XNameAccess xNameAccess
= (XNameAccess
)UnoRuntime
.queryInterface( XNameAccess
.class,
693 if ( xNameAccess
!= null && xNameAccess
.hasByName( "LinkName" ) )
694 m_xStorage
.removeElement( "LinkName" );
696 XLinkageSupport xLinkage
= (XLinkageSupport
)UnoRuntime
.queryInterface( XLinkageSupport
.class,
698 if ( xLinkage
!= null )
700 xLinkage
.breakLink( m_xStorage
, "EmbedSub" );
705 System
.out
.println( "No XLinkageSupport in ConvertLink... !" );
707 catch( Exception e1
)
709 System
.out
.println( "Exception in ConvertLinkToEmbed:try 1 :" + e1
);
714 else if ( aAction
.m_nID
== ACTIVATE_INPLACE
)
717 if ( m_xEmbedObj
!= null )
719 // in general it is better to check acceptable states
721 m_xEmbedObj
.changeState( EmbedStates
.EMBED_INPLACE_ACTIVE
);
723 catch( Exception ex
)
725 System
.out
.println( "Exception on inplace activation " + ex
);
729 else if ( aAction
.m_nID
== DEACTIVATE
)
733 if ( m_xEmbedObj
!= null )
737 nOldState
= m_xEmbedObj
.getCurrentState();
738 } catch( Exception e
)
741 if ( nOldState
== EmbedStates
.EMBED_ACTIVE
742 || nOldState
== EmbedStates
.EMBED_INPLACE_ACTIVE
743 || nOldState
== EmbedStates
.EMBED_UI_ACTIVE
)
746 m_xEmbedObj
.changeState( EmbedStates
.EMBED_RUNNING
);
748 catch( Exception ex
)
750 System
.out
.println( "Exception on inplace activation " + ex
);
755 System
.out
.println( "Deactivation of nonactive object!" );
761 System
.out
.println( "Unknoun action is requested: " + aAction
.m_nID
+ "\n" );
766 m_aActionsList
.clear();
768 synchronized( m_oInHandlerLock
)
770 m_bInHandler
= false;
776 public void actionRegister( byte nActionID
, String sParam
)
778 synchronized( m_oActionsNumberLock
)
780 int nSize
= m_aActionsList
.size();
784 m_aActionsList
.add( new ActionObject( nActionID
, sParam
) );
787 ActionObject aAction
= m_aActionsList
.get( nSize
- 1 );
788 if ( aAction
!= null && aAction
.m_nID
!= DESTROY
)
789 m_aActionsList
.add( new ActionObject( nActionID
, sParam
) );
795 public void SaveAsOperation()
797 if ( m_xStorage
!= null && m_xEmbedObj
!= null )
799 FileDialog aFileDialog
= new FileDialog( m_aFrame
, "SaveAs", FileDialog
.SAVE
);
801 if ( aFileDialog
.getFile() != null )
803 String aFileName
= aFileDialog
.getDirectory() + aFileDialog
.getFile();
804 File aFile
= new File( aFileName
);
807 // create object from specified file
808 String aFileURI
= getValidURL( aFile
.toURI().toASCIIString() );
809 actionRegister( SAVE_AS
, aFileURI
);
814 JOptionPane
.showMessageDialog( m_aFrame
, "No document is embedded!", "Error:", JOptionPane
.ERROR_MESSAGE
);
818 public void destroy()
820 // redirect the call through the timer and call super.destroy();
821 actionRegister( DESTROY
, null );
823 for ( int i
= 0; i
< 3 && !m_bDestroyed
; i
++ )
827 } catch ( Exception e
)
832 System
.out
.println( "The object application can not exit correctly!" );
839 public void update( Graphics g
)
844 public void paint( Graphics g
)
848 // m_aNativeView.paint( g );
853 public void createVclWindow()
855 synchronized( m_oImageLock
)
857 if ( m_xVCLWindow
== null && m_xServiceFactory
!= null && m_xEmbedObj
!= null && m_xBitmap
!= null )
859 java
.awt
.Rectangle aBounds
= getBounds();
860 m_xVCLWindow
= WindowHelper
.createWindow( m_xServiceFactory
, m_aNativeView
, aBounds
);
861 m_xVCLWindow
.setVisible( true );
863 com
.sun
.star
.awt
.Size aBitmapSize
= new com
.sun
.star
.awt
.Size( 200, 100 );
865 XVisualObject xVisObj
= (XVisualObject
)UnoRuntime
.queryInterface( XVisualObject
.class, m_xEmbedObj
);
867 com
.sun
.star
.awt
.Size aVisSize
= xVisObj
.getVisAreaSize( Aspects
.MSASPECT_CONTENT
);
868 m_nXPixelSize
= aVisSize
.Width
/ aBitmapSize
.Width
;
869 m_nYPixelSize
= aVisSize
.Height
/ aBitmapSize
.Height
;
875 if ( m_xBitmap
!= null )
876 aBitmapSize
= m_xBitmap
.getSize();
878 System
.out
.println( "The visual area is Width = " + aBitmapSize
.Width
+ "; Height = " + aBitmapSize
.Height
);
880 com
.sun
.star
.awt
.Rectangle aRect
= new com
.sun
.star
.awt
.Rectangle(
883 Math
.min( (int)aBounds
.getWidth() - 20, aBitmapSize
.Width
),
884 Math
.min( (int)aBounds
.getHeight() - 20, aBitmapSize
.Height
) );
886 m_aBitmapPainter
= new BitmapPainter( m_xMainThreadExecutor
, m_xVCLWindow
, m_xBitmap
, aRect
);
891 public void generateNewImage()
893 if ( m_xEmbedObj
!= null )
896 int nOldState
= m_xEmbedObj
.getCurrentState();
897 int nState
= nOldState
;
898 if ( nOldState
== EmbedStates
.EMBED_LOADED
)
900 m_xEmbedObj
.changeState( EmbedStates
.EMBED_RUNNING
);
901 nState
= EmbedStates
.EMBED_RUNNING
;
904 if ( nState
== EmbedStates
.EMBED_UI_ACTIVE
|| nState
== EmbedStates
.EMBED_INPLACE_ACTIVE
905 || nState
== EmbedStates
.EMBED_ACTIVE
|| nState
== EmbedStates
.EMBED_RUNNING
)
907 XComponentSupplier xCompProv
= (XComponentSupplier
)UnoRuntime
.queryInterface(
908 XComponentSupplier
.class,
910 if ( xCompProv
!= null )
912 XCloseable xCloseable
= xCompProv
.getComponent();
913 XTransferable xTransfer
= (XTransferable
)UnoRuntime
.queryInterface(
916 if ( xTransfer
!= null )
918 DataFlavor aFlavor
= new DataFlavor();
919 aFlavor
.MimeType
= "application/x-openoffice;windows_formatname=\"Bitmap\"";
920 aFlavor
.HumanPresentableName
= "Bitmap";
921 aFlavor
.DataType
= new Type( byte[].class );
923 Object aAny
= xTransfer
.getTransferData( aFlavor
);
924 if ( aAny
!= null && AnyConverter
.isArray( aAny
) )
926 synchronized( m_oImageLock
)
928 m_xBitmap
= WindowHelper
.getVCLBitmapFromBytes( m_xServiceFactory
, aAny
);
929 if ( m_aBitmapPainter
!= null )
931 m_aBitmapPainter
.setBitmap( m_xBitmap
);
933 if ( m_xBitmap
!= null )
936 com
.sun
.star
.awt
.Size aBitmapSize
= m_xBitmap
.getSize();
937 com
.sun
.star
.awt
.Size aVisSize
= new com
.sun
.star
.awt
.Size(
938 (int)( aBitmapSize
.Width
* m_nXScaling
),
939 (int)( aBitmapSize
.Height
* m_nYScaling
) );
940 m_aBitmapPainter
.setSize( aVisSize
);
951 System
.out
.println( "paint() : can not get XTransferable for the component!\n" );
954 System
.out
.println( "paint() : XComponentSupplier is not implemented!\n" );
957 catch( com
.sun
.star
.uno
.Exception e
)
959 // dialogs should not be used in paint()
960 System
.out
.println( "Exception in paint(): " + e
);
965 public void mouseClicked( MouseEvent e
)
967 if( e
.getModifiers() == InputEvent
.BUTTON1_MASK
)
969 actionRegister( ACTIVATE_OUTPLACE
, null );
973 public void mousePressed( MouseEvent e
){};
974 public void mouseEntered( MouseEvent e
){};
975 public void mouseExited( MouseEvent e
){};
976 public void mouseReleased( MouseEvent e
){};
978 class NewMenuItem
extends MenuItem
implements ActionListener
// Menu New
982 super( "New", new MenuShortcut( KeyEvent
.VK_A
));
983 addActionListener( this );
986 public void actionPerformed( ActionEvent e
)
988 actionRegister( NEW_DOCUMENT
, null );
992 class SaveAsMenuItem
extends MenuItem
implements ActionListener
// Menu SaveAs...
994 public SaveAsMenuItem()
996 super( "SaveAs..." );
997 addActionListener( this );
1000 public void actionPerformed( ActionEvent e
)
1002 // open SaveAs dialog and store
1008 class OpenFileMenuItem
extends MenuItem
implements ActionListener
// Menu Open
1010 public OpenFileMenuItem()
1012 super( "Open", new MenuShortcut( KeyEvent
.VK_C
));
1013 addActionListener( this );
1016 public void actionPerformed( ActionEvent e
)
1018 // open OpenFile dialog and load doc
1019 FileDialog aFileDialog
= new FileDialog( m_aFrame
, "Open" );
1021 if ( aFileDialog
.getFile() != null )
1023 String aFileName
= aFileDialog
.getDirectory() + aFileDialog
.getFile();
1024 File aFile
= new File( aFileName
);
1025 if ( aFile
!= null )
1027 // create object from specified file
1028 String aFileURI
= getValidURL( aFile
.toURI().toASCIIString() );
1029 actionRegister( OPEN_FILE
, aFileURI
);
1035 class SaveMenuItem
extends MenuItem
implements ActionListener
// Menu Save
1037 public SaveMenuItem()
1039 super( "Save", new MenuShortcut( KeyEvent
.VK_D
));
1040 addActionListener( this );
1043 public void actionPerformed( ActionEvent e
)
1045 // if has persistance store there
1046 // if not open SaveAs dialog and store
1047 if ( m_xStorage
!= null && m_xEmbedObj
!= null )
1051 if ( m_xStorage
== null )
1053 JOptionPane
.showMessageDialog( m_aFrame
,
1054 "No storage for oned file!",
1056 JOptionPane
.ERROR_MESSAGE
);
1061 actionRegister( SAVE
, null );
1069 JOptionPane
.showMessageDialog( m_aFrame
, "No document is embedded!", "Error:", JOptionPane
.ERROR_MESSAGE
);
1073 class NewObjectMenuItem
extends MenuItem
implements ActionListener
// Menu NewObject
1075 public NewObjectMenuItem()
1077 super( "Create", new MenuShortcut( KeyEvent
.VK_N
));
1078 addActionListener( this );
1081 public void actionPerformed( ActionEvent e
)
1083 Object
[] possibleValues
= { "com.sun.star.comp.Writer.TextDocument",
1084 "com.sun.star.comp.Writer.GlobalDocument",
1085 "com.sun.star.comp.Writer.WebDocument",
1086 "com.sun.star.comp.Calc.SpreadsheetDocument",
1087 "com.sun.star.comp.Draw.PresentationDocument",
1088 "com.sun.star.comp.Draw.DrawingDocument",
1089 "com.sun.star.comp.Math.FormulaDocument",
1092 String selectedValue
= (String
)JOptionPane
.showInputDialog( null, "DocumentType", "Select",
1093 JOptionPane
.INFORMATION_MESSAGE
, null,
1094 possibleValues
, possibleValues
[0] );
1096 actionRegister( NEW_OBJECT
, selectedValue
);
1100 class LoadObjectMenuItem
extends MenuItem
implements ActionListener
// Menu LoadObject
1102 public LoadObjectMenuItem()
1104 super( "Load from file", new MenuShortcut( KeyEvent
.VK_L
));
1105 addActionListener( this );
1108 public void actionPerformed( ActionEvent e
)
1110 // open OpenFile dialog and load doc
1111 FileDialog aFileDialog
= new FileDialog( m_aFrame
, "Select sources to use for object init" );
1113 if ( aFileDialog
.getFile() != null )
1115 String aFileName
= aFileDialog
.getDirectory() + aFileDialog
.getFile();
1116 File aFile
= new File( aFileName
);
1117 if ( aFile
!= null )
1119 // create object from specified file
1120 String aFileURI
= getValidURL( aFile
.toURI().toASCIIString() );
1121 actionRegister( OBJECT_FROM_FILE
, aFileURI
);
1127 class LinkObjectMenuItem
extends MenuItem
implements ActionListener
// Menu LinkObject
1129 public LinkObjectMenuItem()
1131 super( "Create link", new MenuShortcut( KeyEvent
.VK_M
));
1132 addActionListener( this );
1135 public void actionPerformed( ActionEvent e
)
1137 // open OpenFile dialog and load doc
1138 FileDialog aFileDialog
= new FileDialog( m_aFrame
, "Select sources to use for object init" );
1140 if ( aFileDialog
.getFile() != null )
1142 String aFileName
= aFileDialog
.getDirectory() + aFileDialog
.getFile();
1143 File aFile
= new File( aFileName
);
1144 if ( aFile
!= null )
1146 // create object from specified file
1147 String aFileURI
= getValidURL( aFile
.toURI().toASCIIString() );
1148 actionRegister( LINK_FROM_FILE
, aFileURI
);
1154 class ConvertLinkToEmbedMenuItem
extends MenuItem
implements ActionListener
// Menu LinkObject
1156 public ConvertLinkToEmbedMenuItem()
1158 super( "Convert link to embed", new MenuShortcut( KeyEvent
.VK_M
));
1159 addActionListener( this );
1162 public void actionPerformed( ActionEvent e
)
1164 actionRegister( CONVERT_LINK_TO_OBJECT
, null );
1168 class ActivateOutplaceMenuItem
extends MenuItem
implements ActionListener
// Menu ActiveteOutplace
1170 public ActivateOutplaceMenuItem()
1172 super( "Activate outplace", new MenuShortcut( KeyEvent
.VK_A
));
1173 addActionListener( this );
1176 public void actionPerformed( ActionEvent e
)
1178 actionRegister( ACTIVATE_OUTPLACE
, null );
1182 class ActivateInplaceMenuItem
extends MenuItem
implements ActionListener
// Menu ActivateInplace
1184 public ActivateInplaceMenuItem()
1186 super( "Activate inplace", new MenuShortcut( KeyEvent
.VK_I
));
1187 addActionListener( this );
1190 public void actionPerformed( ActionEvent e
)
1192 actionRegister( ACTIVATE_INPLACE
, null );
1196 class DeactivateMenuItem
extends MenuItem
implements ActionListener
// Menu Deactivate
1198 public DeactivateMenuItem()
1200 super( "Deactivate", new MenuShortcut( KeyEvent
.VK_D
));
1201 addActionListener( this );
1204 public void actionPerformed( ActionEvent e
)
1206 actionRegister( DEACTIVATE
, null );
1211 public XEmbeddedObject
createEmbedObject( String aServiceName
)
1213 XEmbeddedObject xEmbObj
= null;
1214 byte[] pClassID
= new byte[16];
1216 if ( aServiceName
.equals( "com.sun.star.comp.Writer.TextDocument" ) )
1218 int[] pTempClassID
= { 0x8B, 0xC6, 0xB1, 0x65, 0xB1, 0xB2, 0x4E, 0xDD,
1219 0xAA, 0x47, 0xDA, 0xE2, 0xEE, 0x68, 0x9D, 0xD6 };
1220 for ( int ind
= 0; ind
< 16; ind
++ )
1221 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1223 else if ( aServiceName
.equals( "com.sun.star.comp.Writer.GlobalDocument" ) )
1225 int[] pTempClassID
= { 0xB2, 0x1A, 0x0A, 0x7C, 0xE4, 0x03, 0x41, 0xFE,
1226 0x95, 0x62, 0xBD, 0x13, 0xEA, 0x6F, 0x15, 0xA0 };
1227 for ( int ind
= 0; ind
< 16; ind
++ )
1228 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1230 else if ( aServiceName
.equals( "com.sun.star.comp.Writer.WebDocument" ) )
1232 int[] pTempClassID
= { 0xA8, 0xBB, 0xA6, 0x0C, 0x7C, 0x60, 0x45, 0x50,
1233 0x91, 0xCE, 0x39, 0xC3, 0x90, 0x3F, 0xAC, 0x5E };
1234 for ( int ind
= 0; ind
< 16; ind
++ )
1235 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1237 else if ( aServiceName
.equals( "com.sun.star.comp.Calc.SpreadsheetDocument" ) )
1239 int[] pTempClassID
= { 0x47, 0xBB, 0xB4, 0xCB, 0xCE, 0x4C, 0x4E, 0x80,
1240 0xA5, 0x91, 0x42, 0xD9, 0xAE, 0x74, 0x95, 0x0F };
1241 for ( int ind
= 0; ind
< 16; ind
++ )
1242 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1244 else if ( aServiceName
.equals( "com.sun.star.comp.Draw.PresentationDocument" ) )
1246 int[] pTempClassID
= { 0x91, 0x76, 0xE4, 0x8A, 0x63, 0x7A, 0x4D, 0x1F,
1247 0x80, 0x3B, 0x99, 0xD9, 0xBF, 0xAC, 0x10, 0x47 };
1248 for ( int ind
= 0; ind
< 16; ind
++ )
1249 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1251 else if ( aServiceName
.equals( "com.sun.star.comp.Draw.DrawingDocument" ) )
1253 int[] pTempClassID
= { 0x4B, 0xAB, 0x89, 0x70, 0x8A, 0x3B, 0x45, 0xB3,
1254 0x99, 0x1C, 0xCB, 0xEE, 0xAC, 0x6B, 0xD5, 0xE3 };
1255 for ( int ind
= 0; ind
< 16; ind
++ )
1256 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1258 else if ( aServiceName
.equals( "com.sun.star.comp.Math.FormulaDocument" ) )
1260 int[] pTempClassID
= { 0x07, 0x8B, 0x7A, 0xBA, 0x54, 0xFC, 0x45, 0x7F,
1261 0x85, 0x51, 0x61, 0x47, 0xE7, 0x76, 0xA9, 0x97 };
1262 for ( int ind
= 0; ind
< 16; ind
++ )
1263 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1265 else if ( aServiceName
.equals( "BitmapImage" ) )
1267 int[] pTempClassID
= { 0xD3, 0xE3, 0x4B, 0x21, 0x9D, 0x75, 0x10, 0x1A,
1268 0x8C, 0x3D, 0x00, 0xAA, 0x00, 0x1A, 0x16, 0x52 };
1269 for ( int ind
= 0; ind
< 16; ind
++ )
1270 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1273 if ( pClassID
!= null )
1275 // create embedded object based on the class ID
1277 Object oEmbedCreator
= m_xServiceFactory
.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" );
1278 XEmbedObjectCreator xEmbedCreator
= (XEmbedObjectCreator
)UnoRuntime
.queryInterface(
1279 XEmbedObjectCreator
.class,
1281 if ( xEmbedCreator
!= null )
1283 Object oEmbObj
= xEmbedCreator
.createInstanceInitNew( pClassID
,
1287 new PropertyValue
[0] );
1288 xEmbObj
= (XEmbeddedObject
)UnoRuntime
.queryInterface( XEmbeddedObject
.class, oEmbObj
);
1291 JOptionPane
.showMessageDialog( m_aFrame
,
1292 "Can't create EmbedCreator!",
1294 JOptionPane
.ERROR_MESSAGE
);
1296 catch( Exception e
)
1298 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in createInstanceInitNew():", JOptionPane
.ERROR_MESSAGE
);
1302 JOptionPane
.showMessageDialog( m_aFrame
, "Can't retrieve class ID!", "Error:", JOptionPane
.ERROR_MESSAGE
);
1307 public XEmbeddedObject
createLinkObject( String aLinkURL
)
1309 XEmbeddedObject xEmbObj
= null;
1312 Object oLinkCreator
= m_xServiceFactory
.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" );
1313 XLinkCreator xLinkCreator
= (XLinkCreator
)UnoRuntime
.queryInterface(
1316 if ( xLinkCreator
!= null )
1318 PropertyValue
[] aMedDescr
= { new PropertyValue(), new PropertyValue() };
1319 aMedDescr
[0].Name
= "URL";
1320 aMedDescr
[0].Value
= (Object
) aLinkURL
;
1321 aMedDescr
[1].Name
= "ReadOnly";
1322 aMedDescr
[1].Value
= (Object
) new Boolean( false );
1323 Object oEmbObj
= xLinkCreator
.createInstanceLink( m_xStorage
, "EmbedSub", aMedDescr
, new PropertyValue
[0] );
1324 xEmbObj
= (XEmbeddedObject
)UnoRuntime
.queryInterface( XEmbeddedObject
.class, oEmbObj
);
1327 JOptionPane
.showMessageDialog( m_aFrame
,
1328 "Can't create LinkCreator!",
1330 JOptionPane
.ERROR_MESSAGE
);
1332 catch( Exception e
)
1334 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in createLinkObject():", JOptionPane
.ERROR_MESSAGE
);
1342 public XEmbeddedObject
loadEmbedObject( String aFileURI
)
1344 XEmbeddedObject xEmbObj
= null;
1346 Object oEmbedCreator
= m_xServiceFactory
.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" );
1347 XEmbedObjectCreator xEmbedCreator
= (XEmbedObjectCreator
)UnoRuntime
.queryInterface(
1348 XEmbedObjectCreator
.class,
1350 if ( xEmbedCreator
!= null )
1352 PropertyValue
[] aMedDescr
= { new PropertyValue(), new PropertyValue() };
1353 aMedDescr
[0].Name
= "URL";
1354 aMedDescr
[0].Value
= (Object
) aFileURI
;
1355 aMedDescr
[1].Name
= "ReadOnly";
1356 aMedDescr
[1].Value
= (Object
) new Boolean( false );
1357 Object oEmbObj
= xEmbedCreator
.createInstanceInitFromMediaDescriptor( m_xStorage
,
1360 new PropertyValue
[0] );
1361 xEmbObj
= (XEmbeddedObject
)UnoRuntime
.queryInterface( XEmbeddedObject
.class, oEmbObj
);
1364 JOptionPane
.showMessageDialog( m_aFrame
,
1365 "Can't create EmbedFactory!",
1367 JOptionPane
.ERROR_MESSAGE
);
1369 catch( Exception e
)
1371 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in loadEmbedObject():", JOptionPane
.ERROR_MESSAGE
);
1377 public void clearObjectAndStorage()
1379 synchronized( m_oImageLock
)
1394 if ( m_xEmbedObj
!= null )
1397 XCloseable xClose
= (XCloseable
)UnoRuntime
.queryInterface( XCloseable
.class, m_xEmbedObj
);
1398 if ( xClose
!= null )
1399 xClose
.close( true );
1401 catch ( Exception ex
)
1406 if ( m_xStorage
!= null )
1409 XComponent xComponent
= (XComponent
)UnoRuntime
.queryInterface( XComponent
.class, m_xStorage
);
1410 if ( xComponent
!= null )
1411 xComponent
.dispose();
1413 catch ( Exception ex
)
1419 public XStorage
createTempStorage()
1421 XStorage xTempStorage
= null;
1424 Object oStorageFactory
= m_xServiceFactory
.createInstance( "com.sun.star.embed.StorageFactory" );
1425 XSingleServiceFactory xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
1426 XSingleServiceFactory
.class,
1428 if ( xStorageFactory
!= null )
1430 Object oStorage
= xStorageFactory
.createInstance();
1431 xTempStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
1434 JOptionPane
.showMessageDialog( m_aFrame
,
1435 "Can't create StorageFactory!",
1437 JOptionPane
.ERROR_MESSAGE
);
1439 catch( Exception e
)
1441 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in createTempStorage():", JOptionPane
.ERROR_MESSAGE
);
1444 return xTempStorage
;
1447 public void saveObjectAsFileURI( String aFileURI
)
1450 Object oStorageFactory
= m_xServiceFactory
.createInstance( "com.sun.star.embed.StorageFactory" );
1451 XSingleServiceFactory xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
1452 XSingleServiceFactory
.class,
1454 if ( xStorageFactory
!= null )
1456 XEmbedPersist xPersist
= (XEmbedPersist
)UnoRuntime
.queryInterface( XEmbedPersist
.class, m_xEmbedObj
);
1457 if ( xPersist
!= null )
1459 Object aArgs
[] = new Object
[2];
1460 aArgs
[0] = aFileURI
;
1461 aArgs
[1] = new Integer( ElementModes
.ELEMENT_READWRITE
);
1463 Object oStorage
= xStorageFactory
.createInstanceWithArguments( aArgs
);
1464 XStorage xTargetStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
1466 PropertyValue aProps
[] = { new PropertyValue() };
1467 aProps
[0].Name
= "StoreVisualReplacement";
1468 aProps
[0].Value
= new Boolean( m_bStoreVisRepl
);
1470 xPersist
.storeAsEntry( xTargetStorage
, "EmbedSub", new PropertyValue
[0], aProps
);
1471 xPersist
.saveCompleted( true );
1473 // the object must be already based on new storage
1474 XComponent xComponent
= (XComponent
)UnoRuntime
.queryInterface( XComponent
.class, m_xStorage
);
1475 xComponent
.dispose();
1477 m_xStorage
= xTargetStorage
;
1480 XTransactedObject xTransact
= (XTransactedObject
)UnoRuntime
.queryInterface( XTransactedObject
.class,
1482 if ( xTransact
!= null )
1486 JOptionPane
.showMessageDialog( m_aFrame
, "No XEmbedPersist!", "Error:", JOptionPane
.ERROR_MESSAGE
);
1489 JOptionPane
.showMessageDialog( m_aFrame
,
1490 "Can't create StorageFactory!",
1492 JOptionPane
.ERROR_MESSAGE
);
1494 catch( Exception e
)
1496 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in saveStorageToFileURI():", JOptionPane
.ERROR_MESSAGE
);
1501 public void loadFileURI( String aFileURI
)
1505 Object oStorageFactory
= m_xServiceFactory
.createInstance( "com.sun.star.embed.StorageFactory" );
1506 XSingleServiceFactory xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
1507 XSingleServiceFactory
.class,
1509 Object aArgs
[] = new Object
[2];
1510 aArgs
[0] = aFileURI
;
1511 aArgs
[1] = new Integer( ElementModes
.ELEMENT_READWRITE
);
1513 Object oStorage
= xStorageFactory
.createInstanceWithArguments( aArgs
);
1514 XStorage xTargetStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
1516 Object oEmbedCreator
= m_xServiceFactory
.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" );
1517 XEmbedObjectCreator xEmbedCreator
= (XEmbedObjectCreator
)UnoRuntime
.queryInterface(
1518 XEmbedObjectCreator
.class,
1521 XNameAccess xNameAccess
= (XNameAccess
)UnoRuntime
.queryInterface( XNameAccess
.class,
1523 if ( xNameAccess
== null )
1525 JOptionPane
.showMessageDialog( m_aFrame
, "No XNameAccess!", "Error:", JOptionPane
.ERROR_MESSAGE
);
1529 Object oEmbObj
= null;
1530 if ( xNameAccess
.hasByName( "LinkName" ) && xTargetStorage
.isStreamElement( "LinkName" ) )
1533 // OOo links will not be tested until they have correct persistence
1534 XStream xLinkStream = xTargetStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_READ );
1535 if ( xLinkStream != null )
1537 XInputStream xInStream = xLinkStream.getInputStream();
1538 if ( xInStream != null )
1540 byte[][] pBuff = new byte[1][0];
1541 int nRead = xInStream.readBytes( pBuff, 1000 );
1542 m_aLinkURI = new String( pBuff[0] );
1543 xInStream.closeInput();
1544 oEmbObj = xEmbedCreator.createInstanceLink( m_aLinkURI );
1551 oEmbObj
= xEmbedCreator
.createInstanceInitFromEntry( xTargetStorage
,
1554 new PropertyValue
[0] );
1556 m_xEmbedObj
= (XEmbeddedObject
)UnoRuntime
.queryInterface( XEmbeddedObject
.class, oEmbObj
);
1558 if ( m_xEmbedObj
!= null )
1560 m_xStorage
= xTargetStorage
;
1564 JOptionPane
.showMessageDialog( m_aFrame
,
1565 "Can't create EmbedObject from storage!",
1567 JOptionPane
.ERROR_MESSAGE
);
1569 catch( Exception e
)
1571 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in loadFileURI():", JOptionPane
.ERROR_MESSAGE
);
1575 public void storeLinkToStorage()
1577 if ( m_xStorage
!= null && m_bLinkObj
)
1580 XStream xLinkStream
= m_xStorage
.openStreamElement( "LinkName", ElementModes
.ELEMENT_WRITE
);
1582 if ( xLinkStream
!= null )
1584 XOutputStream xLinkOutStream
= xLinkStream
.getOutputStream();
1585 XTruncate xTruncate
= (XTruncate
) UnoRuntime
.queryInterface( XTruncate
.class,
1587 if ( xLinkOutStream
!= null && xTruncate
!= null )
1589 xTruncate
.truncate();
1591 char[] aLinkChar
= m_aLinkURI
.toCharArray();
1592 byte[] aLinkBytes
= new byte[ aLinkChar
.length
];
1593 for ( int ind
= 0; ind
< aLinkChar
.length
; ind
++ )
1594 aLinkBytes
[ind
] = (byte)aLinkChar
[ind
];
1596 xLinkOutStream
.writeBytes( aLinkBytes
);
1597 xLinkOutStream
.closeOutput();
1599 XComponent xComponent
= (XComponent
) UnoRuntime
.queryInterface( XComponent
.class,
1601 if ( xComponent
!= null )
1602 xComponent
.dispose();
1605 JOptionPane
.showMessageDialog( m_aFrame
,
1606 "The substream can not be truncated or written!",
1608 JOptionPane
.ERROR_MESSAGE
);
1612 JOptionPane
.showMessageDialog( m_aFrame
,
1613 "Can't create/open substream!",
1615 JOptionPane
.ERROR_MESSAGE
);
1617 catch( Exception e
)
1619 JOptionPane
.showMessageDialog( m_aFrame
,
1621 "Exception in storeLinkToStorage:",
1622 JOptionPane
.ERROR_MESSAGE
);
1628 public void storeLinkAsFileURI( String aFileURI
)
1631 Object oStorageFactory
= m_xServiceFactory
.createInstance( "com.sun.star.embed.StorageFactory" );
1632 XSingleServiceFactory xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
1633 XSingleServiceFactory
.class,
1635 if ( xStorageFactory
!= null )
1637 Object aArgs
[] = new Object
[2];
1638 aArgs
[0] = aFileURI
;
1639 aArgs
[1] = new Integer( ElementModes
.ELEMENT_READWRITE
);
1641 Object oStorage
= xStorageFactory
.createInstanceWithArguments( aArgs
);
1642 XStorage xTargetStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
1644 XComponent xComponent
= (XComponent
)UnoRuntime
.queryInterface( XComponent
.class, m_xStorage
);
1645 xComponent
.dispose();
1647 m_xStorage
= xTargetStorage
;
1650 storeLinkToStorage();
1652 XTransactedObject xTransact
= (XTransactedObject
)UnoRuntime
.queryInterface( XTransactedObject
.class,
1654 if ( xTransact
!= null )
1658 JOptionPane
.showMessageDialog( m_aFrame
,
1659 "Can't create StorageFactory!",
1661 JOptionPane
.ERROR_MESSAGE
);
1663 catch( Exception e
)
1665 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in saveStorageToFileURI():", JOptionPane
.ERROR_MESSAGE
);
1669 public String
getValidURL( String sFileURL
)
1671 // m_xTransformer must be set!
1672 URL
[] aURLs
= { new URL() };
1673 aURLs
[0].Complete
= sFileURL
;
1676 if ( !m_xTransformer
.parseSmart( aURLs
, "" ) )
1677 throw new Exception();
1679 catch( Exception e
)
1681 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in getValidURL():", JOptionPane
.ERROR_MESSAGE
);
1684 return aURLs
[0].Complete
;
1687 public void disposeObject()
1690 // usage of object, storage and bitmap painter should be locked
1691 // but since possibility of rasecondition is very low
1692 // it is not really required for testing application
1694 clearObjectAndStorage();
1696 if ( m_aBitmapPainter
!= null )
1698 m_aBitmapPainter
.disconnectListener();
1699 m_aBitmapPainter
= null;