ChangeParaAdjust.bsh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * This file is part of the LibreOffice project.
  3. *
  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/.
  7. */
  8. import com.sun.star.beans.XPropertySet;
  9. import com.sun.star.lang.XServiceInfo;
  10. import com.sun.star.uno.UnoRuntime;
  11. import com.sun.star.frame.XModel;
  12. import com.sun.star.container.XEnumeration;
  13. import com.sun.star.container.XEnumerationAccess;
  14. import com.sun.star.text.XTextDocument;
  15. import com.sun.star.text.XText;
  16. oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
  17. if ( oDoc == null )
  18. oDoc = XSCRIPTCONTEXT.getDocument();
  19. xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
  20. xText = xTextDoc.getText();
  21. XEnumerationAccess xEnumAcc = (XEnumerationAccess)(UnoRuntime.queryInterface(XEnumerationAccess.class, xText));
  22. XEnumeration xEnum = xEnumAcc.createEnumeration();
  23. while (xEnum.hasMoreElements()) {
  24. Object xObj = xEnum.nextElement();
  25. XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xObj);
  26. if (xServiceInfo.supportsService("com.sun.star.text.Paragraph")) {
  27. XPropertySet xSet = UnoRuntime.queryInterface(XPropertySet.class, xServiceInfo );
  28. // Set the justification to be center justified
  29. xSet.setPropertyValue( "ParaAdjust", com.sun.star.style.ParagraphAdjust.CENTER );
  30. }
  31. }
  32. return 0;