Example usage for javax.swing.text StyleConstants isBold

List of usage examples for javax.swing.text StyleConstants isBold

Introduction

In this page you can find the example usage for javax.swing.text StyleConstants isBold.

Prototype

public static boolean isBold(AttributeSet a) 

Source Link

Document

Checks whether the bold attribute is set.

Usage

From source file:plugin.notes.gui.NotesView.java

/**
 *  Updates Editing buttons based on the location of the cursor
 *
 *@param  textPane  text pane to update buttons base on
 *@param  pos       current text position
 *//*ww w .  j a va2  s  .com*/
private void updateButtons(JTextPane textPane, int pos) {
    StyledDocument doc = textPane.getStyledDocument();
    AttributeSet set = doc.getCharacterElement(pos - 1).getAttributes();
    AttributeSet set1 = doc.getCharacterElement(pos).getAttributes();

    if (StyleConstants.isBold(set) && StyleConstants.isBold(set1)) {
        highlightButton(boldButton);
    } else {
        stdButton(boldButton);
    }

    if (StyleConstants.isItalic(set) && StyleConstants.isItalic(set1)) {
        highlightButton(italicButton);
    } else {
        stdButton(italicButton);
    }

    if (StyleConstants.isUnderline(set) && StyleConstants.isUnderline(set1)) {
        highlightButton(underlineButton);
    } else {
        stdButton(underlineButton);
    }

    int align = StyleConstants.getAlignment(set);
    stdButton(leftJustifyButton);
    stdButton(rightJustifyButton);
    stdButton(centerJustifyButton);

    if (align == StyleConstants.ALIGN_LEFT) {
        highlightButton(leftJustifyButton);
    } else if (align == StyleConstants.ALIGN_RIGHT) {
        highlightButton(rightJustifyButton);
    } else if (align == StyleConstants.ALIGN_CENTER) {
        highlightButton(centerJustifyButton);
    }

    int fontSize = StyleConstants.getFontSize(set);

    for (int i = 0; i < sizeCB.getItemCount(); i++) {
        String value = (String) sizeCB.getItemAt(i);

        if (value.equals(Integer.toString(fontSize))) {
            sizeCB.setSelectedItem(value);

            break;
        }
    }
}