Example usage for javax.swing JTextPane getLogicalStyle

List of usage examples for javax.swing JTextPane getLogicalStyle

Introduction

In this page you can find the example usage for javax.swing JTextPane getLogicalStyle.

Prototype

public Style getLogicalStyle() 

Source Link

Document

Fetches the logical style assigned to the paragraph represented by the current position of the caret, or null.

Usage

From source file:Main.java

public static void main(String[] argv) {
    JTextPane textPane = new JTextPane();

    List list = new ArrayList();

    TabStop[] tstops = (TabStop[]) list.toArray(new TabStop[0]);
    TabSet tabs = new TabSet(tstops);

    Style style = textPane.getLogicalStyle();
    StyleConstants.setTabSet(style, tabs);
    textPane.setLogicalStyle(style);/*w  w w.j  a v  a 2  s .c om*/
}

From source file:org.colombbus.tangara.EditorFrame.java

/**
 * This method changes the standard size of a TAB for a given JTextPane.
 *
 * @param the/*from   w  w w.j  a va 2 s  .com*/
 *            JTextPane where to apply this method.
 */
public void setTabSizeOf(JTextPane textPane) {
    int spacesPerTab = tabSize;
    FontMetrics fm = textPane.getFontMetrics(textPane.getFont());
    int charWidth = fm.charWidth(' ');
    int tabWidth = charWidth * spacesPerTab;

    TabStop[] tabStops = new TabStop[200];

    for (int j = 0; j < tabStops.length; j++) {
        int tab = j + 1;
        tabStops[j] = new TabStop(tab * tabWidth);
    }

    TabSet tabSet = new TabSet(tabStops);

    Style style = textPane.getLogicalStyle();
    StyleConstants.setTabSet(style, tabSet);
    textPane.setLogicalStyle(style);
}

From source file:org.openmicroscopy.shoola.util.ui.MessengerDialog.java

/**
 * Builds the UI component displaying the exception.
 * /*  w  ww. ja  v  a  2 s .  c om*/
 * @return See above.
 */
private JTextPane buildExceptionArea() {
    JTextPane pane = UIUtilities.buildExceptionArea();
    StyledDocument document = pane.getStyledDocument();
    Style style = pane.getLogicalStyle();
    //Get the full debug text
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    exception.printStackTrace(pw);
    try {
        document.insertString(document.getLength(), sw.toString(), style);
    } catch (BadLocationException e) {
    }

    return pane;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/** Builds the UI component displaying the exception.*/
public static JTextPane buildExceptionArea() {
    StyleContext context = new StyleContext();
    StyledDocument document = new DefaultStyledDocument(context);

    JTextPane textPane = new JTextPane(document);
    textPane.setOpaque(false);// ww  w  . j  a v  a 2s .  c  o  m
    textPane.setEditable(false);

    // Create one of each type of tab stop
    List<TabStop> list = new ArrayList<TabStop>();

    // Create a left-aligned tab stop at 100 pixels from the left margin
    float pos = 15;
    int align = TabStop.ALIGN_LEFT;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);

    // Create a right-aligned tab stop at 200 pixels from the left margin
    pos = 15;
    align = TabStop.ALIGN_RIGHT;
    leader = TabStop.LEAD_NONE;
    tstop = new TabStop(pos, align, leader);
    list.add(tstop);

    // Create a center-aligned tab stop at 300 pixels from the left margin
    pos = 15;
    align = TabStop.ALIGN_CENTER;
    leader = TabStop.LEAD_NONE;
    tstop = new TabStop(pos, align, leader);
    list.add(tstop);

    // Create a decimal-aligned tab stop at 400 pixels from the left margin
    pos = 15;
    align = TabStop.ALIGN_DECIMAL;
    leader = TabStop.LEAD_NONE;
    tstop = new TabStop(pos, align, leader);
    list.add(tstop);

    // Create a tab set from the tab stops
    TabSet tabs = new TabSet(list.toArray(new TabStop[0]));

    // Add the tab set to the logical style;
    // the logical style is inherited by all paragraphs
    Style style = textPane.getLogicalStyle();
    StyleConstants.setTabSet(style, tabs);
    textPane.setLogicalStyle(style);
    Style debugStyle = document.addStyle("StyleName", null);
    StyleConstants.setForeground(debugStyle, Color.BLACK);
    StyleConstants.setFontFamily(debugStyle, "SansSerif");
    StyleConstants.setFontSize(debugStyle, 12);
    StyleConstants.setBold(debugStyle, false);
    return textPane;
}