当前位置: 首页>>代码示例>>Java>>正文


Java AttributedString类代码示例

本文整理汇总了Java中java.text.AttributedString的典型用法代码示例。如果您正苦于以下问题:Java AttributedString类的具体用法?Java AttributedString怎么用?Java AttributedString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AttributedString类属于java.text包,在下文中一共展示了AttributedString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: while

import java.text.AttributedString; //导入依赖的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

示例2: testAttributedStringSerialization3

import java.text.AttributedString; //导入依赖的package包/类
/**
 * Tests the serialization of an {@link AttributedString}.
 */
public void testAttributedStringSerialization3() {
    AttributedString s1 = new AttributedString("ABC");
    s1.addAttribute(TextAttribute.LANGUAGE, "English");
    AttributedString s2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(buffer);
        SerialUtilities.writeAttributedString(s1, out);
        out.close();

        ByteArrayInputStream bais = new ByteArrayInputStream(
                buffer.toByteArray());
        ObjectInputStream in = new ObjectInputStream(bais);
        s2 = SerialUtilities.readAttributedString(in);
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertTrue(AttributedStringUtilities.equal(s1, s2));
}
 
开发者ID:mdzio,项目名称:ccu-historian,代码行数:25,代码来源:SerialUtilitiesTest.java

示例3: getComposedTextAttribute

import java.text.AttributedString; //导入依赖的package包/类
private static AttributedString getComposedTextAttribute(DocumentEvent e) {
    if (e instanceof BaseDocumentEvent) {
        AttributeSet attribs = ((BaseDocumentEvent) e).getChangeAttributes();
        if (attribs != null) {
            Object value = attribs.getAttribute(StyleConstants.ComposedTextAttribute);
            if (value instanceof AttributedString) {
                return (AttributedString) value;
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ComposedTextHighlighting.java

示例4: formatToCharacterIterator

import java.text.AttributedString; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @stable ICU 49
 */
@Override
public AttributedCharacterIterator formatToCharacterIterator(Object obj) {
    StringBuffer toAppendTo = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    toAppendTo = format(obj, toAppendTo, pos);

    // supporting only DateFormat.Field.TIME_ZONE
    AttributedString as = new AttributedString(toAppendTo.toString());
    as.addAttribute(DateFormat.Field.TIME_ZONE, DateFormat.Field.TIME_ZONE);

    return as.getIterator();
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:18,代码来源:TimeZoneFormat.java

示例5: TextLayout

import java.text.AttributedString; //导入依赖的package包/类
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and an attribute set.
 * <p>
 * All the text is styled using the provided attributes.
 * <p>
 * <code>string</code> must specify a single paragraph of text because an
 * entire paragraph is required for the bidirectional algorithm.
 * @param string the text to display
 * @param attributes the attributes used to style the text
 * @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(String string, Map<? extends Attribute,?> attributes,
                  FontRenderContext frc)
{
    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

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

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    char[] text = string.toCharArray();
    Font font = singleFont(text, 0, text.length, attributes);
    if (font != null) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = new AttributedString(string, attributes);
        standardInit(as.getIterator(), text, frc);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:TextLayout.java

示例6: dispatchCommittedText

import java.text.AttributedString; //导入依赖的package包/类
/**
 * Dispatches committed text from XIM to the awt event queue. This
 * method is invoked from the event handler in canvas.c in the
 * AWT Toolkit thread context and thus inside the AWT Lock.
 * @param   str     committed text
 * @param   long    when
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchCommittedText(String str, long when) {
    if (str == null)
        return;

    if (composedText == null) {
        AttributedString attrstr = new AttributedString(str);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             str.length(),
                             null,
                             null,
                             when);
    } else {
        // if there is composed text, wait until the preedit
        // callback is invoked.
        committedText = str;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:X11InputMethod.java

示例7: flushText

import java.text.AttributedString; //导入依赖的package包/类
/**
 * Flushes composed and committed text held in this context.
 * This method is invoked in the AWT Toolkit (X event loop) thread context
 * and thus inside the AWT Lock.
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void flushText() {
    String flush = (committedText != null ? committedText : "");
    if (composedText != null) {
        flush += composedText.toString();
    }

    if (!flush.equals("")) {
        AttributedString attrstr = new AttributedString(flush);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             flush.length(),
                             null,
                             null,
                             EventQueue.getMostRecentEventTime());
        composedText = null;
        committedText = null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:X11InputMethod.java

示例8: getRawDataIterator

import java.text.AttributedString; //导入依赖的package包/类
/**
 * Gets a lazy list of raw data in frames with the given stream, starting at
 * this frame and extending backwards over previous frames. The data is
 * coloured according to time difference with a given time, and control
 * codes are coloured red and translated into a human-readable form.
 * @param relativeTime The time, relative to the start of the ttyrec, to
 * colour the data relative to.
 * @param stream The stream from which the raw data should be returned.
 * @return A lazy list of raw data from frames with the given stream.
 */
public Iterable<AttributedString> getRawDataIterator(final double relativeTime, final int stream) {
	return () -> new Iterator<AttributedString>() {
           int lastSeqNumber = seqNumber;
           public boolean hasNext() {
               return hasNextAnnotation(
                       relativeTime, lastSeqNumber, stream);
           }
           public AttributedString next() {
               AttributedStringAndNumber asan = nextAnnotation(
                       relativeTime, lastSeqNumber, stream);
               lastSeqNumber = asan.getN();
               return asan.getA();
           }
           public void remove() {
               throw new UnsupportedOperationException(
                       "Attempt to modify an immutable list");
           }
       };
}
 
开发者ID:Elronnd,项目名称:ttyrec2video,代码行数:30,代码来源:TtyrecFrame.java

示例9: TextLayout

import java.text.AttributedString; //导入依赖的package包/类
/**
 * Constructs a {@code TextLayout} from a {@code String}
 * and an attribute set.
 * <p>
 * All the text is styled using the provided attributes.
 * <p>
 * {@code string} must specify a single paragraph of text because an
 * entire paragraph is required for the bidirectional algorithm.
 * @param string the text to display
 * @param attributes the attributes used to style the text
 * @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(String string, Map<? extends Attribute,?> attributes,
                  FontRenderContext frc)
{
    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

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

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    char[] text = string.toCharArray();
    Font font = singleFont(text, 0, text.length, attributes);
    if (font != null) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = new AttributedString(string, attributes);
        standardInit(as.getIterator(), text, frc);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:TextLayout.java

示例10: dispatchCommittedText

import java.text.AttributedString; //导入依赖的package包/类
/**
 * Dispatches committed text from XIM to the awt event queue. This
 * method is invoked from the event handler in canvas.c in the
 * AWT Toolkit thread context and thus inside the AWT Lock.
 * @param   str     committed text
 * @param   when    when
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchCommittedText(String str, long when) {
    if (str == null)
        return;

    if (composedText == null) {
        AttributedString attrstr = new AttributedString(str);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             str.length(),
                             null,
                             null,
                             when);
    } else {
        // if there is composed text, wait until the preedit
        // callback is invoked.
        committedText = str;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:X11InputMethod.java

示例11: main

import java.text.AttributedString; //导入依赖的package包/类
public static void main(String[] args) {

        // Create a new AttributedString with one attribute.
        Hashtable attributes = new Hashtable();
        attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
        AttributedString origString = new AttributedString("Hello world.", attributes);

        // Create an iterator over part of the AttributedString.
        AttributedCharacterIterator iter = origString.getIterator(null, 4, 6);

        // Attempt to create a new AttributedString from the iterator.
        // This will throw IllegalArgumentException.
        AttributedString newString = new AttributedString(iter);

        // Without the exception this would get executed.
        System.out.println("DONE");
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:TestAttributedStringCtor.java

示例12: getLineBreakMeasurers

import java.text.AttributedString; //导入依赖的package包/类
private LineBreakMeasurer[] getLineBreakMeasurers(Graphics2D g) {
    if (lbmTexto == null && (Texto != null && !Texto.equals(""))) {
        lbmTexto = new LineBreakMeasurer[Textos.length];
        for (int i = 0; i < lbmTexto.length; i++) {
            String tmp = Textos[i].isEmpty()? " " : Textos[i];
            AttributedString attribString = new AttributedString(tmp);
            attribString.addAttribute(TextAttribute.FONT, getFont());
            //attribString.addAttribute(TextAttribute.FONT, getFont());
            AttributedCharacterIterator attribCharIterator = attribString.getIterator();
            //FontRenderContext frc = new FontRenderContext(null, true, false);
            FontRenderContext frc = g.getFontRenderContext();
            lbmTexto[i] = new LineBreakMeasurer(attribCharIterator, frc);
        }
    }
    return lbmTexto;
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:17,代码来源:DesenhadorDeTexto.java

示例13: getPreferredSize

import java.text.AttributedString; //导入依赖的package包/类
@Override
public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    if (tipText == null || tipText.isEmpty()) {
        return new Dimension(0, 0);
    }

    float x = 0f;
    float y = 0f;
    for (String line : lineBreak.split(tipText)) {
        if (line.isEmpty()) {
            y += LEADING;
            continue;
        }
        AttributedCharacterIterator styledText
            = new AttributedString(line).getIterator();
        LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);

        while (measurer.getPosition() < styledText.getEndIndex()) {

            TextLayout layout = measurer.nextLayout(maximumWidth);

            x = Math.max(x, layout.getVisibleAdvance());
            y += layout.getAscent() + layout.getDescent() + layout.getLeading();

        }
    }
    return new Dimension((int) (x + 2 * margin),
                         (int) (y + 2 * margin));

}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:32,代码来源:FreeColToolTipUI.java

示例14: dumpACIWord

import java.text.AttributedString; //导入依赖的package包/类
protected void dumpACIWord(AttributedString as) {
    if (as == null) return;

    StringBuffer chars = new StringBuffer();
    StringBuffer brkStr = new StringBuffer();
    AttributedCharacterIterator aci = as.getIterator();
    AttributedCharacterIterator.Attribute WORD_LIMIT =
        TextLineBreaks.WORD_LIMIT;

    for (char ch = aci.current();
         ch!=AttributedCharacterIterator.DONE;
         ch = aci.next()) {

            chars.append( ch ).append( ' ' ).append( ' ' );
            int w = ((Integer)aci.getAttribute(WORD_LIMIT)).intValue();
            brkStr.append( w ).append( ' ' );
            if (w < 10) {
                // for small values append another ' '
                brkStr.append( ' ' );
            }
    }
    System.out.println( chars.toString() );
    System.out.println( brkStr.toString() );
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:25,代码来源:SVGFlowRootElementBridge.java

示例15: decorateAttributedString

import java.text.AttributedString; //导入依赖的package包/类
public void decorateAttributedString(Graphics2D g2, AttributedString attributedWord, ChangeableAttributedString newAttrString) {

        Color oldColor = g2.getColor();
        Composite oldComp = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(alphaCompositeType));

        for (int j = 0; j < attributedWord.getIterator().getEndIndex(); j++) {
            g2.setColor(holesColorGenerator.getNextColor());

            Rectangle2D bounds = newAttrString.getBounds(j).getFrame();
            double circleMaxSize = (double) bounds.getWidth() / 2;
            for (int i = 0; i < numberOfHolesPerGlyph.intValue(); i++) {
                double circleSize = circleMaxSize * (1 + myRandom.nextDouble()) / 2;
                double circlex = bounds.getMinX() + bounds.getWidth() * circleXRatio
                        * myRandom.nextDouble();
                double circley = bounds.getMinY() - bounds.getHeight() * circleYRatio
                        * myRandom.nextDouble();
                Ellipse2D circle = new Ellipse2D.Double(circlex, circley, circleSize, circleSize);
                g2.fill(circle);
            }
        }
        g2.setColor(oldColor);
        g2.setComposite(oldComp);
    }
 
开发者ID:pengqiuyuan,项目名称:g2,代码行数:25,代码来源:BaffleTextDecorator.java


注:本文中的java.text.AttributedString类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。