Date Field

From Apache OpenOffice Wiki
Jump to: navigation, search

The date field control extends the text field control and is used for displaying and entering dates. The model is described in

Properties of
Date long. The date value displayed in the control. The type of the property is long and specified by the number format YYYYMMDD, where YYYY denotes fully qualified years, MM months, and DD days.
DateFormat short. The DateFormat is a key that determines the number format of the displayed date.
DateMax long. The maximum date that the user can enter
DateMin long. The minimum date that the user can enter
DateShowCentury This property is deprecated and should not be used.
Dropdown boolean. The Dropdown property enables a calendar that the user can drop down to select a date.
Spin boolean. The Spin property defines whether the control displays a spin button. This method reduces scrolling and selecting, to a one-step process.
StrictFormat boolean. If set to true, only the allowed characters as specified by the DateFormat property are accepted. All other entries typed with the keyboard are ignored.
  public XPropertySet insertDateField(XSpinListener _xSpinListener, int _nPosX, int _nPosY, int _nWidth){
  XPropertySet xDFModelPSet = null;
      // create a unique name by means of an own implementation...
      String sName = createUniqueName(m_xDlgModelNameContainer, "DateField");
      // create a controlmodel at the multiservicefactory of the dialog model... 
      Object oDFModel = m_xMSFDialogModel.createInstance("");
      XMultiPropertySet xDFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oDFModel);
      // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 
      new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "Width"},
      new Object[] {Boolean.TRUE, new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nWidth)});
      // The controlmodel is not really available until inserted to the Dialog container 
      m_xDlgModelNameContainer.insertByName(sName, oDFModel);
      xDFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oDFModel);
      // The following properties may also be set with XMultiPropertySet but we
      // use the XPropertySet interface merely for reasons of demonstration 
      xDFModelPSet.setPropertyValue("DateFormat", new Short((short) 7));
      xDFModelPSet.setPropertyValue("DateMin", new Integer(20070401));
      xDFModelPSet.setPropertyValue("DateMax", new Integer(20070501));
      xDFModelPSet.setPropertyValue("Date", new Integer(20000415)); 
      Object oDFControl = m_xDlgContainer.getControl(sName);
      // add a SpinListener that is notified on each change of the controlvalue... 
      XSpinField xSpinField = (XSpinField) UnoRuntime.queryInterface(XSpinField.class, oDFControl);
  }catch ( ex){
      /* perform individual exception handling here.
       * Possible exception types are:
      return xDFModelPSet;
Documentation note.png Note: Basic developers can use the runtime functions CDateToIso() or CDateFromIso() to convert the date in ISO format from or to a serial date number that is generated by the DateSerial() or the DateValue() function.

Although the date field control provides a spin button, there is no Step property. In this control, the interval steps of the spin button are set automatically and depend on the position of the cursor within the date display. This means that if, for example, the cursor is within the month section of the date display, only the months are controlled by the spin button.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages