当前位置: 首页>>代码示例>>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;未经允许,请勿转载。