OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[impress]how to set background image using java

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
satishbejgum
Power User
Power User


Joined: 17 Sep 2007
Posts: 74

PostPosted: Fri Jan 11, 2008 10:44 am    Post subject: [impress]how to set background image using java Reply with quote

Hello Everyone

Can any any tell me how set a image as back ground for slide, it need not to be embedded in to the file
Thanks
Back to top
View user's profile Send private message
satishbejgum
Power User
Power User


Joined: 17 Sep 2007
Posts: 74

PostPosted: Mon Jun 23, 2008 10:07 pm    Post subject: Reply with quote

Code:
 public void callinMain() {
        try {
            java.io.File sourceFile = new java.io.File("C:/Documents and Settings/prameelar/Desktop/wwwwwww.odp");
            StringBuffer sUrl = new StringBuffer("file:///");
            sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
            XComponent xComponent = loadDocument(sUrl.toString());
            com.sun.star.style.XStyleFamiliesSupplier xSFS = (com.sun.star.style.XStyleFamiliesSupplier) UnoRuntime.queryInterface(com.sun.star.style.XStyleFamiliesSupplier.class, xComponent);
            com.sun.star.container.XNameAccess xFamilies = xSFS.getStyleFamilies();
            String[] Families = xFamilies.getElementNames();
            Object aFamilyObj = xFamilies.getByName(Families[1]); //page style
            com.sun.star.container.XNameAccess xStyles = (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, aFamilyObj);
            String[] elementNames = xStyles.getElementNames();
            for (int i = 0; i < elementNames.length; i++) {
                String string = elementNames[i];
                System.out.println(string);
                if (string.equals("background")) {
                    XPropertySet xpro = (XPropertySet) AnyConverter.toObject(XPropertySet.class, xStyles.getByName(string));
                    sourceFile = new java.io.File("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Picture1.jpg");
                    sUrl = new StringBuffer("file:///");
                    sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
                    String convertedURL = getInternalURL(xComponent, sUrl.toString(), "name");
                    xpro.setPropertyValue("FillStyle", FillStyle.BITMAP_value);
                    xpro.setPropertyValue("FillBackground", new Boolean(true));
                    xpro.setPropertyValue("FillBitmapURL", convertedURL);
                    xpro.setPropertyValue("FillBitmapTile", new Boolean(false));
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(Bullets.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
Back to top
View user's profile Send private message
ssureshkumar
Power User
Power User


Joined: 21 Dec 2005
Posts: 71

PostPosted: Wed Jun 25, 2008 4:27 am    Post subject: Reply with quote

Hi sathish,
Thanks for posting this code. This is useful for all.
Can you please post the code for the method

getInternalURL(xComponent, sUrl.toString(), "name");

thanks,
Suresh.
Back to top
View user's profile Send private message
satishbejgum
Power User
Power User


Joined: 17 Sep 2007
Posts: 74

PostPosted: Wed Jun 25, 2008 9:25 pm    Post subject: Reply with quote

Code:
public String getInternalURL(XComponent xDrawDoc, String srcUrl, String imgName)  {
        try {

            XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc);
            Object xBitObj = xFactory.createInstance("com.sun.star.drawing.BitmapTable");
            XNameContainer bitMaps = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xBitObj);           
            bitMaps.insertByName(imgName, srcUrl);
            return (String) bitMaps.getByName(imgName);
        } catch (Exception ex) {
           
        }
        return null;
    }
Back to top
View user's profile Send private message
ssureshkumar
Power User
Power User


Joined: 21 Dec 2005
Posts: 71

PostPosted: Fri Jun 27, 2008 5:19 am    Post subject: Reply with quote

hi sathish,
thanks for posting the code.
but it throws com.sun.star.container.NoSuchElementException in the
line (String) bitMaps.getByName(imgName);

can you please help in this regard?

Thanks,
Suresh.
Back to top
View user's profile Send private message
satishbejgum
Power User
Power User


Joined: 17 Sep 2007
Posts: 74

PostPosted: Sun Jun 29, 2008 8:43 pm    Post subject: Reply with quote

I think there no image to that path.
do a sample test, debug your code.
when you enter into getInternalURL method, check what is value of srcUrl.
copy that value and paste on the address bar of your browser.
i think you wont get that image.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group