Example usage for javax.swing.text StyleConstants getAlignment

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

Introduction

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

Prototype

public static int getAlignment(AttributeSet a) 

Source Link

Document

Gets the alignment setting.

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
 */// w ww  . j  a v  a 2s. c om
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;
        }
    }
}