Java Code Examples for javax.swing.text.DateFormatter

The following are top voted examples for showing how to use javax.swing.text.DateFormatter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: PhET   File: DateEditor.java   View source code 6 votes vote down vote up
public DateEditor() {
    super( new JFormattedTextField() );
    textField = (JFormattedTextField) getComponent();

    textField.setFormatterFactory( new DefaultFormatterFactory( new DateFormatter( Entry.LOAD_FORMAT ) ) );
    textField.setFocusLostBehavior( JFormattedTextField.PERSIST );

    textField.getInputMap().put( KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), "check" );
    textField.getActionMap().put( "check", new AbstractAction() {
        public void actionPerformed( ActionEvent e ) {
            if ( !textField.isEditValid() ) { //The text is invalid.
                if ( userSaysRevert() ) { //reverted
                    textField.postActionEvent(); //inform the editor
                }
            }
            else {
                try {              //The text is valid,
                    textField.commitEdit();     //so use it.
                    textField.postActionEvent(); //stop editing
                }
                catch ( java.text.ParseException exc ) {
                }
            }
        }
    } );
}
 
Example 2
Project: High-Frequency-Data-Order-Book-Analyser   File: SimulationParameters.java   View source code 6 votes vote down vote up
/**
 * Creates new form FileSelection
 */
public SimulationParameters() {
    initComponents();
    this.setResizable(false);
    this.setTitle("File Selection");
    fileReader = new FileRead();
    initialiseDateComboBox(fileReader);

    JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(SpinnerTime, "HH:mm:ss");
    DateFormatter formatter = (DateFormatter) timeEditor.getTextField().getFormatter();
    formatter.setAllowsInvalid(false); // Make sure no invalid input is allowed
    SpinnerTime.setEditor(timeEditor);
    String StartTime = "08:30:00";
    Date time;
    try {
        time = new SimpleDateFormat("HH:mm:ss").parse(StartTime);
        SpinnerTime.setValue(time); // will only show the current time
    } catch (ParseException ex) {
        Logger.getLogger(SimulationParameters.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 3
Project: jspresso-ce   File: JDateField.java   View source code 6 votes vote down vote up
private void initDefaultBehaviour(Locale locale) {
  setRenderer(new FixedDayRenderer());
  setHeaderRenderer(new TranslatedHeaderRenderer(locale));
  new FormatSymbols((DateFormatter) getFormattedTextField().getFormatter(),
      locale);
  getFormattedTextField().setBorder(
      BorderFactory.createEmptyBorder(1, 5, 1, 5));
  SwingUtil.enableSelectionOnFocusGained(getFormattedTextField());
  addFocusListener(new FocusAdapter() {

    @Override
    public void focusGained(FocusEvent e) {
      if (!e.isTemporary()) {
        JTextField tf = ((DateField) e.getSource()).getFormattedTextField();
        tf.requestFocusInWindow();
      }
    }
  });
  setValue(null);
}
 
Example 4
Project: poc-opennms-spreadsheet-category-manager   File: Starter.java   View source code 6 votes vote down vote up
@Deprecated
//not used yet
private File setupWorkspace() {
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    DateFormatter dateFormatter = new DateFormatter(dateFormat);
    String dateString = "not_set_yet";
    File workspace = null;
    try {
        dateString = dateFormatter.valueToString(new Date());
        workspace = new File(WORKSPACE_NAME + File.separator + dateString);
        workspace.mkdirs();
    } catch (ParseException ex) {
        logger.error("Date String parsing went wrong", ex);
    }
    if (workspace != null && !(workspace.exists() && workspace.canRead() && workspace.canWrite())) {
        logger.error("Problem with Workspace folder '{}'", WORKSPACE_NAME + File.separator + dateString);
        System.exit(1);
    }
    return workspace;
}
 
Example 5
Project: cn1   File: JFormattedTextFieldTest.java   View source code 6 votes vote down vote up
public void testCreateFormattersFactory() {
    DefaultFormatterFactory factory;
    tf.setValue(new Integer(34));
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof NumberFormatter);
    //TODO: check if factory.getDefaultFormatter() should be same to factory.getDisplayFormatter()
    // or factory.getEditFormatter().
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue(new Date());
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof DateFormatter);
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue("sdffsdf");
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
    tf.setFormatterFactory(null);
    tf.setValue(Color.RED);
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
}
 
Example 6
Project: cn1   File: JSpinnerTest.java   View source code 6 votes vote down vote up
public void testDateEditor_DateEditor() {
    spinner.setModel(new SpinnerDateModel());
    DateEditor dateEditor = (DateEditor) spinner.getEditor();
    spinner.setEditor(dateEditor);
    assertTrue(dateEditor.getTextField().isEditable());
    assertTrue(dateEditor.getTextField().getFormatter() instanceof DateFormatter);
    assertNull(((DateFormatter) dateEditor.getTextField().getFormatter()).getMinimum());
    assertNull(((DateFormatter) dateEditor.getTextField().getFormatter()).getMaximum());
    assertTrue(dateEditor.getFormat().equals(new SimpleDateFormat()));
    spinner.setModel(abstractModel);
    testExceptionalCase(new IllegalArgumentCase() {
        @Override
        public void exceptionalAction() throws Exception {
            new JSpinner.DateEditor(spinner);
        }
    });
}
 
Example 7
Project: cn1   File: JSpinnerTest.java   View source code 6 votes vote down vote up
public void testDateEditor_formatter() {
    spinner.setModel(new SpinnerDateModel());
    DateEditor dateEditor = new DateEditor(spinner);
    spinner.setEditor(dateEditor);
    final Date date1 = new Date(777);
    DateFormatter dateFormatter = ((DateFormatter) dateEditor.getTextField().getFormatter());
    dateFormatter.setMaximum(date1);
    assertSame(dateFormatter.getMaximum(), date1);
    assertSame(dateEditor.getModel().getEnd(), date1);
    final Date date2 = new Date(555);
    dateEditor.getModel().setEnd(date2);
    assertSame(dateFormatter.getMaximum(), date2);
    assertSame(dateEditor.getModel().getEnd(), date2);
    SpinnerDateModel old = (SpinnerDateModel) spinner.getModel();
    spinner.setModel(abstractModel);
    final Date date3 = new Date(555);
    old.setEnd(date3);
    assertEquals(((DateFormatter) ((DateEditor) spinner.getEditor()).getTextField()
            .getFormatter()).getMaximum(), date3);
}
 
Example 8
Project: freeVM   File: JFormattedTextFieldTest.java   View source code 6 votes vote down vote up
public void testCreateFormattersFactory() {
    DefaultFormatterFactory factory;
    tf.setValue(new Integer(34));
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof NumberFormatter);
    //TODO: check if factory.getDefaultFormatter() should be same to factory.getDisplayFormatter()
    // or factory.getEditFormatter().
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue(new Date());
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof DateFormatter);
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue("sdffsdf");
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
    tf.setFormatterFactory(null);
    tf.setValue(Color.RED);
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
}
 
Example 9
Project: freeVM   File: JSpinnerTest.java   View source code 6 votes vote down vote up
public void testDateEditor_DateEditor() {
    spinner.setModel(new SpinnerDateModel());
    DateEditor dateEditor = (DateEditor) spinner.getEditor();
    spinner.setEditor(dateEditor);
    assertTrue(dateEditor.getTextField().isEditable());
    assertTrue(dateEditor.getTextField().getFormatter() instanceof DateFormatter);
    assertNull(((DateFormatter) dateEditor.getTextField().getFormatter()).getMinimum());
    assertNull(((DateFormatter) dateEditor.getTextField().getFormatter()).getMaximum());
    assertTrue(dateEditor.getFormat().equals(new SimpleDateFormat()));
    spinner.setModel(abstractModel);
    testExceptionalCase(new IllegalArgumentCase() {
        @Override
        public void exceptionalAction() throws Exception {
            new JSpinner.DateEditor(spinner);
        }
    });
}
 
Example 10
Project: freeVM   File: JFormattedTextFieldTest.java   View source code 6 votes vote down vote up
public void testCreateFormattersFactory() {
    DefaultFormatterFactory factory;
    tf.setValue(new Integer(34));
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof NumberFormatter);
    //TODO: check if factory.getDefaultFormatter() should be same to factory.getDisplayFormatter()
    // or factory.getEditFormatter().
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue(new Date());
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof DateFormatter);
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue("sdffsdf");
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
    tf.setFormatterFactory(null);
    tf.setValue(Color.RED);
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
}
 
Example 11
Project: freeVM   File: JSpinnerTest.java   View source code 6 votes vote down vote up
public void testDateEditor_DateEditor() {
    spinner.setModel(new SpinnerDateModel());
    DateEditor dateEditor = (DateEditor) spinner.getEditor();
    spinner.setEditor(dateEditor);
    assertTrue(dateEditor.getTextField().isEditable());
    assertTrue(dateEditor.getTextField().getFormatter() instanceof DateFormatter);
    assertNull(((DateFormatter) dateEditor.getTextField().getFormatter()).getMinimum());
    assertNull(((DateFormatter) dateEditor.getTextField().getFormatter()).getMaximum());
    assertTrue(dateEditor.getFormat().equals(new SimpleDateFormat()));
    spinner.setModel(abstractModel);
    testExceptionalCase(new IllegalArgumentCase() {
        @Override
        public void exceptionalAction() throws Exception {
            new JSpinner.DateEditor(spinner);
        }
    });
}
 
Example 12
Project: freeVM   File: JSpinnerTest.java   View source code 6 votes vote down vote up
public void testDateEditor_formatter() {
    spinner.setModel(new SpinnerDateModel());
    DateEditor dateEditor = new DateEditor(spinner);
    spinner.setEditor(dateEditor);
    final Date date1 = new Date(777);
    DateFormatter dateFormatter = ((DateFormatter) dateEditor.getTextField().getFormatter());
    dateFormatter.setMaximum(date1);
    assertSame(dateFormatter.getMaximum(), date1);
    assertSame(dateEditor.getModel().getEnd(), date1);
    final Date date2 = new Date(555);
    dateEditor.getModel().setEnd(date2);
    assertSame(dateFormatter.getMaximum(), date2);
    assertSame(dateEditor.getModel().getEnd(), date2);
    SpinnerDateModel old = (SpinnerDateModel) spinner.getModel();
    spinner.setModel(abstractModel);
    final Date date3 = new Date(555);
    old.setEnd(date3);
    assertEquals(((DateFormatter) ((DateEditor) spinner.getEditor()).getTextField()
            .getFormatter()).getMaximum(), date3);
}
 
Example 13
Project: wichtel   File: FormatFactory.java   View source code 6 votes vote down vote up
/**
 * Creates a {@link DateFormatter} for display-mode from a given {@link DateFormat}.
 *
 * @param format for the formatter
 * @return created {@link DateFormatter}
 * @see DateFormat
 * @see DateFormatter
 * @since 0.0.1
 */
public static DateFormatter createDateFormatterDisplay(final DateFormat format) {
	if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(format));
	if (null == format) {
		throw new RuntimeExceptionIsNull("format"); //$NON-NLS-1$
	}

	final DateFormatter result = new DateFormatter(format) {
		private static final long serialVersionUID = 8705680761187261160L;

		{
			setCommitsOnValidEdit(true);
		}
	};

	if (log.isDebugEnabled()) log.debug(HelperLog.methodExit(result));
	return result;
}
 
Example 14
Project: wichtel   File: FormatFactory.java   View source code 6 votes vote down vote up
/**
 * Creates a {@link DateFormatter} for edit-mode from a given {@link DateFormat}.
 *
 * @param format for the formatter
 * @return created {@link DateFormatter}
 * @see DateFormat
 * @see DateFormatter
 * @since 0.0.1
 */
public static DateFormatter createDateFormatterEdit(final DateFormat format) {
	if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(format));
	if (null == format) {
		throw new RuntimeExceptionIsNull("format"); //$NON-NLS-1$
	}

	final DateFormatter result = new DateFormatter(format) {
		private static final long serialVersionUID = 8705680761187261160L;

		{
			setCommitsOnValidEdit(true);
		}
	};

	if (log.isDebugEnabled()) log.debug(HelperLog.methodExit(result));
	return result;
}
 
Example 15
Project: JRLib   File: MonthDateSpinner.java   View source code 6 votes vote down vote up
public MonthDateSpinner(MonthDate value, MonthDate min, MonthDate max) {
    super(new SpinnerDateModel(MDF.toDate(value), toDate(min), toDate(max), STEP_UNIT));
    SpinnerDateModel model = (SpinnerDateModel) super.getModel();
    minDate = (Date) model.getStart();
    maxDate = (Date) model.getEnd();
    
    JFormattedTextField text = ((JSpinner.DateEditor) getEditor()).getTextField();
    DateFormatter df = new DateFormatter(new SimpleDateFormat(PATTERN));
    text.setFormatterFactory(new DefaultFormatterFactory(df));
    text.setColumns(PATTERN.length());
    text.setEditable(false);
    text.setHorizontalAlignment(JTextField.RIGHT);

    revalidate();
    repaint();
}
 
Example 16
Project: smile_1.5.0_java7   File: DateCellEditor.java   View source code 5 votes vote down vote up
/**
 * Constructor.
 */
public DateCellEditor(DateFormat dateFormat) {
    super(new JFormattedTextField());
    textField = (JFormattedTextField) getComponent();

    this.dateFormat = dateFormat;
    DateFormatter dateFormatter = new DateFormatter(dateFormat);

    textField.setFormatterFactory(new DefaultFormatterFactory(dateFormatter));
    textField.setHorizontalAlignment(JTextField.TRAILING);
    textField.setFocusLostBehavior(JFormattedTextField.PERSIST);

    // React when the user presses Enter while the editor is
    // active.  (Tab is handled as specified by
    // JFormattedTextField's focusLostBehavior property.)
    textField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
    textField.getActionMap().put("check", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!textField.isEditValid()) { //The text is invalid.
                Toolkit.getDefaultToolkit().beep();
                textField.selectAll();
            } else {
                try {              //The text is valid,
                    textField.commitEdit();     //so use it.
                    textField.postActionEvent(); //stop editing
                } catch (java.text.ParseException ex) {
                }
            }
        }
    });
}
 
Example 17
Project: j2se_for_android   File: JFormattedTextField.java   View source code 5 votes vote down vote up
/**
 * Returns an AbstractFormatterFactory suitable for the passed in Object
 * type.
 */
private AbstractFormatterFactory getDefaultFormatterFactory(Object type) {
	if (type instanceof DateFormat) {
		return new DefaultFormatterFactory(new DateFormatter(
				(DateFormat) type));
	}
	if (type instanceof NumberFormat) {
		return new DefaultFormatterFactory(new NumberFormatter(
				(NumberFormat) type));
	}
	if (type instanceof Format) {
		return new DefaultFormatterFactory(new InternationalFormatter(
				(Format) type));
	}
	if (type instanceof Date) {
		return new DefaultFormatterFactory(new DateFormatter());
	}
	if (type instanceof Number) {
		AbstractFormatter displayFormatter = new NumberFormatter();
		((NumberFormatter) displayFormatter).setValueClass(type.getClass());
		AbstractFormatter editFormatter = new NumberFormatter(
				new DecimalFormat("#.#"));
		((NumberFormatter) editFormatter).setValueClass(type.getClass());

		return new DefaultFormatterFactory(displayFormatter,
				displayFormatter, editFormatter);
	}
	return new DefaultFormatterFactory(new DefaultFormatter());
}
 
Example 18
Project: JGrafix   File: EixoHorizontalComLabels.java   View source code 5 votes vote down vote up
@Override
public List refreshTicks(Graphics2D g2, AxisState state,
        Rectangle2D dataArea, RectangleEdge edge) {
    try {
        long l1 = this.getMaximumDate().getTime();
        long l2 = this.getMinimumDate().getTime();
        int diasExibidos = (int) ((l1 - l2) / ref);
        if (diasExibidos == diasExibidosAnterior && ticksAnteriores != null) {
            return ticksAnteriores; // otimizacao
        } else {
            List result = new ArrayList();
            int j = 0;
            for (int i = acao.getNumeroRegistros() - 1; i >= 0; i--) {
                int n = (int) (diasExibidos / QUANTIDADE_DATAS);
                if (j++ % n == 0) {
                    result.add(new DateTick(acao.getRegistro(i).getDataCorrida().getStart(),
                            new DateFormatter(new SimpleDateFormat("dd/MM/yy")).valueToString(acao.getRegistro(i).getData().getStart()),
                            TextAnchor.TOP_CENTER,
                            TextAnchor.TOP_RIGHT, 0));
                } else {
                    result.add(new DateTick(acao.getRegistro(i).getDataCorrida().getStart(),
                            "",
                            TextAnchor.TOP_CENTER,
                            TextAnchor.TOP_RIGHT, 0));
                }
            }
            ticksAnteriores = result;
            diasExibidosAnterior = diasExibidos;
            return result;
        }
    } catch (Exception e) {
        return new ArrayList();
    }
}
 
Example 19
Project: swingx   File: JXDatePickerVisualCheck.java   View source code 5 votes vote down vote up
/**
 * From forum: have spinner with the same timezone.
 */
public void interactiveTimeZoneFormat() {
    final JSpinner spinner = new JSpinner(new SpinnerDateModel());
    final JXDatePicker picker = new JXDatePicker();
    picker.setTimeZone(TimeZone.getTimeZone("GMT-10"));
    picker.setDate(new Date());
    spinner.setValue(picker.getDate());
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss", picker.getLocale());
    format.setTimeZone(picker.getTimeZone());
    JFormattedTextField textField = ((DefaultEditor) spinner.getEditor()).getTextField();
    textField.setFormatterFactory(
            new DefaultFormatterFactory(new DateFormatter(format)));
    PropertyChangeListener l = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ("date".equals(evt.getPropertyName())) {
                if (picker.getDate() != null)
                 spinner.setValue(picker.getDate());
            }
        }
        
    };
    picker.addPropertyChangeListener(l);
    JXPanel panel = new JXPanel();
    panel.add(picker);
    panel.add(spinner);
    showInFrame(panel, "formats in picker and spinner");
}
 
Example 20
Project: swingx   File: JXDatePickerTest.java   View source code 5 votes vote down vote up
/**
 * Issue #1144-swingx: JXDatePicker must accept custom formatter.
 * Use core DateFormatter - issue manifests in throwing classcastEx
 */
@Test
public void testCustomFormatterCore() {
    JXDatePicker picker = new JXDatePicker();
    DefaultFormatterFactory factory = new DefaultFormatterFactory(new DateFormatter());
    picker.getEditor().setFormatterFactory(factory);
    picker.updateUI();
}
 
Example 21
Project: jspresso-ce   File: DefaultSwingViewFactory.java   View source code 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected IView<JComponent> createDatePropertyView(IPropertyViewDescriptor propertyViewDescriptor,
                                                   IActionHandler actionHandler, Locale locale) {
  IDatePropertyDescriptor propertyDescriptor = (IDatePropertyDescriptor) propertyViewDescriptor.getModelDescriptor();
  IValueConnector connector;
  JComponent viewComponent;
  TimeZone timeZone =
      propertyDescriptor.isTimeZoneAware() ? actionHandler.getClientTimeZone() : actionHandler.getReferenceTimeZone();
  DateFormat format = createDateFormat(propertyViewDescriptor, propertyDescriptor, timeZone, actionHandler, locale);
  IFormatter<?, String> formatter = createFormatter(format);
  if (propertyViewDescriptor.isReadOnly()) {
    if (propertyViewDescriptor.getAction() != null) {
      viewComponent = createJLink(propertyViewDescriptor);
    } else {
      viewComponent = createJLabel(propertyViewDescriptor, true);
    }
    connector = new JLabelConnector(propertyDescriptor.getName(), (JLabel) viewComponent);
    ((JLabelConnector) connector).setFormatter(formatter);
  } else {
    viewComponent = createJDateField(propertyViewDescriptor, locale);
    ((JDateField) viewComponent).getFormattedTextField().setFormatterFactory(
        new DefaultFormatterFactory(new DateFormatter(format)));
    connector = new JDateFieldConnector(propertyDescriptor.getName(), (JDateField) viewComponent);
  }
  adjustSizes(propertyViewDescriptor, viewComponent, formatter, getDateTemplateValue(propertyDescriptor),
      Toolkit.getDefaultToolkit().getScreenResolution() / 3);
  connector.setExceptionHandler(actionHandler);
  IView<JComponent> view = constructView(viewComponent, propertyViewDescriptor, connector);
  return view;
}
 
Example 22
Project: cn1   File: JFormattedTextField.java   View source code 5 votes vote down vote up
private AbstractFormatterFactory createFactory(final Object value) {
    DefaultFormatterFactory factory = new DefaultFormatterFactory();
    if (value instanceof Number) {
        factory.setDefaultFormatter(new NumberFormatter());
    } else if (value instanceof Date) {
        factory.setDefaultFormatter(new DateFormatter());
    } else {
        factory.setDefaultFormatter(new DefaultFormatter());
    }
    return factory;
}
 
Example 23
Project: cn1   File: JFormattedTextField.java   View source code 5 votes vote down vote up
private AbstractFormatter createFormatter(final Format format) {
    if (format instanceof DateFormat) {
        return new DateFormatter((DateFormat) format);
    } else if (format instanceof NumberFormat) {
        return new NumberFormatter((NumberFormat) format);
    } else {
        return new InternationalFormatter(format);
    }
}
 
Example 24
Project: snap-desktop   File: DateTimePicker.java   View source code 5 votes vote down vote up
private void updateTextFieldFormat() {
    if (timeSpinner == null) {
        return;
    }
    JFormattedTextField tf = ((JSpinner.DefaultEditor) timeSpinner.getEditor()).getTextField();
    DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory();
    DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter();
    // Change the date format to only show the hours
    formatter.setFormat(timeFormat);
}
 
Example 25
Project: nosql4idea   File: DateTimePicker.java   View source code 5 votes vote down vote up
private void updateTextFieldFormat() {
    if (timeSpinner == null) return;
    JFormattedTextField tf = ((JSpinner.DefaultEditor) timeSpinner.getEditor()).getTextField();
    DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory();
    DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter();
    // Change the date format to only show the hours
    formatter.setFormat(timeFormat);
}
 
Example 26
Project: freeVM   File: JFormattedTextField.java   View source code 5 votes vote down vote up
private AbstractFormatterFactory createFactory(final Object value) {
    DefaultFormatterFactory factory = new DefaultFormatterFactory();
    if (value instanceof Number) {
        factory.setDefaultFormatter(new NumberFormatter());
    } else if (value instanceof Date) {
        factory.setDefaultFormatter(new DateFormatter());
    } else {
        factory.setDefaultFormatter(new DefaultFormatter());
    }
    return factory;
}
 
Example 27
Project: freeVM   File: JFormattedTextField.java   View source code 5 votes vote down vote up
private AbstractFormatter createFormatter(final Format format) {
    if (format instanceof DateFormat) {
        return new DateFormatter((DateFormat) format);
    } else if (format instanceof NumberFormat) {
        return new NumberFormatter((NumberFormat) format);
    } else {
        return new InternationalFormatter(format);
    }
}
 
Example 28
Project: freeVM   File: JSpinnerTest.java   View source code 5 votes vote down vote up
public void testDateEditor_formatter() {
    spinner.setModel(new SpinnerDateModel());
    DateEditor dateEditor = new DateEditor(spinner);
    spinner.setEditor(dateEditor);
    final Date date1 = new Date(777);
    DateFormatter dateFormatter = ((DateFormatter) dateEditor.getTextField().getFormatter());
    dateFormatter.setMaximum(date1);
    assertSame(dateFormatter.getMaximum(), date1);
    assertSame(dateEditor.getModel().getEnd(), date1);
    final Date date2 = new Date(555);
    dateEditor.getModel().setEnd(date2);
    assertSame(dateFormatter.getMaximum(), date2);
    assertSame(dateEditor.getModel().getEnd(), date2);
    SpinnerDateModel old = (SpinnerDateModel) spinner.getModel();
    spinner.setModel(abstractModel);
    final Date date3 = new Date(555);
    old.setEnd(date3);
    assertEquals(((DateFormatter) ((DateEditor) spinner.getEditor()).getTextField()
            .getFormatter()).getMaximum(), date3);
}
 
Example 29
Project: freeVM   File: JFormattedTextField.java   View source code 5 votes vote down vote up
private AbstractFormatterFactory createFactory(final Object value) {
    DefaultFormatterFactory factory = new DefaultFormatterFactory();
    if (value instanceof Number) {
        factory.setDefaultFormatter(new NumberFormatter());
    } else if (value instanceof Date) {
        factory.setDefaultFormatter(new DateFormatter());
    } else {
        factory.setDefaultFormatter(new DefaultFormatter());
    }
    return factory;
}
 
Example 30
Project: freeVM   File: JFormattedTextField.java   View source code 5 votes vote down vote up
private AbstractFormatter createFormatter(final Format format) {
    if (format instanceof DateFormat) {
        return new DateFormatter((DateFormat) format);
    } else if (format instanceof NumberFormat) {
        return new NumberFormatter((NumberFormat) format);
    } else {
        return new InternationalFormatter(format);
    }
}
 
Example 31
Project: TechScore   File: DetailsPane.java   View source code 5 votes vote down vote up
/**
 * Creates a new <code>DetailsPane</code> instance.
 *
 */
public DetailsPane(Regatta reg) {
  super("Details");
  this.setIcon(Factory.getImageIcon("img/Edit16.gif", this.toString()));
  this.df = new DateFormatter(DateFormat.getDateInstance(DateFormat.SHORT,
					   Locale.US));
  this.tf = new DateFormatter(DateFormat.getTimeInstance(DateFormat.SHORT,
					   Locale.US));
  this.setLayout(new GridBagLayout());
  this.setRegatta(reg);
}
 
Example 32
Project: FTC-FieldMgmt   File: myDateField.java   View source code 5 votes vote down vote up
public myDateField() {
    this.setValue(new Date());
    this.setFormatterFactory(new DefaultFormatterFactory(new DateFormatter(new SimpleDateFormat("yyyy-MM-dd HH:mm"))));
    this.setValue(Calendar.getInstance().getTime());

    this.addPropertyChangeListener("value", new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {

        }
    });
}
 
Example 33
Project: jdk8u-jdk   File: Test6462562.java   View source code 4 votes vote down vote up
TestFormattedTextField create(DateFormat format) {
    DateFormatter fmt = new DateFormatter(format);
    return new TestFormattedTextField(fmt);
}
 
Example 34
Project: openjdk-jdk10   File: Test6462562.java   View source code 4 votes vote down vote up
TestFormattedTextField create(DateFormat format) {
    DateFormatter fmt = new DateFormatter(format);
    return new TestFormattedTextField(fmt);
}
 
Example 35
Project: openjdk9   File: Test6462562.java   View source code 4 votes vote down vote up
TestFormattedTextField create(DateFormat format) {
    DateFormatter fmt = new DateFormatter(format);
    return new TestFormattedTextField(fmt);
}
 
Example 36
Project: jdk8u_jdk   File: Test6462562.java   View source code 4 votes vote down vote up
TestFormattedTextField create(DateFormat format) {
    DateFormatter fmt = new DateFormatter(format);
    return new TestFormattedTextField(fmt);
}
 
Example 37
Project: lookaside_java-1.8.0-openjdk   File: Test6462562.java   View source code 4 votes vote down vote up
TestFormattedTextField create(DateFormat format) {
    DateFormatter fmt = new DateFormatter(format);
    return new TestFormattedTextField(fmt);
}
 
Example 38
Project: swingx   File: DatePickerDemo.java   View source code 4 votes vote down vote up
private void configureComponents() {
    dateEchoField.setEditable(false);
    AbstractFormatter formatter = new DateFormatter(DateFormat.getDateTimeInstance());
    AbstractFormatterFactory tf = new DefaultFormatterFactory(formatter);
    dateEchoField.setFormatterFactory(tf);
}
 
Example 39
Project: tellervo   File: BasicDatePickerUI.java   View source code 4 votes vote down vote up
private DefaultFormatterFactory createFormatterFactory() {
	return new DefaultFormatterFactory(new DateFormatter(peer
			.getDateFormat()));
}
 
Example 40
Project: infobip-open-jdk-8   File: Test6462562.java   View source code 4 votes vote down vote up
TestFormattedTextField create(DateFormat format) {
    DateFormatter fmt = new DateFormatter(format);
    return new TestFormattedTextField(fmt);
}