Java Code Examples for com.ibm.icu.util.ULocale#getDefault()

The following examples show how to use com.ibm.icu.util.ULocale#getDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputParameterDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private ULocale cvonvertFormatLocale( ScalarParameterHandle paraHandle )
{
	ULocale formatLocale = null;
	Object formatValue = paraHandle.getProperty( IScalarParameterModel.FORMAT_PROP );
	if ( formatValue instanceof FormatValue )
	{
		PropertyHandle propHandle = paraHandle.getPropertyHandle( IScalarParameterModel.FORMAT_PROP );
		FormatValue formatValueToSet = (FormatValue) formatValue;
		FormatValueHandle formatHandle = (FormatValueHandle) formatValueToSet.getHandle( propHandle );
		formatLocale = formatHandle.getLocale( );
	}
	if ( formatLocale == null )
	{
		formatLocale = ULocale.getDefault( );
	}
	return formatLocale;
}
 
Example 2
Source File: ExecutionContext.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * create a new context. Call close to finish using the execution context
 */
public ExecutionContext( EngineTask engineTask )
{
	if ( engineTask != null )
	{
		task = engineTask;
		engine = (ReportEngine) task.getEngine( );
		log = task.getLogger( );
	}
	else
	{
		log = Logger.getLogger( ExecutionContext.class.getName( ) );
	}

	ulocale = ULocale.getDefault( );
	timeZone = TimeZone.getDefault( );
	eventHandlerManager = new EventHandlerManager( );
}
 
Example 3
Source File: FormatCurrencyNumPattern.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the default number of fraction digits that should be displayed
 * for the default currency for given locale.
 * 
 * @param locale
 * @return
 */
public static int getDefaultFractionDigits( ULocale locale )
{
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}

	Currency currency = Currency.getInstance( locale );
	if ( currency != null )
	{
		return currency.getDefaultFractionDigits( );
	}

	return 2;
}
 
Example 4
Source File: ImageAreaLayout.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private BlockTextArea createInnerTextLayout( )
{
	IReportContent report = image.getReportContent( );
	if ( report == null )
	{
		return null;
	}
	ITextContent promptTextContent = report.createTextContent( image );
	ULocale locale = ULocale.forLocale( context.getLocale( ) );
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}
	EngineResourceHandle resourceHandle = new EngineResourceHandle(
			locale );

	String prompt = resourceHandle
			.getMessage( MessageConstants.UPDATE_USER_AGENT_PROMPT );

	promptTextContent.setText( prompt );
	return new BlockTextArea( root, context, promptTextContent );
}
 
Example 5
Source File: CascadingParametersDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void updateFormatField( )
{
	String displayFormat;
	IChoiceSet choiceSet = getFormatChoiceSet( getSelectedDataType( ) );
	if ( choiceSet == null )
	{// Boolean type;
		displayFormat = DEUtil.getMetaDataDictionary( )
				.getChoiceSet( DesignChoiceConstants.CHOICE_STRING_FORMAT_TYPE )
				.findChoice( DesignChoiceConstants.STRING_FORMAT_TYPE_UNFORMATTED )
				.getDisplayName( );
	}
	else
	{
		if ( formatCategroy == null
				|| choiceSet.findChoice( formatCategroy ) == null )
			return;
		displayFormat = choiceSet.findChoice( formatCategroy )
				.getDisplayName( );
		if ( isCustom( ) )
		{
			displayFormat += ":  " + formatPattern; //$NON-NLS-1$
		}
	}
	formatField.setText( "" + displayFormat ); //$NON-NLS-1$
	changeFormat.setEnabled( choiceSet != null );

	if ( selectedParameter != null )
	{
		ULocale locale = formatLocale;
		if ( locale == null )
			locale = ULocale.getDefault( );
		doPreview( isCustom( ) ? formatPattern : formatCategroy, locale );
	}
}
 
Example 6
Source File: SimpleDateFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private void initialize() {
    if (locale == null) {
        locale = ULocale.getDefault(Category.FORMAT);
    }
    if (formatData == null) {
        formatData = new DateFormatSymbols(locale);
    }
    if (calendar == null) {
        calendar = Calendar.getInstance(locale);
    }
    if (numberFormat == null) {
        NumberingSystem ns = NumberingSystem.getInstance(locale);
        if (ns.isAlgorithmic()) {
            numberFormat = NumberFormat.getInstance(locale);
        } else {
            String digitString = ns.getDescription();
            String nsName = ns.getName();
            // Use a NumberFormat optimized for date formatting
            numberFormat = new DateNumberFormat(locale, digitString, nsName);
        }
    }
    // Note: deferring calendar calculation until when we really need it.
    // Instead, we just record time of construction for backward compatibility.
    defaultCenturyBase = System.currentTimeMillis();

    setLocale(calendar.getLocale(ULocale.VALID_LOCALE ), calendar.getLocale(ULocale.ACTUAL_LOCALE));
    initLocalZeroPaddingNumberFormat();

    if (override != null) {
       initNumberFormatters(locale);
    }

    parsePattern();
}
 
Example 7
Source File: SelectionChoiceComparator.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public SelectionChoiceComparator( boolean sortDisplayValue, String format, boolean sortDirection, ULocale locale)
{
	this.sortDirection = sortDirection;
	this.sortDisplayValue = sortDisplayValue;
    this.format = format;
    this.locale = locale;
    if( null == this.locale)
    {
    	this.locale = ULocale.getDefault( );
    }
}
 
Example 8
Source File: DateGroupCalculator.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public DateGroupCalculator( Object intervalStart, double intervalRange, ULocale locale, TimeZone timeZone ) throws BirtException
{
	super( intervalStart, intervalRange );
	ULocale aLocale = locale == null ? ULocale.getDefault( ):locale;
	TimeZone aZone = timeZone == null? TimeZone.getDefault( ):timeZone;
	
	Calendar c = Calendar.getInstance( aLocale );
	c.setTimeZone( aZone );
	c.clear( );
	c.set( 1970, 0, 1 );
	this.defaultStart = c.getTime( );
	this.dateTimeUtil = new DateTimeUtil( aLocale, aZone );
}
 
Example 9
Source File: BirtDateTime.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public Object execute( Object[] arguments, IScriptFunctionContext scriptContext )
		throws BirtException
{
	if ( scriptContext != null )
	{
		Object locale = scriptContext.findProperty(
				org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.LOCALE );
		if ( !( locale instanceof ULocale ) )
		{
			locale = ULocale.getDefault( );
		}
		if ( threadLocale.get( ) != locale )
		{
			threadLocale.set( (ULocale) locale );
			List<SimpleDateFormat> sdfList = new ArrayList<SimpleDateFormat>( );
			sdfList.add(
					new SimpleDateFormat( "MMM", threadLocale.get( ) ) );
			sdfList.add(
					new SimpleDateFormat( "MMMM", threadLocale.get( ) ) );
			sdfList.add(
					new SimpleDateFormat( "EEE", threadLocale.get( ) ) );
			sdfList.add(
					new SimpleDateFormat( "EEEE", threadLocale.get( ) ) );
			threadSDFArray.set( sdfList );
		}

		Object timeZone = scriptContext.findProperty(
				org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.TIMEZONE );
		if ( !( timeZone instanceof TimeZone ) )
		{
			timeZone = TimeZone.getDefault( );
		}
		if ( threadTimeZone.get( ) != timeZone )
		{
			threadTimeZone.set( (TimeZone) timeZone );
		}
	}
	return this.executor.execute( arguments, scriptContext );
}
 
Example 10
Source File: ICULocaleService.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Return the name of the current fallback locale.  If it has changed since this was
 * last accessed, the service cache is cleared.
 */
public String validateFallbackLocale() {
    ULocale loc = ULocale.getDefault();
    if (loc != fallbackLocale) {
        synchronized (this) {
            if (loc != fallbackLocale) {
                fallbackLocale = loc;
                fallbackLocaleName = loc.getBaseName();
                clearServiceCache();
            }
        }
    }
    return fallbackLocaleName;
}
 
Example 11
Source File: JndiDataSource.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Utility method to format externalized message, without using JDBCException.
 */
private String getMessage( String errorCode, String argument )
{
    if( sm_resourceHandle == null )
        sm_resourceHandle = new JdbcResourceHandle( ULocale.getDefault() );

    String msgText = sm_resourceHandle.getMessage( errorCode );
    if( argument == null )
        return msgText;
    return MessageFormat.format( msgText, new Object[]{ argument } );
}
 
Example 12
Source File: NumberFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the currency in effect for this formatter.  Subclasses
 * should override this method as needed.  Unlike getCurrency(),
 * this method should never return null.
 * @return a non-null Currency
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
protected Currency getEffectiveCurrency() {
    Currency c = getCurrency();
    if (c == null) {
        ULocale uloc = getLocale(ULocale.VALID_LOCALE);
        if (uloc == null) {
            uloc = ULocale.getDefault(Category.FORMAT);
        }
        c = Currency.getInstance(uloc);
    }
    return c;
}
 
Example 13
Source File: DisplayAdapter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public final ULocale getULocale( )
{
	return ( lcl == null ) ? ULocale.getDefault( ) : lcl;
}
 
Example 14
Source File: FormatDateTimeLayoutPeer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void createTable( Composite parent )
{
	super.createTable( parent );

	ULocale locale = getLocale( );
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}

	TableColumn tableColumValue = new TableColumn( customFormatTable,
			SWT.NONE );
	tableColumValue.setText( LABEL_TABLE_COLUMN_EXAMPLE_FORMAT_NAME );
	tableColumValue.setWidth( 90 );
	tableColumValue.setResizable( true );

	TableColumn tableColumnDisplay = new TableColumn( customFormatTable,
			SWT.NONE );
	tableColumnDisplay.setText( LABEL_TABLE_COLUMN_EXAMPLE_FORMAT_RESULT );
	tableColumnDisplay.setWidth( 120 );
	tableColumnDisplay.setResizable( true );

	TableColumn tableColumnFormatCode = new TableColumn( customFormatTable,
			SWT.NONE );
	tableColumnFormatCode.setText( LABEL_TABLE_COLUMN_EXAMPLE_FORMAT_CODE );
	tableColumnFormatCode.setWidth( 120 );
	tableColumnFormatCode.setResizable( true );

	String[][] items = getTableItems( locale );
	for ( int i = 0; i < items.length; i++ )
	{
		new TableItem( customFormatTable, SWT.NONE ).setText( items[i] );
	}

	customFormatTable.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent e )
		{
			customFormatCodeTextBox.setText( ( (TableItem) e.item ).getText( FORMAT_CODE_INDEX ) );
			updatePreview( );
			notifyFormatChange( );
		}
	} );
}
 
Example 15
Source File: FormatStringLayoutPeer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void createTable( Composite parent )
{
	super.createTable( parent );

	ULocale locale = getLocale( );
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}

	TableColumn tableColumValue = new TableColumn( customFormatTable,
			SWT.NONE );
	tableColumValue.setText( LABEL_TABLE_COLUMN_EXAMPLE_FORMAT_CODE );
	tableColumValue.setWidth( 150 );
	tableColumValue.setResizable( true );

	TableColumn tableColumnDisplay = new TableColumn( customFormatTable,
			SWT.NONE );
	tableColumnDisplay.setText( LABEL_TABLE_COLUMN_EXAMPLE_FORMAT_RESULT );
	tableColumnDisplay.setWidth( 200 );
	tableColumnDisplay.setResizable( true );

	new TableItem( customFormatTable, SWT.NONE ).setText( new String[]{
			formatAdapter.getDisplayName4Category( DesignChoiceConstants.STRING_FORMAT_TYPE_UPPERCASE ),
			new StringFormatter( FormatStringPattern.getPatternForCategory( DesignChoiceConstants.STRING_FORMAT_TYPE_UPPERCASE,
					locale ),
					locale ).format( DEFAULT_PREVIEW_TEXT )
	} );
	new TableItem( customFormatTable, SWT.NONE ).setText( new String[]{
			formatAdapter.getDisplayName4Category( DesignChoiceConstants.STRING_FORMAT_TYPE_LOWERCASE ),
			new StringFormatter( FormatStringPattern.getPatternForCategory( DesignChoiceConstants.STRING_FORMAT_TYPE_LOWERCASE,
					locale ),
					locale ).format( DEFAULT_PREVIEW_TEXT )
	} );
	new TableItem( customFormatTable, SWT.NONE ).setText( new String[]{
			formatAdapter.getDisplayName4Category( DesignChoiceConstants.STRING_FORMAT_TYPE_ZIP_CODE_4 ),
			new StringFormatter( FormatStringPattern.getPatternForCategory( DesignChoiceConstants.STRING_FORMAT_TYPE_ZIP_CODE_4,
					locale ),
					locale ).format( SAMPLE_TEXT_ZIP_C0DE4 )
	} );
	new TableItem( customFormatTable, SWT.NONE ).setText( new String[]{
			formatAdapter.getDisplayName4Category( DesignChoiceConstants.STRING_FORMAT_TYPE_PHONE_NUMBER ),
			new StringFormatter( FormatStringPattern.getPatternForCategory( DesignChoiceConstants.STRING_FORMAT_TYPE_PHONE_NUMBER,
					locale ),
					locale ).format( SAMPLE_TEXT_PHONE_NUMBER )
	} );
	new TableItem( customFormatTable, SWT.NONE ).setText( new String[]{
			formatAdapter.getDisplayName4Category( DesignChoiceConstants.STRING_FORMAT_TYPE_SOCIAL_SECURITY_NUMBER ),
			new StringFormatter( FormatStringPattern.getPatternForCategory( DesignChoiceConstants.STRING_FORMAT_TYPE_SOCIAL_SECURITY_NUMBER,
					locale ),
					locale ).format( SAMPLE_TEXT_SOCIAL_SECURITY_NUMBER )
	} );
	new TableItem( customFormatTable, SWT.NONE ).setText( new String[]{
			formatAdapter.getDisplayName4Category( FormatStringAdapter.STRING_FORMAT_TYPE_PRESERVE_SPACE ),
			new StringFormatter( FormatStringPattern.getPatternForCategory( FormatStringAdapter.STRING_FORMAT_TYPE_PRESERVE_SPACE,
					locale ),
					locale ).format( SAMPLE_TEXT_PRESERVE_SPACE )
	} );

	customFormatTable.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent e )
		{
			String displayName = ( (TableItem) e.item ).getText( FORMAT_TYPE_INDEX );

			String pattern = formatAdapter.getPattern4DisplayName( displayName,
					getLocale( ) );

			customFormatCodeTextBox.setText( pattern );

			updatePreview( );
			notifyFormatChange( );
		}
	} );
}
 
Example 16
Source File: DataSetAdapter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public ULocale getULocale( )
{
	return ( lcl == null ) ? ULocale.getDefault( ) : lcl;
}
 
Example 17
Source File: PluralFormat.java    From fitnotifications with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the locale used by this <code>PluraFormat</code> object.
 * Note: Calling this method resets this <code>PluraFormat</code> object,
 *     i.e., a pattern that was applied previously will be removed,
 *     and the NumberFormat is set to the default number format for
 *     the locale.  The resulting format behaves the same as one
 *     constructed from {@link #PluralFormat(ULocale, PluralRules.PluralType)}
 *     with PluralType.CARDINAL.
 * @param ulocale the <code>ULocale</code> used to configure the
 *     formatter. If <code>ulocale</code> is <code>null</code>, the
 *     default <code>FORMAT</code> locale will be used.
 * @see Category#FORMAT
 * @deprecated ICU 50 This method clears the pattern and might create
 *             a different kind of PluralRules instance;
 *             use one of the constructors to create a new instance instead.
 */
@Deprecated
public void setLocale(ULocale ulocale) {
    if (ulocale == null) {
        ulocale = ULocale.getDefault(Category.FORMAT);
    }
    init(null, PluralType.CARDINAL, ulocale, null);
}
 
Example 18
Source File: RuleBasedNumberFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a RuleBasedNumberFormat that behaves according to the description
 * passed in.  The formatter uses the default <code>FORMAT</code> locale.
 * <p>
 * The localizations data provides information about the public
 * rule sets and their localized display names for different
 * locales. The first element in the list is an array of the names
 * of the public rule sets.  The first element in this array is
 * the initial default ruleset.  The remaining elements in the
 * list are arrays of localizations of the names of the public
 * rule sets.  Each of these is one longer than the initial array,
 * with the first String being the ULocale ID, and the remaining
 * Strings being the localizations of the rule set names, in the
 * same order as the initial array.
 * @param description A description of the formatter's desired behavior.
 * See the class documentation for a complete explanation of the description
 * syntax.
 * @param localizations a list of localizations for the rule set
 * names in the description.
 * @see Category#FORMAT
 * @stable ICU 3.2
 */
public RuleBasedNumberFormat(String description, String[][] localizations) {
    locale = ULocale.getDefault(Category.FORMAT);
    init(description, localizations);
}
 
Example 19
Source File: ICUService.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Convenience override of getDisplayNames(ULocale, Comparator, String) that
 * uses the current default Locale as the locale, null as
 * the comparator, and null for the matchID.
 */
public SortedMap<String, String> getDisplayNames() {
    ULocale locale = ULocale.getDefault(Category.DISPLAY);
    return getDisplayNames(locale, null, null);
}
 
Example 20
Source File: RuleBasedNumberFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a RuleBasedNumberFormat that behaves according to the description
 * passed in.  The formatter uses the default <code>FORMAT</code> locale.
 * @param description A description of the formatter's desired behavior.
 * See the class documentation for a complete explanation of the description
 * syntax.
 * @see Category#FORMAT
 * @stable ICU 2.0
 */
public RuleBasedNumberFormat(String description) {
    locale = ULocale.getDefault(Category.FORMAT);
    init(description, null);
}