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


Java Format.formatToCharacterIterator方法代碼示例

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


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

示例1: formatAndAppend

import java.text.Format; //導入方法依賴的package包/類
public void formatAndAppend(Format formatter, Object arg) {
    if (attributes == null) {
        append(formatter.format(arg));
    } else {
        AttributedCharacterIterator formattedArg = formatter.formatToCharacterIterator(arg);
        int prevLength = length;
        append(formattedArg);
        // Copy all of the attributes from formattedArg to our attributes list.
        formattedArg.first();
        int start = formattedArg.getIndex();  // Should be 0 but might not be.
        int limit = formattedArg.getEndIndex();  // == start + length - prevLength
        int offset = prevLength - start;  // Adjust attribute indexes for the result string.
        while (start < limit) {
            Map<Attribute, Object> map = formattedArg.getAttributes();
            int runLimit = formattedArg.getRunLimit();
            if (map.size() != 0) {
                for (Map.Entry<Attribute, Object> entry : map.entrySet()) {
                   attributes.add(
                       new AttributeAndPosition(
                           entry.getKey(), entry.getValue(),
                           offset + start, offset + runLimit));
                }
            }
            start = runLimit;
            formattedArg.setIndex(start);
        }
    }
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:29,代碼來源:MessageFormat.java

示例2: select

import java.text.Format; //導入方法依賴的package包/類
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(JSpinner spinner)
{
	JComponent editor = spinner.getEditor();

	if( editor instanceof JSpinner.DateEditor )
	{
		JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
		JFormattedTextField ftf = dateEditor.getTextField();
		Format format = dateEditor.getFormat();
		Object value = spinner.getValue();

		if( format != null && value != null )
		{
			SpinnerDateModel model = dateEditor.getModel();
			DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());

			if( field != null )
			{
				try
				{
					AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
					if( !select(ftf, iterator, field) && field == DateFormat.Field.HOUR0 )
					{
						select(ftf, iterator, DateFormat.Field.HOUR1);
					}
				}
				catch( IllegalArgumentException iae )
				{
					// ??
				}
			}
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:39,代碼來源:FlatterSpinnerUI.java


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