當前位置: 首頁>>代碼示例>>Java>>正文


Java Format.Field方法代碼示例

本文整理匯總了Java中java.text.Format.Field方法的典型用法代碼示例。如果您正苦於以下問題:Java Format.Field方法的具體用法?Java Format.Field怎麽用?Java Format.Field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.Format的用法示例。


在下文中一共展示了Format.Field方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCalendarField

import java.text.Format; //導入方法依賴的package包/類
/**
 * Returns the calendarField under the start of the selection, or -1 if
 * there is no valid calendar field under the selection (or the spinner
 * isn't editing dates.
 */
private int getCalendarField(JSpinner spinner)
{
	JComponent editor = spinner.getEditor();

	if( editor instanceof JSpinner.DateEditor )
	{
		JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
		JFormattedTextField ftf = dateEditor.getTextField();
		int start = ftf.getSelectionStart();
		JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();

		if( formatter instanceof InternationalFormatter )
		{
			Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);

			for( int counter = 0; counter < fields.length; counter++ )
			{
				if( fields[counter] instanceof DateFormat.Field )
				{
					int calendarField;

					if( fields[counter] == DateFormat.Field.HOUR1 )
					{
						calendarField = Calendar.HOUR;
					}
					else
					{
						calendarField = ((DateFormat.Field) fields[counter]).getCalendarField();
					}
					if( calendarField != -1 )
					{
						return calendarField;
					}
				}
			}
		}
	}
	return -1;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:45,代碼來源:FlatterSpinnerUI.java

示例2: formatToCharacterIterator

import java.text.Format; //導入方法依賴的package包/類
AttributedCharacterIterator formatToCharacterIterator(Object obj, Unit unit) {
    if (!(obj instanceof Number))
        throw new IllegalArgumentException();
    Number number = (Number) obj;
    StringBuffer text = new StringBuffer();
    unit.writePrefix(text);
    attributes.clear();
    if (obj instanceof BigInteger) {
        format((BigInteger) number, text, new FieldPosition(0), true);
    } else if (obj instanceof java.math.BigDecimal) {
        format((java.math.BigDecimal) number, text, new FieldPosition(0)
                      , true);
    } else if (obj instanceof Double) {
        format(number.doubleValue(), text, new FieldPosition(0), true);
    } else if (obj instanceof Integer || obj instanceof Long) {
        format(number.longValue(), text, new FieldPosition(0), true);
    } else {
        throw new IllegalArgumentException();
    }
    unit.writeSuffix(text);
    AttributedString as = new AttributedString(text.toString());

    // add NumberFormat field attributes to the AttributedString
    for (int i = 0; i < attributes.size(); i++) {
        FieldPosition pos = attributes.get(i);
        Format.Field attribute = pos.getFieldAttribute();
        as.addAttribute(attribute, attribute, pos.getBeginIndex(), pos.getEndIndex());
    }

    // return the CharacterIterator from AttributedString
    return as.getIterator();
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:33,代碼來源:DecimalFormat.java


注:本文中的java.text.Format.Field方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。