Package javax.swing.text

Examples of javax.swing.text.Style


*/
public void format() {
    JTextPane textPane = (JTextPane)getComponent();

    Format format = field.getFormat();
    Style style = StyleContext.getDefaultStyleContext()
  .getStyle(StyleContext.DEFAULT_STYLE);

    // Save selection and select all text
    int selStart = textPane.getSelectionStart();
    int selEnd = textPane.getSelectionEnd();
View Full Code Here


    super(parent, name);
    textPane = new JTextPane();
    document = textPane.getDocument();
    scrollPane = new JScrollPane(textPane);

    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style black = textPane.addStyle("black", def);
    ColorConstants.setForeground(black, Color.black);

    Style white = textPane.addStyle("white", def);
    ColorConstants.setForeground(white, Color.white);

    Style gray = textPane.addStyle("gray", def);
    ColorConstants.setForeground(gray, Color.gray);

    Style blue = textPane.addStyle("blue", def);
    ColorConstants.setForeground(blue, Color.blue);

    Style cyan = textPane.addStyle("cyan", def);
    ColorConstants.setForeground(cyan, Color.cyan);

    Style yellow = textPane.addStyle("yellow", def);
    ColorConstants.setForeground(yellow, Color.yellow);

    Style green = textPane.addStyle("green", def);
    ColorConstants.setForeground(green, Color.green);

    Style darkGreen = textPane.addStyle("darkgreen", def);
    ColorConstants.setForeground(darkGreen, new Color(0, 100, 0));

    Style red = textPane.addStyle("red", def);
    ColorConstants.setForeground(red, Color.red);
  }
View Full Code Here

    });
  }

  public void addIcon(ImageIcon icon) throws GUIException {
    String name = "icon" + counter;
    Style style = textPane.addStyle(name, null);
    StyleConstants.setIcon(style, icon);
    addText(name, name);
    counter++;
  }
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

    }

    /** Change the text on the Editor Pane */
    public void changeText(String text) {

        Style def = StyleContext.getDefaultStyleContext().getStyle(
                StyleContext.DEFAULT_STYLE);

        // Default style for text
        Style regular = taArea0.addStyle("regular", def);
        StyleConstants.setFontSize(regular, 14);
        StyleConstants.setFontFamily(def, "SansSerif");

        // Bold style for "Did you know ???"
        Style s = taArea0.addStyle("bold", regular);
        StyleConstants.setFontSize(s, 18);
        StyleConstants.setItalic(s, true);

        String[] initString = {
                GanttLanguage.getInstance().getText("didYouKnow") + "\n\n", // bold
View Full Code Here

     *
     * @exception BadLocationException if the range is invalid
     */
    static int drawUnselectedText( View view, XMLScanner scanner, XMLContext context, Graphics g, int x, int y, int start, int end) throws BadLocationException {
        Document doc = view.getDocument();
        Style lastStyle = null;
        String lastToken = null;
        int mark = start;

        Color forceColor = null;
        if (view instanceof XMLView) {
            Color bgPaintColor = ((XMLView)view).getBgPaintColor();
            if (bgPaintColor != null) {
                if ( bgPaintColor.equals(XMLView.ERROR_COLOR) || bgPaintColor.equals(XMLView.DEBUG_STOP_COLOR) ) {
                    forceColor = Color.white;
                }
            }
        }

        while ( start < end) {
            updateScanner( scanner, doc, start);

            int p = Math.min( scanner.getEndOffset(), end);
            p = (p <= start) ? end : p;

            Style style = context.getStyle( scanner.token);

            // If the style changes, do paint...
            if ( style != lastStyle && lastStyle != null) {
                // color change, flush what we have
                g.setColor( forceColor != null ? forceColor : context.getForeground( lastStyle));
View Full Code Here

     *
     * @exception BadLocationException if the range is invalid
     */
    static int drawSelectedText( View view, XMLScanner scanner, XMLContext context, Graphics g, int x, int y, int start, int end) throws BadLocationException {
        Document doc = view.getDocument();
        Style lastStyle = null;
        String lastToken = null;
        int mark = start;

        g.setColor(Color.white);

        while ( start < end) {
            updateScanner( scanner, doc, start);

            int p = Math.min( scanner.getEndOffset(), end);
            p = (p <= start) ? end : p;

            Style style = context.getStyle( scanner.token);

            // If the style changes, do paint...
            if ( style != lastStyle && lastStyle != null) {
                // color change, flush what we have
                g.setFont( g.getFont().deriveFont( context.getFontStyle( lastStyle)));
View Full Code Here

     * @param token the token to set the font for.
     * @param style the font-style value for the token.
     */
    public void setFontStyle( String token, int style) {

        Style s = this.getStyle( token);

        StyleConstants.setItalic( s, (style & Font.ITALIC) > 0);
        StyleConstants.setBold( s, (style & Font.BOLD) > 0);
    }
View Full Code Here

     * @param token the token to set the foreground for.
     * @param color the foreground color value for the token.
     */
    public void setForeground( String token, Color color) {

        Style s = getStyle( token);
        StyleConstants.setForeground( s, color);
    }
View Full Code Here

     * @param token the style value for the token.
     * @return the foreground color value for the token.
     */
    public Color getForeground( String token) {
        if ( token != null) {
            Style s = (Style)styles.get( token);
           
            if ( s != null) {
                return super.getForeground( s);
            }
        }
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.