Currency Field

From Apache OpenOffice Wiki
Jump to: navigation, search



The currency field control com.sun.star.awt.UnoControlCurrencyField can be considered a specialization of the com.sun.star.awt.UnoControlNumericField. It is used for entering and displaying currency values. In addition to the currency value, reflected by the property Value, a currency symbol, set by the CurrencySymbol property, is displayed. If the PrependCurrencySymbol property is set to true, the currency symbol is displayed in front of the currency value.

  public XTextComponent insertCurrencyField(XTextListener _xTextListener, int _nPositionX, int _nPositionY, int _nWidth){
  XTextComponent xTextComponent = null;
  try{
      // create a unique name by means of an own implementation...
      String sName = createUniqueName(m_xDlgModelNameContainer, "CurrencyField");
 
      // create a controlmodel at the multiservicefactory of the dialog model... 
      Object oCFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlCurrencyFieldModel");
      XMultiPropertySet xCFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oCFModel);
 
      // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 
      xCFModelMPSet.setPropertyValues(
      new String[] {"Height", "Name", "PositionX", "PositionY", "Width"},
      new Object[] { new Integer(12), sName, new Integer(_nPositionX), new Integer(_nPositionY), new Integer(_nWidth)});
 
      // The controlmodel is not really available until inserted to the Dialog container 
      m_xDlgModelNameContainer.insertByName(sName, oCFModel);
      XPropertySet xCFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oCFModel);
 
      // The following properties may also be set with XMultiPropertySet but we
      // use the XPropertySet interface merely for reasons of demonstration
      xCFModelPSet.setPropertyValue("PrependCurrencySymbol", Boolean.TRUE);
      xCFModelPSet.setPropertyValue("CurrencySymbol", "$");
      xCFModelPSet.setPropertyValue("Value", new Double(2.93));
 
      // add a textlistener that is notified on each change of the controlvalue...
      Object oCFControl = m_xDlgContainer.getControl(sName);
      xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, oCFControl);
      xTextComponent.addTextListener(_xTextListener);
  }catch (com.sun.star.uno.Exception ex){
      /* perform individual exception handling here.
       * Possible exception types are:
       * com.sun.star.lang.IllegalArgumentException,
       * com.sun.star.lang.WrappedTargetException,
       * com.sun.star.container.ElementExistException,
       * com.sun.star.beans.PropertyVetoException,
       * com.sun.star.beans.UnknownPropertyException,
       * com.sun.star.uno.Exception
       */
      ex.printStackTrace(System.out);
  }
      return xTextComponent;
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages