Package javax.swing.text

Examples of javax.swing.text.AttributeSet


        StyleConstants.setStrikeThrough(attrs, true);
        StyleConstants.setAlignment(attrs, StyleConstants.ALIGN_CENTER);
        textPane.getStyledDocument().setParagraphAttributes(paragraph.getStartOffset(),
                paragraph.getEndOffset() - paragraph.getStartOffset(), attrs, true);
        // tests
        AttributeSet textAttrs;
        textPane.setCaretPosition(1);
        textAttrs = textPane.getParagraphAttributes();
        assertFalse(StyleConstants.isUnderline(textAttrs));
        assertTrue(StyleConstants.isStrikeThrough(textAttrs));
        assertEquals(StyleConstants.ALIGN_CENTER, StyleConstants.getAlignment(textAttrs));
View Full Code Here


        assertEquals(StyleConstants.ALIGN_CENTER, StyleConstants.getAlignment(textAttrs));
    }

    public void testSetParagraphAttributes() {
        StyledDocument doc = textPane.getStyledDocument();
        AttributeSet textAttrs;
        // The attributes are applied to the paragraph at the current caret
        // position.
        textPane.setCaretPosition(1);
        StyleConstants.setSubscript(attrs, false);
        doc.setParagraphAttributes(0, doc.getLength(), attrs, false);
View Full Code Here

            }
        });
    }

    public void testGetCharacterAttributes() {
        AttributeSet textAttrs;
        textPane.setCaretPosition(1);
        textAttrs = textPane.getCharacterAttributes();
        assertTrue(StyleConstants.isUnderline(textAttrs));
        assertEquals(StyleConstants.ALIGN_CENTER, StyleConstants.getAlignment(textAttrs));
        assertTrue(StyleConstants.isStrikeThrough(textAttrs));
View Full Code Here

                .getInputAttributes();
        assertSame(textPane.getInputAttributes(), inpAttr);
    }

    public void testInsertComponent() {
        AttributeSet attributes;
        textPane.setCaretPosition(1);
        attrs = textPane.getInputAttributes();
        assertAttributes(attrs, false, false, true, false, false, true);
        textPane.insertComponent(new JButton("Format C:\\>"));
        assertAttributes(attrs, false, false, false, false, false, false);
View Full Code Here

            }
        });
        assertAttributes(attrs, false, false, false, false, false, false);
        Element iconElement = textPane.getStyledDocument().getDefaultRootElement()
                .getElement(0).getElement(1);
        AttributeSet attributes = iconElement.getAttributes();
        assertNotNull(attributes.getAttribute(StyleConstants.IconAttribute));
        assertAttributes(attributes, false, false, false, false, false, false);
    }
View Full Code Here

        assertNotNull(attributes.getAttribute(StyleConstants.IconAttribute));
        assertAttributes(attributes, false, false, false, false, false, false);
    }

    public void testReplaceSelection() throws BadLocationException {
        AttributeSet textAttrs;
        // There is replacement and selection
        textPane.select(6, 22);
        textAttrs = getCharacterAttributes(6);
        assertTrue(StyleConstants.isUnderline(getCharacterAttributes(5)));
        assertFalse(StyleConstants.isUnderline(getCharacterAttributes(6)));
View Full Code Here

                    final int len = pi.read(buf);
                    if (len == -1) {
                        break;
                    }
                    Document doc = textArea.getDocument();
                    AttributeSet attset = styleContext.getStyle(type);
                    String snippet = new String(buf, 0, len);
                    doc.insertString(doc.getLength(),
                                     snippet, attset);
                    printStream.print(snippet);
                    textArea.setCaretPosition(textArea.getDocument().
View Full Code Here

        putValue(SHORT_DESCRIPTION, desc);
        putValue(MNEMONIC_KEY, mnemonic);
    }
   
    public void actionPerformed(ActionEvent e) {
    AttributeSet attr = new SimpleAttributeSet();
    FontDialog fontD = new FontDialog(frame, I18N.getText("drawing","Choose_font"), attr);
    fontD.setModal(true);
    fontD.setVisible(true);

    attr = fontD.getAttributes();
    String family = StyleConstants.getFontFamily(attr);
    if (family != null) {
      board.setFontFamily(family);
    }
    int size = StyleConstants.getFontSize(attr);
    if (size > 0) {
      board.setFontSize(size);
    }

    int fontStyle = Font.PLAIN;
    String value;
    if (attr.isDefined(CSS.Attribute.FONT_STYLE)) {
      value = attr.getAttribute(CSS.Attribute.FONT_STYLE).toString();
      if (value.equalsIgnoreCase(StyleConstants.Italic.toString())) {
        fontStyle = Font.ITALIC;
      }
    }
    if (attr.isDefined(CSS.Attribute.FONT_WEIGHT)) {
      value = attr.getAttribute(CSS.Attribute.FONT_WEIGHT).toString();
      if (value.equalsIgnoreCase(StyleConstants.Bold.toString())) {
        if (fontStyle == Font.ITALIC) {
          fontStyle = Font.ITALIC|Font.BOLD;
        } else {
          fontStyle = Font.BOLD;
View Full Code Here

  /************************Methods to convert wordlist to xml*************************/
 
  private void parseElement(StringBuffer xhtml,int start, int end,boolean openStyle)
  {//msn transport needs lettertype + color in 1 style to work
    if(start>=end)return;
    AttributeSet set = ((Word)wordList.get(start)).getAttributes();
    int newEnd =0;
    if(set==null);//remove empty set
    else if (set.isDefined(StyleConstants.FontFamily))
    { 
      String insert ="font-family: " + StyleConstants.getFontFamily(set);
      newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.FontFamily);
//      xhtml.append("<span style=\"");
//    xhtml.append();
//    Object value = set.getAttribute(StyleConstants.FontFamily);
//    newEnd = getStyleEnd(StyleConstants.FontFamily,value,start,end);
//    parseElement(xhtml, start, newEnd,true);
//    xhtml.append("</span>");
     
     
      openStyle=false;
    }
    else if (set.isDefined(StyleConstants.FontSize))
    { 
      String insert =" font-size: " + StyleConstants.getFontSize(set) + "pt";
      newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.FontSize);
      openStyle=false;
    }
    else if (set.isDefined(StyleConstants.Foreground))
    {
      String hex = colorToHexString((Color)set.getAttribute(StyleConstants.Foreground));
      String insert =" color: #" + hex;
      newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.Foreground);
      openStyle=false;
     
//      Object value = set.getAttribute(StyleConstants.Foreground);
//      if(!set.isDefined(StyleConstants.Foreground+value.toString()))
//      { 
//        newEnd = getStyleEnd(StyleConstants.Foreground,value,start,end);
//        if(openStyle)
//        {
//           if(newEnd<end)xhtml.append("\"><span style=\"");
//          else xhtml.append(';');
//        }
//        else if(!openStyle) xhtml.append("<span style=\"");
//        String hex = colorToHexString((Color)value);
//        xhtml.append(" color: #" + hex);
//        if(newEnd != 0)
//        {
//          parseElement(xhtml, start, newEnd,true);
//        }
//        if(!openStyle)xhtml.append("</span>");
//        openStyle=false;
//      }
    }
    else if (set.isDefined(StyleConstants.Background))
    {
      String hex = colorToHexString((Color)set.getAttribute(StyleConstants.Background));
      String insert =" background-color: #" + hex;
      newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.Background);
      openStyle=false;
           
//      Object value = set.getAttribute(StyleConstants.Background);
//      if(!set.isDefined(StyleConstants.Background+value.toString()))
//      { 
//        xhtml.append("<span style=\"");
//        String hex = colorToHexString((Color)value);
//        xhtml.append("background: #" + hex);
//        newEnd = getStyleEnd(StyleConstants.Background,value,start,end);
//        if(newEnd != 0)
//        {
//          parseElement(xhtml, start, newEnd,true);
//        }
//        xhtml.append("</span>");
//      }
    }
    else if (set.isDefined(StyleConstants.StrikeThrough))
    { 
      String insert =" text-decoration: line-through";
      newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.StrikeThrough);
      openStyle=false;
     
//      Object value = set.getAttribute(StyleConstants.StrikeThrough);
//      if(!set.isDefined(StyleConstants.StrikeThrough+value.toString()))
//      { 
//        xhtml.append("<span style=\"");
//        xhtml.append("text-decoration: line-through");
//        newEnd = getStyleEnd(StyleConstants.StrikeThrough,value,start,end);
//        if(newEnd != 0)
//        {
//          parseElement(xhtml, start, newEnd,true);
//        }
//        xhtml.append("</span>");
//      }
    }
    else if (set.containsAttribute(StyleConstants.Underline,Boolean.TRUE))
    {
      String insert =" text-decoration: underline";
      newEnd = addStyle(xhtml, start, end, openStyle, set,insert,StyleConstants.Underline);
      openStyle=false;
     
//      Object value = set.getAttribute(StyleConstants.Underline);
//      xhtml.append("<span style=\"");
//      xhtml.append("text-decoration: underline");
//      newEnd = getStyleEnd(StyleConstants.Underline,value,start,end);
//      parseElement(xhtml, start, newEnd,true);
//      xhtml.append("</span>");
     
    }
    else if (StyleConstants.isBold(set))
    {
      if(openStyle)xhtml.append("; margin:0 \">");
      openStyle=false;
      xhtml.append("<strong>");
      Object value = set.getAttribute(StyleConstants.Bold);
      newEnd = getStyleEnd(StyleConstants.Bold,value,start,end);
      parseElement(xhtml, start, newEnd,false);
      xhtml.append("</strong>");
    }
    else if (StyleConstants.isItalic(set))
    {
      if(openStyle)xhtml.append("; margin:0 \">");
      openStyle=false;
      xhtml.append("<em>");
      Object value = set.getAttribute(StyleConstants.Italic);
      newEnd = getStyleEnd(StyleConstants.Italic,value,start,end);
      parseElement(xhtml, start, newEnd,false);
      xhtml.append("</em>");

    }
View Full Code Here

        add(Box.createVerticalGlue(), c);
  }

  public void savePreferences()
  {
    AttributeSet set = fontPanel.getAttributes();
    Color c;
    if (set.isDefined(StyleConstants.Foreground))
    {
      c = (Color) set.getAttribute(StyleConstants.Foreground);
      Preferences.putInteger("xhtml", "foreground", c.getRGB());
    }
    if (set.isDefined(StyleConstants.Background))
    {
      c = (Color) set.getAttribute(StyleConstants.Background);
      Preferences.putInteger("xhtml", "background", c.getRGB());
    }
    if (set.isDefined(StyleConstants.FontFamily))
    {
      Preferences.putString("xhtml", "font-family", StyleConstants.getFontFamily(set));
    }
    if (set.isDefined(StyleConstants.FontSize))
    {
      Preferences.putInteger("xhtml", "font-size", StyleConstants.getFontSize(set));
    }
    Preferences.putBoolean("xhtml","bold",StyleConstants.isBold(set));
    Preferences.putBoolean("xhtml","italic",StyleConstants.isItalic(set));
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.