com.sun.star.beans.XPropertySet Java Examples

The following examples show how to use com.sun.star.beans.XPropertySet. 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: 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 #2
Source File: Annotation.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the text content of the annotation, or null if text content is not available.
 * 
 * @return the text content of the annotation, or null
 * 
 * @author Markus Krüger
 * @date 13.07.2006
 */
public String getText() {
  XServiceInfo info = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, getXTextContent());
  if(info.supportsService(ITextFieldService.ANNOTATION_TEXTFIELD_ID)) {
    XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, getXTextContent());
    try {
      return (String) properties.getPropertyValue("Content");
    }
    catch(UnknownPropertyException unknownPropertyException) {
      //TODO exception handling if needed, do nothing for now
    }
    catch(WrappedTargetException wrappedTargetException) {
      //TODO exception handling if needed, do nothing for now
    }
  }
  return null;
}
 
Example #3
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 #4
Source File: TextTableCell.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns text table of the cell.
 * 
 * @return text table of the cell
 * 
 * @throws TextException if the text table is not available
 * 
 * @author Andreas Bröker
 * @author Markus Krüger
 */
public ITextTable getTextTable() throws TextException {
  if(textTable == null) {
    try {
      XText xText = (XText)UnoRuntime.queryInterface(XText.class, xCell);
      XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xText.getStart());
      Any any = (Any)xPropertySet.getPropertyValue("TextTable");
      XTextTable xTextTable = (XTextTable)any.getObject();
      textTable =  new TextTable(textDocument, xTextTable);
    }
    catch(Exception exception) {
      TextException textException = new TextException(exception.getMessage());
      textException.initCause(exception);
      throw textException;
    }
  }
  return textTable;
}
 
Example #5
Source File: TextContentEnumeration.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns all available text fields.
 * 
 * @return all available text fields
 * 
 * @author Andreas Bröker
 */
public ITextField[] getTextFields() {
  ArrayList arrayList = new ArrayList();    
  XTextCursor textCursor = xTextRange.getText().createTextCursorByRange(xTextRange.getStart());
  XTextRangeCompare xTextRangeCompare = (XTextRangeCompare)UnoRuntime.queryInterface(XTextRangeCompare.class, xTextRange.getText());
  try {      
    while(xTextRangeCompare.compareRegionEnds(textCursor.getStart(), xTextRange.getEnd()) != -1) {
      XPropertySet propertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, textCursor);
      Any any = (Any)propertySet.getPropertyValue("TextField");
      XTextField xTextField = (XTextField)any.getObject();  
      if(xTextField != null)
        arrayList.add(new TextField(textDocument, xTextField));
      if(!textCursor.goRight((short)1, false)) 
        break;
    }
  }
  catch(Exception exception) {
    //do nothing
  }
  
  ITextField[] textFields = new ITextField[arrayList.size()];
  return (ITextField[])arrayList.toArray(textFields);    
}
 
Example #6
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 #7
Source File: Annotation.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the text content of the annotation, or null if text content is not available.
 * 
 * @return the text content of the annotation, or null
 * 
 * @author Markus Krüger
 * @date 13.07.2006
 */
public String getText() {
  XServiceInfo info = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, getXTextContent());
  if(info.supportsService(ITextFieldService.ANNOTATION_TEXTFIELD_ID)) {
    XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, getXTextContent());
    try {
      return (String) properties.getPropertyValue("Content");
    }
    catch(UnknownPropertyException unknownPropertyException) {
      //TODO exception handling if needed, do nothing for now
    }
    catch(WrappedTargetException wrappedTargetException) {
      //TODO exception handling if needed, do nothing for now
    }
  }
  return null;
}
 
Example #8
Source File: OfficeConnection.java    From yarg with Apache License 2.0 6 votes vote down vote up
public void open() throws OpenOfficeException {
    if (this.closed) {
        try {
            XComponentContext localContext = bsc.connect("127.0.0.1", port);
            String connectionString = "socket,host=127.0.0.1,port=" + port;
            XMultiComponentFactory localServiceManager = localContext.getServiceManager();
            XConnector connector = as(XConnector.class,
                    localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext));
            XConnection connection = connector.connect(connectionString);
            XBridgeFactory bridgeFactory = as(XBridgeFactory.class,
                    localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext));
            String bridgeName = "yarg_" + bridgeIndex.incrementAndGet();
            XBridge bridge = bridgeFactory.createBridge(bridgeName, "urp", connection, null);
            XMultiComponentFactory serviceManager = as(XMultiComponentFactory.class, bridge.getInstance("StarOffice.ServiceManager"));
            XPropertySet properties = as(XPropertySet.class, serviceManager);
            xComponentContext = as(XComponentContext.class, properties.getPropertyValue("DefaultContext"));

            officeResourceProvider = new OfficeResourceProvider(xComponentContext, officeIntegration);
            closed = false;
        } catch (Exception e) {
            close();
            throw new OpenOfficeException("Unable to create Open office components.", e);
        }
    }
}
 
Example #9
Source File: TextRange.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns related page style of the text range.
 * 
 * @return page style of the text range
 * 
 * @throws TextException if the page style is not available
 * 
 * @author Andreas Bröker
 */
public IPageStyle getPageStyle() throws TextException {
  if(document == null || !(document instanceof ITextDocument))
  	throw new TextException("Text style not available");
	try {
    XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextRange);
    String pageStyleName = xPropertySet.getPropertyValue("PageStyleName").toString();
    XStyleFamiliesSupplier xStyleFamiliesSupplier = (XStyleFamiliesSupplier)UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, ((ITextDocument)document).getXTextDocument());
    XNameAccess xNameAccess = xStyleFamiliesSupplier.getStyleFamilies();
    Any any = (Any)xNameAccess.getByName("PageStyles");
    XNameContainer xNameContainer = (XNameContainer)any.getObject();
    any = (Any)xNameContainer.getByName(pageStyleName);
    XStyle style = (XStyle)any.getObject();
    return new PageStyle(style);
  }
  catch(Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example #10
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 #11
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 #12
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 #13
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 #14
Source File: NumberFormatService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns number format on the basis of the submitted key.
 * 
 * @param key key of the number format
 * 
 * @return number format on the basis of the submitted key
 * 
 * @throws UtilException if the number format is not available
 * 
 * @author Andreas Bröker
 * @author Markus Krüger
 */
public INumberFormat getNumberFormat(int key) throws UtilException {
  INumberFormat[] allFormats = getNumberFormats();
  for(int i = 0; i < allFormats.length; i++) {
    if(key == allFormats[i].getFormatKey())
      return allFormats[i];
  }
  try {
    XNumberFormats xNumberFormats = xNumberFormatsSupplier.getNumberFormats();
    XPropertySet docProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, textDocument.getXTextDocument());
    Locale docLocale = (Locale) docProps.getPropertyValue("CharLocale");
    XNumberFormatTypes numberFormatTypes = (XNumberFormatTypes)UnoRuntime.queryInterface(XNumberFormatTypes.class, xNumberFormats);
    int newKey = numberFormatTypes.getFormatForLocale(key,docLocale);
    for(int i = 0; i < allFormats.length; i++) {
      if(newKey == allFormats[i].getFormatKey())
        return allFormats[i];
    }
  }
  catch(Exception exception) {
    UtilException utilException = new UtilException(exception.getMessage());
    utilException.initCause(exception);
    throw utilException;
  }
  throw new UtilException("The number format is not available.");
}
 
Example #15
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 #16
Source File: TextTableRow.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the row height.
 * 
 * @return the row height
 * 
 * @author Markus Krüger
 */
public int getHeight() {
  if(textTableCellRange == null)
    return 0;
  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);
    Integer rowHeight = (Integer)propertySetRow.getPropertyValue("Height");
    return rowHeight.intValue();
  }
  catch (Exception exception) {
    return 0;
  }
}
 
Example #17
Source File: TextTableRow.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns if the row height is set to automatically be adjusted or not.
 * 
 * @return if the row height is set to automatically be adjusted or not
 * 
 * @author Markus Krüger
 */
public boolean getAutoHeight() {
  if(textTableCellRange == null)
    return false;
  try {      
    XTextTable xTextTable = (XTextTable)textTableCellRange.getCell(0,0).getTextTable().getXTextContent();
    XTableRows tableRows = xTextTable.getRows();
    int rowIndex = textTableCellRange.getRangeName().getRangeStartRowIndex();
    Object row = tableRows.getByIndex(rowIndex);
    XPropertySet propertySetRow = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, row);
    Boolean rowAutoHeight = (Boolean)propertySetRow.getPropertyValue("IsAutoHeight");      
    return rowAutoHeight.booleanValue();
  }
  catch (Exception exception) {
    return false;
  }
}
 
Example #18
Source File: TextTableCell.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns name of the cell. 
 * 
 * @return name of the cell or null if the name is not available
 * 
 * @author Andreas Bueker
 */
public ITextTableCellName getName() {
	if(textTableCellName == null) {
   XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xCell);
   try {        
     textTableCellName = new TextTableCellName(xPropertySet.getPropertyValue("CellName").toString());
   }
   catch(Exception exception) {
     return null;
   }
	}
	return textTableCellName;
}
 
Example #19
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 #20
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns all masters of the variables text fields with the submitted name
 * prefix.
 * 
 * @param prefix
 *            name prefix to be used
 * 
 * @return all masters of the variables text fields
 * 
 * @throws TextException
 *             if the masters can not be returned
 * 
 * @author Markus Krüger
 * @date 30.05.2007
 */
public IVariableTextFieldMaster[] getVariableTextFieldMasters(String prefix)
		throws TextException {
	try {
		XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime
				.queryInterface(XTextFieldsSupplier.class,
						textDocument.getXTextDocument());
		XNameAccess xNameAccess = xTextFieldsSupplier.getTextFieldMasters();
		String[] names = xNameAccess.getElementNames();
		List masters = new ArrayList();
		for (int i = 0; i < names.length; i++) {
			if (names[i].toLowerCase().startsWith(
					(VARIABLES_TEXTFIELD_MASTER_PREFIX + prefix)
							.toLowerCase())) {
				Any any = null;
				try {
					any = (Any) xNameAccess.getByName(names[i]);
				} catch (NoSuchElementException noSuchElementException) {
					continue;
				}
				XPropertySet xPropertySet = (XPropertySet) UnoRuntime
						.queryInterface(XPropertySet.class, any);
				if (xPropertySet != null) {
					masters.add(new VariableTextFieldMaster(textDocument,
							xPropertySet));
				}
			}
		}
		return (IVariableTextFieldMaster[]) masters
				.toArray(new IVariableTextFieldMaster[masters.size()]);
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #21
Source File: Frame.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns layout manager of the frame. Returns null if a layout manager
 * is not available.
 * 
 * @return layout manager of the frame or null if a layout manager
 * is not available
 * 
 * @throws NOAException if the layout manager can not be requested
 * 
 * @author Andreas Bröker
 * @date 2006/02/05
 */
public ILayoutManager getLayoutManager() throws NOAException {
	try {
		XPropertySet propertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xFrame);
		Object object = propertySet.getPropertyValue("LayoutManager");
		XLayoutManager layoutManager = (XLayoutManager)UnoRuntime.queryInterface(XLayoutManager.class, object);
		if(layoutManager != null)
			return new LayoutManager(layoutManager);
	}
	catch(Throwable throwable) {
		throw new NOAException(throwable);
	}
	return null;
}
 
Example #22
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 #23
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 #24
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 #25
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns master of a user textfield with the submitted name. Returns null
 * if a user textfield with the submitted name is not available.
 * 
 * @param name
 *            name of the master of the user textfield
 * 
 * @return master of a user textfield with the submitted name or null if a
 *         user textfield with the submitted name is not available
 * 
 * @throws TextException
 *             if the user text field can not be provided
 * 
 * @author Andreas Bröker
 */
public ITextFieldMaster getUserTextFieldMaster(String name)
		throws TextException {
	try {
		XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime
				.queryInterface(XTextFieldsSupplier.class,
						textDocument.getXTextDocument());
		XNameAccess xNameAccess = xTextFieldsSupplier.getTextFieldMasters();
		Any any = null;

		try {
			any = (Any) xNameAccess.getByName(USER_TEXTFIELD_MASTER_PREFIX
					+ name);
		} catch (NoSuchElementException noSuchElementException) {
			return null;
		}

		XPropertySet xPropertySet = (XPropertySet) UnoRuntime
				.queryInterface(XPropertySet.class, any);
		if (xPropertySet != null) {
			return new TextFieldMaster(textDocument, xPropertySet);
		} else {
			return null;
		}
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #26
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 #27
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 #28
Source File: TextTable.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Marks the table.
 * 
 * @author Markus Krüger
 * @date 06.08.2007
 */
public void markTable() {
  try {
    String firstCell = "A1";
    String range = firstCell + ":";
    ITextTableRow[] rows = getRows();
    if (rows.length > 0) {
      ITextTableCell[] cells = rows[rows.length - 1].getCells();
      String lastCellName = cells[cells.length - 1].getName().getName();
      range = range + TextTableCellNameHelper.getColumnCharacter(lastCellName)
          + TextTableCellNameHelper.getRowCounterValue(lastCellName);
      ITextTableCellRange cellRange = getCellRange(range);
      ITextDocument textDocument = getTextDocument();
      if (textDocument.isOpen()) {
        XCell cell = getXTextTable().getCellByName(firstCell);
        XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
            cell);
        if (xPropertySet != null) {
          Object value = xPropertySet.getPropertyValue("TextSection");
          boolean select = true;
          XTextSection xTextSection = (XTextSection) UnoRuntime.queryInterface(XTextSection.class,
              value);
          if (xTextSection != null) {
            XPropertySet xTextSectionPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
                xTextSection);
            if (xTextSectionPropertySet != null) {
              Boolean visible = (Boolean) xTextSectionPropertySet.getPropertyValue("IsVisible");
              select = visible.booleanValue();
            }
          }
          if (select)
            textDocument.setSelection(new XInterfaceObjectSelection(cellRange.getXCellRange()));
        }
      }
    }
  }
  catch (Throwable throwable) {
    //no marking possible
  }
}
 
Example #29
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns master of the variables text fields with the submitted name, or
 * null if not availbale.
 * 
 * @param masterName
 *            name of the master to return
 * 
 * @return master of the variables text fields with the submitted name, or
 *         null
 * 
 * @throws TextException
 *             if the master can not be returned
 * 
 * @author Markus Krüger
 * @date 30.05.2007
 */
public IVariableTextFieldMaster getVariableTextFieldMaster(String masterName)
		throws TextException {
	try {
		XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime
				.queryInterface(XTextFieldsSupplier.class,
						textDocument.getXTextDocument());
		XNameAccess xNameAccess = xTextFieldsSupplier.getTextFieldMasters();
		Any any = null;

		try {
			String name = masterName;
			if (!name.toLowerCase().startsWith(
					VARIABLES_TEXTFIELD_MASTER_PREFIX.toLowerCase())) {
				name = VARIABLES_TEXTFIELD_MASTER_PREFIX + name;
			}
			any = (Any) xNameAccess.getByName(name);
		} catch (NoSuchElementException noSuchElementException) {
			return null;
		}

		XPropertySet xPropertySet = (XPropertySet) UnoRuntime
				.queryInterface(XPropertySet.class, any);
		if (xPropertySet != null) {
			return new VariableTextFieldMaster(textDocument, xPropertySet);
		}
		return null;
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #30
Source File: TextTableCell.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns text table cell properties.
 * 
 * @return text table cell properties
 * 
 * @author Andreas Bröker
 */
public ITextTableCellProperties getProperties() {
  if(textTableCellProperties == null) {
    XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xCell);
    textTableCellProperties = new TextTableCellProperties(xPropertySet);
  }
  return textTableCellProperties;
}