Package javax.swing.text

Examples of javax.swing.text.StyleContext


      // seems only to work when the text panel is editable
      {


        StyleContext sc = StyleContext.getDefaultStyleContext();
        AttributeSet attr_set = sc.addAttribute(SimpleAttributeSet.EMPTY,
          StyleConstants.Foreground, color);

        int len = jTextPane1.getDocument().getLength();
        jTextPane1.setCaretPosition(len); // place cursor at the end (with no selection)
        jTextPane1.setCharacterAttributes(attr_set, false);
View Full Code Here


     * Tests constructor.
     * Non-mutable (<code>StyleContext.SmallAttributeSet</code>) is passed
     * as parameter.
     */
    public void testOptionSmallAttrSet() {
        AttributeContext context = new StyleContext();
        attrs = context.addAttribute(context.getEmptySet(), "key", "value");

        item = new Option(attrs);
        final AttributeSet itAttrs = item.getAttributes();
        assertFalse(itAttrs instanceof MutableAttributeSet);
        assertTrue(itAttrs instanceof StyleContext.SmallAttributeSet);
View Full Code Here

    });
  }
 
  AttributeSet scriptAttributeSet(boolean isStatus){
    if (!isStatus) return null;
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.DARK_GRAY);
    aset = sc.addAttribute(aset, StyleConstants.Bold, true);
    return aset;
  }
View Full Code Here

    }
  }
 
  AttributeSet attributeSet(boolean iserror){
    if (!iserror) return null;
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.red);
    aset = sc.addAttribute(aset, StyleConstants.Bold, true);
    return aset;
  }
View Full Code Here

    prefs1.store(out, "Color preferences for annotation viewer.");
  }

  private void loadColorPreferences(File file) throws IOException {
    Style parent = (Style) 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();
      value = prefs1.getProperty(typeName);
      style = sc.addStyle(typeName, parent);
      pos = value.indexOf('+');
      if (pos <= 0) {
        continue;
      }
      // Set foreground.
View Full Code Here

        _focus = focus;
    }

    protected void createStyles (JTextPane text)
    {
        StyleContext sctx = StyleContext.getDefaultStyleContext();
        Style defstyle = sctx.getStyle(StyleContext.DEFAULT_STYLE);

        _nameStyle = text.addStyle("name", defstyle);
        StyleConstants.setForeground(_nameStyle, Color.blue);

        _msgStyle = text.addStyle("msg", defstyle);
View Full Code Here

        super(doc);
        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

        /*
         * Creates a new instance of LexerNode
         */
        LexerNode(boolean isParent) {
            StyleContext sc = StyleContext.getDefaultStyleContext();
            defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
        }
View Full Code Here

        defaultStyle = document.getStyle("default"); //$NON-NLS-1$
    }
   
    @Override
    public void addColoredRegion(final Interval region, final Color color) {
        StyleContext context = StyleContext.getDefaultStyleContext();
        final AttributeSet a = context.addAttribute(defaultStyle, StyleConstants.Foreground, color);
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                document.setCharacterAttributes(region.startsAt(), region.length(), a, true);
View Full Code Here

  /**
   * Append coloring text to TextPane
   */
  private void appendToPane(JTextPane tp, String msg, Color c)
    {
        StyleContext sc = StyleContext.getDefaultStyleContext();
        AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

        aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
        aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

        int len = tp.getDocument().getLength();
        tp.setCaretPosition(len);
        tp.setCharacterAttributes(aset, false);
        tp.replaceSelection(msg);
View Full Code Here

TOP

Related Classes of javax.swing.text.StyleContext

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.