Package javax.swing.text

Examples of javax.swing.text.Style


  }

  private class CancelButtonHandler implements ActionListener {

    public void actionPerformed(ActionEvent event) {
      Style style = AnnotationDisplayCustomizationFrame.this.styleMap
          .get(AnnotationDisplayCustomizationFrame.this.currentTypeName);
      if (style == null) {
        style = AnnotationDisplayCustomizationFrame.this.styleMap.get(CAS.TYPE_NAME_ANNOTATION);
      }
      // assert(style != null);
View Full Code Here


  public void init(String text, MarkupExtent[] extents) {
    this.textPane = new JTextPane();
    this.scrollPane = new JScrollPane(this.textPane);
    this.setContentPane(this.scrollPane);
    Document doc = this.textPane.getDocument();
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    Style level0 = this.textPane.addStyle("level0", def);
    Style level1 = this.textPane.addStyle("level1", level0);
    StyleConstants.setBackground(level1, Color.green);
    Style level2 = this.textPane.addStyle("level2", level0);
    StyleConstants.setBackground(level2, Color.yellow);
    Style level3 = this.textPane.addStyle("level3", level0);
    StyleConstants.setBackground(level3, Color.orange);
    Style[] styleArray = { level0, level1, level2, level3 };
    System.out.println("  Creating the text.");
    MarkupExtent e;
    int level;
View Full Code Here

      // // Annotation and extent span the same text.
      // ++ext.depth;
      // }

    }
    Style unmarkedStyle = StyleContext.getDefaultStyleContext()
            .getStyle(StyleContext.DEFAULT_STYLE);
    Style annotStyle = styleMap.get(CAS.TYPE_NAME_ANNOTATION);
    // Copy our internal extents to the public representation.
    final int size = list.size();
    AnnotationExtent[] extentArray = new AnnotationExtent[size];
    Style style;
    for (int i = 0; i < size; i++) {
      ext = list.get(i);
      switch (ext.depth) {
        case 0: {
          extentArray[i] = new AnnotationExtent(ext.start, ext.end, unmarkedStyle);
View Full Code Here

    public void testGetPropertyPrefix() {
        assertEquals("TextPane", ui.getPropertyPrefix());
    }

    public void testPropertyChange() throws BadLocationException {
        Style style = textPane.getStyle(StyleContext.DEFAULT_STYLE);
        //Font
        assertFalse(25 == ((Integer) style.getAttribute(StyleConstants.FontSize)).intValue());
        textPane.setFont(font);
        assertEquals(25, ((Integer) style.getAttribute(StyleConstants.FontSize)).intValue());
        assertEquals(font.getName(), style.getAttribute(StyleConstants.FontFamily));
        assertFalse(font.getFontName().equals(style.getAttribute(StyleConstants.FontFamily)));
        assertEquals(font.getName(), style.getAttribute(StyleConstants.FontFamily));
        // Foreground
        assertFalse(Color.BLUE.equals(style.getAttribute(StyleConstants.Foreground)));
        textPane.setForeground(Color.BLUE);
        assertEquals(Color.BLUE, style.getAttribute(StyleConstants.Foreground));
        // Document
        style.addAttribute(StyleConstants.Subscript, Boolean.TRUE);
        StyledDocument newDoc = new DefaultStyledDocument();
        Style newStyle = newDoc.getStyle(StyleContext.DEFAULT_STYLE);
        assertNull(newStyle.getAttribute(StyleConstants.FontSize));
        assertNull(newStyle.getAttribute(StyleConstants.FontFamily));
        newStyle.addAttribute(StyleConstants.FontFamily, "family2");
        newStyle.addAttribute(StyleConstants.FontSize, new Integer(10));
        newStyle.addAttribute(StyleConstants.Italic, Boolean.FALSE);
        newStyle.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
        newStyle.addAttribute(StyleConstants.Subscript, Boolean.FALSE);
        newStyle.addAttribute(StyleConstants.Foreground, Color.RED);
        textPane.setDocument(newDoc);
        assertNotSame(style, newStyle);
        assertEquals(25, ((Integer) newStyle.getAttribute(StyleConstants.FontSize)).intValue());
        assertEquals(font.getName(), newStyle.getAttribute(StyleConstants.FontFamily));
        assertEquals(Boolean.TRUE, newStyle.getAttribute(StyleConstants.Italic));
        assertEquals(Boolean.TRUE, newStyle.getAttribute(StyleConstants.Bold));
        assertEquals(Boolean.TRUE, newStyle.getAttribute(StyleConstants.StrikeThrough));
        assertEquals(Boolean.FALSE, newStyle.getAttribute(StyleConstants.Subscript));
        assertEquals(Color.BLUE, newStyle.getAttribute(StyleConstants.Foreground));
    }
View Full Code Here

        assertEquals(Boolean.FALSE, newStyle.getAttribute(StyleConstants.Subscript));
        assertEquals(Color.BLUE, newStyle.getAttribute(StyleConstants.Foreground));
    }

    public void testProPertyChange_FontFamilyName() {
        Style style = textPane.getStyle(StyleContext.DEFAULT_STYLE);
        textPane.setFont(font);
        assertFalse(font.getFamily().equals(style.getAttribute(StyleConstants.FontFamily)));
        assertEquals(font.getName(), style.getAttribute(StyleConstants.FontFamily));
        StyledDocument newDoc = new DefaultStyledDocument();
        Style newStyle = newDoc.getStyle(StyleContext.DEFAULT_STYLE);
        textPane.setDocument(newDoc);
        assertFalse(font.getFamily().equals(newStyle.getAttribute(StyleConstants.FontFamily)));
        assertEquals(font.getName(), newStyle.getAttribute(StyleConstants.FontFamily));
    }
View Full Code Here

        MutableAttributeSet italicStyle = new SimpleAttributeSet();
        StyleConstants.setItalic(italicStyle, true);
        MutableAttributeSet colorStyle = new SimpleAttributeSet();
        StyleConstants.setForeground(colorStyle, Color.GREEN);

        Style style = doc.addStyle("myStyle", null);
        StyleConstants.setBackground(style, Color.RED);
        style = doc.addStyle("myStylea", null);
        StyleConstants.setForeground(style, Color.GREEN);

        doc.insertString(0, "bold text ", boldStyle);
View Full Code Here

            }
        });
    }

    public void testGetStyle() {
        Style style;
        style = textPane.getStyle(StyleContext.DEFAULT_STYLE);
        assertEquals(StyleContext.DEFAULT_STYLE, style.getName());
        assertSame(textPane.getStyledDocument().getStyle(StyleContext.DEFAULT_STYLE), textPane
                .getStyle(StyleContext.DEFAULT_STYLE));
        textPane.addStyle("child", style);
        style = textPane.getStyle("child");
        assertEquals("child", style.getName());
        assertEquals(StyleContext.DEFAULT_STYLE, ((Style) style.getResolveParent()).getName());
        assertSame(textPane.getStyledDocument().getStyle("child"), textPane.getStyle("child"));
    }
View Full Code Here

        assertEquals(StyleContext.DEFAULT_STYLE, ((Style) style.getResolveParent()).getName());
        assertSame(textPane.getStyledDocument().getStyle("child"), textPane.getStyle("child"));
    }

    public void testAddStyle() {
        Style parent = textPane.addStyle("parent", null);
        Style child = textPane.addStyle("child", parent);
        assertEquals(1, parent.getAttributeCount());
        assertNull(parent.getResolveParent());
        assertEquals(2, child.getAttributeCount());
        assertNotNull(child.getResolveParent());
        parent.addAttribute(StyleConstants.Bold, Boolean.FALSE);
        child.addAttribute(StyleConstants.Bold, Boolean.TRUE);
        assertFalse(((Boolean) parent.getAttribute(StyleConstants.Bold)).booleanValue());
        assertTrue(((Boolean) child.getAttribute(StyleConstants.Bold)).booleanValue());
        // Add styles with diff parameters
        Style parent1 = textPane.addStyle("p1", null);
        Style parent2 = textPane.addStyle("p2", null);
        Object[] styles = { null, null, "one", null, null, parent1, "two", parent2 };
        for (int i = 0; i < styles.length; i += 2) {
            Style style = textPane.addStyle((String) styles[i], (Style) styles[i + 1]);
            assertEquals("Iteration: " + i, (String) styles[i], style.getName());
            assertSame("Iteration: " + i, styles[i + 1], style.getResolveParent());
        }
        // unnamed style
        Style anotherChild = textPane.addStyle(null, parent);
        assertEquals(1, anotherChild.getAttributeCount());
        assertNotNull(anotherChild.getResolveParent());
        //not unique name of the style
        Style anotherStyle;
        anotherStyle = textPane.addStyle("child", null);
        assertNotSame(child, anotherStyle);
        assertNotNull(anotherStyle);
        anotherStyle = textPane.addStyle("child", parent);
        assertNotSame(child, anotherStyle);
View Full Code Here

        assertNotSame(child, anotherStyle);
        assertNotNull(anotherStyle);
    }

    public void testRemoveStyle() {
        Style parent = textPane.addStyle("parent", null);
        Style child = textPane.addStyle("child", parent);
        textPane.removeStyle("parent");
        assertNull(textPane.getStyle("parent"));
        assertEquals(2, child.getAttributeCount());
        assertNotNull(child.getResolveParent());
        assertNull(child.getAttribute("resolver"));
    }
View Full Code Here

        assertNull(child.getAttribute("resolver"));
    }

    public void testGetLogicalStyle() throws BadLocationException {
        textPane.getStyledDocument().insertString(11, "bold", attrs);
        Style style = textPane.addStyle("bold", textPane.getStyle(StyleContext.DEFAULT_STYLE));
        textPane.setCaretPosition(1);
        style.addAttribute(StyleConstants.Bold, Boolean.TRUE);
        textPane.setLogicalStyle(style);
        style = textPane.getLogicalStyle();
        textPane.setCaretPosition(3);
        assertSame(style, textPane.getLogicalStyle());
        assertTrue(((Boolean) style.getAttribute(StyleConstants.Bold)).booleanValue());
        attrs = new SimpleAttributeSet();
        StyleConstants.setBold(attrs, true);
        textPane.setParagraphAttributes(attrs, true);
        assertNull(textPane.getLogicalStyle());
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.Style

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.