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


Java AttributedCharacterIterator類代碼示例

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


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

示例1: getFontAtCurrentPos

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
static Font getFontAtCurrentPos(AttributedCharacterIterator aci) {

        Object value = aci.getAttribute(TextAttribute.FONT);
        if (value != null) {
            return (Font) value;
        }
        if (aci.getAttribute(TextAttribute.FAMILY) != null) {
            return Font.getFont(aci.getAttributes());
        }

        int ch = CodePointIterator.create(aci).next();
        if (ch != CodePointIterator.DONE) {
            FontResolver resolver = FontResolver.getInstance();
            return resolver.getFont(resolver.getFontIndex(ch), aci.getAttributes());
        }
        return null;
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:TextLine.java

示例2: write

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
@Override
public void write(Text text, Writer writer) throws IOException {
  AttributedCharacterIterator iterator = text.getIterator();

  Entry<Attribute, Object> lastAttribute = null;
  while (true) {
    if (iterator.getIndex() == iterator.getEndIndex()) {
      break;
    }

    Entry<Attribute, Object> entry = getAttribute(iterator);

    if (!Objects.equals(entry, lastAttribute)) {
      endEntity(lastAttribute, writer);
      beginEntity(entry, writer);
    }

    writer.write(iterator.current());

    lastAttribute = entry;
    iterator.next();
  }

  endEntity(lastAttribute, writer);
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:26,代碼來源:MarkdownTextWriter.java

示例3: while

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
private static AttributedCharacterIterator getTrimmedTrailingSpacesIterator
        (AttributedCharacterIterator iterator) {
    int curIdx = iterator.getIndex();

    char c = iterator.last();
    while(c != CharacterIterator.DONE && Character.isWhitespace(c)) {
        c = iterator.previous();
    }

    if (c != CharacterIterator.DONE) {
        int endIdx = iterator.getIndex();

        if (endIdx == iterator.getEndIndex() - 1) {
            iterator.setIndex(curIdx);
            return iterator;
        } else {
            AttributedString trimmedText = new AttributedString(iterator,
                    iterator.getBeginIndex(), endIdx + 1);
            return trimmedText.getIterator();
        }
    } else {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:SwingUtilities2.java

示例4: checkIteratorText

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
private static final void checkIteratorText(AttributedCharacterIterator iterator, String expectedText) throws Exception {
    if (iterator.getEndIndex() - iterator.getBeginIndex() != expectedText.length()) {
        throwException(iterator, "text length doesn't match between original text and iterator");
    }

    char c = iterator.first();
    for (int i = 0; i < expectedText.length(); i++) {
        if (c != expectedText.charAt(i)) {
            throwException(iterator, "text content doesn't match between original text and iterator");
        }
        c = iterator.next();
    }
    if (c != CharacterIterator.DONE) {
        throwException(iterator, "iterator text doesn't end with DONE");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:AttributedStringTest.java

示例5: select

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
/**
 * Selects the passed in field, returning true if it is found, false
 * otherwise.
 */
private boolean select(JFormattedTextField ftf, AttributedCharacterIterator iterator, DateFormat.Field field)
{
	int max = ftf.getDocument().getLength();

	iterator.first();
	do
	{
		Map<Attribute, Object> attrs = iterator.getAttributes();

		if( attrs != null && attrs.containsKey(field) )
		{
			int start = iterator.getRunStart(field);
			int end = iterator.getRunLimit(field);

			if( start != -1 && end != -1 && start <= max && end <= max )
			{
				ftf.select(start, end);
			}
			return true;
		}
	}
	while( iterator.next() != CharacterIterator.DONE );
	return false;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:29,代碼來源:FlatterSpinnerUI.java

示例6: getAttribute

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
public Object getAttribute(AttributedCharacterIterator.Attribute att) {
    if (att == TextAttribute.FONT) {
        return fonts[getIndex()];
    } else if (att == TextAttribute.FOREGROUND) {
        return colors[getIndex()];
    } else {
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:AttributedCharacters.java

示例7: getAttributes

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
public Map<AttributedCharacterIterator.Attribute,Object> getAttributes() {
    Map<AttributedCharacterIterator.Attribute,Object> m = new HashMap<AttributedCharacterIterator.Attribute,Object>(1);
    m.put(TextAttribute.FONT, fonts[getIndex()]);
    m.put(TextAttribute.FOREGROUND, colors[getIndex()]);

    return m;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:AttributedCharacters.java

示例8: getRunLimit

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
public int getRunLimit(AttributedCharacterIterator.Attribute att) {
    if ((att != TextAttribute.FONT) && (att != TextAttribute.FOREGROUND)) {
        return getEndIndex(); // undefined attribute
    }

    return getRunLimit();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:AttributedCharacters.java

示例9: standardCreateTextLine

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
/**
 * Create a TextLine from the text.  chars is just the text in the iterator.
 */
public static TextLine standardCreateTextLine(FontRenderContext frc,
                                              AttributedCharacterIterator text,
                                              char[] chars,
                                              float[] baselineOffsets) {

    StyledParagraph styledParagraph = new StyledParagraph(text, chars);
    Bidi bidi = new Bidi(text);
    if (bidi.isLeftToRight()) {
        bidi = null;
    }
    int layoutFlags = 0; // no extra info yet, bidi determines run and line direction
    TextLabelFactory factory = new TextLabelFactory(frc, chars, bidi, layoutFlags);

    boolean isDirectionLTR = true;
    if (bidi != null) {
        isDirectionLTR = bidi.baseIsLeftToRight();
    }
    return createLineFromText(chars, styledParagraph, factory, isDirectionLTR, baselineOffsets);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:TextLine.java

示例10: ComponentLine

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
ComponentLine(AttributedCharacterIterator it, Font defaultFont, Color defaultColor) {
    for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
        Font font = (Font) it.getAttribute(TextAttribute.FONT);
        Color color = (Color) it.getAttribute(TextAttribute.FOREGROUND);
        mySymbols.add(new Symbol(c, createFont(font, defaultFont), createColor(color, defaultColor)));
    }
    checkSpaces(defaultFont, defaultColor);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:ComponentLine.java

示例11: getRunLimit

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
/**
 * Returns the index of the first character following the run
 * with respect to the given attribute containing the current character.
 */
public int getRunLimit(AttributedCharacterIterator.Attribute attribute) {
    if (attribute instanceof TextAttribute) {
        int pos = toModelPosition(getIndex());
        int i = v.getViewIndex(pos, Position.Bias.Forward);
        if (attribute == TextAttribute.FONT) {
            return toIteratorIndex(getFontBoundary(i, 1));
        }
    }
    return getEndIndex();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:TextLayoutStrategy.java

示例12: advanceToFirstFont

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
/**
 * When this returns, the ACI's current position will be at the start of the
 * first run which does NOT contain a GraphicAttribute.  If no such run exists
 * the ACI's position will be at the end, and this method will return false.
 */
static boolean advanceToFirstFont(AttributedCharacterIterator aci) {

    for (char ch = aci.first();
         ch != CharacterIterator.DONE;
         ch = aci.setIndex(aci.getRunLimit()))
    {

        if (aci.getAttribute(TextAttribute.CHAR_REPLACEMENT) == null) {
            return true;
        }
    }

    return false;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:TextLine.java

示例13: translateAttributes

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
private AttributeSet translateAttributes(Map<AttributedCharacterIterator.Attribute, ?> source) {
    for(AttributedCharacterIterator.Attribute sourceKey : source.keySet()) {
        Object sourceValue = source.get(sourceKey);
        
        // Ignore any non-input method related highlights
        if (!(sourceValue instanceof InputMethodHighlight)) {
            continue;
        }
        
        InputMethodHighlight imh = (InputMethodHighlight) sourceValue;
        
        if (imh.isSelected()) {
            return highlightInverse;
        } else {
            return highlightUnderlined;
        }
    }
    
    LOG.fine("No translation for " + source);
    return SimpleAttributeSet.EMPTY;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:ComposedTextHighlighting.java

示例14: getEntitiesWithValues

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private <T> List<Map.Entry<String, T>> getEntitiesWithValues(TextEntity entity) {
  AttributedCharacterIterator iterator = getIterator();
  List<Map.Entry<String, T>> entities = new ArrayList<>();
  StringBuilder builder = new StringBuilder();

  Map<AttributedCharacterIterator.Attribute, T> last = Collections.emptyMap();
  while (iterator.getIndex() != iterator.getEndIndex()) {
    Map<AttributedCharacterIterator.Attribute, T> curr =
        (Map<AttributedCharacterIterator.Attribute, T>) iterator.getAttributes();
    if (curr.containsKey(entity)) {
      builder.append(iterator.current());
    } else {
      if (last.containsKey(entity)) {
        entities.add(
            new AbstractMap.SimpleImmutableEntry<>(builder.toString(), last.get(entity))
        );
        builder.setLength(0);
      }
    }
    last = curr;

    iterator.next();
  }
  if (last.containsKey(entity)) {
    entities.add(
        new AbstractMap.SimpleImmutableEntry<>(builder.toString(), last.get(entity))
    );
  }

  return entities;
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:33,代碼來源:Text.java

示例15: TextLayout

import java.text.AttributedCharacterIterator; //導入依賴的package包/類
/**
 * Constructs a {@code TextLayout} from an iterator over styled text.
 * <p>
 * The iterator must specify a single paragraph of text because an
 * entire paragraph is required for the bidirectional
 * algorithm.
 * @param text the styled text to display
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       {@code TextLayout} and user space.
 */
public TextLayout(AttributedCharacterIterator text, FontRenderContext frc) {

    if (text == null) {
        throw new IllegalArgumentException("Null iterator passed to TextLayout constructor.");
    }

    int start = text.getBeginIndex();
    int limit = text.getEndIndex();
    if (start == limit) {
        throw new IllegalArgumentException("Zero length iterator passed to TextLayout constructor.");
    }

    int len = limit - start;
    text.first();
    char[] chars = new char[len];
    int n = 0;
    for (char c = text.first();
         c != CharacterIterator.DONE;
         c = text.next())
    {
        chars[n++] = c;
    }

    text.first();
    if (text.getRunLimit() == limit) {

        Map<? extends Attribute, ?> attributes = text.getAttributes();
        Font font = singleFont(chars, 0, len, attributes);
        if (font != null) {
            fastInit(chars, font, attributes, frc);
            return;
        }
    }

    standardInit(text, chars, frc);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:51,代碼來源:TextLayout.java


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