@Test public void testCreateFormat() { String formatString = null; Locale locale = new Locale( "test_test" ); TimeZone timeZone = TimeZone.getDefault(); Class parameterType = null; Format format = TextComponentEditHandler.createFormat( formatString, locale, timeZone, parameterType ); assertThat( format, is( nullValue() ) ); formatString = "0.0.0"; format = TextComponentEditHandler.createFormat( formatString, locale, timeZone, parameterType ); assertThat( format, is( nullValue() ) ); parameterType = Number.class; format = TextComponentEditHandler.createFormat( formatString, locale, timeZone, parameterType ); assertThat( format, is( nullValue() ) ); formatString = "#,###,##0.00"; format = TextComponentEditHandler.createFormat( formatString, locale, timeZone, parameterType ); assertThat( format, is( instanceOf( DecimalFormat.class ) ) ); parameterType = Date.class; formatString = "o"; format = TextComponentEditHandler.createFormat( formatString, locale, timeZone, parameterType ); assertThat( format, is( nullValue() ) ); formatString = "dd.MM.yyyy"; format = TextComponentEditHandler.createFormat( formatString, locale, timeZone, parameterType ); assertThat( format, is( instanceOf( SimpleDateFormat.class ) ) ); }
public static Format createFormat( final String formatString, final Locale locale, final TimeZone timeZone, final Class parameterType ) { if ( formatString == null || parameterType == null ) { return null; } if ( Number.class.isAssignableFrom( parameterType ) ) { try { final DecimalFormat decimalFormat = new DecimalFormat( formatString, new DecimalFormatSymbols( locale ) ); decimalFormat.setParseBigDecimal( true ); return decimalFormat; } catch ( Exception e ) { } } if ( Date.class.isAssignableFrom( parameterType ) ) { try { final SimpleDateFormat dateFormat = new SimpleDateFormat( formatString, locale ); dateFormat.setLenient( false ); dateFormat.setTimeZone( timeZone ); return dateFormat; } catch ( Exception e ) { } } return null; }
TextComponentEditHandler implements Runnable, DocumentListener, ActionListener { public static Format createFormat( final String formatString, final Locale locale, final TimeZone timeZone, final Class parameterType ) { if ( formatString == null || parameterType == null ) { return null; } if ( Number.class.isAssignableFrom( parameterType ) ) { try { final DecimalFormat decimalFormat = new DecimalFormat( formatString, new DecimalFormatSymbols( locale ) ); decimalFormat.setParseBigDecimal( true ); return decimalFormat; } catch ( Exception e ) { } } if ( Date.class.isAssignableFrom( parameterType ) ) { try { final SimpleDateFormat dateFormat = new SimpleDateFormat( formatString, locale ); dateFormat.setLenient( false ); dateFormat.setTimeZone( timeZone ); return dateFormat; } catch ( Exception e ) { } } return null; } }
TextComponentEditHandler implements Runnable, DocumentListener, ActionListener { public static Format createFormat( final String formatString, final Locale locale, final TimeZone timeZone, final Class parameterType ) { if ( formatString == null || parameterType == null ) { return null; } if ( Number.class.isAssignableFrom( parameterType ) ) { try { final DecimalFormat decimalFormat = new DecimalFormat( formatString, new DecimalFormatSymbols( locale ) ); decimalFormat.setParseBigDecimal( true ); return decimalFormat; } catch ( Exception e ) { } } if ( Date.class.isAssignableFrom( parameterType ) ) { try { final SimpleDateFormat dateFormat = new SimpleDateFormat( formatString, locale ); dateFormat.setLenient( false ); dateFormat.setTimeZone( timeZone ); return dateFormat; } catch ( Exception e ) { } } return null; } TextComponentEditHandler( final Class type, final String keyName, final JTextComponent textComponent,
      final ParameterUpdateContext updateContext, final Format formatter ); }
TextComponentEditHandler implements Runnable, DocumentListener, ActionListener { public static Format createFormat( final String formatString, final Locale locale, final TimeZone timeZone, final Class parameterType ) { if ( formatString == null || parameterType == null ) { return null; } if ( Number.class.isAssignableFrom( parameterType ) ) { try { final DecimalFormat decimalFormat = new DecimalFormat( formatString, new DecimalFormatSymbols( locale ) ); decimalFormat.setParseBigDecimal( true ); return decimalFormat; } catch ( Exception e ) { } } if ( Date.class.isAssignableFrom( parameterType ) ) { try { final SimpleDateFormat dateFormat = new SimpleDateFormat( formatString, locale ); dateFormat.setLenient( false ); dateFormat.setTimeZone( timeZone ); return dateFormat; } catch ( Exception e ) { } } return null; } TextComponentEditHandler( final Class type, final String keyName, final JTextComponent textComponent,
      final ParameterUpdateContext updateContext, final Format formatter ); boolean isAdjustingToExternalInput(); void setAdjustingToExternalInput( final boolean adjustingToExternalInput ); void insertUpdate( final DocumentEvent e ); void removeUpdate( final DocumentEvent e ); void changedUpdate( final DocumentEvent e ); void run(); void actionPerformed( final ActionEvent e ); static TimeZone createTimeZone( final String selectedItem, final TimeZone defaultValue ); static Format createFormat( final String formatString, final Locale locale, final TimeZone timeZone,
      final Class parameterType ); }
TextComponentEditHandler implements Runnable, DocumentListener, ActionListener { public static Format createFormat( final String formatString, final Locale locale, final TimeZone timeZone, final Class parameterType ) { if ( formatString == null || parameterType == null ) { return null; } if ( Number.class.isAssignableFrom( parameterType ) ) { try { final DecimalFormat decimalFormat = new DecimalFormat( formatString, new DecimalFormatSymbols( locale ) ); decimalFormat.setParseBigDecimal( true ); return decimalFormat; } catch ( Exception e ) { } } if ( Date.class.isAssignableFrom( parameterType ) ) { try { final SimpleDateFormat dateFormat = new SimpleDateFormat( formatString, locale ); dateFormat.setLenient( false ); dateFormat.setTimeZone( timeZone ); return dateFormat; } catch ( Exception e ) { } } return null; } TextComponentEditHandler( final Class type, final String keyName, final JTextComponent textComponent,
      final ParameterUpdateContext updateContext, final Format formatter ); boolean isAdjustingToExternalInput(); void setAdjustingToExternalInput( final boolean adjustingToExternalInput ); void insertUpdate( final DocumentEvent e ); void removeUpdate( final DocumentEvent e ); void changedUpdate( final DocumentEvent e ); void run(); void actionPerformed( final ActionEvent e ); static TimeZone createTimeZone( final String selectedItem, final TimeZone defaultValue ); static Format createFormat( final String formatString, final Locale locale, final TimeZone timeZone,
      final Class parameterType );  }