Package javax.swing.text

Examples of javax.swing.text.AttributeSet


    return;
  }
 
  public
  int getFontSize() {
    AttributeSet attrSet = (AttributeSet) attributes.get(Priority.INFO);
    return StyleConstants.getFontSize(attrSet);
  }
View Full Code Here


    return;
  }
 
  public
  String getFontName() {
    AttributeSet attrSet = (AttributeSet) attributes.get(Priority.INFO);
    return StyleConstants.getFontFamily(attrSet);
  }
View Full Code Here

     */
    public void testGetAttributeString()
    {
        assertEquals( "", SinkUtils.getAttributeString( null ) );

        AttributeSet att = new SinkEventAttributeSet( SinkEventAttributeSet.BOXED );
        String expResult = " decoration=\"boxed\"";
        String result = SinkUtils.getAttributeString( att );
        assertEquals( expResult, result );

        SinkEventAttributes at = new SinkEventAttributeSet( SinkEventAttributeSet.BOLD );
View Full Code Here

     */
    public void testFilterAttributes()
    {
        assertNull( SinkUtils.filterAttributes( null, null ) );

        AttributeSet attributes = new SinkEventAttributeSet( 1 );
        String[] valids = null;

        MutableAttributeSet result = SinkUtils.filterAttributes( attributes, valids );
        assertEquals( 0, result.getAttributeCount() );

View Full Code Here

     * Test of copyAttributes method, of class SinkEventAttributeSet.
     */
    public void testCopyAttributes()
    {
        sinkEventAttributeSet.addAttributes( SinkEventAttributeSet.ITALIC );
        AttributeSet instance = sinkEventAttributeSet.copyAttributes();
        assertTrue( instance.isEqual( sinkEventAttributeSet ) );
    }
View Full Code Here

    }
  }

  private static AttributeSet computeStyle(final javax.swing.text.Element elem, final StyleSheet styles)
  {
    final AttributeSet a = elem.getAttributes();
    final AttributeSet htmlAttr = styles.translateHTMLToCSS(a);
    final ArrayList<AttributeSet> muxList = new ArrayList<AttributeSet>();

    if (htmlAttr.getAttributeCount() != 0)
    {
      muxList.add(htmlAttr);
    }

    if (elem.isLeaf())
    {
      // The swing-parser has a very weird way of storing attributes for the HTML elements. The
      // tag-name is used as key for the attribute set, so you have to know the element type before
      // you can do anything sensible with it. Or as we do here, you have to search for the HTML.Tag
      // object. Arghh.
      final Enumeration keys = a.getAttributeNames();
      while (keys.hasMoreElements())
      {
        final Object key = keys.nextElement();
        if (!(key instanceof HTML.Tag))
        {
          continue;
        }

        if (key == HTML.Tag.A)
        {
          final Object o = a.getAttribute(key);
          if (o instanceof AttributeSet)
          {
            final AttributeSet attr = (AttributeSet) o;
            if (attr.getAttribute(HTML.Attribute.HREF) == null)
            {
              continue;
            }
          }
        }

        final AttributeSet cssRule = styles.getRule((HTML.Tag) key, elem);
        if (cssRule != null)
        {
          muxList.add(cssRule);
        }
      }
    }
    else
    {
      final HTML.Tag t = (HTML.Tag) a.getAttribute(StyleConstants.NameAttribute);
      final AttributeSet cssRule = styles.getRule(t, elem);
      if (cssRule != null)
      {
        muxList.add(cssRule);
      }
    }

    final MutableAttributeSet retval = new SimpleAttributeSet();
    for (int i = muxList.size() - 1; i >= 0; i--)
    {
      final AttributeSet o = muxList.get(i);
      retval.addAttributes(o);
    }
    return retval;
  }
View Full Code Here

      return null;
    }

    if (textElement.isLeaf())
    {
      final AttributeSet attributes = textElement.getAttributes();
      if (HTML.Tag.IMG.equals(attributes.getAttribute(StyleConstants.NameAttribute)))
      {
        final Element result = new Element();
        result.setName(textElement.getName());
        result.setElementType(new ContentType());
        final String src = (String) attributes.getAttribute(HTML.Attribute.SRC);
        final String alt = (String) attributes.getAttribute(HTML.Attribute.TITLE);
        result.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, convertURL(src));
        result.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.TITLE, alt);
        result.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Swing.TOOLTIP, alt);
        if (attributes.isDefined(HTML.Attribute.WIDTH) &&
            attributes.isDefined(HTML.Attribute.HEIGHT))
        {
          result.getStyle().setStyleProperty(ElementStyleKeys.SCALE, Boolean.TRUE);
          result.getStyle().setStyleProperty(ElementStyleKeys.KEEP_ASPECT_RATIO, Boolean.FALSE);
          result.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH,
              parseLength(String.valueOf(attributes.getAttribute(HTML.Attribute.WIDTH))));
          result.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT,
              parseLength(String.valueOf(attributes.getAttribute(HTML.Attribute.HEIGHT))));
        }
        else if (attributes.isDefined(HTML.Attribute.WIDTH))
        {
          result.getStyle().setStyleProperty(ElementStyleKeys.SCALE, Boolean.TRUE);
          result.getStyle().setStyleProperty(ElementStyleKeys.KEEP_ASPECT_RATIO, Boolean.TRUE);
          result.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH,
              parseLength(String.valueOf(attributes.getAttribute(HTML.Attribute.WIDTH))));
          result.getStyle().setStyleProperty(ElementStyleKeys.DYNAMIC_HEIGHT, Boolean.TRUE);
        }
        else if (attributes.isDefined(HTML.Attribute.HEIGHT))
        {
          result.getStyle().setStyleProperty(ElementStyleKeys.SCALE, Boolean.TRUE);
          result.getStyle().setStyleProperty(ElementStyleKeys.KEEP_ASPECT_RATIO, Boolean.TRUE);
          result.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT,
              parseLength(String.valueOf(attributes.getAttribute(HTML.Attribute.HEIGHT))));
          result.getStyle().setStyleProperty(ElementStyleKeys.DYNAMIC_HEIGHT, Boolean.TRUE);
        }
        else
        {
          result.getStyle().setStyleProperty(ElementStyleKeys.SCALE, Boolean.FALSE);
View Full Code Here

  private boolean isInvisible(final javax.swing.text.Element textElement)
  {
    final HTMLDocument htmlDocument = (HTMLDocument) textElement.getDocument();
    final StyleSheet sheet = htmlDocument.getStyleSheet();
    final AttributeSet attr = computeStyle(textElement, sheet);
    final Object o = attr.getAttribute(CSS.Attribute.DISPLAY);
    if ("none".equals(String.valueOf(o)))
    {
      return true;
    }
    final Object tag = findTag(textElement.getAttributes());
View Full Code Here

  private void configureStyle(final javax.swing.text.Element textElement, final Element result)
  {
    final HTMLDocument htmlDocument = (HTMLDocument) textElement.getDocument();
    final StyleSheet sheet = htmlDocument.getStyleSheet();
    final AttributeSet attr = computeStyle(textElement, sheet);
    parseBorderAndBackgroundStyle(result, sheet, attr);
    parseBoxStyle(result, attr);

    final Font font = sheet.getFont(attr);
    if (font != null)
    {
      result.getStyle().setStyleProperty(TextStyleKeys.FONT, font.getFamily());
      result.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, font.getSize());
      result.getStyle().setBooleanStyleProperty(TextStyleKeys.ITALIC, font.isItalic());
      result.getStyle().setBooleanStyleProperty(TextStyleKeys.BOLD, font.isBold());
    }

    final Object letterSpacing = attr.getAttribute(CSS.Attribute.LETTER_SPACING);
    if (letterSpacing != null)
    {
      result.getStyle().setStyleProperty
          (TextStyleKeys.X_OPTIMUM_LETTER_SPACING, parseLength(String.valueOf(letterSpacing)));
    }

    final Object wordSpacing = attr.getAttribute(CSS.Attribute.WORD_SPACING);
    if (wordSpacing != null)
    {
      result.getStyle().setStyleProperty
          (TextStyleKeys.WORD_SPACING, parseLength(String.valueOf(wordSpacing)));
    }

    final Object lineHeight = attr.getAttribute(CSS.Attribute.LINE_HEIGHT);
    if (lineHeight != null)
    {
      result.getStyle().setStyleProperty
          (TextStyleKeys.LINEHEIGHT, parseLength(String.valueOf(lineHeight)));
    }
    final Object textAlign = attr.getAttribute(CSS.Attribute.TEXT_ALIGN);
    if (textAlign != null)
    {
      try
      {
        result.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT,
            ReportParserUtil.parseHorizontalElementAlignment(String.valueOf(textAlign), null));
      }
      catch (ParseException e)
      {
        // ignore ..
      }
    }

    final Object textDecoration = attr.getAttribute(CSS.Attribute.TEXT_DECORATION);
    if (textDecoration != null)
    {
      final String[] strings = StringUtils.split(String.valueOf(textDecoration));
      result.getStyle().setStyleProperty(TextStyleKeys.STRIKETHROUGH, Boolean.FALSE);
      result.getStyle().setStyleProperty(TextStyleKeys.UNDERLINED, Boolean.FALSE);

      for (int i = 0; i < strings.length; i++)
      {
        final String value = strings[i];
        if ("line-through".equals(value))
        {
          result.getStyle().setStyleProperty(TextStyleKeys.STRIKETHROUGH, Boolean.TRUE);
        }
        if ("underline".equals(value))
        {
          result.getStyle().setStyleProperty(TextStyleKeys.UNDERLINED, Boolean.TRUE);
        }
      }
    }


    final Object valign = attr.getAttribute(CSS.Attribute.VERTICAL_ALIGN);
    if (valign != null)
    {
      final VerticalTextAlign valignValue = VerticalTextAlign.valueOf(String.valueOf(valign));
      result.getStyle().setStyleProperty(TextStyleKeys.VERTICAL_TEXT_ALIGNMENT, valignValue);
      try
      {
        result.getStyle().setStyleProperty(ElementStyleKeys.VALIGNMENT,
            ReportParserUtil.parseVerticalElementAlignment(String.valueOf(valign), null));
      }
      catch (ParseException e)
      {
        // ignore ..
      }
    }

    final Object whitespaceText = attr.getAttribute(CSS.Attribute.WHITE_SPACE);
    if (whitespaceText != null)
    {
      final String value = String.valueOf(whitespaceText);
      if ("pre".equals(value))
      {
        result.getStyle().setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.PRESERVE);
        result.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.NONE);
      }
      else if ("nowrap".equals(value))
      {
        result.getStyle().setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.PRESERVE_BREAKS);
        result.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.NONE);
      }
      else
      {
        result.getStyle().setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.COLLAPSE);
        result.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.WRAP);
      }
    }
    else
    {
      result.getStyle().setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.COLLAPSE);
      result.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.WRAP);
    }

    final Object alignAttribute = attr.getAttribute(HTML.Attribute.ALIGN);
    if (alignAttribute != null)
    {
      try
      {
        result.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT,
            ReportParserUtil.parseHorizontalElementAlignment(String.valueOf(alignAttribute), null));
      }
      catch (ParseException e)
      {
        // ignore ..
      }
    }

    final Object titleAttribute = attr.getAttribute(HTML.Attribute.TITLE);
    if (titleAttribute != null)
    {
      result.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.TITLE,
          String.valueOf(titleAttribute));
    }

    final Object textIndentStyle = attr.getAttribute(CSS.Attribute.TEXT_INDENT);
    if (textIndentStyle != null)
    {
      result.getStyle().setStyleProperty
          (TextStyleKeys.FIRST_LINE_INDENT, parseLength(String.valueOf(textIndentStyle)));
    }
View Full Code Here

    return;
  }
 
  public
  int getFontSize() {
    AttributeSet attrSet = (AttributeSet) attributes.get(Priority.INFO);
    return StyleConstants.getFontSize(attrSet);
  }
View Full Code Here

TOP

Related Classes of javax.swing.text.AttributeSet

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.