Package javax.swing.text

Examples of javax.swing.text.Style


        StyleConstants.setItalic(attrs, true);
        textPane.getStyledDocument().insertString(4, "italic\n", attrs);
        StyleConstants.setItalic(attrs, false);
        StyleConstants.setBold(attrs, true);
        // Add style
        Style style = textPane.addStyle("bold", textPane.getStyle(StyleContext.DEFAULT_STYLE));
        // Set style
        textPane.setCaretPosition(1);
        style.addAttribute(StyleConstants.Bold, Boolean.TRUE);
        assertFalse(StyleConstants.isBold(textPane.getParagraphAttributes()));
        textPane.setLogicalStyle(style);
        style = textPane.getLogicalStyle();
        textPane.setCaretPosition(3);
        assertSame(style, textPane.getLogicalStyle());
        assertTrue(((Boolean) style.getAttribute(StyleConstants.Bold)).booleanValue());
        assertTrue(StyleConstants.isBold(textPane.getParagraphAttributes()));
        assertTrue(StyleConstants.isBold(getCharacterAttributes(1)));
        // Set paragraph attributes
        attrs = new SimpleAttributeSet();
        StyleConstants.setBold(attrs, true);
        textPane.setParagraphAttributes(attrs, true);
        assertNull(textPane.getLogicalStyle());
        // Set another style
        textPane.getStyledDocument().setCharacterAttributes(1, 1, attrs, true);
        assertFalse(StyleConstants.isUnderline(textPane.getParagraphAttributes()));
        assertFalse(StyleConstants.isUnderline(getCharacterAttributes(1)));
        style = textPane.addStyle("underline", textPane.getStyle(StyleContext.DEFAULT_STYLE));
        style.addAttribute(StyleConstants.Underline, Boolean.TRUE);
        textPane.setLogicalStyle(style);
        assertNotNull(textPane.getLogicalStyle());
        assertEquals("underline", textPane.getLogicalStyle().getAttribute(
                StyleConstants.NameAttribute));
        assertTrue(StyleConstants.isUnderline(textPane.getParagraphAttributes()));
View Full Code Here


              } catch (NumberFormatException numberFormatException) {
                // no need to change the foreground color
              }
            }

            Style style = null;
            switch (responseLevel) {
            case 3:
              style = statsDoc.getStyle(STYLE_REDIRECT);
              break;
            case 4:
View Full Code Here

    stats.setBackground(getBackground());

    // Add styles to use for different types of status messages
    StyledDocument doc = (StyledDocument) stats.getDocument();

    Style style = doc.addStyle(STYLE_REDIRECT, null);
    StyleConstants.setForeground(style, REDIRECT_COLOR);

    style = doc.addStyle(STYLE_CLIENT_ERROR, null);
    StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);
View Full Code Here

                    } catch (NumberFormatException numberFormatException) {
                        // no need to change the foreground color
                    }
                }

                Style style = null;
                switch (responseLevel) {
                case 3:
                    style = statsDoc.getStyle(STYLE_REDIRECT);
                    break;
                case 4:
View Full Code Here

        stats.setBackground(backGround);

        // Add styles to use for different types of status messages
        StyledDocument doc = (StyledDocument) stats.getDocument();

        Style style = doc.addStyle(STYLE_REDIRECT, null);
        StyleConstants.setForeground(style, REDIRECT_COLOR);

        style = doc.addStyle(STYLE_CLIENT_ERROR, null);
        StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);
View Full Code Here

    } catch (IOException e) {
      handleException(e);
    }
    // Create menus after loading preferences to get code pages.
    this.setJMenuBar(createMenuBar());
    Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    defaultStyle = StyleContext.getDefaultStyleContext().addStyle("defaultAnnot", defaultStyle);
    StyleConstants.setBackground(defaultStyle, selectionColor);
    this.styleMap.put(CAS.TYPE_NAME_ANNOTATION, defaultStyle);
    this.textPopup = new JPopupMenu();
    this.fsTree.addFocusListener(new TreeFocusHandler(this.fsTree));
View Full Code Here

  public void saveColorPreferences(File file) throws IOException {
    Properties prefs1 = new Properties();
    Iterator<String> it = this.styleMap.keySet().iterator();
    String type;
    Style style;
    Color fg, bg;
    while (it.hasNext()) {
      type = it.next();
      style = this.styleMap.get(type);
      fg = StyleConstants.getForeground(style);
View Full Code Here

    FileOutputStream out = new FileOutputStream(file);
    prefs1.store(out, "Color preferences for annotation viewer.");
  }

  public void loadColorPreferences(File file) throws IOException {
    Style parent = this.styleMap.get(CAS.TYPE_NAME_ANNOTATION);
    StyleContext sc = StyleContext.getDefaultStyleContext();
    Properties prefs1 = new Properties();
    FileInputStream in = new FileInputStream(file);
    prefs1.load(in);
    String typeName, value;
    Style style;
    Color color;
    int pos;
    Iterator<?> it = prefs1.keySet().iterator();
    while (it.hasNext()) {
      typeName = (String) it.next();
View Full Code Here

        init();
    }

    private void init() {
        StyleContext styleContext = StyleContext.getDefaultStyleContext();
        Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);

        Style comment = styleContext.addStyle(COMMENT, defaultStyle);
        StyleConstants.setForeground(comment, COMMENT_COLOR);
        StyleConstants.setItalic(comment, true);

        Style quotes = styleContext.addStyle(QUOTES, defaultStyle);
        StyleConstants.setForeground(quotes, Color.MAGENTA.darker().darker());

        Style charQuotes = styleContext.addStyle(SINGLE_QUOTES, defaultStyle);
        StyleConstants.setForeground(charQuotes, Color.GREEN.darker().darker());

        Style slashyQuotes = styleContext.addStyle(SLASHY_QUOTES, defaultStyle);
        StyleConstants.setForeground(slashyQuotes, Color.ORANGE.darker());

        Style digit = styleContext.addStyle(DIGIT, defaultStyle);
        StyleConstants.setForeground(digit, Color.RED.darker());

        Style operation = styleContext.addStyle(OPERATION, defaultStyle);
        StyleConstants.setBold(operation, true);

        Style ident = styleContext.addStyle(IDENT, defaultStyle);

        Style reservedWords = styleContext.addStyle(RESERVED_WORD, defaultStyle);
        StyleConstants.setBold(reservedWords, true);
        StyleConstants.setForeground(reservedWords, Color.BLUE.darker().darker());

        Style leftParens = styleContext.addStyle(IDENT, defaultStyle);

        getRootNode().putStyle(SLASH_STAR_COMMENT, comment);
        getRootNode().putStyle(SLASH_SLASH_COMMENT, comment);
        getRootNode().putStyle(QUOTES, quotes);
        getRootNode().putStyle(SINGLE_QUOTES, charQuotes);
View Full Code Here

                lastBuffer = buffer;
            }
           
            // the start and end indices of a match in the Matcher looking
            int matchEnd = offset;
            Style style = null;
            while (matchEnd < checkPoint && matcher.find(offset)) {
                // when we get something other than -1, we know which regexp
                // matched; the 0 group is the complete expression of the
                // matcher, which would always return a hit based on the above
                // while condition
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.