Pattern Field

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 13:27, 22 December 2020 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



The pattern field control com.sun.star.awt.UnoControlPatternField defines a character code that restricts the user input. This character code that determines what the user may enter is defined by the EditMask property. The length of the edit is equivalent to the number of the possible input positions. If a character is entered that does not correspond to the edit mask, the input is rejected. For example, in the edit mask "NNLNNLLLLL" the character "L" has the meaning of a text constant and the character "N" means that only the digits 0 to 9 can be entered. A complete list of valid characters can be found in the table below. The LiteralMask property contains the initial values that are displayed in the pattern field. The length of the literal mask should always correspond to the length of the edit mask. An example of a literal mask which fits to the edit mask would be "__.__.2002". In this case, the user enters only 4 digits when entering a date. If StrictFormat is set to true, the text will be checked during user input. If StrictFormat is not set to true the text is not checked until the focus is leaving the control.

Character of property EditMask Meaning
L A text constant. This position cannot be edited. The character is displayed at the corresponding position of the Literal Mask.
a The characters a-z and A-Z can be entered. Capital characters are not converted to lowercase characters.
A The characters A-Z can be entered. If a lowercase letter is entered, it is automatically converted to a capital letter
c The characters a-z, A-Z, and 0-9 can be entered. Capital characters are not converted to lowercase characters.
C The characters A-Z and 0-9 can be entered. If a lowercase letter is entered, it is automatically converted to a capital letter.
N Only the characters 0-9 can be entered.
x All printable characters can be entered.
X All printable characters can be entered. If a lowercase letter is used, it is automatically converted to a capital letter.
  public XPropertySet insertPatternField(int _nPosX, int _nPosY, int _nWidth){
  XPropertySet xPFModelPSet = null;
  try{
      // create a unique name by means of an own implementation...
      String sName = createUniqueName(m_xDlgModelNameContainer, "PatternField");
 
      // create a controlmodel at the multiservicefactory of the dialog model... 
      Object oPFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlPatternFieldModel");
      XMultiPropertySet xPFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oPFModel);
 
      // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 
      xPFModelMPSet.setPropertyValues(
      new String[] {"Height", "Name", "PositionX", "PositionY", "Width"},
      new Object[] { 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, oPFModel);
      xPFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oPFModel);
 
      // The following properties may also be set with XMultiPropertySet but we
      // use the XPropertySet interface merely for reasons of demonstration 
      xPFModelPSet.setPropertyValue("LiteralMask", "__.05.2007");
      // Allow only numbers for the first two digits...
      xPFModelPSet.setPropertyValue("EditMask", "NNLLLLLLLL");
      // verify the user input immediately...
      xPFModelPSet.setPropertyValue("StrictFormat", Boolean.TRUE);
  }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 xPFModelPSet;
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages