Package javax.swing.text

Examples of javax.swing.text.DefaultFormatter$DocumentFilterImpl


    harness.check (field.getFormatter().getClass(), DefaultFormatter.class);
   

    harness.checkPoint ("setting formatter changes the text");
    MaskFormatter mask = null;
    DefaultFormatter nullFormatter = new DefaultFormatter();
    try
      {
        mask = new MaskFormatter ("UUUUUUU");
      }
    catch (ParseException pe)
View Full Code Here


   * @param h the test harness to use
   */
  private void testDefaultValue(TestHarness h)
  {
    h.checkPoint("defaultValue");
    DefaultFormatter f = new DefaultFormatter();
    h.check(f.getValueClass(), null);
  }
View Full Code Here

    }

    private void customInit() {
        setFocusLostBehavior(COMMIT);
        if (getFormatter() instanceof DefaultFormatter) {
            final DefaultFormatter d = (DefaultFormatter)getFormatter();
            AbstractAction toggleOverwrite = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    d.setOverwriteMode(!(d.getOverwriteMode()));
                }
            };
            getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0), TOGGLE_OVERWRITE_MODE_ACTION);
            getActionMap().put(TOGGLE_OVERWRITE_MODE_ACTION, toggleOverwrite);
        }
View Full Code Here

        return formatter;
    }

    private DefaultFormatter createFormatter(Class<?> valueClass, FormatProvider formatProvider)
    {
      DefaultFormatter formatter;
      //PM:18/3/08 BMO-22
      //CraigM: 28/04/2008: Added back in so Domain classes will work
      if (DomainDataValue.class.isAssignableFrom(valueClass) && format == null) {
        // Represents a user defined DataValue
        formatter = new DataFieldFormatter();
      }
      else if (DateTimeData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = new DateTimeDataFormatter(formatProvider.getDateFormat(format));
        }
        else {
          formatter = new DateTimeDataFormatter(formatProvider.getDefaultDateFormat());
        }
      }

      // Handle DecimalDatas differently from DoubleDatas as they have a different default.  CraigM: 24/03/2008
      else if (DecimalData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDefaultDecimalFormat());
        }
      }
      else if (DoubleData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDefaultDoubleFormat());
        }
      }
      else if (IntegerData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getIntegerDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getIntegerDataInstance(formatProvider.getDefaultIntegerFormat());
        }
      }
      // TF:14/10/2009:If we're using a primitive numeric type like double, we want these mapped the same as if we're using Double.class
      else if(Number.class.isAssignableFrom(valueClass) || valueClass.isPrimitive()) {
        if (format != null) {
          formatter = new ForteNumberFormatter(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = new ForteNumberFormatter(formatProvider.getDefaultDoubleFormat());
        }
      }
      else {
        formatter = new DataFieldFormatter();
      }
      formatter.setValueClass(valueClass);

        return applyInputMask(formatter);
    }
View Full Code Here

        return formatter;
    }

    private DefaultFormatter createFormatter(Class<?> valueClass, FormatProvider formatProvider)
    {
      DefaultFormatter formatter;
      //PM:18/3/08 BMO-22
      //CraigM: 28/04/2008: Added back in so Domain classes will work
      if (DomainDataValue.class.isAssignableFrom(valueClass) && format == null) {
        // Represents a user defined DataValue
        formatter = new DataFieldFormatter();
      }
      else if (DateTimeData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = new DateTimeDataFormatter(formatProvider.getDateFormat(format));
        }
        else {
          formatter = new DateTimeDataFormatter(formatProvider.getDefaultDateFormat());
        }
      }

      // Handle DecimalDatas differently from DoubleDatas as they have a different default.  CraigM: 24/03/2008
      else if (DecimalData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDefaultDecimalFormat());
        }
      }
      else if (DoubleData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDefaultDoubleFormat());
        }
      }
      else if (IntegerData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getIntegerDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getIntegerDataInstance(formatProvider.getDefaultIntegerFormat());
        }
      }
      // TF:14/10/2009:If we're using a primitive numeric type like double, we want these mapped the same as if we're using Double.class
      else if(Number.class.isAssignableFrom(valueClass) || valueClass.isPrimitive()) {
        if (format != null) {
          formatter = new ForteNumberFormatter(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = new ForteNumberFormatter(formatProvider.getDefaultDoubleFormat());
        }
      }
      else {
        formatter = new DataFieldFormatter();
      }
      formatter.setValueClass(valueClass);

        return applyInputMask(formatter);
    }
View Full Code Here

        return formatter;
    }

    private DefaultFormatter createFormatter(Class<?> valueClass, FormatProvider formatProvider)
    {
      DefaultFormatter formatter;
      //PM:18/3/08 BMO-22
      //CraigM: 28/04/2008: Added back in so Domain classes will work
      if (DomainDataValue.class.isAssignableFrom(valueClass) && format == null) {
        // Represents a user defined DataValue
        formatter = new DataFieldFormatter();
      }
      else if (DateTimeData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = new DateTimeDataFormatter(formatProvider.getDateFormat(format));
        }
        else {
          formatter = new DateTimeDataFormatter(formatProvider.getDefaultDateFormat());
        }
      }

      // Handle DecimalDatas differently from DoubleDatas as they have a different default.  CraigM: 24/03/2008
      else if (DecimalData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDefaultDecimalFormat());
        }
      }
      else if (DoubleData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getDecimalDataInstance(formatProvider.getDefaultDoubleFormat());
        }
      }
      else if (IntegerData.class.isAssignableFrom(valueClass)) {
        if (format != null) {
          formatter = NumericDataFormatter.getIntegerDataInstance(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = NumericDataFormatter.getIntegerDataInstance(formatProvider.getDefaultIntegerFormat());
        }
      }
      // TF:14/10/2009:If we're using a primitive numeric type like double, we want these mapped the same as if we're using Double.class
      else if(Number.class.isAssignableFrom(valueClass) || valueClass.isPrimitive()) {
        if (format != null) {
          formatter = new ForteNumberFormatter(formatProvider.getDecimalFormat(format));
        }
        else {
          formatter = new ForteNumberFormatter(formatProvider.getDefaultDoubleFormat());
        }
      }
      else {
        formatter = new DataFieldFormatter();
      }
      formatter.setValueClass(valueClass);

        return applyInputMask(formatter);
    }
View Full Code Here

        this.valueCommitPolicy = policy;
    }

    public AbstractFormatter getFormatter(JFormattedTextField source) {
        Object value = source.getValue();
        DefaultFormatter formatter;
        if (value instanceof Date) {
            formatter = new DateFormatter();
        }
        else if (value instanceof Number) {
            formatter = new NumberFormatter();
        }
        else {
            formatter = new DefaultFormatter();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Factory returning new formatter " + formatter + " for text field " + source);
        }
        valueCommitPolicy.configure(source, formatter);
        if (valueClass != null) {
            formatter.setValueClass(valueClass);
        }
        else if (value != null) {
            formatter.setValueClass(value.getClass());
        }
        return formatter;
    }
View Full Code Here

        if (value instanceof Number) {
            factory.setDefaultFormatter(new NumberFormatter());
        } else if (value instanceof Date) {
            factory.setDefaultFormatter(new DateFormatter());
        } else {
            factory.setDefaultFormatter(new DefaultFormatter());
        }
        return factory;
    }
View Full Code Here

            yearTextField.addPropertyChangeListener("value", spinListener);
           
            // make calendar update whenever an edit is made to the year selection
            JFormattedTextField.AbstractFormatter formatter = yearTextField.getFormatter();
            if (formatter instanceof DefaultFormatter) {
                DefaultFormatter defaultFormatter = (DefaultFormatter)formatter;
                defaultFormatter.setCommitsOnValidEdit(true);
                defaultFormatter.setAllowsInvalid(false);
            }
        }
       
        // set visible size of this editor
        setSize(getPreferredSize());
View Full Code Here

        SpinnerNumberModel spinnerModel = new SpinnerNumberModel(new Integer(1),new Integer(1),new Integer(50), new Integer(1));
        spinnerR = new JSpinner(spinnerModel);
       
        JComponent comp = spinnerR.getEditor();
        JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
        DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
        formatter.setCommitsOnValidEdit(true);
       
        ChangeListener spinnerRListener = new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                model.setR((Integer)spinnerR.getValue());
View Full Code Here

TOP

Related Classes of javax.swing.text.DefaultFormatter$DocumentFilterImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.