Package javax.swing.text

Examples of javax.swing.text.AttributeSet$FontAttribute


      private String getLink(int pos, JEditorPane html) {
        Document doc = html.getDocument();
        if (doc instanceof HTMLDocument) {
          HTMLDocument hdoc = (HTMLDocument) doc;
          Element e = hdoc.getCharacterElement(pos);
          AttributeSet a = e.getAttributes();
          AttributeSet anchor = (AttributeSet) a.getAttribute(HTML.Tag.A);

          if (anchor != null) {
            return (String) anchor.getAttribute(HTML.Attribute.HREF);
          }
        }
        return null;
      }
View Full Code Here


    for (int i = line + 1; i < endLine; i++)
    {
      Element branch = rootElement.getElement( i );
      Element leaf = doc.getCharacterElement( branch.getStartOffset() );
      AttributeSet as = leaf.getAttributes();

      if ( as.isEqual(comment) ) {
        applyHighlighting(content, i);
      }
    }
  }
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 muxList = new ArrayList();

    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 = (AttributeSet) 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(ContentType.INSTANCE);
        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, new Integer(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

      chunk = null;
      element = (Element)elements.get(i);
      parent = element.getParentElement();
      startOffset = element.getStartOffset();
      endOffset = element.getEndOffset();
      AttributeSet attrs = element.getAttributes();

      Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
      Object object = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
      if (object instanceof HTML.Tag)
      {
       
        HTML.Tag htmlTag = (HTML.Tag) object;
        if(htmlTag == Tag.BODY)
        {
          bodyOccurred = true;
          crtOffset = - startOffset;
        }
        else if(htmlTag == Tag.BR)
        {
          chunk = "\n";
        }
        else if(htmlTag == Tag.OL)
        {
          orderedListIndex[i] = 0;
          String parentName = parent.getName().toLowerCase();
          whitespaces[i] = whitespaces[elements.indexOf(parent)] + whitespace;
          if(parentName.equals("li"))
          {
            chunk = "";
          }
          else
          {
            chunk = "\n";
            ++crtOffset;
          }
        }
        else if(htmlTag == Tag.UL)
        {
          whitespaces[i] = whitespaces[elements.indexOf(parent)] + whitespace;

          String parentName = parent.getName().toLowerCase();
          if(parentName.equals("li"))
          {
            chunk = "";
          }
          else
          {
            chunk = "\n";
            ++crtOffset;
          }
         
        }
        else if(htmlTag == Tag.LI)
        {
         
          whitespaces[i] = whitespaces[elements.indexOf(parent)];
          if(element.getElement(0) != null &&
              (element.getElement(0).getName().toLowerCase().equals("ol") || element.getElement(0).getName().toLowerCase().equals("ul"))
              )
          {
            chunk = "";
          }
          else if(parent.getName().equals("ol"))
          {
            int index = elements.indexOf(parent);
            chunk = whitespaces[index] + String.valueOf(++orderedListIndex[index]) + ".  ";
          }
          else
          {
            chunk = whitespaces[elements.indexOf(parent)] + "\u2022  ";
          }
          crtOffset += chunk.length();
        }
        else if (element instanceof LeafElement)
        {
          if (element instanceof RunElement)
          {
            RunElement runElement = (RunElement)element;
            AttributeSet attrSet = (AttributeSet)runElement.getAttribute(Tag.A);
            if (attrSet != null)
            {
              hyperlink = new JRBasePrintHyperlink();
              hyperlink.setHyperlinkType(HyperlinkTypeEnum.REFERENCE);
              hyperlink.setHyperlinkReference((String)attrSet.getAttribute(HTML.Attribute.HREF));
              hyperlink.setLinkTarget((String)attrSet.getAttribute(HTML.Attribute.TARGET));
            }
          }
          try
          {
            chunk = document.getText(startOffset, endOffset - startOffset);
View Full Code Here

    index = ((Integer) matches.get(index)).intValue();
    String word = getLastWord();
    String value = (String) values.get(index);
    value = value.substring(word.length(), value.length());
    try {
      AttributeSet set = getTextField().getDocument().getRootElements()[0]
          .getAttributes();
      getTextField().getDocument().insertString(
          getTextField().getCaretPosition(), value, set);
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

        textPane.getStyledDocument().setCharacterAttributes(0, text.length(), SimpleAttributeSet.EMPTY, true);

        /** Apply the style for each token */
        for (Integer idx : inputTokenIndexes) {
            DBInputTextTokenInfo info = indexToTokenInfoMap.get(idx);
            AttributeSet attribute = indexToConsumeAttributeMap.get(idx);
            if (attribute == null)
                attribute = attributeNonConsumed;

            /** LT attribute override the other */
            if (lookaheadTokenIndexes.contains(idx))
View Full Code Here

        StyleConstants.setBold(blockAttr, true);
    }

    @Override
    public AttributeSet getAttributeForToken(ATEToken token) {
        AttributeSet attr = super.getAttributeForToken(token);
        switch(token.type) {
            case GrammarSyntaxLexer.TOKEN_DECL:
            case GrammarSyntaxLexer.TOKEN_REFERENCE:
                if(((ElementToken)token).lexer)
                    attr = lexerRefAttr;
View Full Code Here

TOP

Related Classes of javax.swing.text.AttributeSet$FontAttribute

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.