Package javax.swing.text

Examples of javax.swing.text.StyleContext$NamedStyle


   */
  public static final Font getDefaultFont() {

    // Use StyleContext to get a composite font for better Asian language
    // support; see Sun bug S282887.
    StyleContext sc = StyleContext.getDefaultStyleContext();
    Font font = null;

    if (isOSX()) {
      // Snow Leopard (1.6) uses Menlo as default monospaced font,
      // pre-Snow Leopard used Monaco.
      font = sc.getFont("Menlo", Font.PLAIN, 12);
      if (!"Menlo".equals(font.getFamily())) {
        font = sc.getFont("Monaco", Font.PLAIN, 12);
        if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen
          font = sc.getFont("Monospaced", Font.PLAIN, 13);
        }
      }
    }
    else {
      // Consolas added in Vista, used by VS2010+.
      font = sc.getFont("Consolas", Font.PLAIN, 13);
      if (!"Consolas".equals(font.getFamily())) {
        font = sc.getFont("Monospaced", Font.PLAIN, 13);
      }
    }

    //System.out.println(font.getFamily() + ", " + font.getName());
    return font;
View Full Code Here


      Style style = styles[i];
      if (style!=null && style.font!=null) {
        if (style.font.getFamily().equals(old.getFamily()) &&
            style.font.getSize()==old.getSize()) {
          int s = style.font.getStyle(); // Keep bold or italic
          StyleContext sc = StyleContext.getDefaultStyleContext();
          style.font= sc.getFont(font.getFamily(), s, font.getSize());
        }
      }
    }
  }
View Full Code Here

            tokenCount + ", found " + tokens.length);
        }

        // Use StyleContext to create fonts to get composite fonts for
        // Asian glyphs.
        StyleContext sc = StyleContext.getDefaultStyleContext();

        // Loop through each token style.  Format:
        // "index,(fg|-),(bg|-),(t|f),((font,style,size)|(-,,))"
        for (int i=0; i<tokenTypeCount; i++) {

          int pos = i*7 + 1;
          int integer = Integer.parseInt(tokens[pos]); // == i
          if (integer!=i)
            throw new Exception("Expected " + i + ", found " +
                      integer);

          Color fg = null; String temp = tokens[pos+1];
          if (!"-".equals(temp)) { // "-" => keep fg as null
            fg = stringToColor(temp);
          }
          Color bg = null; temp = tokens[pos+2];
          if (!"-".equals(temp)) { // "-" => keep bg as null
            bg = stringToColor(temp);
          }

          // Check for "true" or "false" since we don't want to
          // accidentally suck in an int representing the next
          // packed color, and any string != "true" means false.
          temp = tokens[pos+3];
          if (!"t".equals(temp) && !"f".equals(temp))
            throw new Exception("Expected 't' or 'f', found " + temp);
          boolean underline = "t".equals(temp);

          Font font = null;
          String family = tokens[pos+4];
          if (!"-".equals(family)) {
            font = sc.getFont(family,
              Integer.parseInt(tokens[pos+5])// style
              Integer.parseInt(tokens[pos+6]))// size
          }
          scheme.styles[i] = new Style(fg, bg, font, underline);

View Full Code Here

    Font commentFont = baseFont;
    Font keywordFont = baseFont;
    if (fontStyles) {
      // WORKAROUND for Sun JRE bug 6282887 (Asian font bug in 1.4/1.5)
      // That bug seems to be hidden now, see 6289072 instead.
      StyleContext sc = StyleContext.getDefaultStyleContext();
      Font boldFont = sc.getFont(baseFont.getFamily(), Font.BOLD,
          baseFont.getSize());
      Font italicFont = sc.getFont(baseFont.getFamily(), Font.ITALIC,
          baseFont.getSize());
      commentFont = italicFont;//baseFont.deriveFont(Font.ITALIC);
      keywordFont = boldFont;//baseFont.deriveFont(Font.BOLD);
    }
View Full Code Here

   * @param size The size of the font.
   * @return The font.
   */
  private static Font getFont(String family, int style, int size) {
    // Use StyleContext to get a composite font for Asian glyphs.
    StyleContext sc = StyleContext.getDefaultStyleContext();
    return sc.getFont(family, style, size);
  }
View Full Code Here

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

  public 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

        return linkNavigationPanel;
    }

    private Component createSearchPanel() {
        StyleContext styleContent = StyleContext.getDefaultStyleContext();

        AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
        highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
        highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
        highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);

        AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
        emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
        emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);

        searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
        searchPanel.hide();

        return searchPanel.getComponent();
View Full Code Here

  private void initStyles() {
    // Some are commented out because of inconsistencies with what
    // different platforms do with background and foreground colour.

    myStyleContext = new StyleContext();
    rootStyle = myStyleContext.addStyle("root", null);
    StyleConstants.setForeground(rootStyle, ca.nengo.ui.lib.Style.NengoStyle.COLOR_FOREGROUND);

    setChildrenBackground(ca.nengo.ui.lib.Style.NengoStyle.COLOR_BACKGROUND);
    setChildrenForeground(ca.nengo.ui.lib.Style.NengoStyle.COLOR_FOREGROUND);
View Full Code Here

public class ColorPane extends JTextPane {

  public void append(Color c, String s) { // better implementation--uses
                      // StyleContext
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
        StyleConstants.Foreground, c);

    int len = getDocument().getLength(); // same value as
                       // getText().length();
    setCaretPosition(len); // place caret at the end (with no selection)
View Full Code Here

TOP

Related Classes of javax.swing.text.StyleContext$NamedStyle

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.