NumberField.java :  » MVC » aratana » com » aratana » ui » fields » Java Open Source

Java Open Source » MVC » aratana 
aratana » com » aratana » ui » fields » NumberField.java
package com.aratana.ui.fields;

import java.awt.ComponentOrientation;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

@SuppressWarnings("serial")
public class NumberField extends BasicField<Long> {

  public NumberField() {
    setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    setDocument(new PlainDocument() {

      @Override
      public void insertString(final int offs, String str, final AttributeSet a) throws BadLocationException {
        str = str.replaceAll("[^0-9]", "");
        super.insertString(offs, (getMax() > 0 && str.length() + NumberField.this.getText().length() > getMax() ? str.substring(0, getMax() - NumberField.this.getText().length()) : str).toUpperCase(), a);
      }
    });
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.