Numeric Field

From Apache OpenOffice Wiki
Jump to: navigation, search

For developers who want to use a simple numeric field control and find the number formatter too difficult to handle, they can use the numeric field control The control model, specified in is simple to set up as the following table illustrates:

Properties of
DecimalAccuracy short. The DecimalAccuracy property specifies the number of digits displayed to the right of the decimal point.
ShowThousandsSeparator boolean. Determines whether thousands separators are used.
Value double. Specifies the current value of the control.
ValueMax double. Specifies the maximum value that the user can enter.
ValueMin double. Specifies the minimum value that the user can enter.
ValueStep double. Specifies the interval steps when using the spin button.

The code example sets up a numeric field with a defined number format and defines the numerical range within which the Value may be modified.

  public XPropertySet insertNumericField( int _nPosX, int _nPosY, int _nWidth,
                                          double _fValueMin, double _fValueMax, double _fValue,
                                          double _fValueStep, short _nDecimalAccuracy){
  XPropertySet xNFModelPSet = null;
      // create a unique name by means of an own implementation...
      String sName = createUniqueName(m_xDlgModelNameContainer, "NumericField");
      // create a controlmodel at the multiservicefactory of the dialog model... 
      Object oNFModel = m_xMSFDialogModel.createInstance("");
      XMultiPropertySet xNFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oNFModel);
      // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 
      new String[] {"Height", "Name", "PositionX", "PositionY", "Spin", "StrictFormat", "Width"},
      new Object[] { new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), Boolean.TRUE, Boolean.TRUE, new Integer(_nWidth)});
      // The controlmodel is not really available until inserted to the Dialog container
      m_xDlgModelNameContainer.insertByName(sName, oNFModel);
      xNFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oNFModel);
      // The following properties may also be set with XMultiPropertySet but we
      // use the XPropertySet interface merely for reasons of demonstration 
      xNFModelPSet.setPropertyValue("ValueMin", new Double(_fValueMin));
      xNFModelPSet.setPropertyValue("ValueMax", new Double(_fValueMax));
      xNFModelPSet.setPropertyValue("Value", new Double(_fValue));
      xNFModelPSet.setPropertyValue("ValueStep", new Double(_fValueStep));
      xNFModelPSet.setPropertyValue("ShowThousandsSeparator", Boolean.TRUE);
      xNFModelPSet.setPropertyValue("DecimalAccuracy", new Short(_nDecimalAccuracy));
  }catch ( ex){
      /* perform individual exception handling here.
       * Possible exception types are:
      return xNFModelPSet;
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages