Package java.text

Examples of java.text.AttributedString


   * @param stream the outputstream that should receive the object.
   * @throws IOException if an I/O error occured.
   */
  public void writeObject(final Object o, final ObjectOutputStream stream) throws IOException
  {
    final AttributedString as = (AttributedString) o;
    final AttributedCharacterIterator aci = as.getIterator();
    // build a plain string from aci
    // then write the string
    StringBuffer plainStr = new StringBuffer(100);
    char current = aci.first();
    while (current != CharacterIterator.DONE) {
View Full Code Here


  public Object readObject(final ObjectInputStream stream)
          throws IOException, ClassNotFoundException
  {
    // read string and attributes then create result
    final String plainStr = (String) stream.readObject();
    final AttributedString result = new AttributedString(plainStr);
    char c = stream.readChar();
    int start = 0;
    while (c != CharacterIterator.DONE) {
        final int limit = stream.readInt();
        final Map<AttributedCharacterIterator.Attribute,Object> atts =
            (Map<AttributedCharacterIterator.Attribute,Object>) stream.readObject();
        result.addAttributes(atts, start, limit);
        start = limit;
        c = stream.readChar();
    }
    return result;
  }
View Full Code Here

  }

  public void drawTimestamp(Timestamp ts, SceneConfiguration sceneConfig) {
    final TimestampAttributes att = drawAttributes.getTimestampAttributes();
    if (att.isEnabled()) {
      AttributedString string = new AttributedString(att.getDateFormat().get().format(ts));
      string.addAttribute(TextAttribute.FONT, att.getFont());
      string.addAttribute(TextAttribute.FOREGROUND, att.getColor());
      graphics.drawString(string.getIterator(), att.getLeft(), configuration.getImage().getHeight().intValue() - att.getBottom());
    }
  }
View Full Code Here

  }

  public void drawDaycounter(int dayCount, SceneConfiguration sceneConfig) {
    final DaycounterAttributes att = drawAttributes.getDaycounterAttributes();
    if (att.isEnabled()) {
      AttributedString string = new AttributedString(String.format(att.getFormatString(), dayCount));
      string.addAttribute(TextAttribute.FONT, att.getFont());
      string.addAttribute(TextAttribute.FOREGROUND, att.getColor());
      graphics.drawString(string.getIterator(), att.getLeft(), configuration.getImage().getHeight().intValue() - att.getBottom());
    }
  }
View Full Code Here

        // get textFont value from model
        map.put(TextAttribute.FAMILY, itModel.getFontName());
        // get text height value from model
        map.put(TextAttribute.SIZE, new Float(itModel.getFontSize()));
        // make a new attributed string
        attStr = new AttributedString(itModel.getText(), map);

        // listen for ImageTools Model to update fontName
        itModel.pcs.addPropertyChangeListener("fontName", new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                // update map
                map.put(TextAttribute.FAMILY, itModel.getFontName());
                // make a new attributed string
                attStr = new AttributedString(itModel.getText(), map);
            }
        });

        // listen for ImageTools Model to update fontSize
        itModel.pcs.addPropertyChangeListener("fontSize", new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                // update map
                map.put(TextAttribute.SIZE, itModel.getFontSize());
                // make a new attributed string
                attStr = new AttributedString(itModel.getText(), map);
            }
        });

        // listen for ImageTools Model to update text
        itModel.pcs.addPropertyChangeListener("text", new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                // make a new attributed string
                attStr = new AttributedString(itModel.getText(), map);
            }
        });

    } // end constructor
View Full Code Here

        if (string.length() == 0){
            throw new IllegalArgumentException(Messages.getString("awt.02", "string")); //$NON-NLS-1$ //$NON-NLS-2$
        }

        AttributedString as = new AttributedString(string);
        as.addAttribute(TextAttribute.FONT, font);
        this.breaker = new TextRunBreaker(as.getIterator(), frc);
        caretManager = new CaretManager(breaker);
    }
View Full Code Here

        if (string.length() == 0){
            throw new IllegalArgumentException(Messages.getString("awt.02", "string")); //$NON-NLS-1$ //$NON-NLS-2$
        }
       
       
        AttributedString as = new AttributedString(string);
        as.addAttributes(attributes, 0, string.length());
        this.breaker = new TextRunBreaker(as.getIterator(), frc);
        caretManager = new CaretManager(breaker);
    }
View Full Code Here

            final String line = lines[i];

            if ("".equals(line)) {
                cursor.y += lineHeight;
            } else {
                AttributedString styledText = new AttributedString(line);
                LineBreakMeasurer measurer = new LineBreakMeasurer(styledText.getIterator(), frc);

                while (measurer.getPosition() < line.length()) {

                    TextLayout layout = measurer.nextLayout(lineWidth);
View Full Code Here

        return getSimpleIterator(textKit.getSelectedText());
    }

    AttributedCharacterIterator getIterator(final int start,
                                            final int end) {
        AttributedString s = getAttributedString(start, end);
        return (s == null) ? null : s.getIterator(null, start, end);
    }
View Full Code Here

            s = getText(0, end);
        } catch (final BadLocationException e) { }
        if (s == null || start == end) {
            return null;
        }
        AttributedString attributedString = new AttributedString(s);
        for (int i = start; i < end; i++) {
            AttributeSet ass = getAttributeSet(i);
            Enumeration<?> names;
            for (names = ass.getAttributeNames();
                 names.hasMoreElements();) {
                Object key = names.nextElement();
                if (key instanceof AttributedCharacterIterator.Attribute) {
                    AttributedCharacterIterator.Attribute attribute =
                        (AttributedCharacterIterator.Attribute)key;
                    Object value = ass.getAttribute(key);
                    attributedString.addAttribute(attribute, value,
                                                  i - start,
                                                  i + 1 - start);
                }
            }
        }
View Full Code Here

TOP

Related Classes of java.text.AttributedString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.