com.sun.star.lang.XMultiServiceFactory Java Examples

The following examples show how to use com.sun.star.lang.XMultiServiceFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractInliner.java    From yarg with Apache License 2.0 6 votes vote down vote up
protected void insertImage(XComponent document, OfficeResourceProvider officeResourceProvider, XText destination, XTextRange textRange,
                           Image image) throws Exception {
    XMultiServiceFactory xFactory = as(XMultiServiceFactory.class, document);
    XComponentContext xComponentContext = officeResourceProvider.getXComponentContext();
    XMultiComponentFactory serviceManager = xComponentContext.getServiceManager();

    Object oImage = xFactory.createInstance(TEXT_GRAPHIC_OBJECT);
    Object oGraphicProvider = serviceManager.createInstanceWithContext(GRAPHIC_PROVIDER_OBJECT, xComponentContext);

    XGraphicProvider xGraphicProvider = as(XGraphicProvider.class, oGraphicProvider);

    XPropertySet imageProperties = buildImageProperties(xGraphicProvider, oImage, image.imageContent);
    XTextContent xTextContent = as(XTextContent.class, oImage);
    destination.insertTextContent(textRange, xTextContent, true);
    setImageSize(image.width, image.height, oImage, imageProperties);
}
 
Example #2
Source File: ApplicationInfo.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method can be used to get any info from the application that is available.
 * (Possible paths and keys can be retrieved with the dumpInfo method).
 * Returns the object described by the path and key, or <code>null</code> if not available.
 * 
 * @param path the path to the key information
 * @param key the key to get the value for
 * 
 * @return the object described by the path and key, or <code>null</code> if not available
 * 
 * @throws Exception if retreiving the value fails
 * 
 * @author Markus Krüger
 * @date 18.11.2008
 */
public Object getInfo(String path, String key) throws Exception {
  Object configProviderObject = serviceProvider.createService("com.sun.star.comp.configuration.ConfigurationProvider");
  XMultiServiceFactory xConfigServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
      configProviderObject);
  String readConfAccess = "com.sun.star.configuration.ConfigurationAccess";
  PropertyValue[] properties = new PropertyValue[1];
  properties[0] = new PropertyValue();
  properties[0].Name = "nodepath";
  properties[0].Value = path;
  Object configReadAccessObject = xConfigServiceFactory.createInstanceWithArguments(readConfAccess,
      properties);
  XNameAccess xConfigNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
      configReadAccessObject);
  return xConfigNameAccess.getByName(key);
}
 
Example #3
Source File: TextTableService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Constructs new text table.
 * 
 * @param rows rows to be added
 * @param columns columns to be added
 * 
 * @return new table
 * 
 * @throws TextException if the new text table can not be constructed
 * 
 * @author Andreas Bröker
 */
public ITextTable constructTextTable(int rows, int columns) throws TextException {
	if(columns > ITextTable.MAX_COLUMNS_IN_TABLE) {
		throw new TextException("The submitted table is not valid");
	}
  try {
    XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, textDocument.getXTextDocument());
    Object newTable = xMultiServiceFactory.createInstance("com.sun.star.text.TextTable");
    XTextTable newTextTable = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, newTable);
    newTextTable.initialize(rows,columns);
    
    TextTable textTable = new TextTable(textDocument, newTextTable);
    return textTable;
  }
  catch(Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example #4
Source File: RemoteOfficeConnection.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Opens connection to OpenOffice.org.
 * 
 * @return information whether the connection is available
 * 
 * @throws Exception if any error occurs
 */
public boolean openConnection() throws Exception {
  String unoUrl = "uno:socket,host=" + host + ",port=" + port +";urp;StarOffice.ServiceManager";
  XComponentContext xLocalContext = Bootstrap.createInitialComponentContext(null);
  Object connector = xLocalContext.getServiceManager().createInstanceWithContext("com.sun.star.connection.Connector", xLocalContext);
  XConnector xConnector = (XConnector) UnoRuntime.queryInterface(XConnector.class, connector);
  
  String url[] = parseUnoUrl(unoUrl);
  if (null == url) {
    throw new com.sun.star.uno.Exception("Couldn't parse UNO URL "+ unoUrl);
  }
  
  XConnection connection = xConnector.connect(url[0]);
  Object bridgeFactory = xLocalContext.getServiceManager().createInstanceWithContext("com.sun.star.bridge.BridgeFactory", xLocalContext);
  XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class, bridgeFactory);
  xBridge = xBridgeFactory.createBridge("", url[1], connection ,null);
  bridgeFactory = xBridge.getInstance(url[2]);
  xMultiComponentFactory = (XMultiComponentFactory)UnoRuntime.queryInterface(XMultiComponentFactory.class, bridgeFactory);
  XPropertySet xProperySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xMultiComponentFactory);
  Object remoteContext = xProperySet.getPropertyValue("DefaultContext");
  xRemoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, remoteContext);
  xMultiServiceFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xMultiComponentFactory);
  isConnectionEstablished = true;
  return true;      
}
 
Example #5
Source File: VariableTextFieldMaster.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Constructs new variable text field on the basis of this variable text field master.
 * TODO maybe some more parameters are needed???
 * 
 * @param content the content of the variable textfield
 * @param visible if the variable should be visible
 * @param numberFormat the number format used for the variable
 * @param isFormula if the given content is a formula
 * 
 * @return new constructed variable text field on the basis of this variable text field master
 * 
 * @throws NOAException if the new variable text field can not be constructed
 * 
 * @author Markus Krüger
 * @date 30.05.2007
 */
public ITextField constructNewVariableTextField(String content, boolean visible,
    INumberFormat numberFormat, boolean isFormula) throws NOAException {
  try {
    XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, textDocument.getXTextDocument());
    Object textField = xMultiServiceFactory.createInstance(ITextFieldService.VARIABLES_TEXTFIELD_ID);
    XDependentTextField xDependentTextField = (XDependentTextField)UnoRuntime.queryInterface(XDependentTextField.class, textField);
    xDependentTextField.attachTextFieldMaster(xPropertySet);

    XPropertySet xPropertySetField = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xDependentTextField);
    xPropertySetField.setPropertyValue("IsVisible", new Boolean(visible));
    xPropertySetField.setPropertyValue("IsFixedLanguage", new Boolean(false));  
    
    ITextField variableTextField = new TextField(textDocument, xDependentTextField);

    INumberFormatService numberFormatService = textDocument.getNumberFormatService();
    VariableTextFieldHelper.setContent(content,variableTextField,isFormula,numberFormatService);
    if(numberFormat != null)
      VariableTextFieldHelper.applyNumberFormat(numberFormat,variableTextField,isFormula,numberFormatService);
    
    return variableTextField;
  }
  catch(Throwable throwable) {
    throw new NOAException(throwable);
  }
}
 
Example #6
Source File: TextTableCell.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns text service.
 * 
 * @return text service
 * 
 * @author Andreas Bröker
 * @author Markus Krüger
 */
public ITextService getTextService() {
  if(textService == null) {
    XText xText = (XText)UnoRuntime.queryInterface(XText.class, xCell);
    XMultiServiceFactory xMultiServiceFactory = 
      (XMultiServiceFactory)UnoRuntime.queryInterface(
          XMultiServiceFactory.class, getTextDocument().getXTextDocument());
    textService = new TextService(textDocument, xMultiServiceFactory, xText);
  }
  return textService;
}
 
Example #7
Source File: ServiceInterfaceSupplier.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the XDesktop interface from the OpenOffice.org desktop service.
 * 
 * @param xMultiServiceFactory factory in order to construct the service
 * 
 * @return XDesktop interface from the OpenOffice.org desktop service
 * 
 * @throws Exception if any error occurs
 */
public static XDesktop getXDesktop(XMultiServiceFactory xMultiServiceFactory) throws Exception {
	Object service = xMultiServiceFactory.createInstance("com.sun.star.frame.Desktop");
	if(service != null) {
		return (XDesktop)UnoRuntime.queryInterface(XDesktop.class, service);
	}
	else {
		return null;
	}
}
 
Example #8
Source File: TextContentService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convert linked text images to embedded images.
 * 
 * @throws TextException if conversion fails
 * 
 * @author Markus Krüger
 * @date 07.09.2009
 */
public void convertLinkedImagesToEmbeded() throws TextException {
  try {
    XTextGraphicObjectsSupplier graphicObjSupplier = (XTextGraphicObjectsSupplier) UnoRuntime.queryInterface(XTextGraphicObjectsSupplier.class,
        textDocument.getXTextDocument());
    XNameAccess nameAccess = graphicObjSupplier.getGraphicObjects();
    String[] names = nameAccess.getElementNames();
    for (int i = 0; i < names.length; i++) {
      Any xImageAny = (Any) nameAccess.getByName(names[i]);
      Object xImageObject = xImageAny.getObject();
      XTextContent xImage = (XTextContent) xImageObject;
      XServiceInfo xInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xImage);
      if (xInfo.supportsService("com.sun.star.text.TextGraphicObject")) {
        XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
            xImage);
        String name = xPropSet.getPropertyValue("LinkDisplayName").toString();
        String graphicURL = xPropSet.getPropertyValue("GraphicURL").toString();
        //only ones that are not embedded
        if (graphicURL.indexOf("vnd.sun.") == -1) {
          XMultiServiceFactory multiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
              textDocument.getXTextDocument());
          XNameContainer xBitmapContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class,
              multiServiceFactory.createInstance("com.sun.star.drawing.BitmapTable"));
          if (!xBitmapContainer.hasByName(name)) {
            xBitmapContainer.insertByName(name, graphicURL);
            String newGraphicURL = xBitmapContainer.getByName(name).toString();
            xPropSet.setPropertyValue("GraphicURL", newGraphicURL);
          }
        }
      }
    }
  }
  catch (Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example #9
Source File: ParagraphCloneService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs the ParagraphCloneService
 * 
  * @param paragraph paragraph to be used
  * @param document  document to be used
 * 
 * @throws CloneException if any error occurs
 * 
 * @author Sebastian Rösgen
 */
public ParagraphCloneService (IParagraph paragraph, ITextDocument document) throws CloneException{
	this.paragraph = paragraph;
	this.document = document;
	this.serviceFactory = (XMultiServiceFactory)com.sun.star.uno.UnoRuntime.queryInterface(XMultiServiceFactory.class, document.getXTextDocument());
	try {
		analyseParagraph(paragraph);
	}
	catch(TextException excep) {
		CloneException cloneException =  new CloneException(excep.getMessage());
		cloneException.initCause(excep);
		throw cloneException;
	}
}
 
Example #10
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new variable textfield master and returns it, or returns the
 * one that already exists, if it does. TODO maybe some more parameters are
 * needed???
 * 
 * @param name
 *            name of the variable textfield master
 * @param variableType
 *            the type of the variable master found in static members of
 *            com.sun.star.text.SetVariableType (i.e.
 *            SetVariableType.STRING)
 * 
 * @return the variable textfield master with the given name
 * 
 * @throws TextException
 *             if any error occurs during variable textfield master creation
 * 
 * @author Markus Krüger
 * @date 30.05.2007
 */
public IVariableTextFieldMaster createVariableTextFieldMaster(String name,
		short variableType) throws TextException {
	try {
		if (name == null) {
			throw new TextException(
					"The variable name to create can not be null.");
		}
		if (variableType < 0 || variableType > 3) {
			throw new TextException(
					"The variable type must be one of the valid static members of com.sun.star.text.SetVariableType.");
		}

		XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime
				.queryInterface(XMultiServiceFactory.class,
						textDocument.getXTextDocument());

		Object oFieldMaster = xMultiServiceFactory
				.createInstance(ITextFieldService.VARIABLES_TEXTFIELD_MASTER_ID);
		XPropertySet xMasterPropertySet = (XPropertySet) UnoRuntime
				.queryInterface(XPropertySet.class, oFieldMaster);

		// Grundeinstellung festlegen
		xMasterPropertySet.setPropertyValue("Name", name);
		xMasterPropertySet.setPropertyValue("SubType", new Short(
				variableType));
		return new VariableTextFieldMaster(textDocument, xMasterPropertySet);
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #11
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new placeholder textfield.
 * 
 * @param name
 *            name of the placeholder textfield
 * @param hint
 *            the hint of the placeholder textfield, may be null
 * @param placeholderType
 *            the type of the placeholder found in static members of
 *            com.sun.star.text.PlaceholderType (i.e. PlaceholderType.TEXT)
 * 
 * @return new placeholder textfield
 * 
 * @throws TextException
 *             if any error occurs during placeholder textfield creation
 * 
 * @author Markus Krüger
 * @date 30.05.2007
 */
public ITextField createPlaceholderTextField(String name, String hint,
		short placeholderType) throws TextException {
	try {
		if (name == null) {
			throw new TextException(
					"The placeholders name to create can not be null.");
		}
		if (placeholderType < 0 || placeholderType > 4) {
			throw new TextException(
					"The placeholder type must be one of the valid static members of com.sun.star.text.PlaceholderType.");
		}
		XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime
				.queryInterface(XMultiServiceFactory.class,
						textDocument.getXTextDocument());
		Object textField = xMultiServiceFactory
				.createInstance(ITextFieldService.PLACEHOLDER_TEXTFIELD_ID);

		XTextField xTextField = (XTextField) UnoRuntime.queryInterface(
				XTextField.class, textField);

		XPropertySet xPropertySet = (XPropertySet) UnoRuntime
				.queryInterface(XPropertySet.class, xTextField);

		// Grundeinstellung festlegen
		xPropertySet.setPropertyValue("PlaceHolder", name);
		xPropertySet.setPropertyValue("PlaceHolderType", new Short(
				placeholderType));
		if (hint != null) {
			xPropertySet.setPropertyValue("Hint", hint);
		}

		return new TextField(textDocument, xTextField);
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #12
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Adds new user textfield.
 * 
 * @param name
 *            name of the textfield
 * @param content
 *            content of the textfield
 * 
 * @return new textfield
 * 
 * @throws TextException
 *             if any error occurs during textfield creation
 * 
 * @author Andreas Bröker
 */
public ITextField addUserTextField(String name, String content)
		throws TextException {
	try {
		XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime
				.queryInterface(XMultiServiceFactory.class,
						textDocument.getXTextDocument());
		Object textField = xMultiServiceFactory
				.createInstance(ITextFieldService.USER_TEXTFIELD_ID);
		XDependentTextField xDependentTextField = (XDependentTextField) UnoRuntime
				.queryInterface(XDependentTextField.class, textField);

		Object oFieldMaster = xMultiServiceFactory
				.createInstance(ITextFieldService.USER_TEXTFIELD_MASTER_ID);
		XPropertySet xPropertySet = (XPropertySet) UnoRuntime
				.queryInterface(XPropertySet.class, oFieldMaster);

		xPropertySet.setPropertyValue("Name", name);
		xPropertySet.setPropertyValue("Content", content);

		xDependentTextField.attachTextFieldMaster(xPropertySet);

		return new TextField(textDocument, xDependentTextField);
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #13
Source File: TextService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs new TextService.
 * 
 * @param textDocument text document to be used
 * @param xMultiServiceFactory OpenOffice.org XMultiServiceFactory interface
 * @param xText OpenOffice.org XText interface
 *  
 * @throws IllegalArgumentException if the submitted text document or OpenOffice.org XText interface is not valid
 * 
 * @author Andreas Bröker
 * @author Sebastian Rösgen
 * @author Markus Krüger
 */
public TextService(ITextDocument textDocument, XMultiServiceFactory xMultiServiceFactory, XText xText) throws IllegalArgumentException {
  if(textDocument == null)
    throw new IllegalArgumentException("The submitted text document is not valid.");
  
  if(xText == null)
    throw new IllegalArgumentException("Submitted OpenOffice.org interface is not valid.");

  if(xMultiServiceFactory == null)
    throw new IllegalArgumentException("Submitted multi service factory is not valid.");
  
  this.xText = xText;
  this.xMultiServiceFactory = xMultiServiceFactory;
  this.textDocument = textDocument;
}
 
Example #14
Source File: TextFieldMaster.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs new textfield on the basis of this textfield master.
 * 
 * @return new constructed textfield on the basis of this textfield master
 * 
 * @throws NOAException if the new textfield can not be constructed
 * 
 * @author Andreas Bröker
 * @date 16.02.2006
 */
public ITextField constructNewTextField() throws NOAException {
	try {
 	XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, textDocument.getXTextDocument());
   Object textField = xMultiServiceFactory.createInstance(ITextFieldService.USER_TEXTFIELD_ID);
   XDependentTextField xDependentTextField = (XDependentTextField)UnoRuntime.queryInterface(XDependentTextField.class, textField);
   xDependentTextField.attachTextFieldMaster(xPropertySet);
   return new TextField(textDocument, xDependentTextField);
	}
	catch(Throwable throwable) {
		throw new NOAException(throwable);
	}
}
 
Example #15
Source File: ApplicationInfo.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method dumps info from the application described by the path.
 * 
 * @param path the path to be dumped, or null to dump from root
 * 
 * @throws Exception if dumping info fails
 * 
 * @author Markus Krüger
 * @date 18.11.2008
 */
public void dumpInfo(String path) throws Exception {
  if (path == null || path.length() == 0)
    path = NODE_ROOT;
  Object configProviderObject = serviceProvider.createService("com.sun.star.comp.configuration.ConfigurationProvider");
  XMultiServiceFactory xConfigServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
      configProviderObject);
  String readConfAccess = "com.sun.star.configuration.ConfigurationAccess";
  PropertyValue[] properties = new PropertyValue[1];
  properties[0] = new PropertyValue();
  properties[0].Name = "nodepath";
  properties[0].Value = path;
  Object configReadAccessObject = xConfigServiceFactory.createInstanceWithArguments(readConfAccess,
      properties);
  XNameAccess xConfigNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
      configReadAccessObject);
  String[] names = xConfigNameAccess.getElementNames();
  System.out.println(path);
  System.out.println("=======================================");
  for (int i = 0; i < names.length; i++) {
    Object element = xConfigNameAccess.getByName(names[i]);
    if (element instanceof String || element instanceof Boolean
        || element instanceof Number
        || element instanceof Character
        || element instanceof CharSequence) {
      System.out.println(names[i] + ": "
          + element);
    }
    else if (element instanceof String[]) {
      System.out.println(names[i] + ": "
          + Arrays.asList((String[]) element).toString());
    }
    else if (!(element instanceof Any)) {
      dumpInfo(path + "/"
          + names[i]);
    }
  }
}
 
Example #16
Source File: MemoryUsage.java    From kkFileViewOfficeEdit with Apache License 2.0 4 votes vote down vote up
private void addChart(XSpreadsheet sheet)
    throws Exception
{
    Rectangle rect = new Rectangle();
    rect.X = 500;
    rect.Y = 3000;
    rect.Width = 10000;
    rect.Height = 8000;

    XCellRange range = (XCellRange)
        UnoRuntime.queryInterface(XCellRange.class, sheet);

    XCellRange myRange =
        range.getCellRangeByName("A1:B2");

    XCellRangeAddressable rangeAddr = (XCellRangeAddressable)
        UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);

    CellRangeAddress myAddr = rangeAddr.getRangeAddress();

    CellRangeAddress[] addr = new CellRangeAddress[1];
    addr[0] = myAddr;

    XTableChartsSupplier supp = (XTableChartsSupplier)
        UnoRuntime.queryInterface( XTableChartsSupplier.class, sheet);

    XTableCharts charts = supp.getCharts();
    charts.addNewByName("Example", rect, addr, false, true);

    try { Thread.sleep(3000); } catch (java.lang.InterruptedException e) { }

    // get the diagram and Change some of the properties
    XNameAccess chartsAccess = (XNameAccess)
        UnoRuntime.queryInterface( XNameAccess.class, charts);

    XTableChart tchart = (XTableChart)
        UnoRuntime.queryInterface(
            XTableChart.class, chartsAccess.getByName("Example"));

    XEmbeddedObjectSupplier eos = (XEmbeddedObjectSupplier)
        UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, tchart );

    XInterface xifc = eos.getEmbeddedObject();

    XChartDocument xChart = (XChartDocument)
        UnoRuntime.queryInterface(XChartDocument.class, xifc);

    XMultiServiceFactory xDocMSF = (XMultiServiceFactory)
        UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);

    Object diagObject =
        xDocMSF.createInstance("com.sun.star.chart.PieDiagram");

    XDiagram xDiagram = (XDiagram)
        UnoRuntime.queryInterface(XDiagram.class, diagObject);

    xChart.setDiagram(xDiagram);

    XPropertySet propset = (XPropertySet)
        UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() );
    propset.setPropertyValue("String", "JVM Memory Usage");
}
 
Example #17
Source File: MemoryUsage.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
private void addChart(XSpreadsheet sheet)
    throws Exception
{
    Rectangle rect = new Rectangle();
    rect.X = 500;
    rect.Y = 3000;
    rect.Width = 10000;
    rect.Height = 8000;

    XCellRange range = (XCellRange)
        UnoRuntime.queryInterface(XCellRange.class, sheet);

    XCellRange myRange =
        range.getCellRangeByName("A1:B2");

    XCellRangeAddressable rangeAddr = (XCellRangeAddressable)
        UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);

    CellRangeAddress myAddr = rangeAddr.getRangeAddress();

    CellRangeAddress[] addr = new CellRangeAddress[1];
    addr[0] = myAddr;

    XTableChartsSupplier supp = (XTableChartsSupplier)
        UnoRuntime.queryInterface( XTableChartsSupplier.class, sheet);

    XTableCharts charts = supp.getCharts();
    charts.addNewByName("Example", rect, addr, false, true);

    try { Thread.sleep(3000); } catch (java.lang.InterruptedException e) { }

    // get the diagram and Change some of the properties
    XNameAccess chartsAccess = (XNameAccess)
        UnoRuntime.queryInterface( XNameAccess.class, charts);

    XTableChart tchart = (XTableChart)
        UnoRuntime.queryInterface(
            XTableChart.class, chartsAccess.getByName("Example"));

    XEmbeddedObjectSupplier eos = (XEmbeddedObjectSupplier)
        UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, tchart );

    XInterface xifc = eos.getEmbeddedObject();

    XChartDocument xChart = (XChartDocument)
        UnoRuntime.queryInterface(XChartDocument.class, xifc);

    XMultiServiceFactory xDocMSF = (XMultiServiceFactory)
        UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);

    Object diagObject =
        xDocMSF.createInstance("com.sun.star.chart.PieDiagram");

    XDiagram xDiagram = (XDiagram)
        UnoRuntime.queryInterface(XDiagram.class, diagObject);

    xChart.setDiagram(xDiagram);

    XPropertySet propset = (XPropertySet)
        UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() );
    propset.setPropertyValue("String", "JVM Memory Usage");
}
 
Example #18
Source File: TextDocument.java    From noa-libre with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructs new OpenOffice.org swriter document.
 * 
 * @param xTextDocument OpenOffice.org XTextDocument interface
 * @param intitialProperties the properties that were used loading the document
 * 
 * @throws IllegalArgumentException if the submitted OpenOffice.org XTextDocument is not valid
 * 
 * @author Andreas Bröker
 */
public TextDocument(XTextDocument xTextDocument, PropertyValue[] initialProperties)
    throws IllegalArgumentException {
  super((XComponent) UnoRuntime.queryInterface(XComponent.class, xTextDocument),
      initialProperties);
  this.xTextDocument = xTextDocument;
  this.xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
      xTextDocument);
}
 
Example #19
Source File: TextContentService.java    From noa-libre with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructs new TextContentService.
 * 
 * @param textDocument text document to be used
 * @param xText OpenOffice.org XText interface
 * @param xMultiServiceFactory OpenOffice.org XMultiServiceFactory interface
 * 
 * @throws IllegalArgumentException if the submitted text document or OpenOffice.org XText interface 
 * is not valid
 * 
 * @author Andreas Bröker
 * @author Sebastian Rösgen
 * @author Markus Krüger
 */
public TextContentService(ITextDocument textDocument, XMultiServiceFactory xMultiServiceFactory,
    XText xText) throws IllegalArgumentException {
  if (xText == null)
    throw new IllegalArgumentException("Submitted OpenOffice.org XText interface is not valid.");
  if (textDocument == null)
    throw new IllegalArgumentException("Submitted text document is not valid.");
  if (xMultiServiceFactory == null)
    throw new IllegalArgumentException("Submitted multi service factory is not valid.");
  this.xText = xText;
  this.xMultiServiceFactory = xMultiServiceFactory;
  this.textDocument = textDocument;
}
 
Example #20
Source File: TextTableCloneService.java    From noa-libre with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructs the TextTableCloneService
 * 
 * @param table the table to be cloned
  * @param textDocument text document to be used
  * 
  * @throws CloneException TODO: add comment
 */
public TextTableCloneService (ITextTable table, XTextDocument textDocument) throws CloneException {
	this.textTable = table;
	this.textDocument = textDocument;
	this.serviceFactory = (XMultiServiceFactory)com.sun.star.uno.UnoRuntime.queryInterface(XMultiServiceFactory.class, textDocument);
	getTableInfo(table);
}
 
Example #21
Source File: TextDocument.java    From noa-libre with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Returns the XMultiServiceFactory of the document.
 * 
 * @return multiServiceFactory the XMultiServiceFactory of the document
 * 
 * @throws Exception if any error occurs
 */
public XMultiServiceFactory getMultiServiceFactory() throws Exception {
  XMultiServiceFactory multiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
      xTextDocument);
  return multiServiceFactory;
}
 
Example #22
Source File: LocalOfficeConnection.java    From noa-libre with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Returns XMultiServiceFactory.
 * 
 * @return XMultiServiceFactory
 * 
 * @throws Exception if anything fails
 * 
 * @author Andreas Bröker
 * @author Markus Krüger
 */
public XMultiServiceFactory getXMultiServiceFactory() throws Exception {
  return (XMultiServiceFactory) UnoRuntime.queryInterface(
      XMultiServiceFactory.class, getXMultiComponentFactory());
}
 
Example #23
Source File: RemoteOfficeConnection.java    From noa-libre with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Returns XMultiServiceFactory.
 * 
 * @return XMultiServiceFactory
 */
public XMultiServiceFactory getXMultiServiceFactory() {
  return xMultiServiceFactory;
}
 
Example #24
Source File: IOfficeConnection.java    From noa-libre with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Returns XMultiServiceFactory.
 * 
 * @return XMultiServiceFactory
 * 
 * @throws Exception if anything fails
 * 
 * @author Andreas Bröker
 * @author Markus Krüger
 */
public XMultiServiceFactory getXMultiServiceFactory() throws Exception;