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


Java Attribute類代碼示例

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


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

示例1: write

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的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

示例2: insertText

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
/**
 * Tell the component to commit all of the characters in the string to the current
 * text view. This effectively wipes out any text in progress.
 */
private synchronized void insertText(String aString) {
    AttributedString attribString = new AttributedString(aString);

    // Set locale information on the new string.
    attribString.addAttribute(Attribute.LANGUAGE, getLocale(), 0, aString.length());

    TextHitInfo theCaret = TextHitInfo.afterOffset(aString.length() - 1);
    InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
                                                  InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                                                  attribString.getIterator(),
                                                  aString.length(),
                                                  theCaret,
                                                  theCaret);
    LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
    fCurrentText = null;
    fCurrentTextAsString = null;
    fCurrentTextLength = 0;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:CInputMethod.java

示例3: insertText

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
/**
 * Tell the component to commit all of the characters in the string to the current
 * text view. This effectively wipes out any text in progress.
 */
synchronized private void insertText(String aString) {
    AttributedString attribString = new AttributedString(aString);

    // Set locale information on the new string.
    attribString.addAttribute(Attribute.LANGUAGE, getLocale(), 0, aString.length());

    TextHitInfo theCaret = TextHitInfo.afterOffset(aString.length() - 1);
    InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
                                                  InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                                                  attribString.getIterator(),
                                                  aString.length(),
                                                  theCaret,
                                                  theCaret);
    LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
    fCurrentText = null;
    fCurrentTextAsString = null;
    fCurrentTextLength = 0;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:CInputMethod.java

示例4: fromSerializableHashtable

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
public static AttributeValues
fromSerializableHashtable(Hashtable<Object, Object> ht)
{
    AttributeValues result = new AttributeValues();
    if (ht != null && !ht.isEmpty()) {
        for (Map.Entry<Object, Object> e: ht.entrySet()) {
            Object key = e.getKey();
            Object val = e.getValue();
            if (key.equals(DEFINED_KEY)) {
                result.defineAll(((Integer)val).intValue());
            } else {
                try {
                    EAttribute ea =
                        EAttribute.forAttribute((Attribute)key);
                    if (ea != null) {
                        result.set(ea, val);
                    }
                }
                catch (ClassCastException ex) {
                }
            }
        }
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:AttributeValues.java

示例5: beginEntity

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
private void beginEntity(Entry<Attribute, Object> entry, Writer writer) throws IOException {
  if (entry == null) {
    return;
  }

  Attribute entity = entry.getKey();
  if (entity == TextEntity.BOLD) {
    writer.write("<b>");
  } else if (entity == TextEntity.ITALIC) {
    writer.write("<i>");
  } else if (entity == TextEntity.CODE) {
    writer.write("<code>");
  } else if (entity == TextEntity.CODE_BLOCK) {
    writer.write("<pre>");
  } else if (entity == TextEntity.LINK) {
    writer.write("<a href=\"" + escape(entry.getValue().toString()) + "\">");
  } else if (entity == TextEntity.TEXT_MENTION) {
    User user = (User) entry.getValue();
    writer.write("<a href=\"" + escape(TextEntity.TEXT_MENTION_LINK) + user.getId() + "\">");
  }
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:22,代碼來源:HtmlTextWriter.java

示例6: checkIteratorAttribute

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
private static final void checkIteratorAttribute(AttributedCharacterIterator iterator, int index, Attribute key, Object expectedValue) throws Exception {
    iterator.setIndex(index);
    Object value = iterator.getAttribute(key);
    if (!((expectedValue == null && value == null) || (expectedValue != null && expectedValue.equals(value)))) {
        throwException(iterator, "iterator returns wrong attribute value - " + value + " instead of " + expectedValue);
    }
    value = iterator.getAttributes().get(key);
    if (!((expectedValue == null && value == null) || (expectedValue != null && expectedValue.equals(value)))) {
        throwException(iterator, "iterator's map returns wrong attribute value - " + value + " instead of " + expectedValue);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:AttributedStringTest.java

示例7: beginEntity

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
private void beginEntity(Entry<Attribute, Object> entry, Writer writer) throws IOException {
  if (entry == null) {
    return;
  }

  Attribute entity = entry.getKey();
  if (entity == TextEntity.BOLD) {
    writer.write('*');
  } else if (entity == TextEntity.ITALIC) {
    writer.write('_');
  } else if (entity == TextEntity.CODE) {
    writer.write('`');
  } else if (entity == TextEntity.CODE_BLOCK) {
    writer.write("```");
  } else if (entity == TextEntity.LINK || entity == TextEntity.TEXT_MENTION) {
    writer.write("[");
  }
}
 
開發者ID:AgeOfWar,項目名稱:Telejam,代碼行數:19,代碼來源:MarkdownTextWriter.java

示例8: getRunStart

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
public int getRunStart(Attribute attribute) {
    if (currentRunStart == beginIndex || currentRunIndex == -1) {
        return currentRunStart;
    } else {
        Object value = getAttribute(attribute);
        int runStart = currentRunStart;
        int runIndex = currentRunIndex;
        while (runStart > beginIndex &&
                valuesMatch(value, AttributedString.this.getAttribute(attribute, runIndex - 1))) {
            runIndex--;
            runStart = runStarts[runIndex];
        }
        if (runStart < beginIndex) {
            runStart = beginIndex;
        }
        return runStart;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:AttributedString.java

示例9: select

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

    iterator.first();
    do {
        final Map<Attribute,Object> attrs = iterator.getAttributes();
        if (attrs == null || !attrs.containsKey(field)) continue;

        final int start = iterator.getRunStart(field);
        final 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:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:AquaSpinnerUI.java

示例10: TextLayout

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的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

示例11: paragraphInit

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
/**
 * Initialize the paragraph-specific data.
 */
private void paragraphInit(byte aBaseline, CoreMetrics lm,
                           Map<? extends Attribute, ?> paragraphAttrs,
                           char[] text) {

    baseline = aBaseline;

    // normalize to current baseline
    baselineOffsets = TextLine.getNormalizedOffsets(lm.baselineOffsets, baseline);

    justifyRatio = AttributeValues.getJustification(paragraphAttrs);
    NumericShaper shaper = AttributeValues.getNumericShaping(paragraphAttrs);
    if (shaper != null) {
        shaper.shape(text, 0, text.length);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TextLayout.java

示例12: TextLayout

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
/**
 * Constructs a <code>TextLayout</code> 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</code> 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:SunburstApps,項目名稱:OpenJSharp,代碼行數:51,代碼來源:TextLayout.java

示例13: fastInit

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
private void fastInit(char[] chars, Font font,
                      Map<? extends Attribute, ?> attrs,
                      FontRenderContext frc) {

    // Object vf = attrs.get(TextAttribute.ORIENTATION);
    // isVerticalLine = TextAttribute.ORIENTATION_VERTICAL.equals(vf);
    isVerticalLine = false;

    LineMetrics lm = font.getLineMetrics(chars, 0, chars.length, frc);
    CoreMetrics cm = CoreMetrics.get(lm);
    byte glyphBaseline = (byte) cm.baselineIndex;

    if (attrs == null) {
        baseline = glyphBaseline;
        baselineOffsets = cm.baselineOffsets;
        justifyRatio = 1.0f;
    } else {
        paragraphInit(glyphBaseline, cm, attrs, chars);
    }

    characterCount = chars.length;

    textLine = TextLine.fastCreateTextLine(frc, chars, font, cm, attrs);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:TextLayout.java

示例14: getGraphicOrFont

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
/**
 * Extract a GraphicAttribute or Font from the given attributes.
 * If attributes does not contain a GraphicAttribute, Font, or
 * Font family entry this method returns null.
 */
private static Object getGraphicOrFont(
        Map<? extends Attribute, ?> attributes) {

    Object value = attributes.get(TextAttribute.CHAR_REPLACEMENT);
    if (value != null) {
        return value;
    }
    value = attributes.get(TextAttribute.FONT);
    if (value != null) {
        return value;
    }

    if (attributes.get(TextAttribute.FAMILY) != null) {
        return Font.getFont(attributes);
    }
    else {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:StyledParagraph.java

示例15: checkIteratorSubranges

import java.text.AttributedCharacterIterator.Attribute; //導入依賴的package包/類
private static final void checkIteratorSubranges(AttributedCharacterIterator iterator, Attribute key, int[] expectedLimits) throws Exception {
    int previous = 0;
    char c = iterator.first();
    for (int i = 0; i < expectedLimits.length; i++) {
         if (iterator.getRunStart(key) != previous || iterator.getRunLimit(key) != expectedLimits[i]) {
             throwException(iterator, "run boundaries are not as expected: " + iterator.getRunStart(key) + ", " + iterator.getRunLimit(key) + " for key " + key);
         }
         previous = expectedLimits[i];
         c = iterator.setIndex(previous);
    }
    if (c != CharacterIterator.DONE) {
        throwException(iterator, "iterator's run sequence doesn't end with DONE");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:AttributedStringTest.java


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