Java Code Examples for com.sun.star.beans.XPropertySet#setPropertyValue()

The following examples show how to use com.sun.star.beans.XPropertySet#setPropertyValue() . 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: VariableTextFieldHelper.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Applies the given number format to the given variable text field.
 * 
 * @param numberFormat the number format to be set
 * @param variableTextField the variable text field to set number forma for
 * @param isFormula if the variable text field is a formula
 * @param numberFormatService the number format service to be used
 * 
 * @throws NOAException if setting the number format fails
 * 
 * @author Markus Krüger
 * @date 27.07.2007
 */
public static void applyNumberFormat(INumberFormat numberFormat, ITextField variableTextField,
    boolean isFormula, INumberFormatService numberFormatService) throws NOAException {
  try {
    if(numberFormat == null || variableTextField == null || numberFormatService == null)
      return;
    XPropertySet xPropertySetField = 
      (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, variableTextField.getXTextContent());
    String content = (String)xPropertySetField.getPropertyValue("Content");      
    xPropertySetField.setPropertyValue("NumberFormat", new Integer(numberFormat.getFormatKey()));
    setContent(content,variableTextField,isFormula,numberFormatService);
  }
  catch(Throwable throwable) {
    throw new NOAException(throwable);
  }
}
 
Example 2
Source File: DocumentService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Constructs new database document.
 * 
 * @return new constructed database document
 * 
 * @throws NOAException if the new database document can not be constructed
 * 
 * @author Andreas Bröker
 * @date 16.03.2006
 */
private IDatabaseDocument constructDatabaseDocument() throws NOAException {
  try {
    Object dataSource = officeConnection.getXMultiComponentFactory().createInstanceWithContext("com.sun.star.sdb.DataSource",
        officeConnection.getXComponentContext());
    XPropertySet propertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
        dataSource);
    propertySet.setPropertyValue("URL", "sdbc:embedded:hsqldb");
    XDocumentDataSource documentDataSource = (XDocumentDataSource) UnoRuntime.queryInterface(XDocumentDataSource.class,
        dataSource);
    XOfficeDatabaseDocument officeDatabaseDocument = documentDataSource.getDatabaseDocument();
    return new DatabaseDocument(officeDatabaseDocument, null);
  }
  catch (Throwable throwable) {
    throw new NOAException(throwable);
  }
}
 
Example 3
Source File: LayoutManager.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Hide UI element with the submitted resource URL.
 * 
 * @param resourceURL URL of the UI resource to be hidden
 * @param if changes should be persistent
 * 
 * @return information whether the UI resource is hidden after method call
 * 
 * @author Markus Krüger
 * @date 06.05.2010
 */
public boolean hideElement(String resourceURL, boolean persistent) {
  if (resourceURL != null) {
    try {
      XUIElement element = xLayoutManager.getElement(resourceURL);
      if (element != null) {
        XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, element);
        xps.setPropertyValue("Persistent", new Boolean(persistent));
        return xLayoutManager.hideElement(resourceURL);
      }
    }
    catch (Exception e) {
      //ignore and return false
    }
  }
  return false;

}
 
Example 4
Source File: LayoutManager.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Shows UI element with the submitted resource URL.
 * 
 * @param resourceURL URL of the UI resource to be shown
 * @param if changes should be persistent
 * 
 * @return information whether the UI resource is visible after method call
 * 
 * @author Markus Krüger
 * @date 06.05.2010
 */
public boolean showElement(String resourceURL, boolean persistent) {
  if (resourceURL != null) {
    try {
      XUIElement element = xLayoutManager.getElement(resourceURL);
      if (element == null) {
        xLayoutManager.createElement(resourceURL);
      }
      element = xLayoutManager.getElement(resourceURL);
      if (element != null) {
        XPropertySet xps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, element);
        xps.setPropertyValue("Persistent", new Boolean(persistent));
        return xLayoutManager.showElement(resourceURL);
      }
    }
    catch (Exception e) {
      //ignore and return false
    }
  }
  return false;
}
 
Example 5
Source File: AbstractInliner.java    From yarg with Apache License 2.0 6 votes vote down vote up
protected XPropertySet buildImageProperties(XGraphicProvider xGraphicProvider, Object oImage, byte[] imageContent)
        throws Exception {
    XPropertySet imageProperties = as(XPropertySet.class, oImage);

    PropertyValue[] propValues = new PropertyValue[]{new PropertyValue()};
    propValues[0].Name = "InputStream";
    propValues[0].Value = new ByteArrayToXInputStreamAdapter(imageContent);

    XGraphic graphic = xGraphicProvider.queryGraphic(propValues);
    if (graphic != null) {
        imageProperties.setPropertyValue("Graphic", graphic);

        imageProperties.setPropertyValue("HoriOrient", HoriOrientation.NONE);
        imageProperties.setPropertyValue("VertOrient", HoriOrientation.NONE);

        imageProperties.setPropertyValue("HoriOrientPosition", 0);
        imageProperties.setPropertyValue("VertOrientPosition", 0);
    }

    return imageProperties;
}
 
Example 6
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 7
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 8
Source File: TextTableRow.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Sets if the row height is set to automatically be adjusted or not.
 * 
 * @param autoHeight if the row height is set to automatically be adjusted or not
 * 
 * @author Markus Krüger
 */
public void setAutoHeight(boolean autoHeight) {
  if(textTableCellRange == null)
    return;
  try {      
    XTextTable xTextTable = (XTextTable)textTableCellRange.getCell(0,0).getTextTable().getXTextContent();
    XTableRows tableRows = xTextTable.getRows();
    Object row = tableRows.getByIndex(textTableCellRange.getRangeName().getRangeStartRowIndex());
    XPropertySet propertySetRow = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, row);
    propertySetRow.setPropertyValue("IsAutoHeight",new Boolean(autoHeight));
  }
  catch (Exception exception) {
  }
}
 
Example 9
Source File: TextTableRow.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Sets the row height.
 * 
 * @param height the row height to be set
 * 
 * @author Markus Krüger
 */
public void setHeight(int height) {
  if(textTableCellRange == null)
    return;
  try {      
    XTextTable xTextTable = (XTextTable)textTableCellRange.getCell(0,0).getTextTable().getXTextContent();
    XTableRows tableRows = xTextTable.getRows();
    Object row = tableRows.getByIndex(textTableCellRange.getRangeName().getRangeStartRowIndex());
    XPropertySet propertySetRow = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, row);
    propertySetRow.setPropertyValue("Height",new Integer(height));
  }
  catch (Exception exception) {
  }
}
 
Example 10
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 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 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 12
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 13
Source File: TextDocument.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Sets the zoom of the document.
 * 
 * @param zoomType the type of the zoom as in class {@link DocumentZoomType}
 * @param zoomValue the value of the zoom, does only take afect if zoom type is
 * set to DocumentZoomType.BY_VALUE. Values between 20 and 600 are allowed.
 * 
 * @throws DocumentException if zoom fails
 * 
 * @author Markus Krüger
 * @date 06.07.2007
 */
public void zoom(short zoomType, short zoomValue) throws DocumentException {
  try {
    //zoomType valid?
    if (zoomType != DocumentZoomType.BY_VALUE && zoomType != DocumentZoomType.ENTIRE_PAGE
        && zoomType != DocumentZoomType.OPTIMAL
        && zoomType != DocumentZoomType.PAGE_WIDTH
        && zoomType != DocumentZoomType.PAGE_WIDTH_EXACT)
      throw new DocumentException("Invalid zoom type.");
    //zoomType valid?
    if (zoomType == DocumentZoomType.BY_VALUE && (zoomValue < 20 || zoomValue > 600))
      throw new DocumentException("Invalid zoom value. Use values between 20 and 600.");

    XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, getXComponent());
    if (xModel != null) {
      XController xController = xModel.getCurrentController();
      XSelectionSupplier selectionSupplier = (XSelectionSupplier) UnoRuntime.queryInterface(XSelectionSupplier.class,
          xController);
      if (selectionSupplier != null) {
        XViewSettingsSupplier viewSettingsSupplier = (XViewSettingsSupplier) UnoRuntime.queryInterface(XViewSettingsSupplier.class,
            xController);
        if (viewSettingsSupplier != null) {
          XPropertySet propertySet = viewSettingsSupplier.getViewSettings();
          propertySet.setPropertyValue("ZoomType", new Short(zoomType));
          if (zoomType == DocumentZoomType.BY_VALUE)
            propertySet.setPropertyValue("ZoomValue", new Short(zoomValue));
        }
      }
    }
  }
  catch (Throwable throwable) {
    throw new DocumentException(throwable);
  }
}
 
Example 14
Source File: TextCursor.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Inserts page break at the current cursor position. 
 * 
 * @throws NOAException if the page break can not be set
 * 
 * @author Andreas Bröker
 * @date 19.09.2006
 */
public void insertPageBreak() throws NOAException {
  try {
    XCell xCell = (XCell)UnoRuntime.queryInterface(XCell.class, xTextCursor.getText());
    XPropertySet propertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
    propertySet.setPropertyValue("BreakType", BreakType.PAGE_AFTER);
    if(xCell == null) {
      xTextCursor.getText().insertControlCharacter(xTextCursor, ControlCharacter.PARAGRAPH_BREAK, false);
    }      
  }
  catch(Throwable throwable) {
    throw new NOAException("Error inserting page break.",throwable);
  }
}
 
Example 15
Source File: DialogHelper.java    From libreoffice-starter-extension with MIT License 5 votes vote down vote up
public static void setPosition(XDialog dialog, int posX, int posY) {
	XControlModel xDialogModel = UnoRuntime.queryInterface(XControl.class, dialog).getModel();
	XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xDialogModel);
	try {
		xPropSet.setPropertyValue("PositionX", posX);
		xPropSet.setPropertyValue("PositionY", posY);
	} catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException
			| WrappedTargetException e) {
		return;
	}
}
 
Example 16
Source File: DialogHelper.java    From libreoffice-starter-extension with MIT License 5 votes vote down vote up
public static void EnableButton(XDialog dialog, String componentId, boolean enable) {
	XControlContainer xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class,
			dialog);
	// retrieve the control that we want to disable or enable
	XControl xControl = UnoRuntime.queryInterface(XControl.class, xDlgContainer.getControl(componentId));
	XPropertySet xModelPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel());
	try {
		xModelPropertySet.setPropertyValue("Enabled", Boolean.valueOf(enable));
	} catch (IllegalArgumentException | UnknownPropertyException | PropertyVetoException
			| WrappedTargetException e) {
		return;
	}
}
 
Example 17
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 18
Source File: TextContentService.java    From noa-libre with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs new image.
 * 
 * @param graphicInfo the graphic information to construct image with
 * 
 * @return new image
 * 
 * @throws TextException if the image can not be constructed
 * 
 * @author Markus Krüger
 * @date 09.07.2007
 */
public ITextDocumentImage constructNewImage(GraphicInfo graphicInfo) throws TextException {
  try {
    if (xMultiServiceFactory == null)
      throw new TextException("OpenOffice.org XMultiServiceFactory inteface not valid.");

    if (xBitmapContainer == null)
      xBitmapContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class,
          xMultiServiceFactory.createInstance("com.sun.star.drawing.BitmapTable"));

    XTextContent xImage = (XTextContent) UnoRuntime.queryInterface(XTextContent.class,
        xMultiServiceFactory.createInstance("com.sun.star.text.TextGraphicObject"));

    XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xImage);

    String tempId = "tempImageId" + System.currentTimeMillis();
    xBitmapContainer.insertByName(tempId, graphicInfo.getUrl());
    String internalURL = AnyConverter.toString(xBitmapContainer.getByName(tempId));

    xProps.setPropertyValue("AnchorType", graphicInfo.getAnchor());
    xProps.setPropertyValue("GraphicURL", internalURL);
    xProps.setPropertyValue("Width", Integer.valueOf(graphicInfo.getWidth()));
    xProps.setPropertyValue("Height", Integer.valueOf(graphicInfo.getHeight()));
    xProps.setPropertyValue("HoriOrient", Short.valueOf(graphicInfo.getHorizontalAlignment()));
    xProps.setPropertyValue("VertOrient", Short.valueOf(graphicInfo.getVerticalAlignment()));

    ITextDocumentImage textDocumentImage = new TextDocumentImage(textDocument,
        xImage,
        graphicInfo);

    if (imageToImageIds == null)
      imageToImageIds = new HashMap<ITextDocumentImage, String>();
    imageToImageIds.put(textDocumentImage, tempId);

    return textDocumentImage;
  }
  catch (Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example 19
Source File: TextContentService.java    From noa-libre with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ITextDocumentTextShape constructNewTextShape(TextInfo textInfo) throws TextException {
  try {
    if (xMultiServiceFactory == null)
      throw new TextException("OpenOffice.org XMultiServiceFactory interface not valid.");

    if (xTextShapeContainer == null)
      xTextShapeContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class,
          xMultiServiceFactory.createInstance("com.sun.star.drawing.MarkerTable"));

    Object textShape = xMultiServiceFactory.createInstance("com.sun.star.text.TextFrame");

    XTextContent xTextShape = (XTextContent) UnoRuntime.queryInterface(XTextContent.class,
        textShape);

    XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextShape);

    String tempId = "tempTextShapeId" + System.currentTimeMillis();
    xTextShapeContainer.insertByName(tempId, textInfo.getName());

    XNamed xNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, xTextShape);
    xNamed.setName(textInfo.getName());

    xProps.setPropertyValue("AnchorType", textInfo.getAnchor());

    int minWidth = textInfo.getMinimumWidth();
    int minHeight = textInfo.getMinimumHeight();
    if (minWidth != -1) {
      xProps.setPropertyValue("Width", new Integer(minWidth));
    }
    if (minHeight != -1) {
      xProps.setPropertyValue("Height", new Integer(minHeight));
    }
    if (textInfo.isAutoWidth()) {
      xProps.setPropertyValue("WidthType", new Short((short) 2)); //automatic
    }
    if (textInfo.isAutoHeight()) {
      xProps.setPropertyValue("FrameIsAutomaticHeight", new Boolean(true)); //automatic
      xProps.setPropertyValue("SizeType", SizeType.MIN);
    }
    else {
      xProps.setPropertyValue("SizeType", SizeType.FIX);
    }

    xProps.setPropertyValue("HoriOrient", Short.valueOf(textInfo.getHorizontalAlignment()));
    xProps.setPropertyValue("VertOrient", Short.valueOf(textInfo.getVerticalAlignment()));
    int backColor = textInfo.getBackColor();
    if (backColor != -1) {
      xProps.setPropertyValue("BackColor", new Integer(textInfo.getBackColor()));
      xProps.setPropertyValue("BackColorTransparency", new Short((short) 0));
      xProps.setPropertyValue("BackTransparent", new Boolean(false));
    }
    else {
      xProps.setPropertyValue("BackColorTransparency", new Short((short) 100));
      xProps.setPropertyValue("BackTransparent", new Boolean(true));
    }

    ITextDocumentTextShape textDocumentTextShape = new TextDocumentTextShape(textDocument,
        xTextShape,
        textInfo);

    ////////
    XText xShapeText = (XText) UnoRuntime.queryInterface(XText.class, textShape);
    textDocumentTextShape.setXText(xShapeText);
    ////////

    if (textShapeToTextShapeIds == null)
      textShapeToTextShapeIds = new HashMap<ITextDocumentTextShape, String>();
    textShapeToTextShapeIds.put(textDocumentTextShape, tempId);

    return textDocumentTextShape;
  }
  catch (Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example 20
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");
}