Time Field

From Apache OpenOffice Wiki
Jump to: navigation, search



The time field control com.sun.star.awt.UnoControlTimeField and its model com.sun.star.awt.UnoControlTimeFieldModel displays and enters time values.

Properties of com.sun.star.awt.UnoControlTimeFieldModel
Time long. The time value is set and retrieved by the Time property. The time value is of type long and is specified in the ISO format HHMMSShh, where HH are hours, MM are minutes, SS are seconds and hh are hundredth seconds. See the example below.
TimeFormat short. The format of the displayed time is specified by the TimeFormat key that denotes defined formats as specified below where a Time value of 15182300 is assumed:
Key Description Example
0: 24h short 15:18
1 24h long 15:18:23
2 12h short 03:18PM
3 12h long 03:18:23PM
4 Duration short 15:18
5 Duration long 15:18:23
TimeMax long. Similar to to the UnoControlDateField, the minimum and maximum time value that can be entered is given by the TimeMin and TimeMax properties. If the value of Time exceeds one of these two limits the value is automatically reset to the according maximum or minimum value.
TimeMin

Although the time field provides a spin button, there is no Step property. In this control the interval steps are set automatically and depend on the position of the cursor within the time display. For example, if the cursor is within the minute section of the time display only the minutes are controlled by the spin button.

  public XPropertySet insertTimeField(int _nPosX, int _nPosY, int _nWidth, int _nTime, int _nTimeMin, int _nTimeMax){
  XPropertySet xTFModelPSet = null;
  try{
      // create a unique name by means of an own implementation...
      String sName = createUniqueName(m_xDlgModelNameContainer, "TimeField");
 
      // create a controlmodel at the multiservicefactory of the dialog model... 
      Object oTFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlTimeFieldModel");
      XMultiPropertySet xTFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel);
 
      // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 
      xTFModelMPSet.setPropertyValues(
      new String[] {"Height", "Name", "PositionX", "PositionY", "Spin", "Width"},
      new Object[] { new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), Boolean.TRUE, new Integer(_nWidth)});
 
      // The controlmodel is not really available until inserted to the Dialog container
      m_xDlgModelNameContainer.insertByName(sName, oTFModel);
      xTFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTFModel);
 
      // The following properties may also be set with XMultiPropertySet but we
      // use the XPropertySet interface merely for reasons of demonstration 
      xTFModelPSet.setPropertyValue("TimeFormat", new Short((short) 5));
      xTFModelPSet.setPropertyValue("TimeMin", new Integer(_nTimeMin));
      xTFModelPSet.setPropertyValue("TimeMax", new Integer(_nTimeMax));
      xTFModelPSet.setPropertyValue("Time", new Integer(_nTime)); 
  }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 xTFModelPSet;
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages