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
;
128 private Vector m_aActionsList
;
130 private Timer m_aTimer
;
131 private boolean m_bDestroyed
= false;
133 private Object m_oInHandlerLock
;
134 private boolean m_bInHandler
= false;
136 private XURLTransformer m_xTransformer
;
138 private NativeView m_aNativeView
;
139 private XWindow m_xVCLWindow
;
141 private XBitmap m_xBitmap
;
142 private BitmapPainter m_aBitmapPainter
;
145 private final byte DESTROY
= 1;
146 private final byte ACTIVATE_OUTPLACE
= 2;
147 private final byte NEW_DOCUMENT
= 3;
148 private final byte SAVE_AS
= 4;
149 private final byte OPEN_FILE
= 5;
150 private final byte SAVE
= 6;
151 private final byte NEW_OBJECT
= 7;
152 private final byte OBJECT_FROM_FILE
= 8;
153 private final byte LINK_FROM_FILE
= 9;
154 private final byte CONVERT_LINK_TO_OBJECT
= 10;
155 private final byte ACTIVATE_INPLACE
= 11;
156 private final byte DEACTIVATE
= 12;
159 public EmbedContApp( Frame aFrame
, XMultiServiceFactory xServiceFactory
)
162 m_xServiceFactory
= xServiceFactory
;
168 setBackground( Color
.gray
);
170 m_aToolkit
= Toolkit
.getDefaultToolkit();
173 Object oTransformer
= m_xServiceFactory
.createInstance( "com.sun.star.util.URLTransformer" );
174 m_xTransformer
= (XURLTransformer
)UnoRuntime
.queryInterface( XURLTransformer
.class, oTransformer
);
175 } catch( Exception e
) { System
.exit( 0 ); }
177 m_oActionsNumberLock
= new Object();
178 m_aActionsList
= new Vector();
180 m_oInHandlerLock
= new Object();
181 m_oImageLock
= new Object();
184 Object oJob
= m_xServiceFactory
.createInstance( "com.sun.star.comp.thread.MainThreadExecutor" );
185 m_xMainThreadExecutor
= (XJob
)UnoRuntime
.queryInterface( XJob
.class, oJob
);
186 } catch( Exception e
) {}
188 if ( m_xMainThreadExecutor
== null )
190 System
.out
.println( "Can't create MainThreadExecutor! The application is unusable!" );
199 m_pValuesForExecutor
= new NamedValue
[1];
200 m_pValuesForExecutor
[0] = new NamedValue( "JobToExecute", (Object
)this );
202 m_aTimer
= new Timer( 100, this );
206 MenuBar aMenuBar
= m_aFrame
.getMenuBar();
207 if( aMenuBar
== null )
209 aMenuBar
= new MenuBar();
210 m_aFrame
.setMenuBar( aMenuBar
);
213 // Create menus for the menu bar.
216 m_aFileMenu
= new Menu( "File", true );
217 aMenuBar
.add( m_aFileMenu
);
219 MenuItem aItem
= new NewMenuItem();
220 m_aFileMenu
.add( aItem
);
222 aItem
= new OpenFileMenuItem();
223 m_aFileMenu
.add( aItem
);
225 aItem
= new SaveMenuItem();
226 m_aFileMenu
.add( aItem
);
228 aItem
= new SaveAsMenuItem();
229 m_aFileMenu
.add( aItem
);
232 m_aObjectMenu
= new Menu( "Object", true );
233 aMenuBar
.add( m_aObjectMenu
);
235 aItem
= new NewObjectMenuItem();
236 m_aObjectMenu
.add( aItem
);
238 aItem
= new LoadObjectMenuItem();
239 m_aObjectMenu
.add( aItem
);
241 aItem
= new LinkObjectMenuItem();
242 m_aObjectMenu
.add( aItem
);
244 aItem
= new ConvertLinkToEmbedMenuItem();
245 m_aObjectMenu
.add( aItem
);
248 m_aObjectMenu
= new Menu( "Activation", true );
249 aMenuBar
.add( m_aObjectMenu
);
251 aItem
= new ActivateOutplaceMenuItem();
252 m_aObjectMenu
.add( aItem
);
254 aItem
= new ActivateInplaceMenuItem();
255 m_aObjectMenu
.add( aItem
);
257 aItem
= new DeactivateMenuItem();
258 m_aObjectMenu
.add( aItem
);
260 m_aNativeView
= new NativeView();
261 m_aNativeView
.resize( 800, 600 );
262 this.add( m_aNativeView
);
264 // Handle mouse clicks in our window.
265 // addMouseListener( this );
268 public void actionPerformed( ActionEvent evt
)
270 synchronized( m_oInHandlerLock
)
277 synchronized( m_oActionsNumberLock
)
279 if ( m_aActionsList
.size() > 0 )
282 m_xMainThreadExecutor
.execute( m_pValuesForExecutor
);
286 System
.out
.println( "Exception in actionPerformed() : " + e
);
291 synchronized( m_oInHandlerLock
)
293 m_bInHandler
= false;
300 public XWindow
getWindow()
306 public void saveObject()
307 throws com
.sun
.star
.uno
.Exception
309 if ( m_xEmbedObj
!= null )
312 XEmbedPersist xPersist
= (XEmbedPersist
)UnoRuntime
.queryInterface( XEmbedPersist
.class, m_xEmbedObj
);
313 if ( xPersist
!= null )
319 JOptionPane
.showMessageDialog( m_aFrame
, "No XEmbedPersist!", "Error:", JOptionPane
.ERROR_MESSAGE
);
323 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in saveObject:", JOptionPane
.ERROR_MESSAGE
);
331 public void onShowWindow( boolean bVisible
)
333 // for now nothing to do
337 public boolean canInplaceActivate()
342 public void onInplaceActivate()
345 // prepare for inplace activation
348 // workaround for CLIPCHILDREN problem
349 if ( m_aBitmapPainter
!= null )
350 m_aBitmapPainter
.stopPainting();
353 public void onUIActivate()
356 // prepare for UI activate
359 public void onInplaceDeactivate()
362 // inplace deactivation is done
365 // workaround for CLIPCHILDREN problem
366 if ( m_aBitmapPainter
!= null )
367 m_aBitmapPainter
.startPainting();
370 public void onUIDeactivate()
373 // prepare for UI deactivate
376 public XIPMainContainerWindow
getTopmostWindow()
379 // return an implementation of XIPMainContainerWindow
380 // mainly required for ui activation
381 // dummy implementation is enough for inplace activation
386 public XInplaceUIWindow
getDocumentWindow()
389 // return implementation of XInplaceUIWindow
390 // mainly required for ui activation
391 // dummy implementation is enough for inplace activation
396 public com
.sun
.star
.awt
.Rectangle
getPosRect()
398 // provide position rectangle to the object
400 // here object bitmap and scaling factor hold the size
401 com
.sun
.star
.awt
.Size aBitmapSize
= m_xBitmap
.getSize();
402 com
.sun
.star
.awt
.Size aVisSize
= new com
.sun
.star
.awt
.Size(
403 (int)( aBitmapSize
.Width
* m_nXScaling
),
404 (int)( aBitmapSize
.Height
* m_nYScaling
) );
405 return new com
.sun
.star
.awt
.Rectangle( 10, 10, aVisSize
.Width
, aVisSize
.Height
);
409 System
.out
.println( "Position rectangle generation failed!" );
412 return new com
.sun
.star
.awt
.Rectangle( 10, 10, 110, 110 );
415 public com
.sun
.star
.awt
.Rectangle
getClipRect()
417 // provide clip rectangle to the object
418 // in this application position and clip rectangles are the same
421 // here object bitmap and scaling factor hold the size
422 com
.sun
.star
.awt
.Size aBitmapSize
= m_xBitmap
.getSize();
423 com
.sun
.star
.awt
.Size aVisSize
= new com
.sun
.star
.awt
.Size(
424 (int)( aBitmapSize
.Width
* m_nXScaling
),
425 (int)( aBitmapSize
.Height
* m_nYScaling
) );
426 return new com
.sun
.star
.awt
.Rectangle( 10, 10, aVisSize
.Width
, aVisSize
.Height
);
430 System
.out
.println( "Clip rectangle generation failed!" );
433 return new com
.sun
.star
.awt
.Rectangle( 10, 10, 110, 110 );
436 public void translateAccelerators( com
.sun
.star
.awt
.KeyEvent
[] aKeys
)
439 // an accelerator table for object
440 // ui activation related
443 public void scrollObj( com
.sun
.star
.awt
.Size aOffset
)
446 // scrolls the object to a specified offset
447 // not mandatory for the testing application :)
450 public void onPosRectChange( com
.sun
.star
.awt
.Rectangle aPosRect
)
452 // object asks to change the position
453 if ( m_xEmbedObj
!= null )
456 int nState
= m_xEmbedObj
.getCurrentState();
457 // such a position change make sence only when object is
458 // either inplace or ui active
459 if ( nState
== EmbedStates
.EMBED_INPLACE_ACTIVE
460 || nState
== EmbedStates
.EMBED_UI_ACTIVE
)
462 XInplaceObject xInplObj
= (XInplaceObject
)UnoRuntime
.queryInterface( XInplaceObject
.class, m_xEmbedObj
);
463 if ( xInplObj
!= null )
465 xInplObj
.setObjectRects( aPosRect
, aPosRect
); // show the whole object
466 if ( m_aBitmapPainter
!= null )
467 m_aBitmapPainter
.setRect( aPosRect
);
470 System
.out
.println( "Why object that does not support inplace activation behave like inplace object?!" );
473 System
.out
.println( "The object is not active but asks to change visual area!" );
474 } catch( Exception e
)
476 System
.out
.println( "Exception is thrown in onPosRectChange: " + e
);
480 System
.out
.println( "Who asks to change visual area?!!" );
484 public Object
execute( NamedValue
[] pValues
)
486 for( int nInd
= 0; nInd
< m_aActionsList
.size(); nInd
++ )
488 ActionObject aAction
= ( ActionObject
) m_aActionsList
.get( nInd
);
489 if ( aAction
!= null )
491 if ( aAction
.m_nID
== DESTROY
)
493 // free all resources
494 clearObjectAndStorage();
497 else if ( aAction
.m_nID
== ACTIVATE_OUTPLACE
)
499 // activate object if exists and not active
500 if ( m_xEmbedObj
!= null )
503 m_xEmbedObj
.changeState( EmbedStates
.EMBED_ACTIVE
);
505 catch( Exception ex
)
507 System
.out
.println( "Exception on mouse click" + ex
);
511 else if ( aAction
.m_nID
== NEW_DOCUMENT
)
514 clearObjectAndStorage();
518 else if ( aAction
.m_nID
== SAVE_AS
)
520 // open SaveAs dialog and store
522 if ( m_xStorage
!= null && m_xEmbedObj
!= null )
527 storeLinkAsFileURI( aFileURI );
530 saveObjectAsFileURI( aAction
.m_sParam
);
532 catch( Exception ex
)
534 System
.out
.println( "Exception in SaveAsMenuItem: " + ex
);
538 else if ( aAction
.m_nID
== OPEN_FILE
)
541 clearObjectAndStorage();
543 // load from specified file
544 loadFileURI( aAction
.m_sParam
);
546 if ( m_xEmbedObj
!= null )
549 m_xEmbedObj
.setClientSite( this );
551 catch( Exception ex
)
553 System
.out
.println( "Exception in OpenFileMenuItem: " + ex
);
560 else if ( aAction
.m_nID
== SAVE
)
562 if ( m_xStorage
!= null && m_xEmbedObj
!= null )
564 // if has persistance store there
565 // if not it is and error, SaveAs had to be used
569 if ( m_xStorage
!= null )
575 storeLinkToStorage();
577 XTransactedObject xTransact
= (XTransactedObject
)UnoRuntime
.queryInterface( XTransactedObject
.class,
579 if ( xTransact
!= null )
582 catch( Exception ex
)
584 System
.out
.println( "Exception during save operation in SaveMenuItem:" + ex
);
589 System
.out
.println( "No storage for owned file!" );
594 System
.out
.println( "No owned file!" );
598 else if ( aAction
.m_nID
== NEW_OBJECT
)
600 // remove current object an init a new one
601 clearObjectAndStorage();
603 if ( aAction
.m_sParam
!= null )
605 m_xStorage
= createTempStorage();
607 if ( m_xStorage
!= null )
608 m_xEmbedObj
= createEmbedObject( aAction
.m_sParam
);
610 System
.out
.println( "Can't create temporary storage!" );
612 if ( m_xEmbedObj
!= null )
615 m_xEmbedObj
.setClientSite( this );
617 catch( Exception ex
)
619 System
.out
.println( "Exception in NewObjectMenuItem:" + ex
);
627 else if ( aAction
.m_nID
== OBJECT_FROM_FILE
)
629 // first remove current object
630 clearObjectAndStorage();
632 // create object from specified file
633 m_xStorage
= createTempStorage();
635 if ( m_xStorage
!= null )
636 m_xEmbedObj
= loadEmbedObject( aAction
.m_sParam
);
638 if ( m_xEmbedObj
!= null )
641 m_xEmbedObj
.setClientSite( this );
643 catch( Exception ex
)
645 System
.out
.println( "Exception in LoadObjectMenuItem: " + ex
);
652 else if ( aAction
.m_nID
== LINK_FROM_FILE
)
654 // first remove current object
655 clearObjectAndStorage();
657 m_xStorage
= createTempStorage();
659 // create object from specified file
660 m_xEmbedObj
= createLinkObject( aAction
.m_sParam
);
662 if ( m_xEmbedObj
!= null )
664 m_aLinkURI
= aAction
.m_sParam
;
668 m_xEmbedObj
.setClientSite( this );
670 catch( Exception ex
)
672 System
.out
.println( "Exception in LinkObjectMenuItem:" + ex
);
679 else if ( aAction
.m_nID
== CONVERT_LINK_TO_OBJECT
)
683 System
.out
.println( "The object is not a link!" );
687 if ( m_xEmbedObj
!= null )
689 if ( m_xStorage
!= null )
692 XNameAccess xNameAccess
= (XNameAccess
)UnoRuntime
.queryInterface( XNameAccess
.class,
694 if ( xNameAccess
!= null && xNameAccess
.hasByName( "LinkName" ) )
695 m_xStorage
.removeElement( "LinkName" );
697 XLinkageSupport xLinkage
= (XLinkageSupport
)UnoRuntime
.queryInterface( XLinkageSupport
.class,
699 if ( xLinkage
!= null )
701 xLinkage
.breakLink( m_xStorage
, "EmbedSub" );
706 System
.out
.println( "No XLinkageSupport in ConvertLink... !" );
708 catch( Exception e1
)
710 System
.out
.println( "Exception in ConvertLinkToEmbed:try 1 :" + e1
);
715 else if ( aAction
.m_nID
== ACTIVATE_INPLACE
)
718 if ( m_xEmbedObj
!= null )
720 // in general it is better to check acceptable states
722 m_xEmbedObj
.changeState( EmbedStates
.EMBED_INPLACE_ACTIVE
);
724 catch( Exception ex
)
726 System
.out
.println( "Exception on inplace activation " + ex
);
730 else if ( aAction
.m_nID
== DEACTIVATE
)
734 if ( m_xEmbedObj
!= null )
738 nOldState
= m_xEmbedObj
.getCurrentState();
739 } catch( Exception e
)
742 if ( nOldState
== EmbedStates
.EMBED_ACTIVE
743 || nOldState
== EmbedStates
.EMBED_INPLACE_ACTIVE
744 || nOldState
== EmbedStates
.EMBED_UI_ACTIVE
)
747 m_xEmbedObj
.changeState( EmbedStates
.EMBED_RUNNING
);
749 catch( Exception ex
)
751 System
.out
.println( "Exception on inplace activation " + ex
);
756 System
.out
.println( "Deactivation of nonactive object!" );
762 System
.out
.println( "Unknoun action is requested: " + aAction
.m_nID
+ "\n" );
767 m_aActionsList
.clear();
769 synchronized( m_oInHandlerLock
)
771 m_bInHandler
= false;
777 public void actionRegister( byte nActionID
, String sParam
)
779 synchronized( m_oActionsNumberLock
)
781 int nSize
= m_aActionsList
.size();
785 m_aActionsList
.add( new ActionObject( nActionID
, sParam
) );
788 ActionObject aAction
= ( ActionObject
) m_aActionsList
.get( nSize
- 1 );
789 if ( aAction
!= null && aAction
.m_nID
!= DESTROY
)
790 m_aActionsList
.add( new ActionObject( nActionID
, sParam
) );
796 public void SaveAsOperation()
798 if ( m_xStorage
!= null && m_xEmbedObj
!= null )
800 FileDialog aFileDialog
= new FileDialog( m_aFrame
, "SaveAs", FileDialog
.SAVE
);
802 if ( aFileDialog
.getFile() != null )
804 String aFileName
= aFileDialog
.getDirectory() + aFileDialog
.getFile();
805 File aFile
= new File( aFileName
);
808 // create object from specified file
809 String aFileURI
= getValidURL( aFile
.toURI().toASCIIString() );
810 actionRegister( SAVE_AS
, aFileURI
);
815 JOptionPane
.showMessageDialog( m_aFrame
, "No document is embedded!", "Error:", JOptionPane
.ERROR_MESSAGE
);
819 public void destroy()
821 // redirect the call through the timer and call super.destroy();
822 actionRegister( DESTROY
, null );
824 for ( int i
= 0; i
< 3 && !m_bDestroyed
; i
++ )
828 } catch ( Exception e
)
833 System
.out
.println( "The object application can not exit correctly!" );
840 public void update( Graphics g
)
845 public void paint( Graphics g
)
849 // m_aNativeView.paint( g );
854 public void createVclWindow()
856 synchronized( m_oImageLock
)
858 if ( m_xVCLWindow
== null && m_xServiceFactory
!= null && m_xEmbedObj
!= null && m_xBitmap
!= null )
860 java
.awt
.Rectangle aBounds
= getBounds();
861 m_xVCLWindow
= WindowHelper
.createWindow( m_xServiceFactory
, m_aNativeView
, aBounds
);
862 m_xVCLWindow
.setVisible( true );
864 com
.sun
.star
.awt
.Size aBitmapSize
= new com
.sun
.star
.awt
.Size( 200, 100 );
866 XVisualObject xVisObj
= (XVisualObject
)UnoRuntime
.queryInterface( XVisualObject
.class, m_xEmbedObj
);
868 com
.sun
.star
.awt
.Size aVisSize
= xVisObj
.getVisAreaSize( Aspects
.MSASPECT_CONTENT
);
869 m_nXPixelSize
= aVisSize
.Width
/ aBitmapSize
.Width
;
870 m_nYPixelSize
= aVisSize
.Height
/ aBitmapSize
.Height
;
876 if ( m_xBitmap
!= null )
877 aBitmapSize
= m_xBitmap
.getSize();
879 System
.out
.println( "The visual area is Width = " + aBitmapSize
.Width
+ "; Height = " + aBitmapSize
.Height
);
881 com
.sun
.star
.awt
.Rectangle aRect
= new com
.sun
.star
.awt
.Rectangle(
884 Math
.min( (int)aBounds
.getWidth() - 20, aBitmapSize
.Width
),
885 Math
.min( (int)aBounds
.getHeight() - 20, aBitmapSize
.Height
) );
887 m_aBitmapPainter
= new BitmapPainter( m_xMainThreadExecutor
, m_xVCLWindow
, m_xBitmap
, aRect
);
892 public void generateNewImage()
894 if ( m_xEmbedObj
!= null )
897 int nOldState
= m_xEmbedObj
.getCurrentState();
898 int nState
= nOldState
;
899 if ( nOldState
== EmbedStates
.EMBED_LOADED
)
901 m_xEmbedObj
.changeState( EmbedStates
.EMBED_RUNNING
);
902 nState
= EmbedStates
.EMBED_RUNNING
;
905 if ( nState
== EmbedStates
.EMBED_UI_ACTIVE
|| nState
== EmbedStates
.EMBED_INPLACE_ACTIVE
906 || nState
== EmbedStates
.EMBED_ACTIVE
|| nState
== EmbedStates
.EMBED_RUNNING
)
908 XComponentSupplier xCompProv
= (XComponentSupplier
)UnoRuntime
.queryInterface(
909 XComponentSupplier
.class,
911 if ( xCompProv
!= null )
913 XCloseable xCloseable
= xCompProv
.getComponent();
914 XTransferable xTransfer
= (XTransferable
)UnoRuntime
.queryInterface(
917 if ( xTransfer
!= null )
919 DataFlavor aFlavor
= new DataFlavor();
920 aFlavor
.MimeType
= "application/x-openoffice;windows_formatname=\"Bitmap\"";
921 aFlavor
.HumanPresentableName
= "Bitmap";
922 aFlavor
.DataType
= new Type( byte[].class );
924 Object aAny
= xTransfer
.getTransferData( aFlavor
);
925 if ( aAny
!= null && AnyConverter
.isArray( aAny
) )
927 synchronized( m_oImageLock
)
929 m_xBitmap
= WindowHelper
.getVCLBitmapFromBytes( m_xServiceFactory
, aAny
);
930 if ( m_aBitmapPainter
!= null )
932 m_aBitmapPainter
.setBitmap( m_xBitmap
);
934 if ( m_xBitmap
!= null )
937 com
.sun
.star
.awt
.Size aBitmapSize
= m_xBitmap
.getSize();
938 com
.sun
.star
.awt
.Size aVisSize
= new com
.sun
.star
.awt
.Size(
939 (int)( aBitmapSize
.Width
* m_nXScaling
),
940 (int)( aBitmapSize
.Height
* m_nYScaling
) );
941 m_aBitmapPainter
.setSize( aVisSize
);
952 System
.out
.println( "paint() : can not get XTransferable for the component!\n" );
955 System
.out
.println( "paint() : XComponentSupplier is not implemented!\n" );
958 catch( com
.sun
.star
.uno
.Exception e
)
960 // dialogs should not be used in paint()
961 System
.out
.println( "Exception in paint(): " + e
);
966 public void mouseClicked( MouseEvent e
)
968 if( e
.getModifiers() == InputEvent
.BUTTON1_MASK
)
970 actionRegister( ACTIVATE_OUTPLACE
, null );
974 public void mousePressed( MouseEvent e
){};
975 public void mouseEntered( MouseEvent e
){};
976 public void mouseExited( MouseEvent e
){};
977 public void mouseReleased( MouseEvent e
){};
979 class NewMenuItem
extends MenuItem
implements ActionListener
// Menu New
983 super( "New", new MenuShortcut( KeyEvent
.VK_A
));
984 addActionListener( this );
987 public void actionPerformed( ActionEvent e
)
989 actionRegister( NEW_DOCUMENT
, null );
993 class SaveAsMenuItem
extends MenuItem
implements ActionListener
// Menu SaveAs...
995 public SaveAsMenuItem()
997 super( "SaveAs..." );
998 addActionListener( this );
1001 public void actionPerformed( ActionEvent e
)
1003 // open SaveAs dialog and store
1009 class OpenFileMenuItem
extends MenuItem
implements ActionListener
// Menu Open
1011 public OpenFileMenuItem()
1013 super( "Open", new MenuShortcut( KeyEvent
.VK_C
));
1014 addActionListener( this );
1017 public void actionPerformed( ActionEvent e
)
1019 // open OpenFile dialog and load doc
1020 FileDialog aFileDialog
= new FileDialog( m_aFrame
, "Open" );
1022 if ( aFileDialog
.getFile() != null )
1024 String aFileName
= aFileDialog
.getDirectory() + aFileDialog
.getFile();
1025 File aFile
= new File( aFileName
);
1026 if ( aFile
!= null )
1028 // create object from specified file
1029 String aFileURI
= getValidURL( aFile
.toURI().toASCIIString() );
1030 actionRegister( OPEN_FILE
, aFileURI
);
1036 class SaveMenuItem
extends MenuItem
implements ActionListener
// Menu Save
1038 public SaveMenuItem()
1040 super( "Save", new MenuShortcut( KeyEvent
.VK_D
));
1041 addActionListener( this );
1044 public void actionPerformed( ActionEvent e
)
1046 // if has persistance store there
1047 // if not open SaveAs dialog and store
1048 if ( m_xStorage
!= null && m_xEmbedObj
!= null )
1052 if ( m_xStorage
== null )
1054 JOptionPane
.showMessageDialog( m_aFrame
,
1055 "No storage for oned file!",
1057 JOptionPane
.ERROR_MESSAGE
);
1062 actionRegister( SAVE
, null );
1070 JOptionPane
.showMessageDialog( m_aFrame
, "No document is embedded!", "Error:", JOptionPane
.ERROR_MESSAGE
);
1074 class NewObjectMenuItem
extends MenuItem
implements ActionListener
// Menu NewObject
1076 public NewObjectMenuItem()
1078 super( "Create", new MenuShortcut( KeyEvent
.VK_N
));
1079 addActionListener( this );
1082 public void actionPerformed( ActionEvent e
)
1084 Object
[] possibleValues
= { "com.sun.star.comp.Writer.TextDocument",
1085 "com.sun.star.comp.Writer.GlobalDocument",
1086 "com.sun.star.comp.Writer.WebDocument",
1087 "com.sun.star.comp.Calc.SpreadsheetDocument",
1088 "com.sun.star.comp.Draw.PresentationDocument",
1089 "com.sun.star.comp.Draw.DrawingDocument",
1090 "com.sun.star.comp.Math.FormulaDocument",
1093 String selectedValue
= (String
)JOptionPane
.showInputDialog( null, "DocumentType", "Select",
1094 JOptionPane
.INFORMATION_MESSAGE
, null,
1095 possibleValues
, possibleValues
[0] );
1097 actionRegister( NEW_OBJECT
, selectedValue
);
1101 class LoadObjectMenuItem
extends MenuItem
implements ActionListener
// Menu LoadObject
1103 public LoadObjectMenuItem()
1105 super( "Load from file", new MenuShortcut( KeyEvent
.VK_L
));
1106 addActionListener( this );
1109 public void actionPerformed( ActionEvent e
)
1111 // open OpenFile dialog and load doc
1112 FileDialog aFileDialog
= new FileDialog( m_aFrame
, "Select sources to use for object init" );
1114 if ( aFileDialog
.getFile() != null )
1116 String aFileName
= aFileDialog
.getDirectory() + aFileDialog
.getFile();
1117 File aFile
= new File( aFileName
);
1118 if ( aFile
!= null )
1120 // create object from specified file
1121 String aFileURI
= getValidURL( aFile
.toURI().toASCIIString() );
1122 actionRegister( OBJECT_FROM_FILE
, aFileURI
);
1128 class LinkObjectMenuItem
extends MenuItem
implements ActionListener
// Menu LinkObject
1130 public LinkObjectMenuItem()
1132 super( "Create link", new MenuShortcut( KeyEvent
.VK_M
));
1133 addActionListener( this );
1136 public void actionPerformed( ActionEvent e
)
1138 // open OpenFile dialog and load doc
1139 FileDialog aFileDialog
= new FileDialog( m_aFrame
, "Select sources to use for object init" );
1141 if ( aFileDialog
.getFile() != null )
1143 String aFileName
= aFileDialog
.getDirectory() + aFileDialog
.getFile();
1144 File aFile
= new File( aFileName
);
1145 if ( aFile
!= null )
1147 // create object from specified file
1148 String aFileURI
= getValidURL( aFile
.toURI().toASCIIString() );
1149 actionRegister( LINK_FROM_FILE
, aFileURI
);
1155 class ConvertLinkToEmbedMenuItem
extends MenuItem
implements ActionListener
// Menu LinkObject
1157 public ConvertLinkToEmbedMenuItem()
1159 super( "Convert link to embed", new MenuShortcut( KeyEvent
.VK_M
));
1160 addActionListener( this );
1163 public void actionPerformed( ActionEvent e
)
1165 actionRegister( CONVERT_LINK_TO_OBJECT
, null );
1169 class ActivateOutplaceMenuItem
extends MenuItem
implements ActionListener
// Menu ActiveteOutplace
1171 public ActivateOutplaceMenuItem()
1173 super( "Activate outplace", new MenuShortcut( KeyEvent
.VK_A
));
1174 addActionListener( this );
1177 public void actionPerformed( ActionEvent e
)
1179 actionRegister( ACTIVATE_OUTPLACE
, null );
1183 class ActivateInplaceMenuItem
extends MenuItem
implements ActionListener
// Menu ActivateInplace
1185 public ActivateInplaceMenuItem()
1187 super( "Activate inplace", new MenuShortcut( KeyEvent
.VK_I
));
1188 addActionListener( this );
1191 public void actionPerformed( ActionEvent e
)
1193 actionRegister( ACTIVATE_INPLACE
, null );
1197 class DeactivateMenuItem
extends MenuItem
implements ActionListener
// Menu Deactivate
1199 public DeactivateMenuItem()
1201 super( "Deactivate", new MenuShortcut( KeyEvent
.VK_D
));
1202 addActionListener( this );
1205 public void actionPerformed( ActionEvent e
)
1207 actionRegister( DEACTIVATE
, null );
1212 public XEmbeddedObject
createEmbedObject( String aServiceName
)
1214 XEmbeddedObject xEmbObj
= null;
1215 byte[] pClassID
= new byte[16];
1217 if ( aServiceName
.equals( "com.sun.star.comp.Writer.TextDocument" ) )
1219 int[] pTempClassID
= { 0x8B, 0xC6, 0xB1, 0x65, 0xB1, 0xB2, 0x4E, 0xDD,
1220 0xAA, 0x47, 0xDA, 0xE2, 0xEE, 0x68, 0x9D, 0xD6 };
1221 for ( int ind
= 0; ind
< 16; ind
++ )
1222 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1224 else if ( aServiceName
.equals( "com.sun.star.comp.Writer.GlobalDocument" ) )
1226 int[] pTempClassID
= { 0xB2, 0x1A, 0x0A, 0x7C, 0xE4, 0x03, 0x41, 0xFE,
1227 0x95, 0x62, 0xBD, 0x13, 0xEA, 0x6F, 0x15, 0xA0 };
1228 for ( int ind
= 0; ind
< 16; ind
++ )
1229 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1231 else if ( aServiceName
.equals( "com.sun.star.comp.Writer.WebDocument" ) )
1233 int[] pTempClassID
= { 0xA8, 0xBB, 0xA6, 0x0C, 0x7C, 0x60, 0x45, 0x50,
1234 0x91, 0xCE, 0x39, 0xC3, 0x90, 0x3F, 0xAC, 0x5E };
1235 for ( int ind
= 0; ind
< 16; ind
++ )
1236 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1238 else if ( aServiceName
.equals( "com.sun.star.comp.Calc.SpreadsheetDocument" ) )
1240 int[] pTempClassID
= { 0x47, 0xBB, 0xB4, 0xCB, 0xCE, 0x4C, 0x4E, 0x80,
1241 0xA5, 0x91, 0x42, 0xD9, 0xAE, 0x74, 0x95, 0x0F };
1242 for ( int ind
= 0; ind
< 16; ind
++ )
1243 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1245 else if ( aServiceName
.equals( "com.sun.star.comp.Draw.PresentationDocument" ) )
1247 int[] pTempClassID
= { 0x91, 0x76, 0xE4, 0x8A, 0x63, 0x7A, 0x4D, 0x1F,
1248 0x80, 0x3B, 0x99, 0xD9, 0xBF, 0xAC, 0x10, 0x47 };
1249 for ( int ind
= 0; ind
< 16; ind
++ )
1250 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1252 else if ( aServiceName
.equals( "com.sun.star.comp.Draw.DrawingDocument" ) )
1254 int[] pTempClassID
= { 0x4B, 0xAB, 0x89, 0x70, 0x8A, 0x3B, 0x45, 0xB3,
1255 0x99, 0x1C, 0xCB, 0xEE, 0xAC, 0x6B, 0xD5, 0xE3 };
1256 for ( int ind
= 0; ind
< 16; ind
++ )
1257 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1259 else if ( aServiceName
.equals( "com.sun.star.comp.Math.FormulaDocument" ) )
1261 int[] pTempClassID
= { 0x07, 0x8B, 0x7A, 0xBA, 0x54, 0xFC, 0x45, 0x7F,
1262 0x85, 0x51, 0x61, 0x47, 0xE7, 0x76, 0xA9, 0x97 };
1263 for ( int ind
= 0; ind
< 16; ind
++ )
1264 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1266 else if ( aServiceName
.equals( "BitmapImage" ) )
1268 int[] pTempClassID
= { 0xD3, 0xE3, 0x4B, 0x21, 0x9D, 0x75, 0x10, 0x1A,
1269 0x8C, 0x3D, 0x00, 0xAA, 0x00, 0x1A, 0x16, 0x52 };
1270 for ( int ind
= 0; ind
< 16; ind
++ )
1271 pClassID
[ind
] = (byte)pTempClassID
[ind
];
1274 if ( pClassID
!= null )
1276 // create embedded object based on the class ID
1278 Object oEmbedCreator
= m_xServiceFactory
.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" );
1279 XEmbedObjectCreator xEmbedCreator
= (XEmbedObjectCreator
)UnoRuntime
.queryInterface(
1280 XEmbedObjectCreator
.class,
1282 if ( xEmbedCreator
!= null )
1284 Object oEmbObj
= xEmbedCreator
.createInstanceInitNew( pClassID
,
1288 new PropertyValue
[0] );
1289 xEmbObj
= (XEmbeddedObject
)UnoRuntime
.queryInterface( XEmbeddedObject
.class, oEmbObj
);
1292 JOptionPane
.showMessageDialog( m_aFrame
,
1293 "Can't create EmbedCreator!",
1295 JOptionPane
.ERROR_MESSAGE
);
1297 catch( Exception e
)
1299 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in createInstanceInitNew():", JOptionPane
.ERROR_MESSAGE
);
1303 JOptionPane
.showMessageDialog( m_aFrame
, "Can't retrieve class ID!", "Error:", JOptionPane
.ERROR_MESSAGE
);
1308 public XEmbeddedObject
createLinkObject( String aLinkURL
)
1310 XEmbeddedObject xEmbObj
= null;
1313 Object oLinkCreator
= m_xServiceFactory
.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" );
1314 XLinkCreator xLinkCreator
= (XLinkCreator
)UnoRuntime
.queryInterface(
1317 if ( xLinkCreator
!= null )
1319 PropertyValue
[] aMedDescr
= { new PropertyValue(), new PropertyValue() };
1320 aMedDescr
[0].Name
= "URL";
1321 aMedDescr
[0].Value
= (Object
) aLinkURL
;
1322 aMedDescr
[1].Name
= "ReadOnly";
1323 aMedDescr
[1].Value
= (Object
) new Boolean( false );
1324 Object oEmbObj
= xLinkCreator
.createInstanceLink( m_xStorage
, "EmbedSub", aMedDescr
, new PropertyValue
[0] );
1325 xEmbObj
= (XEmbeddedObject
)UnoRuntime
.queryInterface( XEmbeddedObject
.class, oEmbObj
);
1328 JOptionPane
.showMessageDialog( m_aFrame
,
1329 "Can't create LinkCreator!",
1331 JOptionPane
.ERROR_MESSAGE
);
1333 catch( Exception e
)
1335 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in createLinkObject():", JOptionPane
.ERROR_MESSAGE
);
1343 public XEmbeddedObject
loadEmbedObject( String aFileURI
)
1345 XEmbeddedObject xEmbObj
= null;
1347 Object oEmbedCreator
= m_xServiceFactory
.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" );
1348 XEmbedObjectCreator xEmbedCreator
= (XEmbedObjectCreator
)UnoRuntime
.queryInterface(
1349 XEmbedObjectCreator
.class,
1351 if ( xEmbedCreator
!= null )
1353 PropertyValue
[] aMedDescr
= { new PropertyValue(), new PropertyValue() };
1354 aMedDescr
[0].Name
= "URL";
1355 aMedDescr
[0].Value
= (Object
) aFileURI
;
1356 aMedDescr
[1].Name
= "ReadOnly";
1357 aMedDescr
[1].Value
= (Object
) new Boolean( false );
1358 Object oEmbObj
= xEmbedCreator
.createInstanceInitFromMediaDescriptor( m_xStorage
,
1361 new PropertyValue
[0] );
1362 xEmbObj
= (XEmbeddedObject
)UnoRuntime
.queryInterface( XEmbeddedObject
.class, oEmbObj
);
1365 JOptionPane
.showMessageDialog( m_aFrame
,
1366 "Can't create EmbedFactory!",
1368 JOptionPane
.ERROR_MESSAGE
);
1370 catch( Exception e
)
1372 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in loadEmbedObject():", JOptionPane
.ERROR_MESSAGE
);
1378 public void clearObjectAndStorage()
1380 synchronized( m_oImageLock
)
1395 if ( m_xEmbedObj
!= null )
1398 XCloseable xClose
= (XCloseable
)UnoRuntime
.queryInterface( XCloseable
.class, m_xEmbedObj
);
1399 if ( xClose
!= null )
1400 xClose
.close( true );
1402 catch ( Exception ex
)
1407 if ( m_xStorage
!= null )
1410 XComponent xComponent
= (XComponent
)UnoRuntime
.queryInterface( XComponent
.class, m_xStorage
);
1411 if ( xComponent
!= null )
1412 xComponent
.dispose();
1414 catch ( Exception ex
)
1420 public XStorage
createTempStorage()
1422 XStorage xTempStorage
= null;
1425 Object oStorageFactory
= m_xServiceFactory
.createInstance( "com.sun.star.embed.StorageFactory" );
1426 XSingleServiceFactory xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
1427 XSingleServiceFactory
.class,
1429 if ( xStorageFactory
!= null )
1431 Object oStorage
= xStorageFactory
.createInstance();
1432 xTempStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
1435 JOptionPane
.showMessageDialog( m_aFrame
,
1436 "Can't create StorageFactory!",
1438 JOptionPane
.ERROR_MESSAGE
);
1440 catch( Exception e
)
1442 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in createTempStorage():", JOptionPane
.ERROR_MESSAGE
);
1445 return xTempStorage
;
1448 public void saveObjectAsFileURI( String aFileURI
)
1451 Object oStorageFactory
= m_xServiceFactory
.createInstance( "com.sun.star.embed.StorageFactory" );
1452 XSingleServiceFactory xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
1453 XSingleServiceFactory
.class,
1455 if ( xStorageFactory
!= null )
1457 XEmbedPersist xPersist
= (XEmbedPersist
)UnoRuntime
.queryInterface( XEmbedPersist
.class, m_xEmbedObj
);
1458 if ( xPersist
!= null )
1460 Object aArgs
[] = new Object
[2];
1461 aArgs
[0] = aFileURI
;
1462 aArgs
[1] = new Integer( ElementModes
.ELEMENT_READWRITE
);
1464 Object oStorage
= xStorageFactory
.createInstanceWithArguments( aArgs
);
1465 XStorage xTargetStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
1467 PropertyValue aProps
[] = { new PropertyValue() };
1468 aProps
[0].Name
= "StoreVisualReplacement";
1469 aProps
[0].Value
= new Boolean( m_bStoreVisRepl
);
1471 xPersist
.storeAsEntry( xTargetStorage
, "EmbedSub", new PropertyValue
[0], aProps
);
1472 xPersist
.saveCompleted( true );
1474 // the object must be already based on new storage
1475 XComponent xComponent
= (XComponent
)UnoRuntime
.queryInterface( XComponent
.class, m_xStorage
);
1476 xComponent
.dispose();
1478 m_xStorage
= xTargetStorage
;
1481 XTransactedObject xTransact
= (XTransactedObject
)UnoRuntime
.queryInterface( XTransactedObject
.class,
1483 if ( xTransact
!= null )
1487 JOptionPane
.showMessageDialog( m_aFrame
, "No XEmbedPersist!", "Error:", JOptionPane
.ERROR_MESSAGE
);
1490 JOptionPane
.showMessageDialog( m_aFrame
,
1491 "Can't create StorageFactory!",
1493 JOptionPane
.ERROR_MESSAGE
);
1495 catch( Exception e
)
1497 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in saveStorageToFileURI():", JOptionPane
.ERROR_MESSAGE
);
1502 public void loadFileURI( String aFileURI
)
1506 Object oStorageFactory
= m_xServiceFactory
.createInstance( "com.sun.star.embed.StorageFactory" );
1507 XSingleServiceFactory xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
1508 XSingleServiceFactory
.class,
1510 Object aArgs
[] = new Object
[2];
1511 aArgs
[0] = aFileURI
;
1512 aArgs
[1] = new Integer( ElementModes
.ELEMENT_READWRITE
);
1514 Object oStorage
= xStorageFactory
.createInstanceWithArguments( aArgs
);
1515 XStorage xTargetStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
1517 Object oEmbedCreator
= m_xServiceFactory
.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" );
1518 XEmbedObjectCreator xEmbedCreator
= (XEmbedObjectCreator
)UnoRuntime
.queryInterface(
1519 XEmbedObjectCreator
.class,
1522 XNameAccess xNameAccess
= (XNameAccess
)UnoRuntime
.queryInterface( XNameAccess
.class,
1524 if ( xNameAccess
== null )
1526 JOptionPane
.showMessageDialog( m_aFrame
, "No XNameAccess!", "Error:", JOptionPane
.ERROR_MESSAGE
);
1530 Object oEmbObj
= null;
1531 if ( xNameAccess
.hasByName( "LinkName" ) && xTargetStorage
.isStreamElement( "LinkName" ) )
1534 // OOo links will not be tested until they have correct persistence
1535 XStream xLinkStream = xTargetStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_READ );
1536 if ( xLinkStream != null )
1538 XInputStream xInStream = xLinkStream.getInputStream();
1539 if ( xInStream != null )
1541 byte[][] pBuff = new byte[1][0];
1542 int nRead = xInStream.readBytes( pBuff, 1000 );
1543 m_aLinkURI = new String( pBuff[0] );
1544 xInStream.closeInput();
1545 oEmbObj = xEmbedCreator.createInstanceLink( m_aLinkURI );
1552 oEmbObj
= xEmbedCreator
.createInstanceInitFromEntry( xTargetStorage
,
1555 new PropertyValue
[0] );
1557 m_xEmbedObj
= (XEmbeddedObject
)UnoRuntime
.queryInterface( XEmbeddedObject
.class, oEmbObj
);
1559 if ( m_xEmbedObj
!= null )
1561 m_xStorage
= xTargetStorage
;
1565 JOptionPane
.showMessageDialog( m_aFrame
,
1566 "Can't create EmbedObject from storage!",
1568 JOptionPane
.ERROR_MESSAGE
);
1570 catch( Exception e
)
1572 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in loadFileURI():", JOptionPane
.ERROR_MESSAGE
);
1576 public void storeLinkToStorage()
1578 if ( m_xStorage
!= null && m_bLinkObj
)
1581 XStream xLinkStream
= m_xStorage
.openStreamElement( "LinkName", ElementModes
.ELEMENT_WRITE
);
1583 if ( xLinkStream
!= null )
1585 XOutputStream xLinkOutStream
= xLinkStream
.getOutputStream();
1586 XTruncate xTruncate
= (XTruncate
) UnoRuntime
.queryInterface( XTruncate
.class,
1588 if ( xLinkOutStream
!= null && xTruncate
!= null )
1590 xTruncate
.truncate();
1592 char[] aLinkChar
= m_aLinkURI
.toCharArray();
1593 byte[] aLinkBytes
= new byte[ aLinkChar
.length
];
1594 for ( int ind
= 0; ind
< aLinkChar
.length
; ind
++ )
1595 aLinkBytes
[ind
] = (byte)aLinkChar
[ind
];
1597 xLinkOutStream
.writeBytes( aLinkBytes
);
1598 xLinkOutStream
.closeOutput();
1600 XComponent xComponent
= (XComponent
) UnoRuntime
.queryInterface( XComponent
.class,
1602 if ( xComponent
!= null )
1603 xComponent
.dispose();
1606 JOptionPane
.showMessageDialog( m_aFrame
,
1607 "The substream can not be truncated or written!",
1609 JOptionPane
.ERROR_MESSAGE
);
1613 JOptionPane
.showMessageDialog( m_aFrame
,
1614 "Can't create/open substream!",
1616 JOptionPane
.ERROR_MESSAGE
);
1618 catch( Exception e
)
1620 JOptionPane
.showMessageDialog( m_aFrame
,
1622 "Exception in storeLinkToStorage:",
1623 JOptionPane
.ERROR_MESSAGE
);
1629 public void storeLinkAsFileURI( String aFileURI
)
1632 Object oStorageFactory
= m_xServiceFactory
.createInstance( "com.sun.star.embed.StorageFactory" );
1633 XSingleServiceFactory xStorageFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
1634 XSingleServiceFactory
.class,
1636 if ( xStorageFactory
!= null )
1638 Object aArgs
[] = new Object
[2];
1639 aArgs
[0] = aFileURI
;
1640 aArgs
[1] = new Integer( ElementModes
.ELEMENT_READWRITE
);
1642 Object oStorage
= xStorageFactory
.createInstanceWithArguments( aArgs
);
1643 XStorage xTargetStorage
= (XStorage
)UnoRuntime
.queryInterface( XStorage
.class, oStorage
);
1645 XComponent xComponent
= (XComponent
)UnoRuntime
.queryInterface( XComponent
.class, m_xStorage
);
1646 xComponent
.dispose();
1648 m_xStorage
= xTargetStorage
;
1651 storeLinkToStorage();
1653 XTransactedObject xTransact
= (XTransactedObject
)UnoRuntime
.queryInterface( XTransactedObject
.class,
1655 if ( xTransact
!= null )
1659 JOptionPane
.showMessageDialog( m_aFrame
,
1660 "Can't create StorageFactory!",
1662 JOptionPane
.ERROR_MESSAGE
);
1664 catch( Exception e
)
1666 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in saveStorageToFileURI():", JOptionPane
.ERROR_MESSAGE
);
1670 public String
getValidURL( String sFileURL
)
1672 // m_xTransformer must be set!
1673 URL
[] aURLs
= { new URL() };
1674 aURLs
[0].Complete
= sFileURL
;
1677 if ( !m_xTransformer
.parseSmart( aURLs
, "" ) )
1678 throw new Exception();
1680 catch( Exception e
)
1682 JOptionPane
.showMessageDialog( m_aFrame
, e
, "Exception in getValidURL():", JOptionPane
.ERROR_MESSAGE
);
1685 return aURLs
[0].Complete
;
1688 public void disposeObject()
1691 // usage of object, storage and bitmap painter should be locked
1692 // but since possibility of rasecondition is very low
1693 // it is not really required for testing application
1695 clearObjectAndStorage();
1697 if ( m_aBitmapPainter
!= null )
1699 m_aBitmapPainter
.disconnectListener();
1700 m_aBitmapPainter
= null;