Пример #1
0
 public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
   // return immediately when selecting an item
   if (selecting) {
     return;
   }
   // insert the string into the document
   super.insertString(offs, str, a);
   // lookup and select a matching item
   Object item = lookupItem(getText(0, getLength()));
   if (item != null) {
     setSelectedItem(item);
   } else {
     // keep old item selected if there is no match
     item = comboBox.getSelectedItem();
     // imitate no insert (later on offs will be incremented by str.length(): selection won't move
     // forward)
     offs = offs - str.length();
     // provide feedback to the user that his input has been received but can not be accepted
     comboBox
         .getToolkit()
         .beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
   }
   setText(item.toString());
   // select the completed part
   highlightCompletedText(offs + str.length());
 }
Пример #2
0
    @Override
    public void insertString(final int offs, final String str, final AttributeSet a)
        throws BadLocationException {
      // NavigatorLogger.printMessage("Offset:"+offs+" STr:"+str+"L:"+getLength()+"attr:"+a);

      if ((getLength() + str.length()) <= maxLength) {
        final char[] source = str.toCharArray();
        final char[] result = new char[source.length];
        int j = 0;

        for (int i = 0; i < result.length; i++) {
          if (Character.isDigit(source[i])) {
            result[j++] = source[i];
          } else {
            toolkit.beep();
            if (log.isDebugEnabled()) {
              log.debug("insertString: " + source[i]); // NOI18N
            }
          }
        }
        super.insertString(offs, new String(result, 0, j), a);
        checked = false;
      } else {
        toolkit.beep();
      }
      if ((getLength()) == maxLength) { // getLength() ist schon aktualisiert
        if (bringFocus2Next == true) {
          checked = true;
          nextField.requestFocus();
        }
        // NavigatorLogger.printMessage("Sprung");
        // NavigatorLogger.printMessage(nextField);
      }
    }
Пример #3
0
 private void setText(String text) {
   try {
     // remove all text and insert the completed string
     super.remove(0, getLength());
     super.insertString(0, text, null);
   } catch (BadLocationException e) {
     throw new RuntimeException(e.toString());
   }
 }
 public void insertString(int offset, String str, AttributeSet attSet)
     throws BadLocationException {
   if (upperCase) str = str.toUpperCase();
   super.insertString(offset, str, attSet);
 }